Reuse redraws to decrease cpu load
This commit is contained in:
+3
-2
@@ -9,7 +9,7 @@ var pu = []key{
|
||||
{yabl.PPuPresentEnergy, yabl.FPresentCurrent, 4},
|
||||
{yabl.PCpuPresentEnergy, yabl.FPresentCurrent, 5},
|
||||
{yabl.PPuPeriphery, yabl.FConnectorInsert, 6},
|
||||
{yabl.PPuPeriphery, yabl.FDebugContactorOn, 7},
|
||||
{yabl.PPuPeriphery, yabl.FContactorOn, 7},
|
||||
{yabl.PPuPeriphery, yabl.FConnectorLocked, 8},
|
||||
{yabl.PPuPeriphery, yabl.FCpLineLevel, 9},
|
||||
{yabl.PPuPeriphery, yabl.FIsolationState, 10},
|
||||
@@ -23,7 +23,8 @@ var pu = []key{
|
||||
{yabl.PCpuEnergySettings, yabl.FVoltageMax, 18},
|
||||
{yabl.PPuDebug, yabl.FDebugModeOn, 19},
|
||||
{yabl.PPuDebug, yabl.FDebugContactorOutputOn, 20},
|
||||
{yabl.PPuErrors, yabl.FBoardReady, 21},
|
||||
{yabl.PPuPeriphery, yabl.FDebugContactorOn, 21},
|
||||
{yabl.PPuErrors, yabl.FBoardReady, 22},
|
||||
}
|
||||
|
||||
var pu_errors = []key{
|
||||
|
||||
+8
-6
@@ -3,6 +3,7 @@ package ui
|
||||
import (
|
||||
"cli-mon/yabl"
|
||||
"fmt"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
tview "github.com/rivo/tview"
|
||||
"reflect"
|
||||
)
|
||||
@@ -32,14 +33,14 @@ func (t *table) header(header string) *table {
|
||||
|
||||
func (t *table) columns(name string, cols int) *table {
|
||||
for i := 1; i <= cols; i++ {
|
||||
t.SetCell(0, i, tview.NewTableCell(fmt.Sprintf("%s %d", name, i)).SetExpansion(2))
|
||||
t.SetCell(0, i, tview.NewTableCell(fmt.Sprintf("%s %d", name, i)).SetExpansion(2)).SetBackgroundColor(tcell.ColorDefault)
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *table) rows(name string, rows int) *table {
|
||||
for i := 1; i <= rows; i++ {
|
||||
t.SetCell(i, 0, tview.NewTableCell(fmt.Sprintf("%s %d", name, i))) //.SetExpansion(2))
|
||||
t.SetCell(i, 0, tview.NewTableCell(fmt.Sprintf("%s %d", name, i))).SetBackgroundColor(tcell.ColorDefault) //.SetExpansion(2))
|
||||
}
|
||||
return t
|
||||
}
|
||||
@@ -47,7 +48,7 @@ func (t *table) rows(name string, rows int) *table {
|
||||
func newTable(params []key, min, max int, invert bool, short bool) *table {
|
||||
t := &table{}
|
||||
t.Box = tview.NewBox()
|
||||
t.SetBorderColor(tview.Styles.GraphicsColor)
|
||||
//t.SetBorderColor(tview.Styles.GraphicsColor)
|
||||
t.SetSeparator(' ')
|
||||
t.SetContent(nil)
|
||||
t.SetBorders(true)
|
||||
@@ -59,7 +60,7 @@ func newTable(params []key, min, max int, invert bool, short bool) *table {
|
||||
for i := min; i <= max; i++ {
|
||||
k := param
|
||||
k.id = uint(i)
|
||||
cell := tview.NewTableCell("")
|
||||
cell := tview.NewTableCell("").SetBackgroundColor(tcell.ColorDefault)
|
||||
t.views[k] = cell
|
||||
var col = i
|
||||
if min == 0 {
|
||||
@@ -79,10 +80,11 @@ func newTable(params []key, min, max int, invert bool, short bool) *table {
|
||||
desc = fmt.Sprintf("%s.%s", param.action, param.field)
|
||||
}
|
||||
|
||||
cell := tview.NewTableCell(desc).SetBackgroundColor(tcell.ColorDefault)
|
||||
if !invert {
|
||||
t.SetCell(int(param.id), 0, tview.NewTableCell(desc))
|
||||
t.SetCell(int(param.id), 0, cell)
|
||||
} else {
|
||||
t.SetCell(0, int(param.id), tview.NewTableCell(desc))
|
||||
t.SetCell(0, int(param.id), cell)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -21,6 +22,7 @@ const (
|
||||
connectorCount = 6
|
||||
contactorsCount = 18
|
||||
convertersCount = 18
|
||||
redrawMillis = 500
|
||||
)
|
||||
|
||||
type page struct {
|
||||
@@ -38,6 +40,8 @@ type UI interface {
|
||||
type gui struct {
|
||||
app *tview.Application
|
||||
pages *tview.Pages
|
||||
redraw bool
|
||||
ticker *time.Ticker
|
||||
pu *table
|
||||
puErrors *table
|
||||
contactorsErrors *table
|
||||
@@ -99,8 +103,10 @@ func (g *gui) Consume(event *yabl.Event) {
|
||||
g.cpu.update(event)
|
||||
case *yabl.CpuDebug:
|
||||
g.cpu.update(event)
|
||||
default:
|
||||
return
|
||||
}
|
||||
g.app.Draw()
|
||||
g.redraw = true
|
||||
}
|
||||
|
||||
func NewUI() UI {
|
||||
@@ -193,10 +199,23 @@ func NewUI() UI {
|
||||
return event
|
||||
})
|
||||
|
||||
g.redraw = true
|
||||
|
||||
return g
|
||||
}
|
||||
|
||||
func (g *gui) Start() {
|
||||
g.ticker = time.NewTicker(redrawMillis * time.Millisecond)
|
||||
|
||||
go func() {
|
||||
for _ = range g.ticker.C {
|
||||
if g.redraw {
|
||||
g.app.Draw()
|
||||
g.redraw = false
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
if err := g.app.SetRoot(g.pages, true).EnableMouse(true).Run(); err != nil {
|
||||
panic(err)
|
||||
@@ -205,6 +224,7 @@ func (g *gui) Start() {
|
||||
}
|
||||
|
||||
func (g *gui) Stop() {
|
||||
g.ticker.Stop()
|
||||
g.app.Stop()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user