-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable deep sleep (standby) for VL53L0X #22441
Conversation
@@ -79,13 +79,17 @@ struct { | |||
uint16_t distance; | |||
uint16_t distance_prev; | |||
uint16_t buffer[5]; | |||
uint8_t ready = 0; | |||
bool ready = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
It doesn't save neither memory nor code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using integer implies integer values can occur. But this is clearly a true/false situation. There are some other bool variables in the code. Why do you see a difference here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are maximizing the use of "sized int" as much as possible because we control the implementation size.
With bool
I'm unsure if this is being implement as a single byte or as an int
which takes up 4 bytes and may be using more because of alignment.
Can you prove it's using only 1 byte ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally agree. Using uint8 is a common way to ensure that only 8 bits are used. To be sure, I checked if bool behaves the same way. And I can confirm it is also only 8 bits.
AddLog(LOG_LEVEL_DEBUG, PSTR("Size of uint8_t: %d"), sizeof(uint8_t));
AddLog(LOG_LEVEL_DEBUG, PSTR("Size of bool: %d"), sizeof(bool));
AddLog(LOG_LEVEL_DEBUG, PSTR("Size of variable 'ready': %d"), sizeof(Vl53l0x_data[i].ready));
Still 'bool' used. Please change as for the reason explained. |
bool is more clear and uses less flash - looks like bool wins?
bool uint8_t Probably because afaik in C/C++ integer calculations are done with the natural int of the platform, which may need extra instructions to expand the operands and shrink the results. |
* Enable deep sleep (standby) for VL53L0X * Some renamings
Description:
The VL53L0X sensor draws approx. 20 mA which is to much for battery driven applications. This change switched the sensor into the standby mode if deep sleep applies. This reduces the current down to some µAmps.
Related issue (if applicable): fixes # n.a.
Checklist:
NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass