From 3fbf4b5df47b0dd8b3cde501e91b6d8803262c4c Mon Sep 17 00:00:00 2001 From: Valentin Boulanger Date: Sat, 18 Jan 2025 16:25:09 +0100 Subject: [PATCH 1/5] 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 -- 2.49.1 From 6941c06661760e2a210fc1f530c87cd6bfcf1f85 Mon Sep 17 00:00:00 2001 From: Valentin Boulanger Date: Sat, 25 Jan 2025 11:06:03 +0100 Subject: [PATCH 2/5] load peripheral settings in front --- .../src/components/Settings/DeviceCard.svelte | 3 +- .../Settings/InputsOutputsContent.svelte | 66 +++++++++++++++---- frontend/src/lang/en.json | 16 ++++- hardware/MIDIPeripheral.go | 14 +++- hardware/OS2LPeripheral.go | 14 +++- hardware/interfaces.go | 8 +-- peripherals.go | 12 ++++ 7 files changed, 107 insertions(+), 26 deletions(-) diff --git a/frontend/src/components/Settings/DeviceCard.svelte b/frontend/src/components/Settings/DeviceCard.svelte index 408fa2c..cd705f1 100644 --- a/frontend/src/components/Settings/DeviceCard.svelte +++ b/frontend/src/components/Settings/DeviceCard.svelte @@ -15,6 +15,7 @@ export let signalizable = false; export let signalized = false; export let disconnected = false; + export let selected = false; // Emit a delete event when the device is being removed const dispatch = createEventDispatcher(); @@ -36,7 +37,7 @@
-
+

{#if disconnected} {/if}{title}

{type} {location != '' ? "- " : ""}{location}
diff --git a/frontend/src/components/Settings/InputsOutputsContent.svelte b/frontend/src/components/Settings/InputsOutputsContent.svelte index 2b12d8e..d56dbab 100644 --- a/frontend/src/components/Settings/InputsOutputsContent.svelte +++ b/frontend/src/components/Settings/InputsOutputsContent.svelte @@ -1,10 +1,11 @@
-

Available peripherals

+

{$_("projectHardwareAvailableLabel")}

-

Detected

+

{$_("projectHardwareDetectedLabel")}

{#each Object.entries($peripherals) as [serialNumber, peripheral]} {#if peripheral.isDetected} addPeripheral(peripheral)} on:dblclick={() => { @@ -125,40 +144,59 @@ title={peripheral.Name} type={peripheral.ProtocolName} location={peripheral.Location ? peripheral.Location : ""} line1={"S/N: " + peripheral.SerialNumber} addable={!peripheral.isSaved}/> {/if} {/each} -

Others

+

{$_("projectHardwareOthersLabel")}

-

Project peripherals

+

{$_("projectHardwareSavedLabel")}

{#if savedPeripheralNumber > 0} {#each Object.entries($peripherals) as [serialNumber, peripheral]} {#if peripheral.isSaved} - removePeripheral(peripheral)} on:dblclick={() => removePeripheral(peripheral)} - disconnected={!peripheral.isDetected} title={peripheral.Name == "" ? "Please wait..." : peripheral.Name} type={peripheral.ProtocolName} location={peripheral.Location ? peripheral.Location : ""} line1={peripheral.SerialNumber ? "S/N: " + peripheral.SerialNumber : ""} removable signalizable/> + removePeripheral(peripheral)} on:dblclick={() => removePeripheral(peripheral)} on:click={() => selectPeripheral(peripheral)} + disconnected={!peripheral.isDetected} title={peripheral.Name == "" ? "Please wait..." : peripheral.Name} type={peripheral.ProtocolName} location={peripheral.Location ? peripheral.Location : ""} line1={peripheral.SerialNumber ? "S/N: " + peripheral.SerialNumber : ""} selected={serialNumber == selectedPeripheralSN} removable signalizable/> {/if} {/each} {:else} - No hardware saved for this project. + {$_("projectHardwareEmptyLabel")} {/if}
-

Peripheral settings

-
-

Select a peripheral to edit its settings

- +

{$_("projectHardwareSettingsLabel")} ({selectedPeripheralSN == null ? $_("projectHardwareNoSelection") : selectedPeripheralSN})

+
+ {#if Object.keys(selectedPeripheralSettings).length > 0} + {#each Object.entries(selectedPeripheralSettings) as [settingName, settingValue]} +
+ +
+ {/each} + {:else} +

Select a peripheral to edit its settings

+ {/if} + +