pls no break

main
Keegan 2 years ago
commit 116bc1e5c9

Binary file not shown.

@ -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)
}
@ -74,8 +78,12 @@ func (t *TUI) Monitor() {
t.App.QueueUpdateDraw(func() {
t.UpdateDevices(reactor)
})
<<<<<<< HEAD
case device : <-t.SelectedDevice:
fmt.Println("DeviceSelected")
// TODO
=======
>>>>>>> 03b99d8d16e9ca33d05553b749613e30ab9be204
case <-timer:
// time to ping for status
t.App.QueueUpdateDraw(func() {
@ -101,13 +109,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)
}
@ -121,10 +129,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()
@ -134,7 +143,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
}
@ -161,8 +171,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 {
@ -170,12 +178,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)
}
@ -193,5 +201,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)
}
}

Loading…
Cancel
Save