From e07f7f42dea8f1430144fc619a9998106c085e57 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Sun, 8 Nov 2026 22:34:00 +0000 Subject: [PATCH] feat: putting device into user config mode when tool is opened --- constants/constants.go | 6 ++++++ devices/uidevice/device.go | 3 ++- peripheral/devices/devices.go | 7 +++++-- services/devices.go | 5 +++++ services/devices_lookup.go | 13 +++++++++++++ services/telemetry_events.go | 2 +- .../controllers/cdashdisplay_layout.go | 19 +++++++++++++++++++ tui/internal/controllers/device.go | 3 ++- 8 files changed, 53 insertions(+), 5 deletions(-) diff --git a/constants/constants.go b/constants/constants.go index 7eb152c..044e34c 100644 --- a/constants/constants.go +++ b/constants/constants.go @@ -1,5 +1,11 @@ package constants +// Peripheral Names +const ( + CDashDisplay = "CDashDisplay" + UIView = "UIView" +) + // Provider Names const ( IRacingProviderName = "iRacing" diff --git a/devices/uidevice/device.go b/devices/uidevice/device.go index c32032d..dcc493b 100644 --- a/devices/uidevice/device.go +++ b/devices/uidevice/device.go @@ -1,6 +1,7 @@ package uidevice import ( + "esdi/constants" "esdi/peripheral" "esdi/telemetry" ) @@ -9,7 +10,7 @@ type UIDevice struct { dataChan chan telemetry.TelemetryData } -const NAME = "UIView" +const NAME = constants.UIView func NewUIDevice() (peripheral.Peripheral, error) { return &UIDevice{ diff --git a/peripheral/devices/devices.go b/peripheral/devices/devices.go index bfe97fa..b2bf44b 100644 --- a/peripheral/devices/devices.go +++ b/peripheral/devices/devices.go @@ -1,13 +1,16 @@ // Package devices will define the available devices we can communicate with package devices -import "esdi/peripheral/types" +import ( + "esdi/constants" + "esdi/peripheral/types" +) // IDs for our devices. They need to be correctly mapped on the devices // themselves so we can discover them const ( CDashDisplayDevID = 0x01 - CDashDisplayDevName = "CDashDisplay" + CDashDisplayDevName = constants.CDashDisplay ESBtnBoxDevID = 0x02 ) diff --git a/services/devices.go b/services/devices.go index 875b6fb..ae829c1 100644 --- a/services/devices.go +++ b/services/devices.go @@ -107,6 +107,11 @@ func (ds *DeviceService) StopStream() { ds.streamCancel = nil } +func (ds *DeviceService) SetPeripheralUserConfigMode(pname string) error { + ds.PSS.setDeviceBeingConfiguredByUser(pname) + return nil +} + // SetTelemetryChannel sets the TelemCh to the passed channel func (ds *DeviceService) SetTelemetryChannel(ch <-chan telemetry.TelemetryData) { ds.TelemCh = ch diff --git a/services/devices_lookup.go b/services/devices_lookup.go index b53da2e..701d885 100644 --- a/services/devices_lookup.go +++ b/services/devices_lookup.go @@ -30,6 +30,7 @@ const ( DeviceIsConnected DeviceIsUnconfigured DeviceIsConfiguring + DeviceBeingConfiguredByUser DeviceIsConfigured DeviceIsStreaming ) @@ -50,6 +51,8 @@ func DeviceStateToStr(state DeviceState) string { return "DeviceIsUnconfigured" case DeviceIsConfiguring: return "DeviceIsConfiguring" + case DeviceBeingConfiguredByUser: + return "DeviceBeingConfiguredByUser" case DeviceIsConfigured: return "DeviceIsConfigured" case DeviceIsStreaming: @@ -294,6 +297,14 @@ func (pss *PeripheralStateStore) setDeviceIsConfiguring(pname string) { pss.store[pname].State = DeviceIsConfiguring } +func (pss *PeripheralStateStore) setDeviceBeingConfiguredByUser(pname string) { + pss.Logger.Info("device is being configured by the user", "device", pname) + pss.mu.Lock() + defer pss.mu.Unlock() + + pss.store[pname].State = DeviceBeingConfiguredByUser +} + func (pss *PeripheralStateStore) setDeviceConfigured(pname string) { pss.Logger.Info("device is configured and ready for data", "device", pname) @@ -457,6 +468,8 @@ func (pss *PeripheralStateStore) HandleDeviceState() { case DeviceIsConfigured: // Nothing to do here pss.handleDeviceIsConfigured(pName) + case DeviceBeingConfiguredByUser: + // Nothing to do here, need to wait for the user to finish case DeviceIsStreaming: // case DeviceReconnected: diff --git a/services/telemetry_events.go b/services/telemetry_events.go index 8416f21..26f39f8 100644 --- a/services/telemetry_events.go +++ b/services/telemetry_events.go @@ -31,7 +31,7 @@ func (t *TelemetryService) onFindProvider(prov telem.TelemetryProvider) { ch := t.StartStream() t.startedStreaming(ch) - t.Messages <- "provider switch completed" + t.Messages <- "provider switch completed\n" } func (t *TelemetryService) onProviderStopsMidStream() { diff --git a/tui/internal/controllers/cdashdisplay_layout.go b/tui/internal/controllers/cdashdisplay_layout.go index a1a12b6..ac79731 100644 --- a/tui/internal/controllers/cdashdisplay_layout.go +++ b/tui/internal/controllers/cdashdisplay_layout.go @@ -5,6 +5,7 @@ import ( "os" "strconv" + "esdi/constants" "esdi/devices/cdashdisplay" "esdi/services" "esdi/tui/internal/views" @@ -585,3 +586,21 @@ func (lc *LayoutController) changeSelectedLoadout() { lc.LayoutToolView.ShowLayoutList() lc.App.SetFocus(lc.LayoutToolView.LayoutActions.LayoutSelection.Tree) } + +// ##### Event Listener +// OnLayoutToolOpen we need to change focus to the layout tool and move the +// device out of streaming mode or whatever. +// - start by making sure that device is able to be configured +func (lc *LayoutController) OnLayoutToolOpen() { + // Get the device from somewhere + cdash, err := lc.DevService.GetPeripheral(constants.CDashDisplay) + if err != nil { + lc.Messages <- "failed to acquire CDashDisplay " + err.Error() + "\n" + return + } + + lc.DevService.SetPeripheralUserConfigMode(cdash.Name()) + + // Change focus to the layout tree + lc.App.SetFocus(lc.LayoutToolView.LayoutTree.Tree) +} diff --git a/tui/internal/controllers/device.go b/tui/internal/controllers/device.go index 86f67c7..c4c896f 100644 --- a/tui/internal/controllers/device.go +++ b/tui/internal/controllers/device.go @@ -77,7 +77,8 @@ func (mc *DeviceController) AddDeviceAPIListItems() { "layout-tool", mc.LayoutCtrl.LayoutToolView.Flex, ) - mc.App.SetFocus(mc.LayoutCtrl.LayoutToolView.LayoutTree.Tree) + + mc.LayoutCtrl.OnLayoutToolOpen() }) mc.DeviceAPIView.DevAPIList. AddItem("stream", "stream data to the display", func() {