we got the data reading going again

This commit is contained in:
2026-03-03 22:02:42 +00:00
parent 11dc255303
commit f8e65a03d2
5 changed files with 97 additions and 70 deletions
@@ -13,7 +13,7 @@ type DeviceController struct {
*Controller
DeviceAPIView *views.DeviceAPIView
LayoutCtrl *LayoutController
StreamStrl *StreamingCtrl
StreamCtrl *StreamingCtrl
DevService *serv.CDashService
}
@@ -22,7 +22,7 @@ func NewDeviceController(base *Controller, devService *serv.CDashService) *Devic
Controller: base,
LayoutCtrl: NewLayoutController(base, devService),
DevService: devService,
StreamStrl: NewStreamingCtrl(),
StreamCtrl: NewStreamingCtrl(base, devService),
}
// mc.Bus.On(ui.StartStreamingReqEv{}, func(e any) {
@@ -38,8 +38,7 @@ func NewDeviceController(base *Controller, devService *serv.CDashService) *Devic
func (mc *DeviceController) PrintToOutputWindow(msg string) {
mc.App.QueueUpdateDraw(func() {
fmt.Fprintf(mc.DeviceAPIView.OutputWindow.TextArea,
"%s", msg)
fmt.Fprintf(mc.DeviceAPIView.OutputWindow.TextArea, "%s", msg)
})
}
@@ -67,8 +66,8 @@ func (mc *DeviceController) setDeviceAPIViewEvents() {
}
func (mc *DeviceController) AddDeviceAPIListItems() {
mc.DeviceAPIView.DevAPIList.AddItem("layout", "build a layout for CDashDisplay",
func() {
mc.DeviceAPIView.DevAPIList.
AddItem("layout", "build a layout for CDashDisplay", func() {
// Get the api pages
views.AddAndShowPage(
mc.DeviceAPIView.DevAPIToolView.Pages,
@@ -77,6 +76,14 @@ func (mc *DeviceController) AddDeviceAPIListItems() {
)
mc.App.SetFocus(mc.LayoutCtrl.LayoutToolView.LayoutTree.Tree)
})
mc.DeviceAPIView.DevAPIList.
AddItem("stream", "stream data to the display", func() {
views.AddAndShowPage(mc.DeviceAPIView.DevAPIToolView.Pages,
"streaming-tool",
mc.StreamCtrl.StreamView.TextView,
)
mc.App.SetFocus(mc.StreamCtrl.StreamView.TextView)
})
}
func (mc *DeviceController) injectViewCallbacks() {
@@ -85,9 +92,12 @@ func (mc *DeviceController) injectViewCallbacks() {
func (mc *DeviceController) injectControllerCallbacks() {
// Tell the layout controller what to do on exit
mc.LayoutCtrl.OnExit = func() {
giveFocusToAPIList := func() {
mc.App.SetFocus(mc.DeviceAPIView.DevAPIList.List)
}
mc.LayoutCtrl.OnExit = giveFocusToAPIList
mc.StreamCtrl.OnExit = giveFocusToAPIList
}
func (mc *DeviceController) injectChannels() {
@@ -102,6 +112,12 @@ func (mc *DeviceController) injectChannels() {
mc.PrintToOutputWindow(msg)
}
}()
go func() {
for msg := range mc.StreamCtrl.Messages {
mc.PrintToOutputWindow(msg)
}
}()
}
func (mc *DeviceController) mainUI() error {
@@ -194,8 +194,6 @@ func (lc *LayoutController) createWindow() {
// altogether given we won't be able to manipulate it any further
lc.Messages <- "failed to append window to views " + err.Error()
}
lc.App.SetFocus(lc.LayoutToolView.LayoutTree.Tree)
}
func (lc *LayoutController) updateFormView(win *models.UIWindow) error {
@@ -289,9 +287,6 @@ func (lc *LayoutController) updateWindowAction(win *models.UIWindow) {
lc.Messages <- "failed to update window due to " + err.Error() + "\n"
return
}
// I guess it was a success, we must update the view
lc.LayoutToolView.UpdateFormView(win)
}
func (lc *LayoutController) displayLoadedLayouts() {
+57 -6
View File
@@ -2,6 +2,8 @@ package controllers
import (
esdi "esdi/oldEsdi"
"esdi/tui/internal/services"
"esdi/tui/internal/views"
"fmt"
"log"
"os"
@@ -10,6 +12,7 @@ import (
"time"
"github.com/ESilva15/goirsdk"
"github.com/gdamore/tcell/v2"
)
// Car data lengths
@@ -21,6 +24,8 @@ const (
)
type StreamingCtrl struct {
*Controller
Service *services.CDashService
LastMessageTime time.Time
Data *esdi.SimulationData
DataView *esdi.DataPacket
@@ -28,19 +33,57 @@ type StreamingCtrl struct {
LastTime time.Time
Mut sync.Mutex
Irsdk *goirsdk.IBT
StreamView *views.StreamView
Messages chan string
Internal chan string
Run bool
OnExit func()
isRunning bool
}
func NewStreamingCtrl() *StreamingCtrl {
return &StreamingCtrl{
func NewStreamingCtrl(base *Controller, ser *services.CDashService) *StreamingCtrl {
ctrl := &StreamingCtrl{
Controller: base,
Service: ser,
Data: &esdi.SimulationData{},
DataView: &esdi.DataPacket{},
InitialTime: time.Now(),
LastTime: time.Now(),
Messages: make(chan string, 10),
Internal: make(chan string, 10),
Run: false,
StreamView: views.NewStreamView(),
isRunning: false,
}
ctrl.registerHooks()
return ctrl
}
// func (sc *StreamingCtrl) Stop(bus *events.Bus) {
// }
func (sc *StreamingCtrl) registerHooks() {
sc.StreamView.TextView.SetInputCapture(func(ev *tcell.EventKey) *tcell.EventKey {
switch ev.Key() {
case tcell.KeyEsc:
sc.OnExit()
}
switch ev.Rune() {
case 's':
// Start
sc.Start()
case 'p':
// Pause
sc.Stop()
}
return ev
})
}
func (sc *StreamingCtrl) Stop() {
sc.Run = false
}
func (sc *StreamingCtrl) Start() {
// Open the telemetry file
@@ -58,6 +101,8 @@ func (sc *StreamingCtrl) Start() {
go sc.ReadData()
sc.Run = true
// global irsdk is now here
go func() {
ticker := time.NewTicker(time.Second / 60)
@@ -65,15 +110,21 @@ func (sc *StreamingCtrl) Start() {
counter := 0
for t := range ticker.C {
if !sc.Run {
break
}
// whatever
currentTime := time.Now()
delta := currentTime.Sub(startTime)
_ = sc.Stringified() + fmt.Sprintf("%v - %7d\n%5f - %5f",
str := sc.Stringified() + fmt.Sprintf("%v - %7d\n%5f - %5f",
t.UTC(), counter, delta.Seconds(), delta.Seconds()/float64(counter))
// bus.Emit(ui.StreamDataEv{Str: str})
sc.App.QueueUpdateDraw(func() {
sc.StreamView.Update(str)
})
counter++
}
}()
+17 -52
View File
@@ -1,5 +1,7 @@
package views
import "github.com/rivo/tview"
// Car data lengths
const (
SpeedLen = 5
@@ -12,56 +14,19 @@ const (
streamingBoxID = "streaming-box"
)
func streamingWindow() {
// bus.Emit(ui.LogEv{Log: "creating streaming window"})
//
// // Get the ActionPages parent
// box := tview.NewTextView()
// box.SetBorder(true).SetTitle("STREAMING")
// box.SetInputCapture(func(ev *tcell.EventKey) *tcell.EventKey {
// switch ev.Key() {
// case tcell.KeyEsc:
// // well, I really need to design the UI (as if lmao) better
// os.Exit(0)
// }
//
// return ev
// })
//
// var err error
// var boxNode *dom.UINode
//
// // delete the currently existing streaming-box
// actionPages := doc.GetElemByID(LayoutToolActionPagesID).(*tview.Pages)
// actionPages.RemovePage(streamingBoxID)
//
// // Get the currently exisiting streaming box in the dom so we can delete it
// boxNode = doc.GetNodeByID(streamingBoxID)
// if boxNode != nil {
// doc.DeleteElem(boxNode)
// }
//
// // Register this streaming box as an UINode
// boxNode, err = doc.NewUINode(
// streamingBoxID,
// doc.GetElemByID(LayoutToolActionPagesID),
// box,
// )
// if err != nil {
// return
// }
//
// // Add it to the action pages and view it
// // AddAndShowPage(actionPages, boxNode, true)
//
// bus.Emit(ui.StartStreamingReqEv{})
//
// bus.On(ui.StreamDataEv{}, func(e any) {
// bus.Emit(ui.RedrawEv{
// Fn: func() {
// sd := e.(ui.StreamDataEv)
// box.SetText(sd.Str)
// },
// })
// })
type StreamView struct {
TextView *tview.TextView
}
func NewStreamView() *StreamView {
tv := tview.NewTextView()
tv.SetTitle("Streaming Tool").SetBorder(true)
return &StreamView{
TextView: tv,
}
}
func (sv *StreamView) Update(str string) {
sv.TextView.SetText(str)
}