sparkfun / SparkFun_VL53L1X_Arduino_Library

A library for the laser based VL53L1X Time Of Flight distance sensor capable of detecting a target 4m away!
MIT License
88 stars 50 forks source link

Fix casting of registeraddress #36

Closed rneurink closed 4 years ago

rneurink commented 4 years ago

(uint8_t) RegisterAddr>>8 is not correct. This casts the Registeraddress to a uint8_t and shifts it to the right by 8 bits. The cast can be removed as it is unnecessary or put parentheses around the shift like this: (uint8_t) (RegisterAddr>>8)

nseidle commented 4 years ago

Good find! This fixes the getSensorID() issues that I was having.

This error never popped its head up because the vast majority of registers are 0x00FF or lower. There are only two above 0xFF: VL53L1_IDENTIFICATION__MODEL_ID and VL53L1_ROI_CONFIG__MODE_ROI_CENTRE_SPAD.

I've tested this PR against the model ID register and it fixes my read issue. I haven't tested against the ROI Config but I assume it was experiencing similar issues.