Gestion de l'heure d'été

This commit is contained in:
Thierry Fleury
2025-07-15 21:55:22 +02:00
parent af9ccfc532
commit 41b2ecafed
3 changed files with 27 additions and 12 deletions

View File

@ -4,6 +4,7 @@
#include <Arduino.h> #include <Arduino.h>
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <NTPClient.h> #include <NTPClient.h>
#include <Timezone.h>
#include <WiFiUdp.h> #include <WiFiUdp.h>
#include "DiscordAPI.h" #include "DiscordAPI.h"
@ -44,6 +45,7 @@ private:
LedLib* ledLib; LedLib* ledLib;
WiFiUDP* ntpUDP; WiFiUDP* ntpUDP;
NTPClient* timeClient; NTPClient* timeClient;
Timezone* timezone;
/** /**
* @brief Send time to discord * @brief Send time to discord

View File

@ -54,6 +54,8 @@ lib_deps =
; erropix/ESP32 AnalogWrite@0.2 ; erropix/ESP32 AnalogWrite@0.2
adafruit/Adafruit NeoPixel@^1.11.0 adafruit/Adafruit NeoPixel@^1.11.0
arduino-libraries/NTPClient@^3.2.1 arduino-libraries/NTPClient@^3.2.1
paulstoffregen/Time @ ^1.6.1
jchristensen/Timezone@^1.2.5
; Checker settings ; Checker settings
check_tool = clangtidy, cppcheck check_tool = clangtidy, cppcheck

View File

@ -1,5 +1,7 @@
#include "Program.h" #include "Program.h"
#include <TimeLib.h>
#include <time.h>
#include <Timezone.h>
Program::Program() { Program::Program() {
@ -30,7 +32,14 @@ Program::Program() {
this->ntpUDP = new WiFiUDP(); 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", 3600*1);//*2 = gnt+2
this->timeClient->update(); if (this->timeClient->update()) {
setTime(this->timeClient->getEpochTime());
}
// 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);
// Startup Rotary // Startup Rotary
this->encoder = new SwitchableEncodeur(ENCODER_DT, ENCODER_CLK, ENCODER_SWITCH, 3); this->encoder = new SwitchableEncodeur(ENCODER_DT, ENCODER_CLK, ENCODER_SWITCH, 3);
@ -63,24 +72,26 @@ void Program::loop() {
break; break;
case MainMenu::GET_START_HOUR:{ // get NTP Hour case MainMenu::GET_START_HOUR:{ // get NTP Hour
//TODO: géré heure d'été et d'hiver if (this->timeClient->update()) {
this->timeClient->update(); setTime(this->timeClient->getEpochTime());
int hour = this->timeClient->getHours(); }
int min = this->timeClient->getMinutes(); time_t localNow = this->timezone->toLocal(now());
int day = this->timeClient->getDay(); int _hour = hour(localNow);
if(hour >= 12){ int _min = this->timeClient->getMinutes();
hour -= 12; int _day = this->timeClient->getDay();
if(_hour >= 12){
_hour -= 12;
this->pm = true; this->pm = true;
}else{ }else{
this->pm = false; this->pm = false;
} }
this->nLedStart = hour*2; this->nLedStart = _hour*2;
if(min >= 30){ if(_min >= 30){
this->nLedStart++; this->nLedStart++;
} }
this->menu=MainMenu::SELECT_END_HOUR; this->menu=MainMenu::SELECT_END_HOUR;
this->resetMillis = millis(); this->resetMillis = millis();
if(day == 2 || day == 5){ if(_day == 2 || _day == 5){
this->encoder->setValue(21-this->nLedStart); this->encoder->setValue(21-this->nLedStart);
}else{ }else{
this->encoder->setValue(1); this->encoder->setValue(1);