peripheral setting save

This commit is contained in:
2025-01-25 16:00:02 +01:00
parent 0114ed03bf
commit 9d00b99730
9 changed files with 70 additions and 18 deletions

View File

@@ -9,7 +9,7 @@ import (
// AddPeripheral adds a peripheral to the project
func (a *App) AddPeripheral(protocolName string, peripheralID string) error {
// Get the device from its finder
// Get the peripheral from its finder
p, found := a.hardwareManager.GetPeripheral(protocolName, peripheralID)
if !found {
log.Error().Str("file", "peripheral").Str("protocolName", protocolName).Str("periphID", peripheralID).Msg("unable to found the specified peripheral")
@@ -25,7 +25,7 @@ func (a *App) AddPeripheral(protocolName string, peripheralID string) error {
// GetPeripheralSettings gets the peripheral settings
func (a *App) GetPeripheralSettings(protocolName, peripheralID string) (map[string]interface{}, error) {
// Get the device from its finder
// Get the peripheral from its finder
p, found := a.hardwareManager.GetPeripheral(protocolName, peripheralID)
if !found {
log.Error().Str("file", "peripheral").Str("protocolName", protocolName).Str("periphID", peripheralID).Msg("unable to found the specified peripheral")
@@ -35,6 +35,28 @@ func (a *App) GetPeripheralSettings(protocolName, peripheralID string) (map[stri
return p.GetSettings(), nil
}
// UpdatePeripheralSetting updates a specific setting of a peripheral
func (a *App) UpdatePeripheralSetting(protocolName, peripheralID, settingName string, settingValue interface{}) error {
// Get the peripheral from its finder
p, found := a.hardwareManager.GetPeripheral(protocolName, peripheralID)
if !found {
log.Error().Str("file", "peripheral").Str("protocolName", protocolName).Str("periphID", peripheralID).Msg("unable to found the specified peripheral")
return fmt.Errorf("unable to found the peripheral ID '%s'", peripheralID)
}
// Save the setting in the application
if a.projectInfo.PeripheralsInfo == nil {
a.projectInfo.PeripheralsInfo = make(map[string]hardware.PeripheralInfo)
}
if a.projectInfo.PeripheralsInfo[peripheralID].Settings == nil {
a.projectInfo.PeripheralsInfo[peripheralID] = hardware.PeripheralInfo{
Settings: make(map[string]interface{}),
}
}
a.projectInfo.PeripheralsInfo[peripheralID].Settings[settingName] = settingValue
// Apply changes in the peripheral
return p.SetPeripheralSetting(settingName, settingValue)
}
// RemovePeripheral adds a peripheral to the project
func (a *App) RemovePeripheral(protocolName string, peripheralID string) error {
// TODO: Disconnect the peripheral
@@ -46,7 +68,7 @@ func (a *App) RemovePeripheral(protocolName string, peripheralID string) error {
// AddOS2LPeripheral adds a new OS2L peripheral
func (a *App) AddOS2LPeripheral() (hardware.PeripheralInfo, error) {
// Get the OS2L driver
// Get the OS2L finder
os2lDriver, err := a.hardwareManager.GetFinder("OS2L")
if err != nil {
log.Err(err).Str("file", "peripheral").Msg("unable to found the OS2L driver")
@@ -54,7 +76,7 @@ func (a *App) AddOS2LPeripheral() (hardware.PeripheralInfo, error) {
}
log.Trace().Str("file", "peripheral").Msg("OS2L driver got")
// Create a new OS2L peripheral with this driver
// Create a new OS2L peripheral with this finder
os2lPeripheral, err := os2lDriver.CreatePeripheral(a.ctx)
if err != nil {
log.Err(err).Str("file", "peripheral").Msg("unable to create the OS2L peripheral")