generated from thinkode/modelRepository
peripherals saving improvements
This commit is contained in:
22
app.go
22
app.go
@@ -43,6 +43,9 @@ func NewApp() *App {
|
||||
return &App{
|
||||
hardwareManager: hardwareManager,
|
||||
projectSave: "",
|
||||
projectInfo: ProjectInfo{
|
||||
PeripheralsInfo: make(map[string]hardware.PeripheralInfo),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,6 +121,7 @@ func (a *App) GetProjectInfo(projectFile string) (ProjectInfo, error) {
|
||||
log.Fatalf("Unable to read the project file: %v", err)
|
||||
return ProjectInfo{}, err
|
||||
}
|
||||
a.projectInfo = ProjectInfo{}
|
||||
err = yaml.Unmarshal(content, &a.projectInfo)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to get the project information: %v", err)
|
||||
@@ -167,7 +171,7 @@ func (a *App) AddPeripheral(protocolName string, peripheralID string) error {
|
||||
return fmt.Errorf("Unable to localize the peripheral %s", peripheralID)
|
||||
}
|
||||
// Add the peripheral ID to the project
|
||||
a.projectInfo.PeripheralsInfo = append(a.projectInfo.PeripheralsInfo, p.GetInfo())
|
||||
a.projectInfo.PeripheralsInfo[peripheralID] = p.GetInfo()
|
||||
// TODO: Connect the peripheral
|
||||
return nil
|
||||
}
|
||||
@@ -176,7 +180,7 @@ func (a *App) AddPeripheral(protocolName string, peripheralID string) error {
|
||||
func (a *App) RemovePeripheral(protocolName string, peripheralID string) error {
|
||||
// TODO: Disconnect the peripheral
|
||||
// Remove the peripheral ID from the project
|
||||
a.projectInfo.PeripheralsInfo = removePeripheralFromList(a.projectInfo.PeripheralsInfo, peripheralID)
|
||||
delete(a.projectInfo.PeripheralsInfo, peripheralID)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -220,18 +224,8 @@ type ProjectMetaData struct {
|
||||
|
||||
// ProjectInfo defines all the information for a lighting project
|
||||
type ProjectInfo struct {
|
||||
ShowInfo ShowInfo `yaml:"show"` // Show information
|
||||
PeripheralsInfo []hardware.PeripheralInfo `yaml:"peripherals"` // Peripherals information
|
||||
}
|
||||
|
||||
func removePeripheralFromList(slice []hardware.PeripheralInfo, idToRemove string) []hardware.PeripheralInfo {
|
||||
result := []hardware.PeripheralInfo{}
|
||||
for _, peripheral := range slice {
|
||||
if peripheral.SerialNumber != idToRemove {
|
||||
result = append(result, peripheral)
|
||||
}
|
||||
}
|
||||
return result
|
||||
ShowInfo ShowInfo `yaml:"show"` // Show information
|
||||
PeripheralsInfo map[string]hardware.PeripheralInfo `yaml:"peripherals"` // Peripherals information
|
||||
}
|
||||
|
||||
func formatString(input string) string {
|
||||
|
||||
Reference in New Issue
Block a user