package ui import ( "cli-mon/yabl" "fmt" ui "github.com/gizak/termui/v3" "github.com/gizak/termui/v3/widgets" ) func newHeader() *widgets.Paragraph { widget := widgets.NewParagraph() widget.Text = "Press q to quit, Press or to switch tabs" widget.SetRect(0, 0, 50, 1) widget.Border = false widget.TextStyle.Bg = ui.ColorBlue return widget } func newConnectorsView() *ui.Grid { grid := ui.NewGrid() termWidth, termHeight := ui.TerminalDimensions() grid.SetRect(0, headerHeight, termWidth, termHeight) var conn [connectorsCount + 1]*widgets.Paragraph //ui.GridItem for i := 0; i <= connectorsCount; i++ { p := widgets.NewParagraph() p.Text = fmt.Sprintf("No data: #%2.d", i) p.Title = fmt.Sprintf("Connector: #%2.d", i) //p.SetRect(0, 0, 50, 30) p.TextStyle.Bg = ui.ColorBlue p.TextStyle.Fg = ui.ColorWhite p.BorderStyle.Fg = ui.ColorYellow p.Border = true connUI[i] = p conn[i] = p //ui.NewCol(1.0/6, p) } grid.Set( ui.NewRow( 1.0/2, ui.NewCol(1.0/4, conn[1]), ui.NewCol(1.0/4, conn[2]), ui.NewCol(1.0/4, conn[3]), ui.NewCol(1.0/4, conn[4]), ), ui.NewRow( 1.0/2, ui.NewCol(1.0/4, conn[5]), ui.NewCol(1.0/4, conn[6]), ui.NewCol(1.0/4, conn[0]), ), ) return grid } func newContactorsView() *ui.Grid { grid := ui.NewGrid() termWidth, termHeight := ui.TerminalDimensions() grid.SetRect(0, headerHeight, termWidth, termHeight) var cont [contactorsCount + 1]ui.GridItem //var contactors = make([]ui.GridItem, contactorsCount) for i := 1; i <= contactorsCount; i++ { p := widgets.NewParagraph() p.Text = fmt.Sprintf("No data: #%2.d", i) p.Title = fmt.Sprintf("Contactor: #%2.d", i) p.Border = false p.TextStyle.Bg = ui.ColorBlue p.TextStyle.Fg = ui.ColorWhite p.BorderStyle.Fg = ui.ColorYellow p.Border = true contUI[i] = p cont[i] = ui.NewCol(1.0/6, p) } grid.Set( ui.NewRow( 1.0/3, cont[1], cont[2], cont[3], cont[4], cont[5], cont[6], ), ui.NewRow( 1.0/3, cont[7], cont[8], cont[9], cont[10], cont[11], cont[12], ), ui.NewRow( 1.0/3, cont[13], cont[14], cont[15], cont[16], cont[17], cont[18], )) //ui.NewRow(1, ui.InterfaceSlice(contactors)...) grid.Set() return grid } func newContactorsErrView() *widgets.Paragraph { p := widgets.NewParagraph() p.Text = "No data\n" p.Title = "Contactors Errors" p.SetRect(5, 5, 55, 15) p.BorderStyle.Fg = ui.ColorYellow return p } func updateContactorsView(unitId uint) { p := contUI[unitId] s := contactors[unitId].state if s == nil || p == nil { return } p.Text = fmt.Sprintf( "BoardReady: %s\nContactorOn: %s\nUnexpectedState: %s\nIsolated: %s\nDebug: %s", s.ContactorReady, s.ContactorOn, s.UnexpectedState, s.Isolated, s.DebugEnabled) if s.ContactorReady == yabl.BOARD_READY_OK { p.TextStyle.Bg = ui.ColorClear } else { p.TextStyle.Bg = ui.ColorRed } if s.ContactorOn == yabl.ON { p.TitleStyle.Bg = ui.ColorBlue } else { p.TitleStyle.Bg = ui.ColorClear } } func updateConnectorsView(unitId uint) { p := connUI[unitId] s := connectors[unitId].state e := connectors[unitId].energy if s == nil || e == nil { return } fstring := "ConnectorInsert %s\n" + "ContactorOn %s\n" + "ConnectorLocked %s\n" + "LineLevel %s\n" + "IsolationState %s\n" + "ChargingAllowed %s\n" + "PwmEnabled %s\n" + "CpLineVoltage %s\n" + "V2GMode %s\n" + "VoltageBefore %s\n" + "VoltageAfter %s\n" + "PresentCurrent %s" p.Text = fmt.Sprintf( fstring, s.ConnectorInsert, s.ContactorOn, s.ConnectorLocked, s.CpLineLevel, s.IsolationState, s.ChargingAllowed, s.PwmEnabled, s.CpLineVoltage, e.V2GMode, e.VoltageBefore, e.VoltageAfter, e.PresentCurrent) } func updateContactorsStateView() { p := contactorsErr if contactors[1] == nil { return } e := contactors[1].errors if e == nil { return } p.Text = fmt.Sprintf( "BoardReady: %s\nOtherError: %s\nGroupChanged: %s\nUnexpectedFormation: %s\nCpuNotReady: %s\nPuNotReady: %s\nDebug: %s", e.BoardReady, e.OtherError, e.ContactorGroupChanged, e.UnexpectedFormation, e.CpuNotReady, e.PuNotReady, e.Debug, ) if e.BoardReady == yabl.BOARD_READY_OK { p.TextStyle.Bg = ui.ColorClear } else { p.TextStyle.Bg = ui.ColorRed } }