Adding a way to find new devices

This commit is contained in:
2025-10-22 23:15:33 +01:00
parent a748c9644a
commit b60351319f
3 changed files with 75 additions and 5 deletions
+51
View File
@@ -0,0 +1,51 @@
// Package peripheral will handle communicating with peripherals
package peripheral
import (
"fmt"
"path/filepath"
)
type PeripheralType string
const (
DisplayPeripheral PeripheralType = "display"
)
type PeripheralDevice struct {
Port string
Name [32]byte
}
type PeripheralDeviceClerk struct {
Devices map[string]PeripheralDevice
}
func NewPeripheralDeviceClerk() *PeripheralDeviceClerk {
return &PeripheralDeviceClerk{}
}
func (clerk *PeripheralDeviceClerk) listPorts() ([]string, error) {
ttyUSBs, err := filepath.Glob("/dev/ttyUSB*")
if err != nil {
return []string{}, err
}
return ttyUSBs, nil
}
func (clerk *PeripheralDeviceClerk) FindDevices() error {
ports, err := clerk.listPorts()
if err != nil {
return err
}
for _, p := range ports {
fmt.Println(p)
}
return nil
}
// Add a peripheral device manager
// Something that auto discovers available devices