fixed saved peripherals for a new project

This commit is contained in:
2024-12-29 21:22:53 +01:00
parent b69097e2a4
commit 556f24991e
12 changed files with 264 additions and 169 deletions

View File

@@ -7,12 +7,6 @@ import (
"github.com/rs/zerolog/log"
)
// GetPeripherals gets all the peripherals connected
func (a *App) GetPeripherals() error {
log.Debug().Str("file", "peripherals").Msg("getting peripherals...")
return a.hardwareManager.Scan(a.ctx)
}
// AddPeripheral adds a peripheral to the project
func (a *App) AddPeripheral(protocolName string, peripheralID string) error {
// Get the device from its finder
@@ -64,27 +58,66 @@ func (a *App) AddOS2LPeripheral() (hardware.PeripheralInfo, error) {
// FOR TESTING PURPOSE ONLY
func (a *App) ConnectFTDI() error {
// Create a new FTDI object
var err error
a.ftdi, err = hardware.NewFTDIPeripheral("FTDI TEST INTERFACE", "A50825I", 0)
// Connect the FTDI
driver, err := a.hardwareManager.GetDriver("FTDI")
if err != nil {
return err
}
return a.ftdi.Connect()
periph, found := driver.GetPeripheral("A50285BI")
if !found {
return fmt.Errorf("unable to find the peripheral s/n %s", "A50285BI")
}
return periph.Connect(a.ctx)
}
func (a *App) ActivateFTDI() error {
return a.ftdi.Activate()
// Connect the FTDI
driver, err := a.hardwareManager.GetDriver("FTDI")
if err != nil {
return err
}
periph, found := driver.GetPeripheral("A50285BI")
if !found {
return fmt.Errorf("unable to find the peripheral s/n %s", "A50285BI")
}
return periph.Activate(a.ctx)
}
func (a *App) SetDeviceFTDI(channelValue byte) error {
return a.ftdi.SetDeviceProperty(0, 0, channelValue)
// Connect the FTDI
driver, err := a.hardwareManager.GetDriver("FTDI")
if err != nil {
return err
}
periph, found := driver.GetPeripheral("A50285BI")
if !found {
return fmt.Errorf("unable to find the peripheral s/n %s", "A50285BI")
}
return periph.SetDeviceProperty(a.ctx, 0, 0, channelValue)
}
func (a *App) DeactivateFTDI() error {
return a.ftdi.Deactivate()
// Connect the FTDI
driver, err := a.hardwareManager.GetDriver("FTDI")
if err != nil {
return err
}
periph, found := driver.GetPeripheral("A50285BI")
if !found {
return fmt.Errorf("unable to find the peripheral s/n %s", "A50285BI")
}
return periph.Deactivate(a.ctx)
}
func (a *App) DisconnectFTDI() error {
return a.ftdi.Disconnect()
// Connect the FTDI
driver, err := a.hardwareManager.GetDriver("FTDI")
if err != nil {
return err
}
periph, found := driver.GetPeripheral("A50285BI")
if !found {
return fmt.Errorf("unable to find the peripheral s/n %s", "A50285BI")
}
return periph.Disconnect(a.ctx)
}