Yeah, I kinda gave up, i will fix it later or something I recon
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package packets
|
||||
|
||||
import (
|
||||
"esdi/peripheral/communication/constvar"
|
||||
)
|
||||
|
||||
type NewWindowID struct {
|
||||
StartMarker byte
|
||||
ID int16
|
||||
EndMarker byte
|
||||
}
|
||||
|
||||
func (pkt *NewWindowID) Validate() bool {
|
||||
if pkt.StartMarker != constvar.StartOfText ||
|
||||
pkt.EndMarker != constvar.EndOfText {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -16,10 +16,11 @@ const (
|
||||
newWindowCMDID types.Command = 3
|
||||
destroyWindowCMDID types.Command = 4
|
||||
moveWindowCMDID types.Command = 5
|
||||
newLayoutCMDID types.Command = 6
|
||||
)
|
||||
|
||||
var (
|
||||
defaultDecorations = UIDecorations{
|
||||
DefaultDecorations = UIDecorations{
|
||||
HasBorder: 1,
|
||||
BGColour: 0x1041, // Look in the eslabsCurses library for these colours
|
||||
FGColour: 0xffff,
|
||||
@@ -55,6 +56,29 @@ type UIWindow struct {
|
||||
Title [32]byte
|
||||
}
|
||||
|
||||
type LayoutTree struct {
|
||||
Windows map[int]UIWindow
|
||||
}
|
||||
|
||||
func (l *LayoutTree) AddWindow(idx int, w UIWindow) {
|
||||
l.Windows[idx] = w
|
||||
}
|
||||
|
||||
func NewLayoutTree() *LayoutTree {
|
||||
return &LayoutTree{
|
||||
Windows: make(map[int]UIWindow),
|
||||
}
|
||||
}
|
||||
|
||||
type CDashState struct {
|
||||
Layout *LayoutTree
|
||||
}
|
||||
|
||||
// Well fuck it really, this will make do for now really lmao
|
||||
var (
|
||||
state *CDashState
|
||||
)
|
||||
|
||||
var CDashDisplay = Device{
|
||||
ID: CDashDisplayDevID,
|
||||
Name: helper.B32("ESLabs CDashDisplay"),
|
||||
@@ -80,6 +104,13 @@ var CDashDisplay = Device{
|
||||
ArgCheck: moveWindowArgCheck,
|
||||
Fn: moveWindow,
|
||||
},
|
||||
"new-layout": {
|
||||
Identifier: newLayoutCMDID,
|
||||
Name: "new-layout",
|
||||
Desc: "creates a new layout",
|
||||
ArgCheck: nil,
|
||||
Fn: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -121,7 +152,7 @@ func createWindow(dCMD *DeviceCMD, args []string) (types.Command, []byte, error)
|
||||
Width: uint16(width),
|
||||
Height: uint16(height),
|
||||
},
|
||||
Decor: defaultDecorations,
|
||||
Decor: DefaultDecorations,
|
||||
Title: helper.B32(args[4]),
|
||||
}
|
||||
|
||||
@@ -130,6 +161,13 @@ func createWindow(dCMD *DeviceCMD, args []string) (types.Command, []byte, error)
|
||||
return 0, []byte{}, err
|
||||
}
|
||||
|
||||
// All went well so far so we can update the state
|
||||
if state == nil {
|
||||
state = &CDashState{Layout: NewLayoutTree()}
|
||||
}
|
||||
|
||||
state.Layout.AddWindow(0, data)
|
||||
|
||||
return dCMD.GetIdentifier(), bytes, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,10 @@ var DeviceMap = map[int]Device{
|
||||
}
|
||||
|
||||
type Device struct {
|
||||
ID uint8
|
||||
Name [32]byte
|
||||
API map[string]DeviceCMD
|
||||
ID uint8
|
||||
Name [32]byte
|
||||
API map[string]DeviceCMD
|
||||
State any
|
||||
}
|
||||
|
||||
func (dev *Device) HasFunction(f string) *DeviceCMD {
|
||||
@@ -52,8 +53,6 @@ type DeviceCMD struct {
|
||||
Identifier types.Command
|
||||
Name string
|
||||
Desc string
|
||||
Header DeviceCMDHeader
|
||||
Data DeviceCMDPayload
|
||||
ArgCheck ArgCheckFn
|
||||
Fn DeviceCMDFn
|
||||
}
|
||||
@@ -80,3 +79,9 @@ func (dCMD *DeviceCMD) GetName() string {
|
||||
func (dCMD *DeviceCMD) GetDesc() string {
|
||||
return dCMD.Desc
|
||||
}
|
||||
|
||||
type DeviceInstance[T any] struct {
|
||||
Def *Device
|
||||
ID uint8
|
||||
State T
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user