add deep sleep mode
This commit is contained in:
@@ -35,3 +35,8 @@ void Display::print_weight(double val) {
|
|||||||
this->_display->printf("%.2f g", val);
|
this->_display->printf("%.2f g", val);
|
||||||
this->_display->refresh();
|
this->_display->refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Display::clear() {
|
||||||
|
this->_display->clearDisplay();
|
||||||
|
this->_display->refresh();
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
void setup();
|
void setup();
|
||||||
void print(const char* text);
|
void print(const char* text);
|
||||||
void print_weight(double weight);
|
void print_weight(double weight);
|
||||||
|
void clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
#ifndef ENV
|
#ifndef ENV
|
||||||
#define ENV
|
#define ENV
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "driver/rtc_io.h"
|
||||||
|
|
||||||
#include <BLEDevice.h>
|
#include <BLEDevice.h>
|
||||||
#include <BLEUtils.h>
|
#include <BLEUtils.h>
|
||||||
#include <BLEScan.h>
|
#include <BLEScan.h>
|
||||||
@@ -9,6 +12,11 @@
|
|||||||
#include <Adafruit_GFX.h>
|
#include <Adafruit_GFX.h>
|
||||||
#include <Fonts/FreeSans9pt7b.h>
|
#include <Fonts/FreeSans9pt7b.h>
|
||||||
|
|
||||||
|
/********************* General ****************************/
|
||||||
|
#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO)
|
||||||
|
#define WAKEUP_GPIO GPIO_NUM_1
|
||||||
|
#define SLEEP_GPIO 1
|
||||||
|
|
||||||
/********************* NAU7802 ****************************/
|
/********************* NAU7802 ****************************/
|
||||||
|
|
||||||
#define LDO NAU7802_3V3
|
#define LDO NAU7802_3V3
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ Display display;
|
|||||||
Adafruit_NAU7802 nau;
|
Adafruit_NAU7802 nau;
|
||||||
unsigned long _millis = 0;
|
unsigned long _millis = 0;
|
||||||
int32_t val = 0;
|
int32_t val = 0;
|
||||||
|
bool goToSleep = False;
|
||||||
#if BLE
|
#if BLE
|
||||||
BLEServer *pServer = NULL;
|
BLEServer *pServer = NULL;
|
||||||
BLECharacteristic *millisCharacteristic = NULL;
|
BLECharacteristic *millisCharacteristic = NULL;
|
||||||
@@ -26,10 +27,42 @@ int32_t val = 0;
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void print_wakeup_reason() {
|
||||||
|
esp_sleep_wakeup_cause_t wakeup_reason;
|
||||||
|
|
||||||
|
wakeup_reason = esp_sleep_get_wakeup_cause();
|
||||||
|
|
||||||
|
switch (wakeup_reason) {
|
||||||
|
case ESP_SLEEP_WAKEUP_EXT0: Serial.println("Wakeup caused by external signal using RTC_IO"); break;
|
||||||
|
case ESP_SLEEP_WAKEUP_EXT1: Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
|
||||||
|
case ESP_SLEEP_WAKEUP_TIMER: Serial.println("Wakeup caused by timer"); break;
|
||||||
|
case ESP_SLEEP_WAKEUP_TOUCHPAD: Serial.println("Wakeup caused by touchpad"); break;
|
||||||
|
case ESP_SLEEP_WAKEUP_ULP: Serial.println("Wakeup caused by ULP program"); break;
|
||||||
|
default: Serial.printf("Wakeup was not caused by deep sleep: %d\n", wakeup_reason); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void IRAM_ATTR startSleep() {
|
||||||
|
display.clear();
|
||||||
|
|
||||||
|
esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1);
|
||||||
|
|
||||||
|
rtc_gpio_pullup_dis(WAKEUP_GPIO);
|
||||||
|
rtc_gpio_pulldown_en(WAKEUP_GPIO);
|
||||||
|
|
||||||
|
esp_deep_sleep_start();
|
||||||
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
display.setup();
|
display.setup();
|
||||||
|
|
||||||
|
print_wakeup_reason();
|
||||||
|
|
||||||
|
/**** setup sleep interrupt ******/
|
||||||
|
pinMode(SLEEP_GPIO, INPUT);
|
||||||
|
attachInterrupt(digitalPinToInterrupt(SLEEP_GPIO), startSleep, FALLING);
|
||||||
|
|
||||||
if (! nau.begin()) {
|
if (! nau.begin()) {
|
||||||
Serial.println("Failed to find NAU7802");
|
Serial.println("Failed to find NAU7802");
|
||||||
while (1) delay(10); // Don't proceed.
|
while (1) delay(10); // Don't proceed.
|
||||||
Reference in New Issue
Block a user