-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Describe the problem
For the convenience of the user, the library defines a global LTR381RGBClass instance:
Arduino_LTR381RGB/src/LTR381RGB.cpp
Line 578 in 1994245
| LTR381RGBClass RGB(Wire1, LTR381RGB_ADDRESS); |
This definition makes the unwarranted assumption that a Wire1 object will always be defined.
🐛 The library (and even more impactful, the Arduino_Modulino library) fails to compile for any board for which a Wire1 object is not defined.
To reproduce
- Create a sketch with the following content:
#include <Arduino_LTR381RGB.h> void setup() {} void loop() {}
- Select Tools > Board > Arduino SAMD Boards (32-bits ARM Cortex-M0+) > Arduino Nano 33 IoT from the Arduino IDE menus.
ⓘ Nano 33 IoT was chosen arbitrarily for the purposes of the demo. Note that this board is included in the Modulino Light compatibility list. - Select Sketch > Verify/Compile from the Arduino IDE menus.
🐛 Compilation fails:
c:\Users\per\Documents\Arduino\libraries\Arduino_LTR381RGB\src\LTR381RGB.cpp: At global scope:
c:\Users\per\Documents\Arduino\libraries\Arduino_LTR381RGB\src\LTR381RGB.cpp:578:20: error: 'Wire1' was not declared in this scope
LTR381RGBClass RGB(Wire1, LTR381RGB_ADDRESS);
^~~~~
c:\Users\per\Documents\Arduino\libraries\Arduino_LTR381RGB\src\LTR381RGB.cpp:578:20: note: suggested alternative: 'Wire'
LTR381RGBClass RGB(Wire1, LTR381RGB_ADDRESS);
^~~~~
Wire
Arduino_LTR381RGB version
Additional context
I noticed that, at least in some cores (I didn't do a comprehensive survey to determine how much consistency there is across the ecosystem as a whole), there is a WIRE_INTERFACES_COUNT macro:
https://github.com/arduino/ArduinoCore-samd/blob/v1.6.1/variants/arduino_zero/variant.h#L141
This might be used to determine the correct object to use in the global LTR381RGBClass instance:
#if defined(WIRE_INTERFACES_COUNT)
#if WIRE_INTERFACES_COUNT == 1
LTR381RGBClass RGB(Wire, LTR381RGB_ADDRESS);
#else // WIRE_INTERFACES_COUNT == 1
LTR381RGBClass RGB(Wire1, LTR381RGB_ADDRESS);
#endif // WIRE_INTERFACES_COUNT == 1
#endif // defined(WIRE_INTERFACES_COUNT)Originally reported at https://forum.arduino.cc/t/arduino-moduilino-lib-examples-not-compiling/1419606