From 9d00b997306070912243e5fa0b58bfbb07fd132c Mon Sep 17 00:00:00 2001 From: Valentin Boulanger Date: Sat, 25 Jan 2025 16:00:02 +0100 Subject: [PATCH] peripheral setting save --- app.go | 4 +-- .../Settings/InputsOutputsContent.svelte | 23 +++++++++----- .../Settings/ProjectPropertiesContent.svelte | 1 + frontend/src/lang/en.json | 6 ++-- hardware/FTDIPeripheral.go | 7 ++++- hardware/MIDIPeripheral.go | 6 ++++ hardware/OS2LPeripheral.go | 10 +++++-- hardware/interfaces.go | 1 + peripherals.go | 30 ++++++++++++++++--- 9 files changed, 70 insertions(+), 18 deletions(-) diff --git a/app.go b/app.go index f55e03f..36d1024 100644 --- a/app.go +++ b/app.go @@ -28,9 +28,9 @@ type App struct { func NewApp() *App { // Create a new hadware manager hardwareManager := hardware.NewHardwareManager() - // hardwareManager.RegisterFinder(hardware.NewMIDIFinder(5 * time.Second)) + hardwareManager.RegisterFinder(hardware.NewMIDIFinder(5 * time.Second)) hardwareManager.RegisterFinder(hardware.NewFTDIFinder(5 * time.Second)) - // hardwareManager.RegisterFinder(hardware.NewOS2LFinder()) + hardwareManager.RegisterFinder(hardware.NewOS2LFinder()) return &App{ hardwareManager: hardwareManager, projectSave: "", diff --git a/frontend/src/components/Settings/InputsOutputsContent.svelte b/frontend/src/components/Settings/InputsOutputsContent.svelte index 6c5d8a4..1979784 100644 --- a/frontend/src/components/Settings/InputsOutputsContent.svelte +++ b/frontend/src/components/Settings/InputsOutputsContent.svelte @@ -5,7 +5,7 @@ import { t, _ } from 'svelte-i18n' import { generateToast, needProjectSave, peripherals } from "../../stores"; import { get } from "svelte/store" - import { GetPeripheralSettings, AddOS2LPeripheral, RemovePeripheral, ConnectFTDI, ActivateFTDI, DeactivateFTDI, DisconnectFTDI, SetDeviceFTDI, AddPeripheral } from "../../../wailsjs/go/main/App"; + import { UpdatePeripheralSetting, GetPeripheralSettings, AddOS2LPeripheral, RemovePeripheral, ConnectFTDI, ActivateFTDI, DeactivateFTDI, DisconnectFTDI, SetDeviceFTDI, AddPeripheral } from "../../../wailsjs/go/main/App"; import RoundedButton from "../General/RoundedButton.svelte"; function ftdiConnect(){ @@ -129,6 +129,7 @@ } } + // Unselect the peripheral if it is disconnect $: { Object.entries($peripherals).filter(([serialNumber, peripheral]) => { if (!peripheral.isDetected && peripheral.isSaved && selectedPeripheralSN == serialNumber) { @@ -137,12 +138,20 @@ } }); } - function unselectPeripheral(){ - selectedPeripheralSN = null - selectedPeripheralSettings = {} - } + // Get the number of saved peripherals $: savedPeripheralNumber = Object.values($peripherals).filter(peripheral => peripheral.isSaved).length; + + // Validate the peripheral settings + function validate(settingName, settingValue){ + console.log("Peripheral setting '" + settingName + "' set to '" + settingValue + "'") + let peripheralProtocolName = get(peripherals)[selectedPeripheralSN].ProtocolName + UpdatePeripheralSetting(peripheralProtocolName, selectedPeripheralSN, settingName, settingValue).then(()=> { + $needProjectSave = true + }).catch((error) => { + generateToast('error', 'bx-error', $_("peripheralSettingSaveErrorToast")) + }) + }
@@ -183,11 +192,11 @@ {#if Object.keys(selectedPeripheralSettings).length > 0} {#each Object.entries(selectedPeripheralSettings) as [settingName, settingValue]}
- + validate(settingName, event.detail.target.value)} label={$t(settingName)} type="{typeof(settingValue)}" width='100%' value="{settingValue}"/>
{/each} {:else} -

Select a peripheral to edit its settings

+ {$_("projectHardwareNoSettingLabel")} {/if}