[WIP] Sleep

This commit is contained in:
2022-05-03 17:32:27 +02:00
parent a3f967e747
commit 97b0351761
9 changed files with 111 additions and 88 deletions

View File

@@ -8,28 +8,31 @@ static int8_t view_count = -1;
static int8_t view_curr = 0;
static DisplayWrapper** views = 0;
void DrawMain(bool v){
Paint_DrawIcon(89,36, ICON_LOGO, &FontIcon, BLACK, WHITE);
Paint_DrawString_EN(29, 0, "Helcel", &Font45, WHITE, BLACK);
if(v)
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 2 - Font16.Height,"WESP-v0.1", &Font16, WHITE, BLACK);
}
void Display::setup(){
DEV_Module_Init();
EPD_2IN13_V2_Init(EPD_2IN13_V2_FULL);
EPD_2IN13_V2_Clear();
delay(100);
// 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;
if ((BlackImage = (uint8_t *)malloc(Imagesize)) == NULL) exit(1);
Paint_NewImage(BlackImage, EPD_2IN13_V2_WIDTH, EPD_2IN13_V2_HEIGHT, 270, WHITE);
Paint_SelectImage(BlackImage);
Paint_SetMirroring(MIRROR_HORIZONTAL);
Paint_Clear(WHITE);
Paint_DrawIcon(89,36, ICON_LOGO, &FontIcon, BLACK, WHITE);
Paint_DrawString_EN(29, 0, "Helcel", &Font45, WHITE, BLACK);
Paint_SelectImage(BlackImage);
EPD_2IN13_V2_Display(BlackImage);
delay(100);
refresh();
DrawMain(false);
EPD_2IN13_V2_DisplayPart(BlackImage);
}
void Display::drawTime(strDateTime* dt){
Paint_ClearWindows(170, EPD_2IN13_V2_WIDTH - Font24.Height, 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);
if (!dt->valid) return;
Paint_DrawTime(170, 98, dt, &Font24, WHITE, BLACK);
EPD_2IN13_V2_DisplayPart(BlackImage);
@@ -89,7 +92,7 @@ void WeatherDisplay::drawDisplay() {
JsonObject weather_sys = cowm->weather["sys"];
if(!weather_0 || !weather_main || !weather_sys || !weather_wind) return;
Paint_DrawIcon(0,8, getWeatherIcon(weather_0["id"]), &FontIcon, BLACK, WHITE);
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 4 - Font16.Height,weather_0["description"], &Font16, WHITE, BLACK);
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 2 - Font16.Height,weather_0["main"], &Font16, WHITE, BLACK);
Paint_DrawFltUnit(76,0,weather_main["temp"], "C", &Font24, BLACK, WHITE);
Paint_DrawFltUnit(186,6,weather_main["feels_like"], "C", &Font12, BLACK, WHITE);
Paint_DrawIntUnit(76,24,weather_main["pressure"], "hPa", &Font24, BLACK, WHITE);
@@ -108,7 +111,7 @@ void TempDisplay::drawDisplay() {
Paint_DrawFltUnit(76,24,sensor->pres, "hPa", &Font24, BLACK, WHITE);
Paint_DrawFltUnit(76,48,sensor->hum, "%", &Font24, BLACK, WHITE);
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 4 - Font16.Height,"nominal", &Font16, WHITE, BLACK);
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 2 - Font16.Height,"Nominal", &Font16, WHITE, BLACK);
}
void AirDisplay::drawDisplay() {
@@ -131,7 +134,7 @@ void AirDisplay::drawDisplay() {
// particles_50um, ///< 5.0um Particle Count
// particles_100um; ///< 10.0um Particle Count
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 4 - Font16.Height,"nominal", &Font16, WHITE, BLACK);
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 2 - Font16.Height,"Nominal", &Font16, WHITE, BLACK);
}
@@ -144,16 +147,14 @@ void LightDisplay::drawDisplay() {
Paint_DrawFltUnit(76,24*2,sensor->light, "l", &Font24, BLACK, WHITE);
Paint_DrawIntUnit(76,24*3,sensor->light_vis, "vl", &Font24, BLACK, WHITE);
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 4 - Font16.Height,"nominal", &Font16, WHITE, BLACK);
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 2 - Font16.Height,"Nominal", &Font16, WHITE, BLACK);
}
void MainDisplay::drawDisplay() {
Paint_DrawIcon(89,36, ICON_LOGO, &FontIcon, BLACK, WHITE);
Paint_DrawString_EN(29, 0, "Helcel", &Font45, WHITE, BLACK);
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 4 - Font16.Height,"WESP-v0.1", &Font16, WHITE, BLACK);
DrawMain(true);
}
void CustomDisplay::drawDisplay() {
Paint_DrawString_EN(60,0,"CUSTOM", &Font24, WHITE, BLACK);
}
}

View File

