diff --git a/config.ini b/config.ini index c8e382c..ac3ca14 100644 --- a/config.ini +++ b/config.ini @@ -26,3 +26,5 @@ build_flags = -D PIXEL_PIN=4 -D PIXEL_COUNT=24 + + -D RESET_TIME=60000 diff --git a/include/Program.h b/include/Program.h index c49730f..b34c4f1 100644 --- a/include/Program.h +++ b/include/Program.h @@ -40,6 +40,8 @@ private: WiFiUDP* ntpUDP; NTPClient* timeClient; + ulong lastMillis; + /** * @brief Send time to discord * the start time is automaticly set to the current time diff --git a/lib/LedLib/include/LedLib.h b/lib/LedLib/include/LedLib.h index 3d13b94..d26f0e5 100644 --- a/lib/LedLib/include/LedLib.h +++ b/lib/LedLib/include/LedLib.h @@ -11,7 +11,7 @@ public : // Fonction pour allumer correctement les LEDs en fonction du Rotary // Function to manage LEDs colors according to the Rotary - void actLed(int nb); + void actLed(int nb, int start = 0); // Fonction qui renvoie le nombre de LEDs allumées // Function that returns the number of LEDs lit diff --git a/lib/LedLib/scr/LedLib.cpp b/lib/LedLib/scr/LedLib.cpp index 05185b6..0663b14 100644 --- a/lib/LedLib/scr/LedLib.cpp +++ b/lib/LedLib/scr/LedLib.cpp @@ -13,7 +13,7 @@ LedLib::LedLib(int pixelCount, int pixelPin, int bright){ // Fonction pour allumer correctement les LEDs en fonction du Rotary // Function to manage LEDs colors according to the Rotary -void LedLib::actLed(int nb){ +void LedLib::actLed(int nb, int start){ this->ledNb = nb; // On éteint tout @@ -26,11 +26,11 @@ void LedLib::actLed(int nb){ // Boucle dans les LEDs // Loop in LEDs - for (int i = 0; i < nb+1; i++) { + for (int i = start; i < start+nb+1; i++) { // Une LED sur deux est blanche : heure entière, l'autre rouge pour 30m // One LED out of two is white: whole hour, the other red for 30m - if (i%2 == 0) { + if (i-start%2 == 0) { this->strip->setPixelColor(i-1, 255, 255, 255); }else{ this->strip->setPixelColor(i-1, 255, 0, 0); diff --git a/src/Program.cpp b/src/Program.cpp index 3d3e8f6..18ee093 100644 --- a/src/Program.cpp +++ b/src/Program.cpp @@ -44,6 +44,38 @@ void Program::sendTime(String timeEnd){ } void Program::loop() { + ulong currentMillis = millis(); + if (currentMillis + 1000 > this->lastMillis) { + this->lastMillis = currentMillis; + this->encoder->resetMenu(); + this->encoder->resetValue(); + this->ledLib->actLed(0); + } + if(this->encoder->update()){ + switch (this->encoder->getMenu()) { + case 1: + this->encoder->resetValue(); + this->timeClient->update(); + int day = this->timeClient->getDay(); + int hour = this->timeClient->getHours(); + int halfHourNb = hour > 12 ? hour - 12 : hour; + halfHourNb *= 2; + int minute = this->timeClient->getMinutes(); + if(minute > 30){ + halfHourNb++; + } + if(day == 2 || day == 5){ + //TODO: mettre l'heure d'envoie par defaut a 22h + } + int openTime = this->encoder->getValue(); + this->ledLib->actLed(openTime,halfHourNb); + break; + case 2: + this->encoder->resetValue(); + //this->sendTime(); + break; + } + } if(this->encoder->update()){ Serial.print(this->encoder->getValue()); this->ledLib->actLed(this->encoder->getValue());