[M] Dropped Sleep for now (IRQ Isssues)

This commit is contained in:
choelzl 2022-05-04 15:10:06 +02:00
parent 01fcabdba0
commit f05b6492b0
Signed by: sora
GPG Key ID: A362EA0491E2EEA0
4 changed files with 34 additions and 91 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
env.h env.h
build/
.vscode/

View File

@ -1,44 +1,39 @@
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "env.h" #include "env.h"
#include "src/epd/epd_cfg.h"
#include "src/epd/epd_driver.h"
#include "src/epd/epd_paint.h"
#include "src/ntp/ntp.h"
#include "src/owm/owm.h"
#include "src/sensor/sensor.h"
#include "src/touch/gt1151.h"
#include "src/influxdb/influx.h"
#include "src/display/display.h"
#include "src/timedfun/timedfun.h"
#include <Arduino.h> #include <Arduino.h>
#include <Wire.h> #include <Wire.h>
#include <stdlib.h> #include <stdlib.h>
#include <WiFi.h> #include <WiFi.h>
#include <WiFiMulti.h> #include <WiFiMulti.h>
#include "src/epd/epd_cfg.h"
#include "src/epd/epd_driver.h"
#include "src/epd/epd_paint.h"
#include "src/ntp/ntp.h"
#include "src/owm/owm.h"
#include "src/sensor/sensor.h"
#include "src/touch/gt1151.h"
#include "src/influxdb/influx.h"
#include "src/display/display.h"
#include "src/timedfun/timedfun.h"
#define PIN_SDA 18 #define PIN_SDA 18
#define PIN_SCL 23 #define PIN_SCL 23
#define uS_TO_S_FACTOR 1000000 //Conversion factor for micro seconds to seconds #define uS_TO_S_FACTOR 1000000 //Conversion factor for micro seconds to seconds
#define TIME_TO_SLEEP (60*5) #define TIME_TO_SLEEP (60*5)
#define BUTTON_PIN_BITMASK 0x8000
/* Global Variables -----------------------------------------------------------*/ /* Global Variables -----------------------------------------------------------*/
static WiFiMulti wifiMulti; static WiFiMulti wifiMulti;
static TwoWire I2C = TwoWire(0); static TwoWire I2C = TwoWire(0);
TaskHandle_t task_measure; TaskHandle_t task_measure;
TaskHandle_t task_draw; TaskHandle_t task_draw;
TaskHandle_t task_touch; TaskHandle_t task_touch;
static NTPtime* ntp = new NTPtime(NTP_URL); static NTPtime* ntp = new NTPtime(NTP_URL);
static Sensor* sensor = new Sensor(&I2C); static Sensor* sensor = new Sensor(&I2C);
static GT1151* touch = new GT1151(&I2C); static GT1151* touch = new GT1151(&I2C);
@ -46,15 +41,10 @@ static OWM* owm[6] = {new OWM(LOCATION_0, OPENWEATHER_API),
new OWM(LOCATION_1, OPENWEATHER_API), new OWM(LOCATION_1, OPENWEATHER_API),
new OWM(LOCATION_2, OPENWEATHER_API), new OWM(LOCATION_2, OPENWEATHER_API),
NULL,NULL,NULL}; NULL,NULL,NULL};
static Influx* iflx = new Influx(NULL, owm);//TODO: Add sensor static Influx* iflx = new Influx(NULL, owm);//TODO: Add sensor
static TimedFun* tf = new TimedFun(); static TimedFun* tf = new TimedFun();
static bool time_update = true, view_update = true, view_refresh = false; static bool time_update = true, view_update = true, view_refresh = false;
static bool shutdownt = false;
static int shutdownc = 0;
static const int8_t views_size = 6; static const int8_t views_size = 6;
static DisplayWrapper* views[views_size] = { static DisplayWrapper* views[views_size] = {
@ -65,9 +55,6 @@ static DisplayWrapper* views[views_size] = {
new AirDisplay(sensor), new AirDisplay(sensor),
new LightDisplay(sensor), new LightDisplay(sensor),
}; };
/* IRQ ------------------------------------------------------------------------*/ /* IRQ ------------------------------------------------------------------------*/
hw_timer_t * timer = NULL; hw_timer_t * timer = NULL;
void IRAM_ATTR onSecondTimer() { void IRAM_ATTR onSecondTimer() {
@ -89,29 +76,16 @@ void IRAM_ATTR onSecondTimer() {
view_update = true; view_update = true;
time_update = true; time_update = true;
tf->minuteTick(); tf->minuteTick();
}
if(touch->dev.holding) shutdownc++;
else shutdownc = 0;
}
void IRAM_ATTR onTouch(int8_t contacts, GTPoint *points) {
if(touch->dev.holding){
// Serial.printf("Draging:\n");
// Serial.printf("C0: #0 %d,%d \n", touch->dev.dx, touch->dev.dy);
return;
} }
// Serial.printf("Contacts: %d\n", contacts); }
// for (uint8_t i = 0; i < contacts; i++) { void IRAM_ATTR onTouch(int8_t contacts, GTPoint *points) {
// Serial.printf("C%d: #%d %d,%d s:%d\n", i, points[i].id, points[i].x, points[i].y, points[i].a); if(touch->dev.holding) return;
// yield();
// }
if(points[0].y < 125) Display::nextView(); if(points[0].y < 125) Display::nextView();
else Display::prevView(); else Display::prevView();
view_update = true; view_update = true;
} }
/* Setup Functions -----------------------------------------------------------*/ /* Setup Functions -----------------------------------------------------------*/
void setup_TOUCH() { void setup_TOUCH() {
touch->setHandler(onTouch); touch->setHandler(onTouch);
touch->begin(); touch->begin();
@ -150,19 +124,14 @@ void setup_TIMEDFUN() {
} }
void setup_POWER() { void setup_POWER() {
gpio_wakeup_enable(GPIO_NUM_15,GPIO_INTR_HIGH_LEVEL);
esp_sleep_enable_gpio_wakeup();
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
// esp_sleep_enable_ext0_wakeup(GPIO_NUM_15, 1);
// esp_sleep_pd_config(ESP_PD_DOMAIN_VDDSDIO,ESP_PD_OPTION_ON);
} }
/* Setup Functions --------------------------------------------------------------*/ /* Setup Functions --------------------------------------------------------------*/
void setup(){ void setup(){
Serial.begin(115200); Serial.begin(115200);
I2C.begin(PIN_SDA, PIN_SCL); I2C.begin(PIN_SDA, PIN_SCL);
setup_POWER(); setup_POWER();
Display::setup(); Display::setup();
@ -174,9 +143,8 @@ void setup(){
iflx->check(); iflx->check();
Display::setViews(views,views_size); Display::setViews(views,views_size);
tf->updateForce(); tf->updateForce();
shutdownc = 0; tf->setTick(ntp->dt.minute);
xTaskCreatePinnedToCore( xTaskCreatePinnedToCore(
loop_MEASURE, "Task LMeasure", loop_MEASURE, "Task LMeasure",
@ -185,7 +153,6 @@ void setup(){
xTaskCreatePinnedToCore( xTaskCreatePinnedToCore(
loop_DRAW, "Task LDraw", loop_DRAW, "Task LDraw",
10000, NULL, 1, &task_draw, 1); 10000, NULL, 1, &task_draw, 1);
xTaskCreatePinnedToCore( xTaskCreatePinnedToCore(
loop_TOUCH, "Task LTouch", loop_TOUCH, "Task LTouch",
10000, NULL, 1, &task_touch, 1); 10000, NULL, 1, &task_touch, 1);
@ -193,44 +160,13 @@ void setup(){
Serial.println("Completed Setup"); Serial.println("Completed Setup");
} }
/* The main loop -------------------------------------------------------------*/ /* The main loop -------------------------------------------------------------*/
void wakeup(){
view_refresh = true;
view_update = true;
time_update = true;
setup_WIFI();
ntp->updateNTPtime();
vTaskDelay(200);
shutdownc = 0;
}
void loop(){ void loop(){
delay(500); delay(5000);
if(shutdownc >= 3){
Display::clearTime();
EPD_2IN13_V2_Sleep();
Serial.println("Shuting down");
while(touch->dev.holding || touch->dev.pressing){
touch->update();
delay(100);
}
delay(500);
touch->update();
strDateTime odt = (ntp->dt);
delay(2000);
esp_light_sleep_start();//IRQ Raised for some reason
Serial.println("Wakey Wakey");
wakeup();
tf->minuteTick(ntp->dt.minute - odt.minute);
}
} }
void loop_DRAW(void * pvParameters ){ void loop_DRAW(void * pvParameters ){
for(;;){ for(;;){
if(shutdownc >= 2){vTaskDelay(500);continue;}
if(view_refresh) Display::refresh(); if(view_refresh) Display::refresh();
if(view_update) Display::update(); if(view_update) Display::update();
if(time_update) Display::drawTime(&(ntp->dt)); if(time_update) Display::drawTime(&(ntp->dt));
@ -238,23 +174,24 @@ void loop_DRAW(void * pvParameters ){
view_refresh = false; view_refresh = false;
view_update = false; view_update = false;
time_update = false; time_update = false;
vTaskDelay(100); vTaskDelay(100);
} }
} }
void loop_TOUCH(void * pvParameters ){ void loop_TOUCH(void * pvParameters ){
for(;;){ for(;;){
if(shutdownc >= 2){vTaskDelay(500);continue;}
touch->update(); touch->update();
if(!touch->dev.holding) shutdownc = 0;
vTaskDelay(10); vTaskDelay(10);
} }
} }
void loop_MEASURE(void * pvParameters ){ void loop_MEASURE(void * pvParameters ){
for(;;){ for(;;){
if(shutdownc >= 2){vTaskDelay(500);continue;}
tf->update(); tf->update();
vTaskDelay(200); vTaskDelay(200);
} }
} }

View File

@ -18,8 +18,6 @@ void DrawMain(bool v){
void Display::setup(){ void Display::setup(){
DEV_Module_Init(); DEV_Module_Init();
// EPD_2IN13_V2_Init(EPD_2IN13_V2_FULL);
// EPD_2IN13_V2_Clear();
uint16_t Imagesize = ((EPD_2IN13_V2_WIDTH % 8 == 0) ? (EPD_2IN13_V2_WIDTH / 8 ) : (EPD_2IN13_V2_WIDTH / 8 + 1)) * EPD_2IN13_V2_HEIGHT; uint16_t Imagesize = ((EPD_2IN13_V2_WIDTH % 8 == 0) ? (EPD_2IN13_V2_WIDTH / 8 ) : (EPD_2IN13_V2_WIDTH / 8 + 1)) * EPD_2IN13_V2_HEIGHT;
if ((BlackImage = (uint8_t *)malloc(Imagesize)) == NULL) exit(1); if ((BlackImage = (uint8_t *)malloc(Imagesize)) == NULL) exit(1);
@ -33,6 +31,7 @@ void Display::setup(){
void Display::clearTime(){ void Display::clearTime(){
Paint_ClearWindows(170, EPD_2IN13_V2_WIDTH - Font24.Height+2, 170 + Font24.Width * 4.5, EPD_2IN13_V2_WIDTH, WHITE); Paint_ClearWindows(170, EPD_2IN13_V2_WIDTH - Font24.Height+2, 170 + Font24.Width * 4.5, EPD_2IN13_V2_WIDTH, WHITE);
EPD_2IN13_V2_DisplayPart(BlackImage);
} }
void Display::drawTime(strDateTime* dt){ void Display::drawTime(strDateTime* dt){

View File

@ -29,6 +29,11 @@ class TimedFun {
counter += m; counter += m;
} }
void setTick(int64_t m){
counter = m;
old_counter = m;
}
void update(){ void update(){
uint64_t ccounter = old_counter; uint64_t ccounter = old_counter;
old_counter = counter; old_counter = counter;