Skip to content

Commit 25f4474

Browse files
authored
Merge pull request OpenLightingProject#1888 from aroffringa/add-eurolite-serial-check
Add a Eurolite serial number check
2 parents 1a68747 + ee87962 commit 25f4474

4 files changed

Lines changed: 80 additions & 23 deletions

File tree

plugins/usbdmx/EuroliteProFactory.cpp

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#include "plugins/usbdmx/EuroliteProFactory.h"
2222

23+
#include <vector>
24+
2325
#include "libs/usb/LibUsbAdaptor.h"
2426
#include "ola/Logging.h"
2527
#include "ola/base/Flags.h"
@@ -46,12 +48,34 @@ const uint16_t EuroliteProFactory::VENDOR_ID_MK2 = 0x0403;
4648

4749
const char EuroliteProFactory::ENABLE_EUROLITE_MK2_KEY[] =
4850
"enable_eurolite_mk2";
51+
const char EuroliteProFactory::EUROLITE_MK2_SERIAL_KEY[] =
52+
"eurolite_mk2_serial";
4953

5054
EuroliteProFactory::EuroliteProFactory(ola::usb::LibUsbAdaptor *adaptor,
5155
Preferences *preferences)
5256
: BaseWidgetFactory<class EurolitePro>("EuroliteProFactory"),
5357
m_adaptor(adaptor),
5458
m_enable_eurolite_mk2(IsEuroliteMk2Enabled(preferences)) {
59+
const std::vector<std::string> serials =
60+
preferences->GetMultipleValue(EUROLITE_MK2_SERIAL_KEY);
61+
// A single empty string is considered the same as specifying
62+
// no serial numbers. This is useful as a default value.
63+
const bool has_default_value =
64+
serials.size() == 1 && serials[0].empty();
65+
if (!has_default_value) {
66+
for (std::vector<std::string>::const_iterator iter = serials.begin();
67+
iter != serials.end(); ++iter) {
68+
if (iter->empty()) {
69+
OLA_WARN << EUROLITE_MK2_SERIAL_KEY
70+
<< " requires a serial number, but it is empty.";
71+
} else if (STLContains(m_expected_eurolite_mk2_serials, *iter)) {
72+
OLA_WARN << EUROLITE_MK2_SERIAL_KEY << " lists serial "
73+
<< *iter << " more than once.";
74+
} else {
75+
m_expected_eurolite_mk2_serials.insert(*iter);
76+
}
77+
}
78+
}
5579
}
5680

