generated from thinkode/modelRepository
resolved disconnected hardware when it is detected
This commit is contained in:
@@ -38,26 +38,27 @@ func (f *OS2LFinder) RegisterPeripheral(ctx context.Context, peripheralData Peri
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to create the OS2L peripheral: %v", err)
|
||||
}
|
||||
// Connect this peripheral
|
||||
err = os2lPeripheral.Connect(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
f.registeredPeripherals[peripheralData.SerialNumber] = *os2lPeripheral
|
||||
log.Trace().Any("periph", &os2lPeripheral).Str("file", "OS2LFinder").Str("peripheralName", peripheralData.Name).Msg("OS2L peripheral has been created")
|
||||
// Send the change to the front
|
||||
// runtime.EventsEmit(ctx, string(PeripheralArrival), peripheralData)
|
||||
return peripheralData.SerialNumber, nil
|
||||
}
|
||||
|
||||
// UnregisterPeripheral unregisters an existing peripheral
|
||||
func (f *OS2LFinder) UnregisterPeripheral(ctx context.Context, peripheralID string) error {
|
||||
func (f *OS2LFinder) UnregisterPeripheral(peripheralID string) error {
|
||||
peripheral, registered := f.registeredPeripherals[peripheralID]
|
||||
if registered {
|
||||
err := peripheral.Disconnect(ctx)
|
||||
err := peripheral.Disconnect()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
delete(f.registeredPeripherals, peripheralID)
|
||||
// Send the change to the front
|
||||
// runtime.EventsEmit(ctx, string(PeripheralRemoval), peripheral.GetInfo())
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -71,10 +72,10 @@ func (f *OS2LFinder) GetPeripheralSettings(peripheralID string) (map[string]inte
|
||||
// Return the specified peripheral
|
||||
peripheral, found := f.registeredPeripherals[peripheralID]
|
||||
if !found {
|
||||
log.Error().Str("file", "OS2LFinder").Str("peripheralID", peripheralID).Msg("unable to get this peripheral from the FTDI finder")
|
||||
log.Error().Str("file", "OS2LFinder").Str("peripheralID", peripheralID).Msg("unable to get this peripheral from the OS2L finder")
|
||||
return nil, fmt.Errorf("unable to found the peripheral")
|
||||
}
|
||||
log.Debug().Str("file", "OS2LFinder").Str("peripheralID", peripheralID).Msg("peripheral found by the FTDI finder")
|
||||
log.Debug().Str("file", "OS2LFinder").Str("peripheralID", peripheralID).Msg("peripheral found by the OS2L finder")
|
||||
return peripheral.GetSettings(), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user