generated from thinkode/modelRepository
peripheral setting save
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user