Skip to content
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

Merged
merged 2 commits into from
Nov 8, 2024

Conversation

AIexBV
Copy link
Contributor

@AIexBV AIexBV commented Nov 7, 2024

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:

  • The pull request is done against the latest development branch
  • Only relevant files were touched
  • Only one feature/fix was added per PR and the code change compiles without warnings
  • The code change is tested and works with Tasmota core ESP8266 V.2.7.8
  • The code change is tested and works with Tasmota core ESP32 V.3.1.0.241030
  • I accept the CLA.

NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass

@@ -79,13 +79,17 @@ struct {
uint16_t distance;
uint16_t distance_prev;
uint16_t buffer[5];
uint8_t ready = 0;
bool ready = false;
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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 ?

Copy link
Contributor Author

@AIexBV AIexBV Nov 8, 2024

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.

image

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));

tasmota/tasmota_xsns_sensor/xsns_45_vl53l0x.ino Outdated Show resolved Hide resolved
tasmota/tasmota_xsns_sensor/xsns_45_vl53l0x.ino Outdated Show resolved Hide resolved
@Jason2866
Copy link
Collaborator

Still 'bool' used. Please change as for the reason explained.

@joba-1
Copy link
Contributor

joba-1 commented Nov 8, 2024

bool is more clear and uses less flash - looks like bool wins?

#include <Arduino.h>

uint8_t f;  // or bool...

void setup() {
  f = true;
}

void loop() {
  if (f) {
    Serial.println("true");
  }
  else {
    Serial.println("false");
  }
  f = !f;
  delay(1000);
}

bool
RAM: [= ] 6.5% (used 21320 bytes from 327680 bytes)
Flash: [== ] 18.5% (used 242545 bytes from 1310720 bytes)

uint8_t
RAM: [= ] 6.5% (used 21320 bytes from 327680 bytes)
Flash: [== ] 18.5% (used 242549 bytes from 1310720 bytes)

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.
Anyways, being more specific generally helps compilers generate better code.

@arendst arendst merged commit feff388 into arendst:development Nov 8, 2024
59 checks passed
josef109 pushed a commit to josef109/Tasmota that referenced this pull request Nov 10, 2024
* Enable deep sleep (standby) for VL53L0X

* Some renamings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants