figuring a way of having a clean internal interface for the data and other stuff I reckon. I forgot

This commit is contained in:
2026-03-09 18:03:36 +00:00
parent ac76d482d0
commit ef8f4603d6
11 changed files with 196 additions and 126 deletions
+15 -13
View File
@@ -130,30 +130,32 @@ func NewCDashDisplay() (*CDashDisplay, error) {
func (d *CDashDisplay) SendCommand() {
}
func (d *CDashDisplay) CreateWindow(win UIWindow) (int16, error) {
bytes, err := helper.StructToBytes(win)
func (d *CDashDisplay) CreateWindow(win *DesktopUIWindow) (*DesktopUIWindow, error) {
bytes, err := helper.StructToBytes(win.UIWindow)
if err != nil {
return -1, err
return nil, err
}
// Send the command
var wID packets.NewWindowID
err = d.WT.SendCommand(newWindowCMDID, bytes, &wID)
if err != nil {
return -1, err
return nil, err
}
win.UIData.IDX = wID.ID
pLogger.Info(fmt.Sprintf("Recived ID message: %v", wID))
d.State.Layout.AddWindow(wID.ID, win)
d.State.Layout.AddWindow(win)
return wID.ID, nil
return win, nil
}
func (d *CDashDisplay) UpdateWindow(wID int16, win *UIWindow) error {
func (d *CDashDisplay) UpdateWindow(win *DesktopUIWindow) error {
data := UIWindowUpdatePacket{
WinID: wID,
Window: *win,
WinID: win.UIData.IDX,
Window: win.UIWindow,
}
bytes, err := helper.StructToBytes(data)
@@ -172,7 +174,7 @@ func (d *CDashDisplay) UpdateWindow(wID int16, win *UIWindow) error {
// I send the pointer here
// -> it should be the same pointer then right?
pLogger.Debug(fmt.Sprintf("PreUpdate ID: %p", win))
d.State.Layout.Windows[wID] = win
d.State.Layout.Windows[win.UIData.IDX] = win
pLogger.Debug(fmt.Sprintf("PostUpdate ID: %p", win))
// Yeah, same address as suspected
// I can't think about it right now. I'll think about that tomorrow
@@ -245,7 +247,7 @@ func (d *CDashDisplay) MoveWindow(wID int16, delta *helper.Vector) error {
Dims: newDimensions,
}
err := d.updateWindowDimensions(window, packet)
err := d.updateWindowDimensions(&window.UIWindow, packet)
if err != nil {
return err
}
@@ -283,7 +285,7 @@ func (d *CDashDisplay) ResizeWindow(wID int16, delta *helper.Vector) error {
Dims: newDimensions,
}
err := d.updateWindowDimensions(window, packet)
err := d.updateWindowDimensions(&window.UIWindow, packet)
if err != nil {
return err
}
@@ -325,7 +327,7 @@ func (d *CDashDisplay) LoadLayout(layoutName string) error {
}
for _, w := range layout.Windows {
_, err = d.CreateWindow(*w)
_, err = d.CreateWindow(w)
if err != nil {
// NOTE: Add a way to handle multiple errors ?
return err
+5 -5
View File
@@ -3,18 +3,18 @@ package cdashdisplay
import "fmt"
type LayoutTree struct {
Windows map[int16]*UIWindow `yaml:"Windows"`
Windows map[int16]*DesktopUIWindow `yaml:"Windows"`
}
func NewLayoutTree() *LayoutTree {
return &LayoutTree{
Windows: make(map[int16]*UIWindow),
Windows: make(map[int16]*DesktopUIWindow),
}
}
func (l *LayoutTree) AddWindow(idx int16, w UIWindow) {
pLogger.Debug(fmt.Sprintf("adding window '%d' - %v", idx, w))
l.Windows[idx] = &w
func (l *LayoutTree) AddWindow(w *DesktopUIWindow) {
pLogger.Debug(fmt.Sprintf("adding window '%d' - %v", w.UIData.IDX))
l.Windows[w.UIData.IDX] = w
pLogger.Debug(fmt.Sprintf("new map - %v", l.Windows))
}
+14
View File
@@ -45,7 +45,21 @@ type UIWindow struct {
Title FString32 `yaml:"Title"`
}
type DesktopUIWindow struct {
UIWindow
UIData DesktopUIData
}
type DesktopUIData struct {
IDX int16 `yaml:"WID"`
TelemetryField string `yaml:"TelemetryField"`
}
type UIWindowUpdatePacket struct {
WinID int16
Window UIWindow
}
// func getUIWindowDTO(w *DesktopWindowData) *UIWindow {
//
// }
+46 -58
View File
@@ -1,61 +1,49 @@
Windows:
1:
Dims:
X0: 252
Y0: 122
Width: 117
Height: 72
Decor:
BGColour: 4161
FGColour: 65535
TitleColour: 65535
BorderColour: 63488
TitleSize: 2
TextSize: 6
HasBorder: 1
Padding: 0
Opts:
ShowID: 0
WinType: 0
PreviewValue: "255"
Title: SPEEDO
uiwindow:
Dims:
X0: 50
Y0: 46
Width: 117
Height: 70
Decor:
BGColour: 4161
FGColour: 65535
TitleColour: 65535
BorderColour: 63488
TitleSize: 2
TextSize: 6
HasBorder: 1
Padding: 0
Opts:
ShowID: 0
WinType: 0
PreviewValue: "234"
Title: SPEEDO
uidata:
WID: 1
TelemetryField: ""
2:
Dims:
X0: 399
Y0: 120
Width: 155
Height: 70
Decor:
BGColour: 4161
FGColour: 65535
TitleColour: 65535
BorderColour: 63488
TitleSize: 2
TextSize: 6
HasBorder: 1
Padding: 0
Opts:
ShowID: 0
WinType: 0
PreviewValue: "7456"
Title: TACHO
3:
Dims:
X0: 340
Y0: 240
Width: 84
Height: 126
Decor:
BGColour: 4161
FGColour: 65535
TitleColour: 65535
BorderColour: 63488
TitleSize: 2
TextSize: 14
HasBorder: 1
Padding: 0
Opts:
ShowID: 0
WinType: 0
PreviewValue: "6"
Title: GEAR
uiwindow:
Dims:
X0: 200
Y0: 45
Width: 151
Height: 70
Decor:
BGColour: 4161
FGColour: 65535
TitleColour: 65535
BorderColour: 63488
TitleSize: 2
TextSize: 6
HasBorder: 1
Padding: 0
Opts:
ShowID: 0
WinType: 0
PreviewValue: "4356"
Title: TACHO
uidata:
WID: 2
TelemetryField: ""
+15
View File
@@ -94,6 +94,7 @@ const (
Gear
MaxFields
)
const FirstField = Speed
var FieldNames = [MaxFields]string{
Speed: "Speed",
@@ -109,6 +110,20 @@ func GetFieldName(id FieldID) string {
return FieldNames[id]
}
var fieldNameToID map[string]FieldID
func initFieldNamesMap() {
fieldNameToID = make(map[string]FieldID, MaxFields)
for id, name := range FieldNames {
fieldNameToID[name] = FieldID(id)
}
}
func GetFieldID(name string) (FieldID, bool) {
id, ok := fieldNameToID[name]
return id, ok
}
// NOTE: Replace values with a more appropriate custom field approach where
// every custom field only takes as many bytes as required
// NOTE: Add the timing fields here to count frames of data gathering and whatnot
+5
View File
@@ -0,0 +1,5 @@
package telemetry
func Init() {
initFieldNamesMap()
}
+39 -21
View File
@@ -103,7 +103,7 @@ func (lc *LayoutController) registerHooks() {
func (lc *LayoutController) parseWindowFormData(
form views.CDashDisplayWindowFormView,
) (*cdashdisplay.UIWindow, error) {
) (*cdashdisplay.DesktopUIWindow, error) {
xValue, err := strconv.ParseUint(form.X.GetText(), 10, 64)
if err != nil {
@@ -140,6 +140,11 @@ func (lc *LayoutController) parseWindowFormData(
return nil, err
}
telemFieldInputID, telemField := form.TelemetryField.GetCurrentOption()
if telemFieldInputID == -1 {
return nil, fmt.Errorf("no option selected for telemetry field")
}
showIDValue := cdashdisplay.ShowIDFalse
if form.ShowID.IsChecked() {
showIDValue = cdashdisplay.ShowIDTrue
@@ -149,7 +154,7 @@ func (lc *LayoutController) parseWindowFormData(
winDecor.TextSize = uint8(textSizeValue - 1)
winDecor.TitleSize = uint8(titleSizeValue - 1)
uiWindow := &cdashdisplay.UIWindow{
uiWindow := cdashdisplay.UIWindow{
Dims: cdashdisplay.UIDimensions{
X0: uint16(xValue),
Y0: uint16(yValue),
@@ -165,9 +170,20 @@ func (lc *LayoutController) parseWindowFormData(
Title: helper.B32(form.Title.GetText()),
}
return uiWindow, nil
uiData := cdashdisplay.DesktopUIData{
TelemetryField: telemField,
}
return &cdashdisplay.DesktopUIWindow{
UIWindow: uiWindow,
UIData: uiData,
}, nil
}
// createWindow is the function the callback for the "Create" button on the new window
// form
// - parses the contents of the new window form
// - sends that data to the correct device service
func (lc *LayoutController) createWindow() {
window, err := lc.parseWindowFormData(*lc.LayoutToolView.LayoutActions.CreateWindowView.Form)
if err != nil {
@@ -175,13 +191,16 @@ func (lc *LayoutController) createWindow() {
return
}
wID, err := lc.DevService.CreateWindow(window)
lc.Messages <- fmt.Sprintf("pre update w address: %p\n", window)
window, err = lc.DevService.CreateWindow(window)
if err != nil {
lc.Messages <- "failed to create window\n"
return
}
lc.Messages <- fmt.Sprintf("post update w address: %p\n", window)
lc.Messages <- fmt.Sprintf("%+v\n", window)
err = lc.updateFormView(wID, window)
err = lc.updateFormView(window)
if err != nil {
// NOTE: if we fail to append the window to the views we must delete it
// altogether given we won't be able to manipulate it any further
@@ -189,15 +208,19 @@ func (lc *LayoutController) createWindow() {
}
}
func (lc *LayoutController) updateFormView(idx int16, win *cdashdisplay.UIWindow) error {
// updateFormView updates the new window form to be an existing window form and we change
// the buttons for that purpuse
func (lc *LayoutController) updateFormView(win *cdashdisplay.DesktopUIWindow) error {
// OnSuccess we update our form to be an existing window form
err := lc.LayoutToolView.WindowCreatedSuccessfuly(idx, win)
err := lc.LayoutToolView.WindowCreatedSuccessfuly(win)
if err != nil {
return err
}
// Set the update window button behaviour
formView := lc.LayoutToolView.FormQuickAccess[idx]
formView := lc.LayoutToolView.FormQuickAccess[win.UIData.IDX]
lc.Messages <- fmt.Sprintf("QA FORM: %+v\n", lc.LayoutToolView.FormQuickAccess)
err = SetFormButtonCallback(formView.Form.Form, "Update", func() {
lc.Messages <- "pressed update form button\n"
window, err := lc.parseWindowFormData(*formView.Form)
@@ -207,16 +230,9 @@ func (lc *LayoutController) updateFormView(idx int16, win *cdashdisplay.UIWindow
}
lc.Messages <- fmt.Sprintf("window data in form: %v\n", window)
if err != nil {
lc.Messages <- "failed to parse form: " + err.Error() + "\n"
return
}
window.UIData.IDX = formView.WinID
lc.updateWindowAction(idx, win)
// lc.updateWindowAction(&models.UIWindow{
// IDX: win.IDX,
// Window: *window,
// })
lc.updateWindowAction(window)
})
if err != nil {
lc.Messages <- "failed to set callback for update button\n"
@@ -232,6 +248,8 @@ func (lc *LayoutController) updateFormView(idx int16, win *cdashdisplay.UIWindow
return ev
})
lc.App.SetFocus(formView.Form.Form)
return nil
}
@@ -272,8 +290,8 @@ func (lc *LayoutController) newWindowAction() {
lc.App.SetFocus(newWindowForm.Form.Form)
}
func (lc *LayoutController) updateWindowAction(idx int16, win *cdashdisplay.UIWindow) {
err := lc.DevService.UpdateWindow(idx, win)
func (lc *LayoutController) updateWindowAction(win *cdashdisplay.DesktopUIWindow) {
err := lc.DevService.UpdateWindow(win)
lc.Messages <- fmt.Sprintf("Window: %v\n", win)
@@ -284,8 +302,8 @@ func (lc *LayoutController) updateWindowAction(idx int16, win *cdashdisplay.UIWi
}
func (lc *LayoutController) displayLoadedLayouts() {
for idx, w := range lc.DevService.CDash.State.Layout.Windows {
err := lc.updateFormView(idx, w)
for _, w := range lc.DevService.CDash.State.Layout.Windows {
err := lc.updateFormView(w)
if err != nil {
lc.Messages <- "failed to add window to list"
}
+10 -6
View File
@@ -4,6 +4,7 @@ import (
"esdi/cdashdisplay"
helper "esdi/helpers"
"esdi/peripheral"
"fmt"
"log/slog"
)
@@ -43,13 +44,15 @@ func (cds *CDashService) FindDevice() {
cds.Messages <- "found cdashdisplay on: " + display.WT.Cfg.Name + "\n"
}
func (cds *CDashService) CreateWindow(win *cdashdisplay.UIWindow) (int16, error) {
wID, err := cds.CDash.CreateWindow(*win)
func (cds *CDashService) CreateWindow(
win *cdashdisplay.DesktopUIWindow,
) (*cdashdisplay.DesktopUIWindow, error) {
updatedWindow, err := cds.CDash.CreateWindow(win)
if err != nil {
return -1, err
return nil, err
}
return wID, nil
return updatedWindow, nil
}
func (cds *CDashService) LoadLayout(layoutPath string) error {
@@ -60,8 +63,9 @@ func (cds *CDashService) SaveLayout(layoutPath string) error {
return cds.CDash.SaveLayout(layoutPath)
}
func (cds *CDashService) UpdateWindow(idx int16, win *cdashdisplay.UIWindow) error {
return cds.CDash.UpdateWindow(idx, win)
func (cds *CDashService) UpdateWindow(win *cdashdisplay.DesktopUIWindow) error {
cds.Messages <- fmt.Sprintf("Updating a window:\n%+v\n", win)
return cds.CDash.UpdateWindow(win)
}
func (cds *CDashService) DeleteWindow(idx int16) error {
+1 -1
View File
@@ -74,7 +74,7 @@ type ResizeWindowEv struct {
type WindowCreatedEv struct {
ID int16
Win cdashdisplay.UIWindow
Win cdashdisplay.CDashWin
}
type WindowMovedEv struct {
+10 -8
View File
@@ -59,7 +59,7 @@ func NewLayoutTreeView() *LayoutTreeView {
return view
}
func (lt *LayoutTreeView) AddWindow(idx int16, win *cdashdisplay.UIWindow) error {
func (lt *LayoutTreeView) AddWindow(win *cdashdisplay.DesktopUIWindow) error {
root := lt.Tree.GetRoot()
if root == nil {
return fmt.Errorf("unable to get root of treeview")
@@ -67,8 +67,8 @@ func (lt *LayoutTreeView) AddWindow(idx int16, win *cdashdisplay.UIWindow) error
// Create this new node
newWindow := tview.NewTreeNode(
windowInfoPageTitle(idx, win.Title.String()),
).SetReference(idx)
windowInfoPageTitle(win.UIData.IDX, win.Title.String()),
).SetReference(win.UIData.IDX)
root.AddChild(newWindow)
@@ -126,14 +126,16 @@ func NewLayoutToolView() *LayoutToolView {
return view
}
func (ltv *LayoutToolView) WindowCreatedSuccessfuly(idx int16, win *cdashdisplay.UIWindow) error {
func (ltv *LayoutToolView) WindowCreatedSuccessfuly(
win *cdashdisplay.DesktopUIWindow,
) error {
updateWindowForm := NewWindowFormView(win)
// Update the pages ID
ltv.LayoutActions.Pages.RemovePage(LayoutToolNewWindowID)
AddAndShowPage(
ltv.LayoutActions.Pages,
windowInfoPageID(idx),
windowInfoPageID(win.UIData.IDX),
updateWindowForm.Form.Form,
)
@@ -141,10 +143,10 @@ func (ltv *LayoutToolView) WindowCreatedSuccessfuly(idx int16, win *cdashdisplay
ltv.LayoutActions.CreateWindowView = nil
// Add this form thing to the quick access map
ltv.FormQuickAccess[idx] = updateWindowForm
ltv.FormQuickAccess[win.UIData.IDX] = updateWindowForm
// Add it to the tree view
return ltv.LayoutTree.AddWindow(idx, win)
return ltv.LayoutTree.AddWindow(win)
}
func (ltv *LayoutToolView) ShowCreateWindowForm() {
@@ -178,7 +180,7 @@ func (ltv *LayoutToolView) DeleteWindowByNode(node *tview.TreeNode) {
// Did we delete everything ???
}
func (ltv *LayoutToolView) UpdateFormView(idx int16, win *cdashdisplay.UIWindow) {
func (ltv *LayoutToolView) UpdateFormView(idx int16, win *cdashdisplay.DesktopUIWindow) {
// Update the form view
ltv.FormQuickAccess[idx].SetValues(win)
+36 -14
View File
@@ -4,22 +4,24 @@ import (
"fmt"
"esdi/cdashdisplay"
"esdi/telemetry"
"github.com/rivo/tview"
)
type CDashDisplayWindowFormView struct {
Form *tview.Form
X *tview.InputField
Y *tview.InputField
Width *tview.InputField
Height *tview.InputField
Title *tview.InputField
PreviewValue *tview.InputField
ShowID *tview.Checkbox
WinType *tview.DropDown
TitleSize *tview.DropDown
TextSize *tview.DropDown
Form *tview.Form
X *tview.InputField
Y *tview.InputField
Width *tview.InputField
Height *tview.InputField
Title *tview.InputField
PreviewValue *tview.InputField
ShowID *tview.Checkbox
WinType *tview.DropDown
TitleSize *tview.DropDown
TextSize *tview.DropDown
TelemetryField *tview.DropDown
}
func NewCDashDisplayWindowFormView() *CDashDisplayWindowFormView {
@@ -35,6 +37,7 @@ func NewCDashDisplayWindowFormView() *CDashDisplayWindowFormView {
view.WinType = tview.NewDropDown().SetLabel("type").
SetOptions([]string{"string", "bar"}, func(s string, id int) {}).
SetCurrentOption(0)
view.TitleSize = tview.NewDropDown().SetLabel("Title Size").SetCurrentOption(0)
for k := range 20 {
view.TitleSize.AddOption(fmt.Sprintf("%d", k+1), blankDropdownOptionCallback)
@@ -47,6 +50,12 @@ func NewCDashDisplayWindowFormView() *CDashDisplayWindowFormView {
}
view.TextSize.SetCurrentOption(0)
view.TelemetryField = tview.NewDropDown().SetLabel("Telemetry Field")
for _, fieldName := range telemetry.FieldNames {
view.TelemetryField.AddOption(fieldName, blankDropdownOptionCallback)
}
view.TelemetryField.SetCurrentOption(0)
view.Form = tview.NewForm().
AddFormItem(view.X).
AddFormItem(view.Y).
@@ -87,13 +96,16 @@ func NewCreateWindowFormView() *CreateWindowFormView {
type WindowFormView struct {
Form *CDashDisplayWindowFormView
WinID int16
UpdateBtn *tview.Button
}
func NewWindowFormView(win *cdashdisplay.UIWindow) *WindowFormView {
func NewWindowFormView(win *cdashdisplay.DesktopUIWindow) *WindowFormView {
view := &WindowFormView{
Form: NewCDashDisplayWindowFormView(),
Form: NewCDashDisplayWindowFormView(),
WinID: win.UIData.IDX,
}
view.Form.Form.SetTitle(windowEditFormTitle(win.UIData.IDX, win.Title.String()))
view.UpdateBtn = tview.NewButton("Update")
// Need to inject the button functionality later
@@ -106,7 +118,7 @@ func NewWindowFormView(win *cdashdisplay.UIWindow) *WindowFormView {
return view
}
func (fv *WindowFormView) SetValues(win *cdashdisplay.UIWindow) {
func (fv *WindowFormView) SetValues(win *cdashdisplay.DesktopUIWindow) {
fv.Form.X.SetText(fmt.Sprintf("%d", win.Dims.X0))
fv.Form.Y.SetText(fmt.Sprintf("%d", win.Dims.Y0))
fv.Form.Width.SetText(fmt.Sprintf("%d", win.Dims.Width))
@@ -117,6 +129,12 @@ func (fv *WindowFormView) SetValues(win *cdashdisplay.UIWindow) {
fv.Form.WinType.SetCurrentOption(0) // NOTE: this needs to set the correct option
fv.Form.TitleSize.SetCurrentOption(int(win.Decor.TitleSize))
fv.Form.TextSize.SetCurrentOption(int(win.Decor.TextSize))
telemFieldID, ok := telemetry.GetFieldID(win.UIData.TelemetryField)
if !ok {
telemFieldID = 0
}
fv.Form.TelemetryField.SetCurrentOption(int(telemFieldID))
}
func windowInfoPageID(idx int16) string {
@@ -126,3 +144,7 @@ func windowInfoPageID(idx int16) string {
func windowInfoPageTitle(idx int16, title string) string {
return fmt.Sprintf("%s [%02d]", title, idx)
}
func windowEditFormTitle(idx int16, title string) string {
return fmt.Sprintf("[%2d] %s", idx, title)
}