resolved disconnected hardware when it is detected

This commit is contained in:
2025-08-31 11:15:38 +02:00
parent 0db468bfef
commit bc15407cad
14 changed files with 96 additions and 80 deletions

View File

@@ -15,6 +15,7 @@ import (
"time"
"github.com/rs/zerolog/log"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
const (
@@ -54,10 +55,10 @@ func (f *FTDIFinder) RegisterPeripheral(ctx context.Context, peripheralData Peri
}
// UnregisterPeripheral unregisters an existing peripheral
func (f *FTDIFinder) UnregisterPeripheral(ctx context.Context, peripheralID string) error {
func (f *FTDIFinder) UnregisterPeripheral(peripheralID string) error {
peripheral, registered := f.registeredPeripherals[peripheralID]
if registered {
err := peripheral.Disconnect(ctx)
err := peripheral.Disconnect()
if err != nil {
return err
}
@@ -248,13 +249,22 @@ func (f *FTDIFinder) scanPeripherals(ctx context.Context) error {
ProtocolName: "FTDI",
}
// If this peripheral is already registered, connect it
// If this peripheral is already registered, connect it and activate it
peripheral, registered := f.registeredPeripherals[peripheralInfo[1]]
if registered {
runtime.EventsEmit(ctx, string(PeripheralStatus), peripheral.info, "connecting")
time.Sleep(2 * time.Second)
err := peripheral.Connect(ctx, location)
if err != nil {
log.Err(err).Str("file", "FTDIFinder").Str("peripheralSN", peripheralInfo[1]).Msg("unable to connect the peripheral")
}
runtime.EventsEmit(ctx, string(PeripheralStatus), peripheral.info, "deactivated")
time.Sleep(2 * time.Second)
err = peripheral.Activate(ctx)
if err != nil {
log.Err(err).Str("file", "FTDIFinder").Str("peripheralSN", peripheralInfo[1]).Msg("unable to activate the peripheral")
}
runtime.EventsEmit(ctx, string(PeripheralStatus), peripheral.info, "activated")
}
log.Trace().Any("periph", temporaryPeripherals).Str("file", "FTDIFinder").Str("peripheralName", peripheralInfo[2]).Msg("successfully added the FTDI peripheral to the finder")