diff --git a/layouts/layout.yaml b/layouts/layout.yaml index 8028855..ef3e745 100755 --- a/layouts/layout.yaml +++ b/layouts/layout.yaml @@ -1,29 +1,5 @@ Windows: 1: - 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: uiwindow: Dims: X0: 200 @@ -44,6 +20,54 @@ Windows: WinType: 0 PreviewValue: "4356" Title: TACHO + uidata: + WID: 1 + TelemetryField: RPM + 2: + 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: 2 - TelemetryField: "" + TelemetryField: Speed + 3: + uiwindow: + Dims: + X0: 390 + Y0: 45 + Width: 50 + Height: 71 + Decor: + BGColour: 4161 + FGColour: 65535 + TitleColour: 65535 + BorderColour: 63488 + TitleSize: 2 + TextSize: 6 + HasBorder: 1 + Padding: 0 + Opts: + ShowID: 0 + WinType: 0 + PreviewValue: R + Title: Box + uidata: + WID: 3 + TelemetryField: Gear diff --git a/main.go b/main.go index 3e1185f..2ae7b41 100644 --- a/main.go +++ b/main.go @@ -2,8 +2,12 @@ package main import ( "esdi/cmd" + "esdi/telemetry" "log/slog" + "net/http" "os" + + "github.com/arl/statsviz" ) func main() { @@ -18,6 +22,17 @@ func main() { }), ) + // Performance analysis + mux := http.NewServeMux() + statsviz.Register(mux) + + go func() { + http.ListenAndServe("localhost:8001", mux) + }() + + // Setting up some internal data structures + telemetry.Init() + // Launches the cobra package stuff cmd.Execute(logger) } diff --git a/telemetry/data.go b/telemetry/data.go index 84ccb8e..46f42f0 100644 --- a/telemetry/data.go +++ b/telemetry/data.go @@ -85,6 +85,8 @@ func (tf *TelemetryField) String() string { type FieldID uint16 +// We use FirstField to start the count on the fields the user can select +// the first three will be for internal use const ( FirstTimeStamp FieldID = iota PreviousTimeStamp @@ -121,6 +123,9 @@ func initFieldNamesMap() { func GetFieldID(name string) (FieldID, bool) { id, ok := fieldNameToID[name] + if ok { + id = id - FirstField + } return id, ok } diff --git a/tui/internal/controllers/layout.go b/tui/internal/controllers/layout.go index 0d5309d..b9348d2 100644 --- a/tui/internal/controllers/layout.go +++ b/tui/internal/controllers/layout.go @@ -3,6 +3,7 @@ package controllers import ( "esdi/cdashdisplay" helper "esdi/helpers" + "esdi/telemetry" "esdi/tui/internal/services" "esdi/tui/internal/views" "fmt" @@ -212,6 +213,16 @@ func (lc *LayoutController) createWindow() { // the buttons for that purpuse func (lc *LayoutController) updateFormView(win *cdashdisplay.DesktopUIWindow) error { // OnSuccess we update our form to be an existing window form + + lc.Messages <- fmt.Sprintf("Setting up window:\n%+v\n", win) + + telemFieldID, ok := telemetry.GetFieldID(win.UIData.TelemetryField) + if !ok { + telemFieldID = 1000 + } + + lc.Messages <- fmt.Sprintf("field id for: %s is %d\n", win.UIData.TelemetryField, telemFieldID) + err := lc.LayoutToolView.WindowCreatedSuccessfuly(win) if err != nil { return err diff --git a/tui/internal/views/layoutTool_forms.go b/tui/internal/views/layoutTool_forms.go index 74e5a1e..61f6824 100644 --- a/tui/internal/views/layoutTool_forms.go +++ b/tui/internal/views/layoutTool_forms.go @@ -51,7 +51,7 @@ func NewCDashDisplayWindowFormView() *CDashDisplayWindowFormView { view.TextSize.SetCurrentOption(0) view.TelemetryField = tview.NewDropDown().SetLabel("Telemetry Field") - for _, fieldName := range telemetry.FieldNames { + for _, fieldName := range telemetry.FieldNames[3:] { view.TelemetryField.AddOption(fieldName, blankDropdownOptionCallback) } view.TelemetryField.SetCurrentOption(0) @@ -66,7 +66,8 @@ func NewCDashDisplayWindowFormView() *CDashDisplayWindowFormView { AddFormItem(view.ShowID). AddFormItem(view.WinType). AddFormItem(view.TitleSize). - AddFormItem(view.TextSize) + AddFormItem(view.TextSize). + AddFormItem(view.TelemetryField) view.Form.SetBorder(true). SetTitle("New Window Form"). @@ -132,7 +133,7 @@ func (fv *WindowFormView) SetValues(win *cdashdisplay.DesktopUIWindow) { telemFieldID, ok := telemetry.GetFieldID(win.UIData.TelemetryField) if !ok { - telemFieldID = 0 + telemFieldID = 100 } fv.Form.TelemetryField.SetCurrentOption(int(telemFieldID)) }