21-peripherals-settings (#22)

Added the concept of peripheral settings.

Reviewed-on: #22
This commit was merged in pull request #22.
This commit is contained in:
2025-01-25 17:43:45 +00:00
parent 0e3f57f5fb
commit c7fe171cb4
10 changed files with 258 additions and 52 deletions

View File

@@ -21,30 +21,31 @@ const (
// FTDIPeripheral contains the data of an FTDI peripheral
type FTDIPeripheral struct {
name string // The name of the peripheral
serialNumber string // The S/N of the FTDI peripheral
location int // The location of the peripheral
universesNumber int // The number of DMX universes handled by this peripheral
programName string // The temp file name of the executable
dmxSender *exec.Cmd // The command to pilot the DMX sender program
stdin io.WriteCloser // For writing in the DMX sender
stdout io.ReadCloser // For reading from the DMX sender
stderr io.ReadCloser // For reading the errors
disconnectChan chan struct{} // Channel to cancel the connection
errorsChan chan error // Channel to get the errors
name string // The name of the peripheral
serialNumber string // The S/N of the FTDI peripheral
location int // The location of the peripheral
programName string // The temp file name of the executable
settings map[string]interface{} // The settings of the peripheral
dmxSender *exec.Cmd // The command to pilot the DMX sender program
stdin io.WriteCloser // For writing in the DMX sender
stdout io.ReadCloser // For reading from the DMX sender
stderr io.ReadCloser // For reading the errors
disconnectChan chan struct{} // Channel to cancel the connection
errorsChan chan error // Channel to get the errors
}
// NewFTDIPeripheral creates a new FTDI peripheral
func NewFTDIPeripheral(name string, serialNumber string, location int) (*FTDIPeripheral, error) {
log.Info().Str("file", "FTDIPeripheral").Str("name", name).Str("s/n", serialNumber).Int("location", location).Msg("FTDI peripheral created")
settings := make(map[string]interface{})
return &FTDIPeripheral{
name: name,
dmxSender: nil,
serialNumber: serialNumber,
location: location,
universesNumber: 1,
disconnectChan: make(chan struct{}),
errorsChan: make(chan error, 1),
name: name,
dmxSender: nil,
serialNumber: serialNumber,
location: location,
settings: settings,
disconnectChan: make(chan struct{}),
errorsChan: make(chan error, 1),
}, nil
}
@@ -170,6 +171,12 @@ func (p *FTDIPeripheral) Deactivate(ctx context.Context) error {
return fmt.Errorf("unable to deactivate: not connected")
}
// SetPeripheralSettings sets a specific setting for this peripheral
func (p *FTDIPeripheral) SetPeripheralSettings(settings map[string]interface{}) error {
p.settings = settings
return nil
}
// SetDeviceProperty sends a command to the specified device
func (p *FTDIPeripheral) SetDeviceProperty(ctx context.Context, uint32, channelNumber uint32, channelValue byte) error {
if p.dmxSender != nil {
@@ -186,6 +193,11 @@ func (p *FTDIPeripheral) SetDeviceProperty(ctx context.Context, uint32, channelN
return fmt.Errorf("unable to set device property: not connected")
}
// GetSettings gets the peripheral settings
func (p *FTDIPeripheral) GetSettings() map[string]interface{} {
return p.settings
}
// GetInfo gets all the peripheral information
func (p *FTDIPeripheral) GetInfo() PeripheralInfo {
return PeripheralInfo{