Gestion de l'heure d'été #10
@ -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,12 @@ private:
|
|||||||
LedLib* ledLib;
|
LedLib* ledLib;
|
||||||
WiFiUDP* ntpUDP;
|
WiFiUDP* ntpUDP;
|
||||||
NTPClient* timeClient;
|
NTPClient* timeClient;
|
||||||
|
Timezone* timezone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronize local using NTP client
|
||||||
|
*/
|
||||||
|
void syncTime();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send time to discord
|
* @brief Send time to discord
|
||||||
|
@ -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
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "Program.h"
|
#include "Program.h"
|
||||||
|
#include <TimeLib.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <Timezone.h>
|
||||||
|
|
||||||
Program::Program() {
|
Program::Program() {
|
||||||
|
|
||||||
@ -28,9 +30,15 @@ Program::Program() {
|
|||||||
this->discord = new DiscordAPI(DISCORD_HOOK);
|
this->discord = new DiscordAPI(DISCORD_HOOK);
|
||||||
// startup NTP
|
// startup NTP
|
||||||
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");
|
||||||
|
|
||||||
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
|
// Startup Rotary
|
||||||
this->encoder = new SwitchableEncodeur(ENCODER_DT, ENCODER_CLK, ENCODER_SWITCH, 3);
|
this->encoder = new SwitchableEncodeur(ENCODER_DT, ENCODER_CLK, ENCODER_SWITCH, 3);
|
||||||
@ -44,9 +52,19 @@ Program::Program() {
|
|||||||
this->resetMillis = 0;
|
this->resetMillis = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Program::sendTime(String timeEnd){
|
void Program::syncTime() {
|
||||||
String start = (String)this->timeClient->getHours() + "h";
|
if (this->timeClient->update()) {
|
||||||
int startQuater = this->timeClient->getMinutes()/15;
|
setTime(
|
||||||
|
this->timezone->toLocal(
|
||||||
|
this->timeClient->getEpochTime()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Program::sendTime(String timeEnd) {
|
||||||
|
String start = (String)hour() + "h";
|
||||||
|
int startQuater = minute()/15;
|
||||||
if (startQuater != 0){
|
if (startQuater != 0){
|
||||||
start += (String)(startQuater * 15);
|
start += (String)(startQuater * 15);
|
||||||
}
|
}
|
||||||
@ -63,24 +81,23 @@ 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
|
this->syncTime();
|
||||||
this->timeClient->update();
|
int _hour = hour();
|
||||||
int hour = this->timeClient->getHours();
|
int _min = minute();
|
||||||
int min = this->timeClient->getMinutes();
|
int _day = day();
|
||||||
int day = this->timeClient->getDay();
|
if(_hour >= 12){
|
||||||
if(hour >= 12){
|
_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);
|
||||||
|
Reference in New Issue
Block a user