21-peripherals-settings #22

Merged
thinkode merged 5 commits from 21-peripherals-settings into develop 2025-01-25 17:43:46 +00:00
9 changed files with 70 additions and 18 deletions
Showing only changes of commit 9d00b99730 - Show all commits

4
app.go
View File

@@ -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: "",

View File

@@ -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"))
})
}
</script>
<div class="hardware">
@@ -183,11 +192,11 @@
{#if Object.keys(selectedPeripheralSettings).length > 0}
{#each Object.entries(selectedPeripheralSettings) as [settingName, settingValue]}
<div class="peripheralSetting">
<Input label={$t(settingName)} type="{typeof(settingValue)}" width='100%' value="{settingValue}"/>
<Input on:blur={(event) => validate(settingName, event.detail.target.value)} label={$t(settingName)} type="{typeof(settingValue)}" width='100%' value="{settingValue}"/>
</div>
{/each}
{:else}
<p><i>Select a peripheral to edit its settings</i></p>
<i>{$_("projectHardwareNoSettingLabel")}</i>
{/if}
<!-- <button on:click={ftdiConnect}>Connect FTDI 0</button>

View File

@@ -18,6 +18,7 @@
})
}
// Validate the project information
function validate(field, value){
$showInformation[field] = value
console.log($showInformation)

View File

@@ -42,6 +42,7 @@
"projectHardwareOthersLabel": "Others",
"projectHardwareEmptyLabel": "No hardware saved for this project",
"projectHardwareSettingsLabel": "Peripheral settings",
"projectHardwareNoSettingLabel": "No setting can be displayed",
"peripheralArrivalToast": "Peripheral inserted:",
"peripheralRemovalToast": "Peripheral removed:",
@@ -56,8 +57,9 @@
"projectOpenedToast": "The project was opened:",
"projectOpenErrorToast": "Unable to open the project",
"projectCreatedToast": "The project was created",
"peripheralSettingSaveErrorToast": "Unable to save the peripheral setting",
"os2lIpSetting": "IP Address",
"os2lPortSetting": "Port"
"os2lIpSetting": "OS2L server IP",
"os2lPortSetting": "OS2L server port"
}

View File

