generated from thinkode/modelRepository
improved log system
This commit is contained in:
@@ -3,10 +3,13 @@ package main
|
||||
import (
|
||||
"changeme/hardware"
|
||||
"fmt"
|
||||
|
||||
"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)
|
||||
}
|
||||
|
||||
@@ -15,10 +18,13 @@ func (a *App) AddPeripheral(protocolName string, peripheralID string) error {
|
||||
// Get the device from its finder
|
||||
p, found := a.hardwareManager.GetPeripheral(protocolName, peripheralID)
|
||||
if !found {
|
||||
return fmt.Errorf("Unable to localize the peripheral %s", peripheralID)
|
||||
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)
|
||||
}
|
||||
// Add the peripheral ID to the project
|
||||
a.projectInfo.PeripheralsInfo[peripheralID] = p.GetInfo()
|
||||
log.Info().Str("file", "peripheral").Str("protocolName", protocolName).Str("periphID", peripheralID).Msg("peripheral added to project")
|
||||
|
||||
// TODO: Connect the peripheral
|
||||
return nil
|
||||
}
|
||||
@@ -28,6 +34,7 @@ func (a *App) RemovePeripheral(protocolName string, peripheralID string) error {
|
||||
// TODO: Disconnect the peripheral
|
||||
// Remove the peripheral ID from the project
|
||||
delete(a.projectInfo.PeripheralsInfo, peripheralID)
|
||||
log.Info().Str("file", "peripheral").Str("protocolName", protocolName).Str("periphID", peripheralID).Msg("peripheral removed from project")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -36,14 +43,20 @@ func (a *App) AddOS2LPeripheral() (hardware.PeripheralInfo, error) {
|
||||
// Get the OS2L driver
|
||||
os2lDriver, err := a.hardwareManager.GetDriver("OS2L")
|
||||
if err != nil {
|
||||
log.Err(err).Str("file", "peripheral").Msg("unable to found the OS2L driver")
|
||||
return hardware.PeripheralInfo{}, err
|
||||
}
|
||||
log.Trace().Str("file", "peripheral").Msg("OS2L driver got")
|
||||
|
||||
// Create a new OS2L peripheral with this driver
|
||||
os2lPeripheral, err := os2lDriver.CreatePeripheral(a.ctx)
|
||||
if err != nil {
|
||||
return hardware.PeripheralInfo{}, nil
|
||||
log.Err(err).Str("file", "peripheral").Msg("unable to create the OS2L peripheral")
|
||||
return hardware.PeripheralInfo{}, err
|
||||
}
|
||||
|
||||
os2lInfo := os2lPeripheral.GetInfo()
|
||||
log.Info().Str("file", "peripheral").Str("s/n", os2lInfo.SerialNumber).Msg("OS2L peripheral created, adding to project")
|
||||
// Add this new peripheral to the project
|
||||
return os2lInfo, a.AddPeripheral(os2lDriver.GetName(), os2lInfo.SerialNumber)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user