tui fixes

main
KeeganForelight 3 years ago
parent 9d55e41bf9
commit 03b99d8d16

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -3,6 +3,7 @@ package tui
import ( import (
"fmt" "fmt"
"log" "log"
"sync"
"strconv" "strconv"
"time" "time"
"github.com/rivo/tview" "github.com/rivo/tview"
@ -22,6 +23,7 @@ type TUI struct {
//*LocalView //*LocalView
*TUIClient *TUIClient
SelectedReactor <-chan uint32 SelectedReactor <-chan uint32
SelectedDevice <-chan uint32
Err chan error Err chan error
} }
@ -49,9 +51,11 @@ func (t *TUI) Start() {
} }
func (t *TUI) CreateDisplay() { func (t *TUI) CreateDisplay() {
c := make(chan uint32) rc := make(chan uint32)
t.Display = NewDisplay(c) dc := make(chan uint32)
t.SelectedReactor = c t.Display = NewDisplay(rc,dc)
t.SelectedReactor = rc
t.SelectedDevice = dc
t.Flex.AddItem(t.ReactorList,0,1,true). t.Flex.AddItem(t.ReactorList,0,1,true).
AddItem(t.DevicePages,0,2,false) AddItem(t.DevicePages,0,2,false)
} }
@ -73,7 +77,7 @@ func (t *TUI) Monitor() {
t.App.QueueUpdateDraw(func() { t.App.QueueUpdateDraw(func() {
t.UpdateDevices(reactor) t.UpdateDevices(reactor)
}) })
case device : <-t.SelectedDevice: case <-t.SelectedDevice:
// TODO // TODO
case <-timer: case <-timer:
// time to ping for status // time to ping for status
@ -100,13 +104,13 @@ func (t *TUI) UpdateDevices(r ...uint32) {
devices := make(map[uint32]*Device) devices := make(map[uint32]*Device)
for id, dev := range devs { for id, dev := range devs {
if dev.Type == "Reactor" { if dev.Type == "Reactor" {
reactor[id] = dev reactors[id] = dev
} else { } else {
device[id] = dev devices[id] = dev
} }
} }
t.DisplayDevices(devices) t.DisplayDevices(devices, id)
t.DisplayReactors(reactors,r) t.DisplayReactors(reactors)
} else { } else {
t.DisplayReactors(devs) t.DisplayReactors(devs)
} }
@ -120,10 +124,11 @@ type Display struct {
DevicePages *tview.Pages DevicePages *tview.Pages
DeviceList map[string]*tview.List DeviceList map[string]*tview.List
SelectedReactor chan<- uint32 SelectedReactor chan<- uint32
SelectedDevice chan<- uint32
sync.Mutex sync.Mutex
} }
func NewDisplay(ch chan uint32) *Display { func NewDisplay(rc,dc chan uint32) *Display {
d := &Display{} d := &Display{}
d.App = tview.NewApplication() d.App = tview.NewApplication()
d.Flex = tview.NewFlex() d.Flex = tview.NewFlex()
@ -133,7 +138,8 @@ func NewDisplay(ch chan uint32) *Display {
d.DevicePages = tview.NewPages() d.DevicePages = tview.NewPages()
d.ReactorList.SetTitle("Reactors").SetBorder(true) d.ReactorList.SetTitle("Reactors").SetBorder(true)
d.DevicePages.SetTitle("Devices").SetBorder(true) d.DevicePages.SetTitle("Devices").SetBorder(true)
d.SelectedReactor = ch d.SelectedReactor = rc
d.SelectedDevice = dc
return d return d
} }
@ -160,8 +166,6 @@ func (d *Display) DisplayReactors(r map[uint32]*Device) {
func (d *Display) DisplayDevices(devs map[uint32]*Device, rid uint32) { func (d *Display) DisplayDevices(devs map[uint32]*Device, rid uint32) {
//d.Lock() //d.Lock()
numReactorsSelected := d.DevicePages.GetPageCount()
numReactors := d.ReactorList.GetItemCount()
reactorPage := string(rid) reactorPage := string(rid)
var reactorList *tview.List var reactorList *tview.List
if reactorList, ok := d.DeviceList[reactorPage]; !ok { 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.DeviceList[reactorPage] = reactorList
} }
//d.Unlock() //d.Unlock()
for addr, dev := range devs { for _, dev := range devs {
txt := fmt.Sprtinf("%v %v at %x%x",dev.Type,dev.Status,dev.Id,dev.Data) // sensor alive at 0x0 data 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) { 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) 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) { func (d *Display) SelectDevice(index int, main, id string, r rune) {
// called when device is selected in sub menu // 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)
}
} }

Loading…
Cancel
Save