@@ -38,7 +38,6 @@ type FTDIPeripheral struct {
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,
@@ -172,6 +171,12 @@ func (p *FTDIPeripheral) Deactivate(ctx context.Context) error {
return fmt.Errorf("unable to deactivate: not connected")
}
// SetPeripheralSetting sets a specific setting for this peripheral
func (p *FTDIPeripheral) SetPeripheralSetting(settingName string, settingValue interface{}) error {
p.settings[settingName] = settingValue
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 {

View File

@@ -46,6 +46,12 @@ func (p *MIDIPeripheral) Deactivate(ctx context.Context) error {
return nil
}
// SetPeripheralSetting sets a specific setting for this peripheral
func (p *MIDIPeripheral) SetPeripheralSetting(settingName string, settingValue interface{}) error {
p.settings[settingName] = settingValue
return nil
}
// SetDeviceProperty - not implemented for this kind of peripheral
func (p *MIDIPeripheral) SetDeviceProperty(context.Context, uint32, uint32, byte) error {
return nil

View File

@@ -17,8 +17,8 @@ type OS2LPeripheral struct {
func NewOS2LPeripheral(name string, serialNumber string) *OS2LPeripheral {
log.Trace().Str("file", "OS2LPeripheral").Str("name", name).Str("s/n", serialNumber).Msg("OS2L peripheral created")
settings := make(map[string]interface{})
settings["ip"] = "192.168.1.1"
settings["port"] = 9995
settings["os2lIpSetting"] = "192.168.1.1"
settings["os2lPortSetting"] = 9995
return &OS2LPeripheral{
name: name,
serialNumber: serialNumber,
@@ -50,6 +50,12 @@ func (p *OS2LPeripheral) Deactivate(ctx context.Context) error {
return nil
}
// SetPeripheralSetting sets a specific setting for this peripheral
func (p *OS2LPeripheral) SetPeripheralSetting(settingName string, settingValue interface{}) error {
p.settings[settingName] = settingValue
return nil
}
// SetDeviceProperty - not implemented for this kind of peripheral
func (p *OS2LPeripheral) SetDeviceProperty(context.Context, uint32, uint32, byte) error {
return nil

View File

@@ -8,6 +8,7 @@ type Peripheral interface {
Disconnect(context.Context) error // Disconnect the peripheral
Activate(context.Context) error // Activate the peripheral
Deactivate(context.Context) error // Deactivate the peripheral
SetPeripheralSetting(string, interface{}) error // Set a peripheral setting
SetDeviceProperty(context.Context, uint32, uint32, byte) error // Update a device property
GetInfo() PeripheralInfo // Get the peripheral information

View File

@@ -9,7 +9,7 @@ import (
// AddPeripheral adds a peripheral to the project
func (a *App) AddPeripheral(protocolName string, peripheralID string) error {
// Get the device from its finder
// Get the peripheral from its finder
p, found := a.hardwareManager.GetPeripheral(protocolName, peripheralID)
if !found {
log.Error().Str("file", "peripheral").Str("protocolName", protocolName).Str("periphID", peripheralID).Msg("unable to found the specified peripheral")
@@ -25,7 +25,7 @@ func (a *App) AddPeripheral(protocolName string, peripheralID string) error {
// GetPeripheralSettings gets the peripheral settings
func (a *App) GetPeripheralSettings(protocolName, peripheralID string) (map[string]interface{}, error) {
// Get the device from its finder
// Get the peripheral from its finder
p, found := a.hardwareManager.GetPeripheral(protocolName, peripheralID)
if !found {
log.Error().Str("file", "peripheral").Str("protocolName", protocolName).Str("periphID", peripheralID).Msg("unable to found the specified peripheral")
@@ -35,6 +35,28 @@ func (a *App) GetPeripheralSettings(protocolName, peripheralID string) (map[stri
return p.GetSettings(), nil
}
// UpdatePeripheralSetting updates a specific setting of a peripheral
func (a *App) UpdatePeripheralSetting(protocolName, peripheralID, settingName string, settingValue interface{}) error {
// Get the peripheral from its finder
p, found := a.hardwareManager.GetPeripheral(protocolName, peripheralID)
if !found {
log.Error().Str("file", "peripheral").Str("protocolName", protocolName).Str("periphID", peripheralID).Msg("unable to found the specified peripheral")
return fmt.Errorf("unable to found the peripheral ID '%s'", peripheralID)
}
// Save the setting in the application
if a.projectInfo.PeripheralsInfo == nil {
a.projectInfo.PeripheralsInfo = make(map[string]hardware.PeripheralInfo)
}
if a.projectInfo.PeripheralsInfo[peripheralID].Settings == nil {
a.projectInfo.PeripheralsInfo[peripheralID] = hardware.PeripheralInfo{
Settings: make(map[string]interface{}),
}
}
a.projectInfo.PeripheralsInfo[peripheralID].Settings[settingName] = settingValue
// Apply changes in the peripheral
return p.SetPeripheralSetting(settingName, settingValue)
}
// RemovePeripheral adds a peripheral to the project
func (a *App) RemovePeripheral(protocolName string, peripheralID string) error {
// TODO: Disconnect the peripheral
@@ -46,7 +68,7 @@ func (a *App) RemovePeripheral(protocolName string, peripheralID string) error {
// AddOS2LPeripheral adds a new OS2L peripheral
func (a *App) AddOS2LPeripheral() (hardware.PeripheralInfo, error) {
// Get the OS2L driver
// Get the OS2L finder
os2lDriver, err := a.hardwareManager.GetFinder("OS2L")
if err != nil {
log.Err(err).Str("file", "peripheral").Msg("unable to found the OS2L driver")
@@ -54,7 +76,7 @@ func (a *App) AddOS2LPeripheral() (hardware.PeripheralInfo, error) {
}
log.Trace().Str("file", "peripheral").Msg("OS2L driver got")
// Create a new OS2L peripheral with this driver
// Create a new OS2L peripheral with this finder
os2lPeripheral, err := os2lDriver.CreatePeripheral(a.ctx)
if err != nil {
log.Err(err).Str("file", "peripheral").Msg("unable to create the OS2L peripheral")