@@ -11,7 +11,6 @@ import (
|
||||
const (
|
||||
newWindowCMDID types.Command = 3
|
||||
destroyWindowCMDID types.Command = 4
|
||||
moveWindowCMDID types.Command = 5
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -69,13 +68,6 @@ var CDashDisplay = Device{
|
||||
ArgCheck: destroyWindowArgCheck,
|
||||
Fn: destroyWindow,
|
||||
},
|
||||
"move-window": {
|
||||
Identifier: moveWindowCMDID,
|
||||
Name: "move-window",
|
||||
Desc: "Moves a selected window - pass the window ID",
|
||||
ArgCheck: moveWindowArgCheck,
|
||||
Fn: moveWindow,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -91,6 +83,8 @@ func createWindowArgCheck(args []string) error {
|
||||
func createWindow(dCMD *DeviceCMD, args []string) (types.Command, []byte, error) {
|
||||
// Parse the command
|
||||
// x0, y0, width, height, title # add other decorations later on
|
||||
// fmt.Printf("%s command called: %+v\n", dCMD.GetName(), args)
|
||||
|
||||
x0, err := strconv.ParseInt(args[0], 10, 0)
|
||||
if err != nil {
|
||||
return 0, []byte{}, err
|
||||
@@ -138,6 +132,8 @@ func destroyWindowArgCheck(args []string) error {
|
||||
|
||||
func destroyWindow(dCMD *DeviceCMD, args []string) (types.Command, []byte, error) {
|
||||
// Parse the command
|
||||
fmt.Printf("%s command called: %+v\n", dCMD.GetName(), args)
|
||||
|
||||
type UIWindowDestructPacket struct {
|
||||
WinID int16
|
||||
}
|
||||
@@ -158,24 +154,3 @@ func destroyWindow(dCMD *DeviceCMD, args []string) (types.Command, []byte, error
|
||||
|
||||
return dCMD.GetIdentifier(), bytes, nil
|
||||
}
|
||||
|
||||
func moveWindowArgCheck(args []string) error {
|
||||
if len(args) != 1 {
|
||||
return fmt.Errorf("wrong parameters, got %d, want %d. "+
|
||||
"Command asks for: winID", len(args), 1)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func moveWindow(dCMD *DeviceCMD, args []string) (types.Command, []byte, error) {
|
||||
// We can edit this struct to be a generic 'window edit' struct. Either
|
||||
// that or implement a way of passing arbitrary fields to update
|
||||
type UIWindowMovePacket struct {
|
||||
WinID int16
|
||||
Direction uint8
|
||||
Quantity uint8
|
||||
}
|
||||
|
||||
return dCMD.GetIdentifier(), []byte{}, nil
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
// Package devices will define the available devices we can communicate with
|
||||
package devices
|
||||
|
||||
import (
|
||||
"esdi/peripheral/types"
|
||||
"fmt"
|
||||
)
|
||||
import "esdi/peripheral/types"
|
||||
|
||||
// IDs for our devices. They need to be correctly mapped on the devices
|
||||
// themselves so we can discover them
|
||||
@@ -69,7 +66,6 @@ func (dCMD *DeviceCMD) Run(args []string) (types.Command, []byte, error) {
|
||||
}
|
||||
|
||||
// Run the function
|
||||
fmt.Printf("%s command called: %+v\n", dCMD.GetName(), args)
|
||||
return dCMD.Fn(dCMD, args)
|
||||
}
|
||||
|
||||
|
||||
+30
-22
@@ -5,7 +5,6 @@ import (
|
||||
"esdi/peripheral/devices"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type PeripheralType string
|
||||
@@ -48,13 +47,12 @@ func (clerk *PeripheralDeviceClerk) FindDeviceAPI(ID uint8) *devices.Device {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (clerk *PeripheralDeviceClerk) FindDevices() (string, error) {
|
||||
func (clerk *PeripheralDeviceClerk) FindDevices() error {
|
||||
ports, err := clerk.listPorts()
|
||||
if err != nil {
|
||||
return "", err
|
||||
return err
|
||||
}
|
||||
|
||||
var s strings.Builder
|
||||
for _, p := range ports {
|
||||
newDevice := NewPeripheralDevice(p)
|
||||
|
||||
@@ -75,17 +73,17 @@ func (clerk *PeripheralDeviceClerk) FindDevices() (string, error) {
|
||||
fmt.Println(p, string(newDevice.Name[:]))
|
||||
}
|
||||
|
||||
return s.String(), nil
|
||||
// go clerk.clerkBackgroundJob()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (clerk *PeripheralDeviceClerk) ListDevices() (string, error) {
|
||||
var s strings.Builder
|
||||
|
||||
func (clerk *PeripheralDeviceClerk) ListDevices() error {
|
||||
for _, d := range clerk.Devices {
|
||||
s.WriteString(fmt.Sprintf("[%2d] %s\n", d.ID, d.Name))
|
||||
fmt.Printf("[%2d] %s\n", d.ID, d.Name)
|
||||
}
|
||||
|
||||
return s.String(), nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (clerk *PeripheralDeviceClerk) getDevice(ID uint8) *PeripheralDevice {
|
||||
@@ -96,43 +94,53 @@ func (clerk *PeripheralDeviceClerk) getDevice(ID uint8) *PeripheralDevice {
|
||||
return clerk.Devices[ID]
|
||||
}
|
||||
|
||||
func (clerk *PeripheralDeviceClerk) ListDeviceAPI(ID uint8) (string, error) {
|
||||
func (clerk *PeripheralDeviceClerk) ListDeviceAPI(ID uint8) error {
|
||||
dev := clerk.getDevice(ID)
|
||||
if dev == nil {
|
||||
return "", fmt.Errorf("device with ID %d not found", ID)
|
||||
return fmt.Errorf("device with ID %d not found", ID)
|
||||
}
|
||||
|
||||
var s strings.Builder
|
||||
for _, f := range dev.DeviceAPI.API {
|
||||
s.WriteString(fmt.Sprintf("%s\t%s\n", f.Name, f.Desc))
|
||||
fmt.Printf("%s\t%s\n", f.Name, f.Desc)
|
||||
}
|
||||
|
||||
return s.String(), nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (clerk *PeripheralDeviceClerk) RunDeviceFunction(ID uint8, f string,
|
||||
args []string) (string, error) {
|
||||
func (clerk *PeripheralDeviceClerk) RunDeviceFunction(ID uint8, f string, args []string) error {
|
||||
dev := clerk.getDevice(ID)
|
||||
if dev == nil {
|
||||
return "", fmt.Errorf("device with ID %d not found", ID)
|
||||
return fmt.Errorf("device with ID %d not found", ID)
|
||||
}
|
||||
devAPI := dev.DeviceAPI
|
||||
|
||||
cmd := devAPI.HasFunction(f)
|
||||
if cmd == nil {
|
||||
return "", fmt.Errorf("requested function %s doesnt exist", f)
|
||||
return fmt.Errorf("requested function %s doesnt exist", f)
|
||||
}
|
||||
|
||||
// Execute the function
|
||||
command, payload, err := cmd.Run(args)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return err
|
||||
}
|
||||
|
||||
err = dev.SendCommand(command, payload)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return err
|
||||
}
|
||||
|
||||
return "", nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// func (c *PeripheralDeviceClerk) clerkBackgroundJob() {
|
||||
// for {
|
||||
// c.mu.RLock()
|
||||
// for _, d := range c.Devices {
|
||||
// // Check the state of the device
|
||||
// if d.CommState == CommIdle {
|
||||
// }
|
||||
// }
|
||||
// c.mu.Unlock()
|
||||
// }
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user