Browse Source

Implement 1h auto shutdown if no input handling

master
Dashie der otter 8 months ago
parent
commit
fdde906766
Signed by: Dashie <dashie@sigpipe.me> GPG Key ID: C2D57B325840B755
4 changed files with 53 additions and 27 deletions
  1. 42
    24
      LightMeterV2/src/LightMeter.cpp
  2. 10
    1
      LightMeterV2/src/LightMeter.h
  3. 0
    1
      README.MD
  4. 1
    1
      USAGE.md

+ 42
- 24
LightMeterV2/src/LightMeter.cpp View File

@@ -25,6 +25,8 @@ void cfgPushButton(Bounce &bB) {
* Button down = next menu, up = previous menu
*/
void onButtonReleased(Button& btn, uint16_t duration) {
myLightMeter.lastActivity = millis(); // reset counter

Serial.println("button pressed");
// UP button
if (btn.is(uiPbUp)) {
@@ -62,25 +64,8 @@ void onButtonReleased(Button& btn, uint16_t duration) {
} else if (btn.is(uiPbEnter)) {
Serial.println("ENTER button pressed");
if (myLightMeter.state == MSystem) {
oled.clear(PAGE);
oled.setFontType(1);
oled.setCursor(6, 6);
oled.print("Power down.");
oled.display();
delay(1000);
myLightMeter.powerDown();
delay(4000);
myLightMeter.powerDown(false);

myLightMeter.ledStatus(LED_KO);
oled.clear(PAGE);
oled.setCursor(6, 6);
oled.print("Failed !");
oled.display();
delay(1000);

oled.setFontType(0);
oled.clear(PAGE);
oled.display();
myLightMeter.state = MSystemInit;
} else if (myLightMeter.state == MMary) {
if (myLightMeter.heartCount < 7) {
@@ -146,6 +131,10 @@ void setup() {
void loop() {
delay(10); // wait 10ms

if (millis() - myLightMeter.lastActivity > SLEEP_AFTER) {
myLightMeter.powerDown(true);
}

myLightMeter.process();
//Serial.println("loop");
}
@@ -190,13 +179,41 @@ void LightMeter::saveConfigUser() {
}

// Sleep time
void LightMeter::powerDown() {
// Last minute things
saveConfigUser();
delay(10);
void LightMeter::powerDown(bool autosleep) {
oled.clear(PAGE);
oled.setFontType(1);
oled.setCursor(6, 6);
if (autosleep) {
oled.print("Auto sleep zZz");
} else {
oled.print("Power down.");
}
oled.display();
delay(1000);

// Last minute things
saveConfigUser();
delay(10);

// Try to shutdown
digitalWrite(PIN_POWER_ON, LOW);
// Try to shutdown
digitalWrite(PIN_POWER_ON, LOW);

// Oops failed
lastActivity = millis(); // reset counter
delay(4000);

myLightMeter.ledStatus(LED_KO);
oled.clear(PAGE);
oled.setCursor(6, 6);
oled.print("Failed !");
oled.display();
delay(1000);

oled.setFontType(0);
oled.clear(PAGE);
oled.display();

myLightMeter.state = MSystemInit;
}

// state 0 OK, state 1 KO
@@ -641,6 +658,7 @@ void LightMeter::process(void) {

if (curEncoderPos != lastEncoderPos) {
// Encoder moved, set new position
myLightMeter.lastActivity = millis(); // reset counter
lastEncoderPos = curEncoderPos;
}


+ 10
- 1
LightMeterV2/src/LightMeter.h View File

@@ -64,6 +64,13 @@
#define PIN_LED_OK 11
#define PIN_LED_KO 10

/* Auto sleep after
* 3600000 = 1h
* 60000 = 1mn
* 1000 = 1sec
*/
#define SLEEP_AFTER 3600000

// Menu State
enum MState_t {
Minit, // Initial state page
@@ -157,7 +164,7 @@ class LightMeter {
public:
LightMeter(void);
void process();
void powerDown(void);
void powerDown(bool);
void ledStatus(int state);

bool lipoGood;
@@ -169,6 +176,8 @@ class LightMeter {
double lux;
uint8_t heartCount;

uint32_t lastActivity = 0;

MState_t state;
holdState_t triggerState;


+ 0
- 1
README.MD View File

@@ -44,7 +44,6 @@ The TSL2591 doesn't permit changing I2C address, you can only have one.

- Reducing enclosure thickness by around 5mm by trimming the teensyview pins and document the needed size
- Design some sort of sliding window to protect the sensor
- Power saving, shutdown after maybe 1h without use
- Test sensor overflow and alert
- Finish RED/GREEN led handling
- Games, because why not ?

+ 1
- 1
USAGE.md View File

@@ -8,7 +8,7 @@ The top button is the power-on, and previous-menu, the bottom one is next-menu.

To power-on the light meter, press the top button for a few seconds.

To power-down the light meter, go to the system menu and press the encoder.
To power-down the light meter, go to the system menu and press the encoder. An auto-power down is also implemented, if there is no knob or button handling in one hour, it will auto power-off to save battery life.

If charging, a small "plug" icon will appears on left of the battery indicator on top-right.


Loading…
Cancel
Save