[m] Fixed & Cleanup & env.h

This commit is contained in:
choelzl 2022-05-03 20:07:39 +02:00
parent 97b0351761
commit 65e6d883d4
Signed by: sora
GPG Key ID: A362EA0491E2EEA0
6 changed files with 59 additions and 16 deletions

24
env.h.default Normal file
View File

@ -0,0 +1,24 @@
#ifndef TG_ENV_H
#define TG_ENV_H
#define INFLUXDB_URL "https://influx.net"
#define INFLUXDB_TOKEN "LONG_TOKEN=="
#define INFLUXDB_ORG "ORG"
#define INFLUXDB_BUCKET "BUCKET"
#define NTP_URL "ch.pool.ntp.org"
#define LOCATION_0 "Zurich,ch"
#define LOCATION_1 "Oslo,no"
#define LOCATION_2 "Tokyo,jp"
#define LOCATION_3 "Moscow,ru"
#define OPENWEATHER_API "API_KEY"
#define WIFI_REGISTER_AP(wm) \
do { \
wifiMulti.addAP("SSID1", "PASS1"); \
wifiMulti.addAP("SSID2", "PASS2"); \
}while(0)
#endif

View File

@ -150,11 +150,12 @@ void setup_TIMEDFUN() {
}
void setup_POWER() {
esp_sleep_enable_gpio_wakeup();
gpio_wakeup_enable(GPIO_NUM_15,GPIO_INTR_HIGH_LEVEL);
// esp_sleep_enable_ext0_wakeup(GPIO_NUM_15, 1);
esp_sleep_enable_gpio_wakeup();
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
esp_sleep_pd_config(ESP_PD_DOMAIN_VDDSDIO,ESP_PD_OPTION_ON);
// esp_sleep_enable_ext0_wakeup(GPIO_NUM_15, 1);
// esp_sleep_pd_config(ESP_PD_DOMAIN_VDDSDIO,ESP_PD_OPTION_ON);
}
@ -162,11 +163,11 @@ void setup_POWER() {
void setup(){
Serial.begin(115200);
I2C.begin(PIN_SDA, PIN_SCL);
I2C.setPins(PIN_SDA,PIN_SCL);
setup_POWER();
Display::setup();
setup_WIFI();
ntp->updateNTPtime();
setup_TOUCH();
setup_TIMER();
setup_TIMEDFUN();
@ -208,14 +209,18 @@ void loop(){
delay(500);
if(shutdownc >= 3){
Display::clearTime();
EPD_2IN13_V2_Sleep();
Serial.println("Shuting down");
strDateTime odt = (ntp->dt);
vTaskDelay(2000);
// touch->Reset();
while(touch->dev.holding || touch->dev.pressing){
touch->update();
delay(100);
}
delay(500);
touch->update();
vTaskDelay(500);
esp_light_sleep_start();
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);

View File

@ -13,7 +13,7 @@ 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);
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - Font16.Height,"WESP-v0.1", &Font16, WHITE, BLACK);
}
void Display::setup(){
@ -31,10 +31,14 @@ void Display::setup(){
EPD_2IN13_V2_DisplayPart(BlackImage);
}
void Display::clearTime(){
Paint_ClearWindows(170, EPD_2IN13_V2_WIDTH - Font24.Height+2, 170 + Font24.Width * 4.5, EPD_2IN13_V2_WIDTH, WHITE);
}
void Display::drawTime(strDateTime* dt){
Paint_ClearWindows(170, EPD_2IN13_V2_WIDTH - Font24.Height+2, 170 + Font24.Width * 4.5, EPD_2IN13_V2_WIDTH, WHITE);
clearTime();
if (!dt->valid) return;
Paint_DrawTime(170, 98, dt, &Font24, WHITE, BLACK);
Paint_DrawTime(170, EPD_2IN13_V2_WIDTH - Font24.Height+2, dt, &Font24, WHITE, BLACK);
EPD_2IN13_V2_DisplayPart(BlackImage);
};
@ -92,7 +96,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 - 2 - Font16.Height,weather_0["main"], &Font16, WHITE, BLACK);
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 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);
@ -111,7 +115,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 - 2 - Font16.Height,"Nominal", &Font16, WHITE, BLACK);
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - Font16.Height,"Nominal", &Font16, WHITE, BLACK);
}
void AirDisplay::drawDisplay() {
@ -134,7 +138,7 @@ void AirDisplay::drawDisplay() {
// particles_50um, ///< 5.0um Particle Count
// particles_100um; ///< 10.0um Particle Count
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 2 - Font16.Height,"Nominal", &Font16, WHITE, BLACK);
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - Font16.Height,"Nominal", &Font16, WHITE, BLACK);
}
@ -147,7 +151,7 @@ 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 - 2 - Font16.Height,"Nominal", &Font16, WHITE, BLACK);
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - Font16.Height,"Nominal", &Font16, WHITE, BLACK);
}

View File

@ -24,6 +24,7 @@ class DisplayWrapper {
class Display {
public:
static void setup();
static void clearTime();
static void drawTime(strDateTime* dt);
static void refresh();
static void update();

View File

@ -1,5 +1,7 @@
#include "ntp.h"
#include <Arduino.h>
#define LEAP_YEAR(Y) ( ((1970+Y)>0) && !((1970+Y)%4) && ( ((1970+Y)%100) || !((1970+Y)%400) ) )
#define SEC_TO_MS 1000
@ -167,6 +169,8 @@ unsigned long NTPtime::adjustTimeZone(unsigned long _timeStamp, float _timeZone,
strDateTime NTPtime::getNTPtime(float _timeZone, boolean _DayLightSaving) {
Serial.println("NTP: Updating Time");
int cb;
strDateTime _dateTime;
unsigned long _unixTime = 0;
@ -175,6 +179,8 @@ strDateTime NTPtime::getNTPtime(float _timeZone, boolean _DayLightSaving) {
if (_sendPhase) {
if (_sentTime && ((millis() - _sentTime) < _sendInterval)) {
Serial.println("NTP: Too Fast");
return _dateTime;
}
@ -221,6 +227,8 @@ strDateTime NTPtime::getNTPtime(float _timeZone, boolean _DayLightSaving) {
}
}
Serial.println("NTP: OK");
return _dateTime;
}

View File

@ -84,6 +84,7 @@ void GT1151::update() {
uint8_t irq = gtIRQ;
gtIRQ = 0;
interrupts();
// Serial.printf("IRQ: %d\n",irq);
if (irq) onIRQ();
else dev.pressing = false;
}