Gestion de l'heure d'été

This commit is contained in:
Thierry Fleury
2025-07-15 21:55:22 +02:00
parent af9ccfc532
commit e92801abcb
3 changed files with 42 additions and 16 deletions

View File

@ -1,5 +1,7 @@
#include "Program.h"
#include <TimeLib.h>
#include <time.h>
#include <Timezone.h>
Program::Program() {
@ -28,9 +30,15 @@ Program::Program() {
this->discord = new DiscordAPI(DISCORD_HOOK);
// startup NTP
this->ntpUDP = new WiFiUDP();
this->timeClient = new NTPClient(*this->ntpUDP, "pool.ntp.org", 3600*1);//*2 = gnt+2
this->timeClient = new NTPClient(*this->ntpUDP, "pool.ntp.org");
this->timeClient->update();
// setup Timezone
TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120}; // Central European Summer Time
TimeChangeRule CET = {"CET ", Last, Sun, Oct, 3, 60}; // Central European Standard Time
this->timezone = new Timezone(CEST, CET);
// define local time
this->syncTime();
// Startup Rotary
this->encoder = new SwitchableEncodeur(ENCODER_DT, ENCODER_CLK, ENCODER_SWITCH, 3);
@ -44,9 +52,19 @@ Program::Program() {
this->resetMillis = 0;
}
void Program::sendTime(String timeEnd){
String start = (String)this->timeClient->getHours() + "h";
int startQuater = this->timeClient->getMinutes()/15;
void Program::syncTime() {
if (this->timeClient->update()) {
setTime(
this->timezone->toLocal(
this->timeClient->getEpochTime()
)
);
}
}
void Program::sendTime(String timeEnd) {
String start = (String)hour() + "h";
int startQuater = minute()/15;
if (startQuater != 0){
start += (String)(startQuater * 15);
}
@ -63,24 +81,23 @@ void Program::loop() {
break;
case MainMenu::GET_START_HOUR:{ // get NTP Hour
//TODO: géré heure d'été et d'hiver
this->timeClient->update();
int hour = this->timeClient->getHours();
int min = this->timeClient->getMinutes();
int day = this->timeClient->getDay();
if(hour >= 12){
hour -= 12;
this->syncTime();
int _hour = hour();
int _min = minute();
int _day = day();
if(_hour >= 12){
_hour -= 12;
this->pm = true;
}else{
this->pm = false;
}
this->nLedStart = hour*2;
if(min >= 30){
this->nLedStart = _hour*2;
if(_min >= 30){
this->nLedStart++;
}
this->menu=MainMenu::SELECT_END_HOUR;
this->resetMillis = millis();
if(day == 2 || day == 5){
if(_day == 2 || _day == 5){
this->encoder->setValue(21-this->nLedStart);
}else{
this->encoder->setValue(1);