5781
bool EuroliteProFactory::IsEuroliteMk2Enabled(Preferences *preferences) {
@@ -88,13 +112,22 @@ bool EuroliteProFactory::DeviceAdded(
88112
// Eurolite USB-DMX512-PRO MK2?
89113
} else if (descriptor.idVendor == VENDOR_ID_MK2 &&
90114
descriptor.idProduct == PRODUCT_ID_MK2) {
91-
if (m_enable_eurolite_mk2) {
92-
OLA_INFO << "Found a possible new Eurolite USB-DMX512-PRO MK2 device";
93-
LibUsbAdaptor::DeviceInformation info;
94-
if (!m_adaptor->GetDeviceInfo(usb_device, descriptor, &info)) {
95-
return false;
96-
}
115+
LibUsbAdaptor::DeviceInformation info;
116+
if (!m_adaptor->GetDeviceInfo(usb_device, descriptor, &info)) {
117+
return false;
118+
}
119+
120+
const bool serial_matches =
121+
STLContains(m_expected_eurolite_mk2_serials, info.serial);
97122

123+
if (m_enable_eurolite_mk2 || serial_matches) {
124+
if (serial_matches) {
125+
OLA_INFO << "Found a probable new Eurolite USB-DMX512-PRO MK2 device "
126+
<< "with matching serial " << info.serial;
127+
} else {
128+
OLA_INFO << "Found a probable new Eurolite USB-DMX512-PRO MK2 device "
129+
<< "with serial " << info.serial;
130+
}
98131
if (!m_adaptor->CheckManufacturer(EXPECTED_MANUFACTURER_MK2, info)) {
99132
return false;
100133
}
@@ -104,9 +137,12 @@ bool EuroliteProFactory::DeviceAdded(
104137
}
105138
is_mk2 = true;
106139
} else {
107-
OLA_INFO << "Connected FTDI device could be a Eurolite "
108-
<< "USB-DMX512-PRO MK2 but was ignored, because "
109-
<< ENABLE_EUROLITE_MK2_KEY << " was false.";
140+
OLA_INFO << "Connected FTDI device with serial " << info.serial
141+
<< " could be a Eurolite USB-DMX512-PRO MK2 but was "
142+
<< "ignored, because "
143+
<< ENABLE_EUROLITE_MK2_KEY << " was false and "
144+
<< "its serial number was not listed specifically in "
145+
<< EUROLITE_MK2_SERIAL_KEY;
110146
return false;
111147
}
112148
} else {

plugins/usbdmx/EuroliteProFactory.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
#ifndef PLUGINS_USBDMX_EUROLITEPROFACTORY_H_
2222
#define PLUGINS_USBDMX_EUROLITEPROFACTORY_H_
2323

24+
#include <set>
25+
#include <string>
26+
2427
#include "libs/usb/LibUsbAdaptor.h"
2528
#include "ola/base/Macro.h"
2629
#include "olad/Preferences.h"
@@ -46,10 +49,12 @@ class EuroliteProFactory : public BaseWidgetFactory<class EurolitePro> {
4649
static bool IsEuroliteMk2Enabled(Preferences *preferences);
4750

4851
static const char ENABLE_EUROLITE_MK2_KEY[];
52+
static const char EUROLITE_MK2_SERIAL_KEY[];
4953

5054
private:
5155
ola::usb::LibUsbAdaptor *m_adaptor;
5256
bool m_enable_eurolite_mk2;
57+
std::set<std::string> m_expected_eurolite_mk2_serials;
5358

5459
static const uint16_t PRODUCT_ID;
5560
static const uint16_t VENDOR_ID;

plugins/usbdmx/README.md

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This plugin supports various USB DMX devices including:
99
* DMXControl Projects e.V. Nodle U1
1010
* DMXCreator 512 Basic
1111
* Eurolite USB-DMX512 PRO
12-
* Eurolite USB-DMX512 PRO MK2 (when `enable_eurolite_mk2 = true`)
12+
* Eurolite USB-DMX512 PRO MK2 (see notes below)
1313
* Eurolite freeDMX Wi-Fi
1414
* Fadecandy
1515
* FX5 DMX
@@ -20,25 +20,36 @@ This plugin supports various USB DMX devices including:
2020

2121
## Config file : `ola-usbdmx.conf`
2222

23-
`libusb_debug_level = {0,1,2,3,4}`
24-
The debug level for libusb, see http://libusb.sourceforge.net/api-1.0/
23+
`libusb_debug_level = {0,1,2,3,4}`
24+
The debug level for libusb, see http://libusb.sourceforge.net/api-1.0/
2525
0 = No logging, 4 = Verbose debug.
2626

2727
`enable_eurolite_mk2 = {false,true}`
2828
Whether to enable detection of the Eurolite USB-DMX512 PRO MK2.
29-
Default = false. This device is indistinguishable from other devices
29+
Default = `false`. This device is indistinguishable from other devices
3030
with an FTDI chip, and is therefore disabled by default. When enabled,
3131
this plugin will conflict with the usbserial, StageProfi and FTDI USB DMX
32-
plugins.
32+
plugins. If this is undesirable, the `eurolite_mk2_serial` setting can be
33+
used instead, which manually marks a specific USB device as a Eurolite
34+
USB-DMX512 PRO MK2.
3335

34-
`nodle-<serial>-mode = {0,1,2,3,4,5,6,7}`
36+
`eurolite_mk2_serial = <serial>`
37+
Claim the USB device with the given serial number as a Eurolite USB-DMX512
38+
PRO MK2 even when `enable_eurolite_mk2 = false`. This makes it possible
39+
to use the Eurolite USB-DMX512 PRO MK2 together with other devices that
40+
can not be distinguished otherwise. This setting has no effect when
41+
`enable_eurolite_mk2 = true` or if no device is connected with the given
42+
serial. The setting may be specified multiple times to use multiple Eurolite
43+
USB-DMX512 PRO MK2 devices.
44+
45+
`nodle-<serial>-mode = {0,1,2,3,4,5,6,7}`
3546
The mode for the Nodle U1 interface with serial number `<serial>` to operate
36-
in. Default = 6
37-
0 - Standby
38-
1 - DMX In -> DMX Out
39-
2 - PC Out -> DMX Out
40-
3 - DMX In + PC Out -> DMX Out
41-
4 - DMX In -> PC In
42-
5 - DMX In -> DMX Out & DMX In -> PC In
43-
6 - PC Out -> DMX Out & DMX In -> PC In
47+
in. Default = 6
48+
0 - Standby
49+
1 - DMX In -> DMX Out
50+
2 - PC Out -> DMX Out
51+
3 - DMX In + PC Out -> DMX Out
52+
4 - DMX In -> PC In
53+
5 - DMX In -> DMX Out & DMX In -> PC In
54+
6 - PC Out -> DMX Out & DMX In -> PC In
4455
7 - DMX In + PC Out -> DMX Out & DMX In -> PC In

plugins/usbdmx/UsbDmxPlugin.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ bool UsbDmxPlugin::SetDefaultPreferences() {
107107
BoolValidator(),
108108
false);
109109

110+
save |= m_preferences->SetDefaultValue(
111+
EuroliteProFactory::EUROLITE_MK2_SERIAL_KEY,
112+
StringValidator(),
113+
"");
114+
110115
if (save) {
111116
m_preferences->Save();
112117
}

0 commit comments

Comments
 (0)