-
Notifications
You must be signed in to change notification settings - Fork 20
Bug: Incorrect bit operation #9
Copy link
Copy link
Open
Description
The spad map calculation is incorrect.
spads_enabled = 0
for i in range(48):
if i < 12 and is_aperture or spads_enabled >= spad_count:
spad_map[i // 8] &= ~(1 << (i >> 2))
elif spad_map[i // 8] & (1 << (i >> 2)):
spads_enabled += 1
https://github.com/uceeatz/VL53L0X/blob/master/VL53L0X.py#L206
Why? It's easy to see:
When i = 0, i >> 2 is 0
When i = 1, i >> 2 is 0
When i = 2, i >> 2 is 0
When i = 3, i >> 2 is 0
When i = 4, i >> 2 is 1
Corrected version should be something like this:
first_spad_to_enable = 12 if spad_is_aperture else 0
spads_enabled = 0
for i in range(48):
if i < first_spad_to_enable or spads_enabled == spad_count:
ref_spad_map[(i // 8)] &= ~(1 << (i % 8)) # zero this bit.
elif (ref_spad_map[(i // 8)] >> (i % 8)) & 0x1 > 0:
spads_enabled += 1
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels