mirror of
https://github.com/easychen/pushdeer.git
synced 2025-02-23 00:14:56 +08:00
添加时钟
This commit is contained in:
parent
082ed2d3d2
commit
331daec61a
@ -23,11 +23,13 @@ EspMQTTClient mclient(
|
|||||||
MQTT_CLIENT_NAME,
|
MQTT_CLIENT_NAME,
|
||||||
MQTT_PORT
|
MQTT_PORT
|
||||||
);
|
);
|
||||||
|
|
||||||
#include "cubic_12.h"
|
#include "cubic_12.h"
|
||||||
#include "SPI.h"
|
|
||||||
#include <TFT_eSPI.h>
|
#include <TFT_eSPI.h>
|
||||||
TFT_eSPI tft = TFT_eSPI();
|
TFT_eSPI tft = TFT_eSPI();
|
||||||
|
|
||||||
|
#include <NTPClient.h>
|
||||||
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
#include <ESP8266HTTPClient.h>
|
#include <ESP8266HTTPClient.h>
|
||||||
#define BEEP_PIN D8
|
#define BEEP_PIN D8
|
||||||
@ -42,13 +44,17 @@ TFT_eSPI tft = TFT_eSPI();
|
|||||||
|
|
||||||
#include <TJpg_Decoder.h>
|
#include <TJpg_Decoder.h>
|
||||||
|
|
||||||
|
#include <WiFiUdp.h>
|
||||||
|
WiFiUDP ntpUDP;
|
||||||
|
NTPClient timeClient(ntpUDP,"ntp1.aliyun.com",60*60*8,60000);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
mclient.enableDebuggingMessages();
|
mclient.enableDebuggingMessages();
|
||||||
|
|
||||||
|
|
||||||
tft.begin();
|
tft.begin();
|
||||||
// tft.setRotation(1); // 屏幕方向
|
// tft.setRotation(2); // 屏幕方向
|
||||||
tft.fillScreen(TFT_BLACK);
|
tft.fillScreen(TFT_BLACK);
|
||||||
tft.setTextColor(0xFFFF,0x0000);tft.setCursor(0, 0, 1);tft.setTextSize(TXT_SCALE);tft.println("Init ...");
|
tft.setTextColor(0xFFFF,0x0000);tft.setCursor(0, 0, 1);tft.setTextSize(TXT_SCALE);tft.println("Init ...");
|
||||||
Serial.println("tft init");
|
Serial.println("tft init");
|
||||||
@ -64,6 +70,7 @@ void setup() {
|
|||||||
TJpgDec.setCallback(tft_output);
|
TJpgDec.setCallback(tft_output);
|
||||||
|
|
||||||
Serial.println("TJpgDec init");
|
Serial.println("TJpgDec init");
|
||||||
|
timeClient.begin();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,6 +85,8 @@ void onConnectionEstablished()
|
|||||||
|
|
||||||
if (SPIFFS.exists(DOWNLOADED_IMG) == true) TJpgDec.drawFsJpg(0, 0, DOWNLOADED_IMG);
|
if (SPIFFS.exists(DOWNLOADED_IMG) == true) TJpgDec.drawFsJpg(0, 0, DOWNLOADED_IMG);
|
||||||
else tft.fillScreen( TFT_BLACK );
|
else tft.fillScreen( TFT_BLACK );
|
||||||
|
|
||||||
|
show_time(true);
|
||||||
|
|
||||||
#ifdef BEEP_PIN
|
#ifdef BEEP_PIN
|
||||||
if(payload.indexOf("♪") >= 0) tone(BEEP_PIN, 1000, 100);
|
if(payload.indexOf("♪") >= 0) tone(BEEP_PIN, 1000, 100);
|
||||||
@ -114,12 +123,42 @@ void onConnectionEstablished()
|
|||||||
bool ret = file_put_contents(payload, DOWNLOADED_IMG);
|
bool ret = file_put_contents(payload, DOWNLOADED_IMG);
|
||||||
if (SPIFFS.exists(DOWNLOADED_IMG) == true) {
|
if (SPIFFS.exists(DOWNLOADED_IMG) == true) {
|
||||||
TJpgDec.drawFsJpg(0, 0, DOWNLOADED_IMG);
|
TJpgDec.drawFsJpg(0, 0, DOWNLOADED_IMG);
|
||||||
|
show_time(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String lastTime = "2020";
|
||||||
|
String newTime = "";
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
mclient.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) {
|
bool file_put_contents(String url, String filename) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user