diff --git a/cmd/reactor/reactor b/cmd/reactor/reactor index b44cd9b..4170c5e 100755 Binary files a/cmd/reactor/reactor and b/cmd/reactor/reactor differ diff --git a/cmd/server/server b/cmd/server/server index 82a5f6c..691f1ab 100755 Binary files a/cmd/server/server and b/cmd/server/server differ diff --git a/cmd/tui/tui b/cmd/tui/tui index b7cd322..bbf5018 100755 Binary files a/cmd/tui/tui and b/cmd/tui/tui differ diff --git a/internal/pkg/tui/tui.go b/internal/pkg/tui/tui.go index 7df6784..0422736 100644 --- a/internal/pkg/tui/tui.go +++ b/internal/pkg/tui/tui.go @@ -3,6 +3,7 @@ package tui import ( "fmt" "log" + "sync" "strconv" "time" "github.com/rivo/tview" @@ -22,6 +23,7 @@ type TUI struct { //*LocalView *TUIClient SelectedReactor <-chan uint32 + SelectedDevice <-chan uint32 Err chan error } @@ -49,9 +51,11 @@ func (t *TUI) Start() { } func (t *TUI) CreateDisplay() { - c := make(chan uint32) - t.Display = NewDisplay(c) - t.SelectedReactor = c + rc := make(chan uint32) + dc := make(chan uint32) + t.Display = NewDisplay(rc,dc) + t.SelectedReactor = rc + t.SelectedDevice = dc t.Flex.AddItem(t.ReactorList,0,1,true). AddItem(t.DevicePages,0,2,false) } @@ -73,7 +77,7 @@ func (t *TUI) Monitor() { t.App.QueueUpdateDraw(func() { t.UpdateDevices(reactor) }) - case device : <-t.SelectedDevice: + case <-t.SelectedDevice: // TODO case <-timer: // time to ping for status @@ -100,13 +104,13 @@ func (t *TUI) UpdateDevices(r ...uint32) { devices := make(map[uint32]*Device) for id, dev := range devs { if dev.Type == "Reactor" { - reactor[id] = dev + reactors[id] = dev } else { - device[id] = dev + devices[id] = dev } } - t.DisplayDevices(devices) - t.DisplayReactors(reactors,r) + t.DisplayDevices(devices, id) + t.DisplayReactors(reactors) } else { t.DisplayReactors(devs) } @@ -120,10 +124,11 @@ type Display struct { DevicePages *tview.Pages DeviceList map[string]*tview.List SelectedReactor chan<- uint32 + SelectedDevice chan<- uint32 sync.Mutex } -func NewDisplay(ch chan uint32) *Display { +func NewDisplay(rc,dc chan uint32) *Display { d := &Display{} d.App = tview.NewApplication() d.Flex = tview.NewFlex() @@ -133,7 +138,8 @@ func NewDisplay(ch chan uint32) *Display { d.DevicePages = tview.NewPages() d.ReactorList.SetTitle("Reactors").SetBorder(true) d.DevicePages.SetTitle("Devices").SetBorder(true) - d.SelectedReactor = ch + d.SelectedReactor = rc + d.SelectedDevice = dc return d } @@ -160,8 +166,6 @@ func (d *Display) DisplayReactors(r map[uint32]*Device) { func (d *Display) DisplayDevices(devs map[uint32]*Device, rid uint32) { //d.Lock() - numReactorsSelected := d.DevicePages.GetPageCount() - numReactors := d.ReactorList.GetItemCount() reactorPage := string(rid) var reactorList *tview.List if reactorList, ok := d.DeviceList[reactorPage]; !ok { @@ -169,12 +173,12 @@ func (d *Display) DisplayDevices(devs map[uint32]*Device, rid uint32) { d.DeviceList[reactorPage] = reactorList } //d.Unlock() - for addr, dev := range devs { - txt := fmt.Sprtinf("%v %v at %x%x",dev.Type,dev.Status,dev.Id,dev.Data) // sensor alive at 0x0 data + for _, dev := range devs { + txt := fmt.Sprintf("%v %v at %x%x",dev.Type,dev.Status,dev.Id,dev.Data) // sensor alive at 0x0 data if reactorList.GetItemCount() > int(dev.Index) { - reactorList.RemoveUten(int(dev.Index) + reactorList.RemoveItem(int(dev.Index)) } - reactorList.InsertItem(int(dev.Index),txt,string(id),rune(49+reactor.Index),nil) + reactorList.InsertItem(int(dev.Index),txt,string(dev.Id),rune(49+dev.Index),nil) } d.DevicePages.SwitchToPage(reactorPage) } @@ -192,5 +196,10 @@ func (d *Display) SelectReactor(index int, main, id string, r rune) { func (d *Display) SelectDevice(index int, main, id string, r rune) { // called when device is selected in sub menu - // TODO + fmt.Println("SELECTED DEV") + if id, err := strconv.Atoi(id); err != nil { + log.Fatal(err) + } else { + d.SelectedDevice <-uint32(id) + } }