@@ -3,7 +3,6 @@
#define DEVICE "ESP32"
#include <Arduino.h>
#include <WiFi.h>
#include <InfluxDbClient.h>
@@ -61,7 +60,6 @@ class Influx {
}
void record(){
if(WiFi.status() != WL_CONNECTED) return;
uint8_t i = 0;
while(owm && owm[i] != NULL){
record_weather(owm[i]);
@@ -71,7 +69,6 @@ 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]);
@@ -83,7 +80,7 @@ class Influx {
void record_local(){
if(!sensor) return;
if(WiFi.status() != WL_CONNECTED) return;
Serial.println("InfluxDB: Uploading Local Data");
dp.clearFields();
dp.clearTags();
@@ -120,7 +117,8 @@ class Influx {
dp.addField("particles_50um", sensor->pmd.particles_50um);
dp.addField("particles_100um", sensor->pmd.particles_100um);
client.writePoint(dp);
client.writePoint(dp);
Serial.println("InfluxDB: OK");
}
void record_weather(){
@@ -129,8 +127,11 @@ class Influx {
void record_weather(OWM* owm){
if(!owm) return;
if(!owm->valid_weather) return;
if(WiFi.status() != WL_CONNECTED) return;
Serial.println("InfluxDB: Uploading OWM Data");
if(!owm->valid_weather) {
Serial.println("InfluxDB: Error, not valid weather");
return;
}
JsonObject weather_0 = owm->weather["weather"][0];
JsonObject weather_main = owm->weather["main"];
@@ -167,6 +168,7 @@ class Influx {
dp.addField("precipitation_snow_3h",weather_snow?float(weather_snow["3h"]):0.0);
client.writePoint(dp);
Serial.println("InfluxDB: OK");
}

View File

@@ -226,7 +226,6 @@ 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;
};

View File

@@ -2,7 +2,6 @@
#define NTPtime_h
#include <WiFiUdp.h>
#include <WiFi.h>
struct strDateTime {
byte hour;

View File

@@ -1,9 +1,9 @@
#ifndef OWM_H
#define OWM_H
#include <Arduino.h>
#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")
@@ -18,20 +18,24 @@ class OWM{
bool valid_weather = false;
bool update(){
if(WiFi.status() != WL_CONNECTED) return false;
Serial.println("OWWM: Updating Data");
String response = httpGETRequest(OPENWEATHER_URL(location,key).c_str());
DeserializationError error = deserializeJson(weather, response);
if (error) {
Serial.println("OWWM: Error, request or response invalid");
valid_weather = false;
return false;
}
if(weather["weather"]==NULL ||weather["main"]==NULL ||
weather["wind"]==NULL || weather["sys"]==NULL ){
Serial.println("OWWM: Error, missing fields");
valid_weather = false;
return false;
}
Serial.println("OWWM: OK");
valid_weather = true;
return true;
}

View File

@@ -3,7 +3,7 @@
#ifndef TG_TIMEDFUN_H
#define TG_TIMEDFUN_H
#include <map>
#include <vector>
#include <stdint.h>
#include <Arduino.h>
@@ -14,22 +14,27 @@ class TimedFun {
TimedFun(){};
void registerFun(timedfun_ptr p, uint64_t s){
funmap[p] = s;
funmap.push_back(std::pair<timedfun_ptr,uint64_t>(p,s));
};
void registerFunCond(timedfun_ptr p, uint64_t s){
funmap[p] = s;
funmap.push_back(std::pair<timedfun_ptr,uint64_t>(p,s));
};
void minuteTick(){
++counter;
}
void minuteTick(int64_t m){
counter += m;
}
void update(){
uint64_t ccounter = old_counter;
old_counter = counter;
for (const auto &e : funmap){
if((counter % e.second == 0) ||
((counter-old_counter) >= e.second) ||
((counter%e.second) < (old_counter%e.second))){
if( ((counter % e.second == 0) && (counter != ccounter)) ||
((counter-ccounter) >= e.second) || ((counter%e.second) < (ccounter%e.second))){
e.first();
}
}
@@ -37,15 +42,17 @@ class TimedFun {
};
void updateForce(){
Serial.println("TF: Force updating all");
for (const auto &e : funmap){
e.first();
}
Serial.println("TF: OK");
}
private:
uint64_t counter = 0;
uint64_t old_counter = 0;
std::map<timedfun_ptr,uint64_t> funmap;
std::vector<std::pair<timedfun_ptr,uint64_t>> funmap;
};

View File

@@ -56,7 +56,7 @@ int16_t GT1151::readInput(GTPoint* points) {
void GT1151::Reset(void){
pinMode(GT1151_INT_PIN, OUTPUT);
pinMode(GT1151_RESET_PIN, OUTPUT);
pinMode(GT1151_INT_PIN, INPUT);
digitalWrite(GT1151_RESET_PIN, HIGH);
delay(100);

View File

@@ -49,6 +49,7 @@ class GT1151{
void update(void);
void begin(void);
void Reset(void);
void Gesture(void);
void setHandler(void (*handler)(int8_t, GTPoint*));
@@ -56,7 +57,6 @@ class GT1151{
void (*touchHandler)(int8_t, GTPoint*);
TwoWire* wire;
void Reset(void);
void armIRQ(void);
void onIRQ(void);