Skip to content

Compilation fails for any board without Wire1 object #8

@per1234

Description

@per1234

Describe the problem

For the convenience of the user, the library defines a global LTR381RGBClass instance:

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

  1. Create a sketch with the following content:
    #include <Arduino_LTR381RGB.h>
    void setup() {}
    void loop() {}
  2. 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.
  3. 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

1994245

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: codeRelated to content of the project itselftype: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions