generated from thinkode/modelRepository
24-activate-peripherals #26
@@ -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")
|
||||
|
||||
@@ -20,6 +20,7 @@ type PeripheralInfo struct {
|
||||
Name string `yaml:"name"` // Name of the peripheral
|
||||
SerialNumber string `yaml:"sn"` // S/N of the peripheral
|
||||
ProtocolName string `yaml:"protocol"` // Protocol name of the peripheral
|
||||
IsOpen bool // Open flag for peripheral connection
|
||||
Settings map[string]interface{} `yaml:"settings"` // Peripheral settings
|
||||
}
|
||||
|
||||
|
||||
11
hardware/third-party/ftdi/detectFTDI.cpp
vendored
11
hardware/third-party/ftdi/detectFTDI.cpp
vendored
@@ -28,8 +28,17 @@ int main() {
|
||||
|
||||
for (int i = 0; i < numDevs; i++) {
|
||||
if (devInfo[i].SerialNumber[0] != '\0') {
|
||||
std::cout << i << ":" << devInfo[i].SerialNumber << ":" << devInfo[i].Description << std::endl;
|
||||
std::cout << i << ":" << devInfo[i].SerialNumber << ":" << devInfo[i].Description << ":";
|
||||
|
||||
// Add information about the hardware open state
|
||||
if (devInfo[i].Flags & FT_FLAGS_OPENED) {
|
||||
std::cout << "O" << std::endl;
|
||||
} else {
|
||||
std::cout << "C" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(devInfo);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user