add ArduinoOTA handling, add correct local time and improve scrolling behavior
This commit is contained in:
parent
2f81453782
commit
95986805c9
|
|
@ -17,3 +17,6 @@ lib_deps =
|
|||
witnessmenow/UniversalTelegramBot @ ^1.3.0
|
||||
adafruit/Adafruit GFX Library @ 1.12.3
|
||||
build_flags=-DTELEGRAM_DEBUG
|
||||
; OTA update path: hostname is flipdottelegram.fritz.box
|
||||
upload_protocol = espota
|
||||
upload_port = 172.30.30.50
|
||||
|
|
|
|||
39
src/main.cpp
39
src/main.cpp
|
|
@ -36,7 +36,7 @@ void printOpen(String Args)
|
|||
|
||||
void printClose(String Args)
|
||||
{
|
||||
Text = "geschlossen";
|
||||
Text = "leider zu";
|
||||
}
|
||||
|
||||
void printText(String Args)
|
||||
|
|
@ -108,9 +108,12 @@ void setup()
|
|||
// attempt to connect to Wifi network:
|
||||
Serial.print("Connecting to Wifi SSID ");
|
||||
Serial.print(WIFI_SSID);
|
||||
WiFi.setHostname("flipdottelegram");
|
||||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
Serial.print("!");
|
||||
Serial.print(WiFi.status());
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
|
@ -119,7 +122,7 @@ void setup()
|
|||
|
||||
Serial.print("Retrieving time: ");
|
||||
configTime(0, 0, "pool.ntp.org"); // get UTC time via NTP
|
||||
// configTzTime("CET-1CEST,M3.5.0,M10.5.0/3", "pool.ntp.org");
|
||||
configTzTime("CET-1CEST,M3.5.0,M10.5.0/3", "pool.ntp.org");
|
||||
time_t now = time(nullptr);
|
||||
while (now < 24 * 3600)
|
||||
{
|
||||
|
|
@ -130,19 +133,34 @@ void setup()
|
|||
Serial.println(now);
|
||||
|
||||
|
||||
ArduinoOTA.setHostname("flipdottelegram");
|
||||
ArduinoOTA.begin();
|
||||
ArduinoOTA.onStart(onOTAStart);
|
||||
|
||||
tele.init();
|
||||
|
||||
printClose("");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
unsigned long now = millis();
|
||||
static unsigned long lastDisplayRefresh = now;
|
||||
static unsigned long lastTelegramRefresh = now;
|
||||
|
||||
ArduinoOTA.handle();
|
||||
|
||||
tele.cyclic(now);
|
||||
yield();
|
||||
|
||||
if ((now - lastDisplayRefresh) > 3000)
|
||||
if ((now - lastTelegramRefresh) > 5000)
|
||||
{
|
||||
lastTelegramRefresh = now;
|
||||
tele.cyclic(now);
|
||||
}
|
||||
|
||||
if ((now - lastDisplayRefresh) > 2000)
|
||||
{
|
||||
lastDisplayRefresh = now;
|
||||
//fill canvas with black pixels
|
||||
canvas.fillScreen(0);
|
||||
|
||||
|
|
@ -155,15 +173,19 @@ void loop()
|
|||
//get the substring ffor this iteration
|
||||
String SubText = Text.substring(offset, offset + MAX_CHAR_PER_LINE);
|
||||
|
||||
//increase the offset and reset it at the end of the scrol
|
||||
offset++;
|
||||
if (offset + MAX_CHAR_PER_LINE > TextLength)
|
||||
if (SubText.length() < MAX_CHAR_PER_LINE)
|
||||
{
|
||||
// if the text is the last line start over
|
||||
offset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//increase the offset and reset it at the end of the scrol
|
||||
offset += 4;
|
||||
}
|
||||
|
||||
//write substring to canvas
|
||||
displayText(SubText.c_str(), true, 15, 4);
|
||||
displayText(SubText.c_str(), true, 0, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -173,7 +195,6 @@ void loop()
|
|||
if(getLocalTime(&timeinfo))
|
||||
{
|
||||
strftime(buffer, 6, "%R", &timeinfo);
|
||||
return;
|
||||
}
|
||||
displayText(buffer, true, 0, 4);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user