save peripherals in project file

This commit is contained in:
2024-12-20 17:18:57 +01:00
parent 17b5d39fc4
commit 9964ccef7e
19 changed files with 316 additions and 228 deletions

View File

@@ -29,16 +29,16 @@ var (
// HardwareManager is the class who manages the hardware
type HardwareManager struct {
finders []PeripheralFinder // The list of peripherals finders
peripherals []Peripheral // The current list of peripherals
deviceChangedEvent chan struct{} // The event when the devices list changed
finders map[string]PeripheralFinder // The map of peripherals finders
peripherals []Peripheral // The current list of peripherals
deviceChangedEvent chan struct{} // The event when the devices list changed
ctx context.Context
}
// NewHardwareManager creates a new HardwareManager
func NewHardwareManager() *HardwareManager {
return &HardwareManager{
finders: make([]PeripheralFinder, 0),
finders: make(map[string]PeripheralFinder),
peripherals: make([]Peripheral, 0),
deviceChangedEvent: make(chan struct{}),
}
@@ -120,10 +120,25 @@ func (h *HardwareManager) Start(ctx context.Context) error {
// RegisterFinder registers a new peripherals finder
func (h *HardwareManager) RegisterFinder(finder PeripheralFinder) {
h.finders = append(h.finders, finder)
h.finders[finder.GetName()] = finder
fmt.Printf("Success registered the %s finder\n", finder.GetName())
}
// GetPeripheral gets the peripheral object from the parent finder
func (h *HardwareManager) GetPeripheral(finderName string, peripheralID string) (Peripheral, bool) {
// Get the parent finder
parentFinder := h.finders[finderName]
// If no finder found, return false
if parentFinder == nil {
fmt.Println("Unable to get the finder")
return nil, false
}
fmt.Println("Finder ok, returning the peripheral")
// Contact the finder to get the device
return parentFinder.GetPeripheral(peripheralID)
}
// Scan scans all the peripherals for the registered finders
func (h *HardwareManager) Scan(ctx context.Context) error {
if len(h.finders) == 0 {