From 331daec61aec1255cfa21afba569778211cdaed3 Mon Sep 17 00:00:00 2001 From: Easy Date: Wed, 6 Apr 2022 13:02:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=B6=E9=92=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iot/deeresp/deeresp.ino | 43 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/iot/deeresp/deeresp.ino b/iot/deeresp/deeresp.ino index b8a6e51..8d20c02 100644 --- a/iot/deeresp/deeresp.ino +++ b/iot/deeresp/deeresp.ino @@ -23,11 +23,13 @@ EspMQTTClient mclient( MQTT_CLIENT_NAME, MQTT_PORT ); + #include "cubic_12.h" -#include "SPI.h" #include TFT_eSPI tft = TFT_eSPI(); +#include + #ifdef ESP8266 #include #define BEEP_PIN D8 @@ -42,13 +44,17 @@ TFT_eSPI tft = TFT_eSPI(); #include +#include +WiFiUDP ntpUDP; +NTPClient timeClient(ntpUDP,"ntp1.aliyun.com",60*60*8,60000); + void setup() { Serial.begin(115200); mclient.enableDebuggingMessages(); tft.begin(); - // tft.setRotation(1); // 屏幕方向 + // tft.setRotation(2); // 屏幕方向 tft.fillScreen(TFT_BLACK); tft.setTextColor(0xFFFF,0x0000);tft.setCursor(0, 0, 1);tft.setTextSize(TXT_SCALE);tft.println("Init ..."); Serial.println("tft init"); @@ -64,6 +70,7 @@ void setup() { TJpgDec.setCallback(tft_output); Serial.println("TJpgDec init"); + timeClient.begin(); } @@ -78,6 +85,8 @@ void onConnectionEstablished() if (SPIFFS.exists(DOWNLOADED_IMG) == true) TJpgDec.drawFsJpg(0, 0, DOWNLOADED_IMG); else tft.fillScreen( TFT_BLACK ); + + show_time(true); #ifdef BEEP_PIN if(payload.indexOf("♪") >= 0) tone(BEEP_PIN, 1000, 100); @@ -114,12 +123,42 @@ void onConnectionEstablished() bool ret = file_put_contents(payload, DOWNLOADED_IMG); if (SPIFFS.exists(DOWNLOADED_IMG) == true) { TJpgDec.drawFsJpg(0, 0, DOWNLOADED_IMG); + show_time(true); } }); } +String lastTime = "2020"; +String newTime = ""; + void loop() { mclient.loop(); + show_time(false); +} + +void show_time(bool force) +{ + timeClient.update(); + newTime = String(timeClient.getHours()) + ':' + String(timeClient.getMinutes()) ; + if( lastTime != newTime ) + { + echo_time( newTime ); + lastTime = newTime; + } + else + { + if( force ) echo_time( newTime ); + } +} + +void echo_time( String thetime ) +{ + tft.setCursor(96, 120, 1); + tft.setTextSize(1); + tft.setTextColor(TFT_WHITE,TFT_BLACK); + tft.println(thetime); + + tft.setTextSize(TXT_SCALE); } bool file_put_contents(String url, String filename) {