added open flag indicator for FTDI

This commit is contained in:
2025-10-19 19:56:05 +02:00
parent bc15407cad
commit 65e2def501
3 changed files with 14 additions and 4 deletions

View File

@@ -232,10 +232,10 @@ func (f *FTDIFinder) scanPeripherals(ctx context.Context) error {
scanner := bufio.NewScanner(stdout)
for scanner.Scan() {
peripheralString := scanner.Text()
// The program output is like '0:1:2' where 0 is the location, 1 is the S/N and 2 is the name
// The program output is like '0:1:2:3' where 0 is the location, 1 is the S/N, 2 is the name and 3 is the open flag [O/C]
peripheralInfo := strings.Split(peripheralString, ":")
log.Trace().Str("file", "FTDIFinder").Str("scannedString", peripheralString).Str("peripheralName", peripheralInfo[2]).Str("peripheralSN", peripheralInfo[1]).Msg("new FTDI peripheral detected")
log.Trace().Str("file", "FTDIFinder").Str("scannedString", peripheralString).Str("peripheralOpenFlag", peripheralInfo[3]).Str("peripheralName", peripheralInfo[2]).Str("peripheralSN", peripheralInfo[1]).Msg("new FTDI peripheral detected")
// Convert the location to an integer
location, err := strconv.Atoi(peripheralInfo[0])
if err != nil {
@@ -246,6 +246,7 @@ func (f *FTDIFinder) scanPeripherals(ctx context.Context) error {
temporaryPeripherals[peripheralInfo[1]] = PeripheralInfo{
Name: peripheralInfo[2],
SerialNumber: peripheralInfo[1],
IsOpen: peripheralInfo[3] == "O",
ProtocolName: "FTDI",
}
@@ -253,7 +254,6 @@ func (f *FTDIFinder) scanPeripherals(ctx context.Context) error {
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")