V2.19 230327 Sommerzeit stellt die Uhr jetzt auch vor (nicht zurück); neues SDK

This commit is contained in:
2023-03-27 17:12:19 +02:00
parent addcac6d6e
commit f521606f74
2 changed files with 73 additions and 118 deletions

View File

@@ -1,4 +1,4 @@
#define VERSION (char *) "V2.17"
#define VERSION (char *) "V2.19"
/*
V2.12 230205 neues SDK 8266; AP+Wifi Client; lokaleip eingebaut
@@ -7,6 +7,8 @@
V2.15 230212 Verbesserung AP_STA modus;Wlan auf 1 Connect beschränkt;
V2.16 230212 MaxConnect auf 2; Beacon auf 250ms
V2.17 230227 alle unbekannten Seiten Leiten auf die IP um
V2.18 230313 Sommerzeitprüfung auch offline eingebaut; Auf doRTCSecond umgebaut;
V2.19 230327 Sommerzeit stellt die Uhr jetzt auch vor (nicht zurück); neues SDK
*/
// Pins for LED MATRIX
@@ -71,7 +73,8 @@ char ChipID[10] = "ERROR";
#include <RV-3029-C2.h>
RV3029 rtc;
const int PINRTC_CLOCK = 12;
boolean rtcEnabled = false;
bool rtcEnabled = false;
bool doRTCSecond = false;
uint8_t temperature=0;
#include <TimeLib.h>
@@ -87,7 +90,8 @@ char ChipID[10] = "ERROR";
float brightness = 0.80;
int8_t lastminutes = -1;
boolean iDL = false;
bool iDL = false;
bool savediDL = false;
uint8_t lastTimeSyncTyp = 0;
long lastTimeSyncTime = 0;
@@ -111,35 +115,21 @@ void display_update_enable(bool is_enable){
display_ticker.detach();
}
//Led mit Helligkeit setzen
//Led setzen
void setPixelColor(uint8_t x,uint8_t y, uint8_t red, uint8_t green ,uint8_t blue){
/*red = ceil(red * brightness);
green = ceil(green * brightness);
blue = ceil(blue * brightness);*/
display.drawPixelRGB888(x, y, red, green, blue);
//
}
//Zeichene eine Linie waagrecht x/y und z als länge
void LineH(uint8_t x, uint8_t y, uint8_t z, uint8_t red, uint8_t green ,uint8_t blue){
uint16_t color = display.color565(red, green, blue);
display.drawFastHLine(x,y,z,color);
//display.display(display_draw_time);
/*for(uint8_t c = 0; c<z; c++){
setPixelColor(x+c,y, red, green, blue);
}*/
//display.display(display_draw_time);
}
//Zeichene eine Linie senkrecht x/y und z als länge
void LineV(uint8_t x, uint8_t y, uint8_t z, uint8_t red, uint8_t green, uint8_t blue){
uint16_t color = display.color565(red, green, blue);
display.drawFastVLine(x,y,z,color);
//display.display(display_draw_time);
/*for(uint8_t c = 0; c<z; c++){
setPixelColor(x,y+c, red, green, blue);
}*/
//display.display(display_draw_time);
}
//eigene Schriften
@@ -149,17 +139,9 @@ void LineV(uint8_t x, uint8_t y, uint8_t z, uint8_t red, uint8_t green, uint8_t
#include <char10x16.h>
void doClearLEDsSeconds(int8_t ycorrection=0){
for(uint8_t x=0;x<5;x++){
display.drawFastHLine(56,26 + x + ycorrection, 7, 0);
}
/*for(uint16_t x=56;x<MATRIX_WIDTH;x++){
for(uint16_t y=26;y<MATRIX_HEIGHT;y++){
display.drawPixelRGB888(x,y, 0, 0, 0);
//
}
//display.display(display_draw_time);
}*/
}
void doClearLEDsStatus(){
@@ -170,16 +152,6 @@ void doClearLEDsStatus(){
void doClearLEDs(boolean incFirstLine = false){
display.fillScreen(0);
/*if(incFirstLine)
display.clearDisplay();
else{
for(uint16_t x=0;x<MATRIX_WIDTH;x++){
for(uint16_t y=1;y<MATRIX_HEIGHT;y++){
display.drawPixelRGB888(x,y, 0, 0, 0);
}
//display.display(display_draw_time);
}
}*/
}
void showOVALZ(void){
@@ -212,22 +184,6 @@ void showNTOOLS(void){
spalte += Out5x7Char('e',spalte,zeile,0,0,255)+1;
}
void show3x5(uint8_t x, uint8_t y, char text[] , uint8_t red, uint8_t green, uint8_t blue){
uint8_t textlen = strlen(text);
for(uint8_t b=0;b<textlen;b++){
x += Out3x5Char(text[b],x,y,red,green,blue)+1;
}
}
void show5x7(uint8_t x, uint8_t y, char text[] , uint8_t red, uint8_t green, uint8_t blue){
uint8_t textlen = strlen(text);
for(uint8_t b=0;b<textlen;b++){
x += Out5x7Char(text[b],x,y,red,green,blue)+1;
}
}
uint8_t drawTactical(time_t t,uint8_t x = 0, uint8_t y = 0 ){
uint8_t r = tacticalTimeColor[0];
uint8_t g = tacticalTimeColor[1];
@@ -388,12 +344,6 @@ void showTimeTactical(time_t t){
void showTime(time_t t){
uint16_t tmp = 0;
uint8_t x = 0;
uint8_t y = 0;
uint8_t r = timeColor[0];
uint8_t g = timeColor[1];
uint8_t b = timeColor[2];
tmp = minute(t);
if(lastminutes != tmp){
@@ -494,9 +444,6 @@ uint16_t ACcolor = display.color565(255, 255, 255);
uint16_t ACcolorBlk = display.color565(0, 0, 0);
void drawAnalogSecond(int second){
//uint y = ((clock_radius-1)*cos(PI -(2*PI )/60*second))+clock_center_y;
//uint x = ((clock_radius-1)*sin(PI -(2*PI )/60*second))+clock_center_x;
//display.drawCircle(x, y, 1, 0x0ff000);
uint y = ((clock_radius)*cos(PI-(2*PI)/60*second))+clock_center_y;
uint x = ((clock_radius)*sin(PI-(2*PI)/60*second))+clock_center_x;
display.drawLine(clock_center_x,clock_center_y,x,y,display.color565(255, 0, 0));
@@ -512,18 +459,13 @@ void drawAnalogHour(int hour, int minute){
uint y = ((clock_radius-4)*cos(PI-(2*PI)/12*hour-(2*PI)/720*minute))+clock_center_y;
uint x = ((clock_radius-4)*sin(PI-(2*PI)/12*hour-(2*PI)/720*minute))+clock_center_x;
//uint y1 = ((clock_radius-4)*cos(PI-(2*PI)/12*hour-(2*PI)/720*minute))+clock_center_y+1;
//uint x1 = ((clock_radius-4)*sin(PI-(2*PI)/12*hour-(2*PI)/720*minute))+clock_center_x+1;
uint y2 = ((clock_radius-4)*cos(PI-(2*PI)/12*hour-(2*PI)/720*minute))+clock_center_y-1;
uint x2 = ((clock_radius-4)*sin(PI-(2*PI)/12*hour-(2*PI)/720*minute))+clock_center_x-1;
display.drawLine(clock_center_x,clock_center_y,x,y,display.color565(88, 255, 0));
//display.drawLine(clock_center_x+1,clock_center_y+1,x1,y1,display.color565(88, 255, 0));
display.drawLine(clock_center_x-1,clock_center_y-1,x2,y2,display.color565(88, 255, 0));
}
void drawAnalogFace(void){
// draw the center of the clock
//display.drawCircle(clock_center_x, clock_center_y,3, ACcolor);
display.fillCircle(clock_center_x, clock_center_y,2, ACcolor);
// draw hour pointers around the face of a clock
@@ -641,10 +583,7 @@ void doSetTime(unsigned long t){
void IRAM_ATTR rtc_clock(){ //Interrupt vom RTC
if(digitalRead(PINRTC_CLOCK)){
ti_second = millis() - 1020;
//display.drawPixelRGB888(4,0,0,255,0);
}else{
//display.drawPixelRGB888(4,0,0,0,0);
doRTCSecond = true;
}
}
@@ -661,6 +600,33 @@ uint8_t isDayLight(uint8_t hour, uint8_t day, uint8_t wday, uint8_t month){
return 1;
}
uint8_t isDayLightEx(void){
long currentUNIXTime = now();
byte Month, Day, Hour, WDay;
Month = month(currentUNIXTime);
Day = day(currentUNIXTime);
Hour = hour(currentUNIXTime);
WDay = weekday();
return isDayLight(Hour,Day,WDay,Month);
}
void checkiDL(void){
iDL = isDayLightEx();
if(iDL != savediDL){
long currentUNIXTime = now();
if(iDL){
currentUNIXTime += (SECS_PER_HOUR);
}else{
currentUNIXTime -= (SECS_PER_HOUR);
}
setTime(currentUNIXTime);
doSetTime(currentUNIXTime);
savediDL = iDL;
EEPROM.put(10, savediDL);
EEPROM.commit();
}
}
//NTP Update auf ganz lange
uint32_t sntp_update_delay_MS_rfc_not_less_than_15000 (){
return 365 * 24 * 60 * 60 * 1000UL; // 365 Tage
@@ -688,6 +654,8 @@ void setup() {
if(brightness > 1.0)
brightness = 1.0;
EEPROM.get(10, savediDL);
timeColor[0] = EEPROM.read(11);
timeColor[1] = EEPROM.read(12);
timeColor[2] = EEPROM.read(13);
@@ -709,7 +677,6 @@ void setup() {
EEPROM.get(151,appass);
display.begin(16);
//display.setBrightness(255);
display.setBrightness(ceil(255 * brightness));
display.setFastUpdate(true);
doClearLEDs(true);
@@ -719,7 +686,6 @@ void setup() {
display_update_enable(true);
Wire.begin(1,3);
//Wire.setClock(400000);
//RTC
if (rtc.begin() == false) {
display.drawPixelRGB888(0,0,255,0,0);
@@ -731,15 +697,7 @@ void setup() {
rtcEnabled = true;
pinMode(PINRTC_CLOCK, INPUT_PULLUP);
setTime(rtc.getUNIX());
long currentUNIXTime = now();
byte Month, Day, Hour, Minute, Second, WDay;
Month = month(currentUNIXTime);
Day = day(currentUNIXTime);
Hour = hour(currentUNIXTime);
Minute = minute(currentUNIXTime);
Second = second(currentUNIXTime);
WDay = weekday();
iDL = isDayLight(Hour,Day,WDay,Month);
checkiDL();
}
char NetName[30];
@@ -749,9 +707,7 @@ void setup() {
strcpy(APName, "NTUhr VPx ");
strcat(APName, ChipID);
WiFi.persistent(false);
WiFi.mode(WIFI_AP_STA);
WiFi.begin(ssid,pass);
WiFi.hostname(NetName);
int xc = 0;
@@ -791,21 +747,25 @@ void setup() {
}
if(timenow > SECS_YR_2000){
timenow += 1;
int Year;
byte Month, Day, Hour;
uint8_t Month, Day, Hour;
setTime(timenow);
Year = year(timenow);
Month = month(timenow);
Day = day(timenow);
Hour = hour(timenow);
if(isDayLight(Hour,Day,weekday(),Month))
iDL = isDayLight(Hour,Day,weekday(),Month);
if(iDL)
timenow += (SECS_PER_HOUR * 2);
else
timenow += (SECS_PER_HOUR);
setTime(timenow);
if(rtcEnabled){
doSetTime(timenow);
}
lastTimeSyncTyp = 2;
lastTimeSyncTime = timenow;
savediDL = iDL;
EEPROM.put(10, savediDL);
EEPROM.commit();
display.drawPixelRGB888(2,0,0,255,0);
display_doupdate();
}else{
@@ -829,7 +789,6 @@ void setup() {
delay(100);
WiFi.softAPConfig(ip_local, ip_gateway, ip_subnet);
//appass = ;
APEnabled = WiFi.softAP(APName, appass,2,0,2,250);
if(!APEnabled)
display.drawPixelRGB888(3,0,255,0,0);
@@ -843,13 +802,6 @@ void setup() {
display_doupdate();
//für die automatische Umleitung
/*webServer.on("/generate_204", HTTP_GET, [](AsyncWebServerRequest *request){html_root(request);}); //Android captive portal.
webServer.on("/fwlink", HTTP_GET, [](AsyncWebServerRequest *request){html_root(request);}); //Microsoft captive portal.
webServer.on("/connecttest.txt", HTTP_GET, [](AsyncWebServerRequest *request){html_root(request);}); //www.msftconnecttest.com
webServer.on("/hotspot-detect.html", HTTP_GET, [](AsyncWebServerRequest *request){html_root(request);}); //captive.apple.com
webServer.on("/success.txt", HTTP_GET, [](AsyncWebServerRequest *request){html_handle_success(request);}); //detectportal.firefox.com/sucess.txt
webServer.on("/redirect", HTTP_GET, [](AsyncWebServerRequest *request){html_root(request);}); //Microsoft captive portal.*/
webServer.onNotFound([](AsyncWebServerRequest *request){html_handle_notsuccess(request);});
//eigene Seiten
@@ -871,28 +823,22 @@ void setup() {
void loop(){
if (millis() - ti_second > 1000) {
ti_second = millis();
}
if(doRTCSecond){
doRTCSecond = false;
if((timeStatus() != timeNotSet)){
time_t currentUNIXTime = now();
if(rtcEnabled){
currentUNIXTime = rtc.getUNIX();
setTime(currentUNIXTime);
}
byte Month, Day, Hour, Minute, Second, WDay;
Month = month(currentUNIXTime);
Day = day(currentUNIXTime);
uint8_t Hour, Minute, Second, WDay;
Hour = hour(currentUNIXTime);
Minute = minute(currentUNIXTime);
Second = second(currentUNIXTime);
WDay = weekday();
if((isDayLight(Hour,Day,WDay,Month) != iDL) && (((Month == 10) & (Hour >= 3)) | (Month == 3))){
if(iDL){
doSetTime(currentUNIXTime - SECS_PER_HOUR);
}else{
doSetTime(currentUNIXTime + SECS_PER_HOUR);
}
iDL = isDayLight(Hour,Day,WDay,Month);
}
//Sonntag und NTP = Reset ..
checkiDL();
//Sonntag Reset ..
if((WDay == 1) && (Hour == 3) && (Minute == 1) && (Second == 0)){
ESP.restart();
}
@@ -922,8 +868,8 @@ void loop(){
}
rtc.getTEMPERATURE(&temperature);
}
dnsServer.processNextRequest();
//yield();
if(APEnabled)
dnsServer.processNextRequest();
}
//alles was WEB ist ...
@@ -1006,6 +952,9 @@ void html_poll(AsyncWebServerRequest *request) {
itoa(kw,tempBuff,DEC);
strcat(ret,(char *)",");
strcat(ret,tempBuff);
itoa(iDL,tempBuff,DEC);
strcat(ret,(char *)",");
strcat(ret,tempBuff);
strcat(ret,(char *)"]");
request->send(200, "text/plain", ret);
}
@@ -1021,6 +970,16 @@ void html_do(AsyncWebServerRequest *request) {
doSetTime(l_value);
lastTimeSyncTyp = 3;
lastTimeSyncTime = now();
//isDayLight (Sommerzeit) prüfen
uint8_t Month, Day, Hour;
setTime(l_value);
Month = month(l_value);
Day = day(l_value);
Hour = hour(l_value);
iDL = isDayLight(Hour,Day,weekday(),Month);
savediDL = iDL;
EEPROM.put(10, savediDL);
EEPROM.commit();
}else if(request->hasParam(PARAM_SHOWWHAT)) {
s_value = request->getParam(PARAM_SHOWWHAT)->value();
timeIndex = s_value.toInt();
@@ -1138,13 +1097,4 @@ char * html_processor(const String& var){
return localip;
}
return (char *) "not defined";
}
String toggleState(int toggle){
switch(toggle){
case 0:
break;
}
return "";
}