apply settings for OS2L

This commit is contained in:
2025-11-13 16:00:50 +01:00
parent 18a3a716ef
commit c7d9f35080
6 changed files with 124 additions and 72 deletions

View File

@@ -60,7 +60,7 @@ func (f *OS2LFinder) RegisterPeripheral(ctx context.Context, peripheralData Peri
// Create a new OS2L peripheral
peripheral, err := NewOS2LPeripheral(peripheralData)
if err != nil {
return "", fmt.Errorf("unable to create the OS2L peripheral: %v", err)
return "", fmt.Errorf("unable to create the OS2L peripheral: %w", err)
}
// Set the event callback
peripheral.SetEventCallback(func(event any) {
@@ -79,21 +79,17 @@ func (f *OS2LFinder) RegisterPeripheral(ctx context.Context, peripheralData Peri
go func() {
defer f.wg.Done()
// Connect the OS2L peripheral
runtime.EventsEmit(ctx, string(PeripheralStatusUpdated), peripheralData, PeripheralStatusConnecting)
err = peripheral.Connect(ctx)
if err != nil {
runtime.EventsEmit(ctx, string(PeripheralStatusUpdated), peripheralData, PeripheralStatusDisconnected)
log.Err(err).Str("file", "OS2LFinder").Str("peripheralSN", peripheralData.SerialNumber).Msg("unable to connect the peripheral")
return
}
runtime.EventsEmit(ctx, string(PeripheralStatusUpdated), peripheralData, PeripheralStatusDeactivated)
// Peripheral connected, activate it
err = peripheral.Activate(ctx)
if err != nil {
log.Err(err).Str("file", "OS2LFinder").Str("peripheralSN", peripheralData.SerialNumber).Msg("unable to activate the OS2L peripheral")
return
}
runtime.EventsEmit(ctx, string(PeripheralStatusUpdated), peripheralData, PeripheralStatusActivated)
}()
// Emits the event in the hardware
@@ -114,14 +110,12 @@ func (f *OS2LFinder) UnregisterPeripheral(ctx context.Context, peripheralData Pe
log.Err(err).Str("sn", peripheralData.SerialNumber).Msg("unable to deactivate the peripheral")
return nil
}
runtime.EventsEmit(ctx, string(PeripheralStatusUpdated), peripheralData, PeripheralStatusDeactivated)
// Disconnecting peripheral
err = peripheral.Disconnect()
err = peripheral.Disconnect(ctx)
if err != nil {
log.Err(err).Str("sn", peripheralData.SerialNumber).Msg("unable to disconnect the peripheral")
return nil
}
runtime.EventsEmit(ctx, string(PeripheralStatusUpdated), peripheralData, PeripheralStatusDisconnected)
}
// The OS2L peripheral has gone
@@ -138,7 +132,7 @@ func (f *OS2LFinder) GetName() string {
}
// GetPeripheralSettings gets the peripheral settings
func (f *OS2LFinder) GetPeripheralSettings(peripheralID string) (map[string]interface{}, error) {
func (f *OS2LFinder) GetPeripheralSettings(peripheralID string) (map[string]any, error) {
// Return the specified peripheral
peripheral, found := f.saved[peripheralID]
if !found {
@@ -150,15 +144,16 @@ func (f *OS2LFinder) GetPeripheralSettings(peripheralID string) (map[string]inte
}
// SetPeripheralSettings sets the peripheral settings
func (f *OS2LFinder) SetPeripheralSettings(peripheralID string, settings map[string]interface{}) error {
func (f *OS2LFinder) SetPeripheralSettings(ctx context.Context, peripheralID string, settings map[string]any) error {
// Return the specified peripheral
peripheral, found := f.saved[peripheralID]
if !found {
log.Error().Str("file", "OS2LFinder").Str("peripheralID", peripheralID).Msg("unable to get this peripheral from the FTDI finder")
return fmt.Errorf("unable to found the peripheral")
}
log.Debug().Str("file", "OS2LFinder").Str("peripheralID", peripheralID).Msg("peripheral found by the FTDI finder")
return peripheral.SetSettings(settings)
// Set the peripheral settings
return peripheral.SetSettings(ctx, settings)
}
// Start starts the finder