pololu / vl53l0x-arduino

Pololu Arduino library for VL53L0X time-of-flight distance sensor
https://www.pololu.com/product/2490
Other
346 stars 162 forks source link

Make this library compatible with STM32Duino #24

Closed TiagoSeverino closed 2 years ago

kevin-pololu commented 6 years ago

I'm not sure why it would be necessary to cast the result of each calculation to an int before passing it to Wire.write() (which takes a uint8_t anyway). What happens when you try to run the code without your changes?

TiagoSeverino commented 6 years ago

When I compile, it throws an error: VL53L0X.cpp:305:36: error: call of overloaded 'write(long unsigned int)' is ambiguous.

I had to cast all values to make it work. I guess my compiler assumes the result of the bitwise operation is an uint32_t.

I'm using PlatformIO in Visual Studio Code, with STM32Duino on a STM32F103C8T6.

kevin-pololu commented 2 years ago

Sorry, seems like we forgot about this back then. I just released an update that should fix this issue using a slightly different method (casting to uint8_t instead of int). Thanks for bringing it to our attention and submitting a pull request though.

For some background, we now understand the issue is due to some platform definitions having multiple (unnecessary?) overloads of the Wire.write() function that take different types (such as uint8_t and int), and when we try to call it with something that doesn't exactly match one of those types (in this case a long unsigned int), the compiler doesn't know which overload to use. So the best thing to do seems to be explicitly casting the argument to uint8_t since write() only operates with one byte at a time anyway.