From 3fbf4b5df47b0dd8b3cde501e91b6d8803262c4c Mon Sep 17 00:00:00 2001 From: Valentin Boulanger Date: Sat, 18 Jan 2025 16:25:09 +0100 Subject: [PATCH] added the settings structure to the peripherals --- hardware/FTDIPeripheral.go | 43 ++++++++++++++++++++++---------------- hardware/interfaces.go | 3 ++- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/hardware/FTDIPeripheral.go b/hardware/FTDIPeripheral.go index aa91558..1e1a484 100644 --- a/hardware/FTDIPeripheral.go +++ b/hardware/FTDIPeripheral.go @@ -21,30 +21,32 @@ 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{}) + settings["universesNumber"] = uint64(1) 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 } @@ -186,6 +188,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{ diff --git a/hardware/interfaces.go b/hardware/interfaces.go index ff3cec1..4b7eccc 100644 --- a/hardware/interfaces.go +++ b/hardware/interfaces.go @@ -10,7 +10,8 @@ type Peripheral interface { Deactivate(context.Context) error // Deactivate the peripheral SetDeviceProperty(context.Context, uint32, uint32, byte) error // Update a device property - GetInfo() PeripheralInfo // Get the peripheral information + GetInfo() PeripheralInfo // Get the peripheral information + GetSettings() map[string]interface{} // Get the peripheral settings } // PeripheralInfo represents a peripheral information