diff --git a/frontend/src/runtime-events.js b/frontend/src/runtime-events.js index 961acb9..1902a40 100644 --- a/frontend/src/runtime-events.js +++ b/frontend/src/runtime-events.js @@ -27,11 +27,12 @@ function removePeripheral (peripheralInfo){ let lastSavedProperty = peripheralsList[peripheralInfo.SerialNumber]?.isSaved let needToDelete = (lastSavedProperty !== true) ? true : false peripherals.update((storedPeripherals) => { - if (needToDelete){ - delete storedPeripherals[peripheralInfo.SerialNumber]; - return { ...storedPeripherals }; - } - storedPeripherals[peripheralInfo.SerialNumber].isDetected = false + if (needToDelete){ + delete storedPeripherals[peripheralInfo.SerialNumber]; + return { ...storedPeripherals }; + } + storedPeripherals[peripheralInfo.SerialNumber].isDetected = false + storedPeripherals[peripheralInfo.SerialNumber].Status = "disconnected" return {...storedPeripherals} }) generateToast('warning', 'bxs-hdd', get(_)("peripheralRemovalToast") + ' ' + peripheralInfo.Name + '') diff --git a/hardware/FTDIFinder.go b/hardware/FTDIFinder.go index f24812f..df00560 100644 --- a/hardware/FTDIFinder.go +++ b/hardware/FTDIFinder.go @@ -60,11 +60,13 @@ func (f *FTDIFinder) RegisterPeripheral(ctx context.Context, peripheralData Peri err = ftdiPeripheral.Connect(ctx) if err != nil { log.Err(err).Str("file", "FTDIFinder").Str("peripheralSN", peripheralData.SerialNumber).Msg("unable to connect the peripheral") + return peripheralData.SerialNumber, nil } // Peripheral connected, activate it err = ftdiPeripheral.Activate(ctx) if err != nil { log.Err(err).Str("file", "FTDIFinder").Str("peripheralSN", peripheralData.SerialNumber).Msg("unable to activate the peripheral") + return peripheralData.SerialNumber, nil } // Peripheral activated return peripheralData.SerialNumber, nil @@ -131,7 +133,7 @@ func (f *FTDIFinder) Start(ctx context.Context) error { return nil } -// ForceScan explicily asks for scanning peripherals +// ForceScan explicitly asks for scanning peripherals func (f *FTDIFinder) ForceScan() { select { case f.scanChannel <- struct{}{}: diff --git a/hardware/FTDIPeripheral.go b/hardware/FTDIPeripheral.go index 1c22062..c8ed185 100644 --- a/hardware/FTDIPeripheral.go +++ b/hardware/FTDIPeripheral.go @@ -51,6 +51,7 @@ func (p *FTDIPeripheral) Connect(ctx context.Context) error { serialNumber := C.CString(p.info.SerialNumber) defer C.free(unsafe.Pointer(serialNumber)) if C.dmx_connect(p.dmxSender, serialNumber) != C.DMX_OK { + runtime.EventsEmit(ctx, string(PeripheralStatus), p.info, "disconnected") log.Error().Str("file", "FTDIPeripheral").Str("s/n", p.info.SerialNumber).Msg("unable to connect the DMX device") return errors.Errorf("unable to connect '%s'") } @@ -92,9 +93,11 @@ func (p *FTDIPeripheral) Activate(ctx context.Context) error { err := C.dmx_activate(p.dmxSender) if err != C.DMX_OK { + runtime.EventsEmit(ctx, string(PeripheralStatus), p.info, "deactivated") return errors.Errorf("unable to activate the DMX sender!") } + // Test only C.dmx_setValue(p.dmxSender, C.uint16_t(1), C.uint8_t(255)) C.dmx_setValue(p.dmxSender, C.uint16_t(5), C.uint8_t(255))