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
4749const char EuroliteProFactory::ENABLE_EUROLITE_MK2_KEY[] =
4850 " enable_eurolite_mk2" ;
51+ const char EuroliteProFactory::EUROLITE_MK2_SERIAL_KEY[] =
52+ " eurolite_mk2_serial" ;
4953
5054EuroliteProFactory::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
5781bool 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 {
0 commit comments