Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
e92801abcb |
@ -4,6 +4,7 @@
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <NTPClient.h>
|
||||
#include <Timezone.h>
|
||||
#include <WiFiUdp.h>
|
||||
|
||||
#include "DiscordAPI.h"
|
||||
@ -44,6 +45,12 @@ private:
|
||||
LedLib* ledLib;
|
||||
WiFiUDP* ntpUDP;
|
||||
NTPClient* timeClient;
|
||||
Timezone* timezone;
|
||||
|
||||
/**
|
||||
* Synchronize local using NTP client
|
||||
*/
|
||||
void syncTime();
|
||||
|
||||
/**
|
||||
* @brief Send time to discord
|
||||
|
@ -54,6 +54,8 @@ lib_deps =
|
||||
; erropix/ESP32 AnalogWrite@0.2
|
||||
adafruit/Adafruit NeoPixel@^1.11.0
|
||||
arduino-libraries/NTPClient@^3.2.1
|
||||
paulstoffregen/Time @ ^1.6.1
|
||||
jchristensen/Timezone@^1.2.5
|
||||
|
||||
; Checker settings
|
||||
check_tool = clangtidy, cppcheck
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user