[WIP] Powermanagement
This commit is contained in:
parent
56fe0e50a1
commit
a3f967e747
49
metesp.ino
49
metesp.ino
@ -27,8 +27,12 @@
|
||||
#define PIN_SCL 23
|
||||
|
||||
|
||||
#define uS_TO_S_FACTOR 1000000 //Conversion factor for micro seconds to seconds
|
||||
#define TIME_TO_SLEEP (60*5)
|
||||
|
||||
/* Global Variables -----------------------------------------------------------*/
|
||||
|
||||
RTC_DATA_ATTR int bootCount = 0;
|
||||
|
||||
static WiFiMulti wifiMulti;
|
||||
static TwoWire I2C = TwoWire(0);
|
||||
@ -108,9 +112,6 @@ void IRAM_ATTR onTouch(int8_t contacts, GTPoint *points) {
|
||||
}
|
||||
|
||||
/* Setup Functions -----------------------------------------------------------*/
|
||||
void setup_EPD(){
|
||||
Display::setup();
|
||||
}
|
||||
|
||||
void setup_TOUCH() {
|
||||
touch->setHandler(onTouch);
|
||||
@ -147,23 +148,53 @@ void setup_TIMEDFUN() {
|
||||
REGISTER_TIMEDFUN_CALL(NTP_TF, 60);
|
||||
}
|
||||
|
||||
void setup_POWER() {
|
||||
esp_sleep_enable_ext0_wakeup(GPIO_NUM_15, 1);
|
||||
esp_sleep_enable_ext0_wakeup(GPIO_NUM_13, 1);
|
||||
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_VDDSDIO,ESP_PD_OPTION_ON);
|
||||
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Setup Functions --------------------------------------------------------------*/
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
|
||||
I2C.begin(PIN_SDA, PIN_SCL, 100000);
|
||||
I2C.begin(PIN_SDA, PIN_SCL);
|
||||
I2C.setPins(PIN_SDA,PIN_SCL);
|
||||
setup_EPD();
|
||||
|
||||
++bootCount;
|
||||
Serial.println("Boot number: " + String(bootCount));
|
||||
print_wakeup_reason();
|
||||
|
||||
Display::setup();
|
||||
setup_TOUCH();
|
||||
setup_WIFI();
|
||||
setup_TIMER();
|
||||
setup_TIMEDFUN();
|
||||
|
||||
iflx->check();
|
||||
Display::setViews(views,views_size);
|
||||
|
||||
|
||||
iflx->check();
|
||||
tf->updateForce();
|
||||
shutdownc = 0;
|
||||
|
||||
xTaskCreatePinnedToCore(
|
||||
loop_MEASURE, "Task LMeasure",
|
||||
@ -173,6 +204,7 @@ void setup(){
|
||||
loop_DRAW, "Task LDraw",
|
||||
10000, NULL, 1, &task_draw, 1);
|
||||
|
||||
Serial.println("Completed Setup");
|
||||
}
|
||||
|
||||
|
||||
@ -185,6 +217,7 @@ void loop_DRAW(void * pvParameters ){
|
||||
for(;;){
|
||||
touch->update();
|
||||
if(shutdownc >= 10){
|
||||
Serial.println("Shuting down");
|
||||
Display::refresh();
|
||||
EPD_2IN13_V2_Sleep();
|
||||
esp_deep_sleep_start();
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#define DEVICE "ESP32"
|
||||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
|
||||
#include <InfluxDbClient.h>
|
||||
@ -60,6 +61,7 @@ class Influx {
|
||||
}
|
||||
|
||||
void record(){
|
||||
if(WiFi.status() != WL_CONNECTED) return;
|
||||
uint8_t i = 0;
|
||||
while(owm && owm[i] != NULL){
|
||||
record_weather(owm[i]);
|
||||
@ -69,6 +71,7 @@ class Influx {
|
||||
}
|
||||
|
||||
void record(bool w, bool s){
|
||||
if(WiFi.status() != WL_CONNECTED) return;
|
||||
uint8_t i = 0;
|
||||
while(w && owm && owm[i] != NULL){
|
||||
record_weather(owm[i]);
|
||||
@ -80,6 +83,8 @@ class Influx {
|
||||
|
||||
void record_local(){
|
||||
if(!sensor) return;
|
||||
if(WiFi.status() != WL_CONNECTED) return;
|
||||
|
||||
dp.clearFields();
|
||||
dp.clearTags();
|
||||
dp.addTag("device", "WESP0");
|
||||
@ -125,6 +130,7 @@ class Influx {
|
||||
void record_weather(OWM* owm){
|
||||
if(!owm) return;
|
||||
if(!owm->valid_weather) return;
|
||||
if(WiFi.status() != WL_CONNECTED) return;
|
||||
|
||||
JsonObject weather_0 = owm->weather["weather"][0];
|
||||
JsonObject weather_main = owm->weather["main"];
|
||||
|
@ -226,6 +226,7 @@ strDateTime NTPtime::getNTPtime(float _timeZone, boolean _DayLightSaving) {
|
||||
|
||||
|
||||
void NTPtime::updateNTPtime(){
|
||||
if(WiFi.status() != WL_CONNECTED) return;
|
||||
strDateTime ndt = getNTPtime(1.0f, true);
|
||||
if(ndt.valid) dt = ndt;
|
||||
};
|
@ -2,6 +2,7 @@
|
||||
#define NTPtime_h
|
||||
|
||||
#include <WiFiUdp.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
struct strDateTime {
|
||||
byte hour;
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <HTTPClient.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
|
||||
#define OPENWEATHER_URL(loc, api) ("https://api.openweathermap.org/data/2.5/weather?q=" + loc + "&appid=" + api + "&units=metric")
|
||||
@ -17,6 +18,7 @@ class OWM{
|
||||
bool valid_weather = false;
|
||||
|
||||
bool update(){
|
||||
if(WiFi.status() != WL_CONNECTED) return false;
|
||||
String response = httpGETRequest(OPENWEATHER_URL(location,key).c_str());
|
||||
DeserializationError error = deserializeJson(weather, response);
|
||||
|
||||
|
@ -3,6 +3,9 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
#define SENSOR_DATA_LENGTH 32
|
||||
|
||||
/****************************************************************/
|
||||
bool PMSA003::Initialize(){
|
||||
bool success(true);
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#define PMSA003_ADDRESS (0x12)
|
||||
|
||||
#define SENSOR_DATA_LENGTH 32
|
||||
|
||||
typedef struct PMSAQIdata {
|
||||
uint16_t pm10_standard, ///< Standard PM1.0
|
||||
@ -95,7 +94,7 @@ private:
|
||||
bool ReadChipID();
|
||||
|
||||
bool ReadRegister(uint8_t addr,uint8_t data[],uint8_t length);
|
||||
bool ReadData(uint8_t data[SENSOR_DATA_LENGTH]);
|
||||
bool ReadData(uint8_t* data);
|
||||
|
||||
bool WriteSettings();
|
||||
bool WriteRegister(uint16_t addr,uint8_t data);
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "sgp40.h"
|
||||
|
||||
#define SENSOR_DATA_LENGTH 3
|
||||
|
||||
/****************************************************************/
|
||||
bool SGP40::Initialize(){
|
||||
|
@ -8,8 +8,6 @@
|
||||
|
||||
#define SGP40_ADDRESS (0x59)
|
||||
|
||||
#define SENSOR_DATA_LENGTH 3
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
/// SGP40 - Driver class for SGP40 sensor
|
||||
///
|
||||
@ -55,7 +53,7 @@ private:
|
||||
bool ReadChipID();
|
||||
|
||||
bool ReadRegister(uint8_t addr,uint8_t data[],uint8_t length);
|
||||
bool ReadData(uint8_t data[SENSOR_DATA_LENGTH], float RH, float T);
|
||||
bool ReadData(uint8_t* data, float RH, float T);
|
||||
|
||||
bool WriteSettings();
|
||||
bool WriteRegister(uint16_t addr,uint8_t data);
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "tsl25911.h"
|
||||
|
||||
|
||||
#define SENSOR_DATA_LENGTH 4
|
||||
|
||||
#define ENABLE_POWEROFF (0x00) ///< Flag for ENABLE register to disable
|
||||
#define ENABLE_POWERON (0x01) ///< Flag for ENABLE register to enable
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
#define TSL25911_ADDRESS (0x29)
|
||||
|
||||
#define SENSOR_DATA_LENGTH 4
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
/// TSL25911 - Driver class for TSL25911 sensor
|
||||
@ -111,7 +110,7 @@ private:
|
||||
bool ReadChipID();
|
||||
|
||||
bool ReadRegister(uint8_t addr,uint8_t data[],uint8_t length);
|
||||
bool ReadData(uint32_t data[SENSOR_DATA_LENGTH]);
|
||||
bool ReadData(uint32_t* data);
|
||||
|
||||
void WriteSettings();
|
||||
bool WriteRegister(uint8_t addr,uint8_t data);
|
||||
|
@ -1,8 +1,5 @@
|
||||
#include "gt1151.h"
|
||||
|
||||
#define GT1151_RESET_PIN 02
|
||||
#define GT1151_INT_PIN 15
|
||||
|
||||
|
||||
volatile uint8_t gtIRQ = 0;
|
||||
void IRAM_ATTR _gt_irq_handler() {
|
||||
|
@ -4,6 +4,12 @@
|
||||
#ifndef __GT1151_H
|
||||
#define __GT1151_H
|
||||
|
||||
|
||||
#define GT1151_RESET_PIN 02
|
||||
#define GT1151_INT_PIN 15 //RTC_GPIO13
|
||||
|
||||
|
||||
|
||||
#define GT1151_ADDRESS 0x14
|
||||
#define GT1151_ADDRESS_28 0x14
|
||||
#define GT1151_ADDRESS_BA 0x5D
|
||||
|
Loading…
x
Reference in New Issue
Block a user