Skip to content

Commit ebc5129

Browse files
committed
支持显示农历日期
1 parent 3d15dcd commit ebc5129

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

src/SmallDesktopDisplay.cpp

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ const int timeZone = 8; //东八区
171171
// wifi连接UDP设置参数
172172
WiFiUDP Udp;
173173
WiFiClient wificlient;
174+
#if SHOW_LUNAR
175+
WiFiClientSecure wifiClientSecure;
176+
#endif
174177
unsigned int localPort = 8000;
175178
float duty = 0;
176179

@@ -286,7 +289,7 @@ void humidityWin()
286289
clk.fillSprite(0x0000); //填充率
287290
clk.drawRoundRect(0, 0, 52, 6, 3, 0xFFFF); //空心圆角矩形 起始位x,y,长度,宽度,圆弧半径,颜色
288291
clk.fillRoundRect(1, 1, huminum, 4, 2, humicol); //实心圆角矩形
289-
clk.pushSprite(45, 222); //窗口位置
292+
clk.pushSprite(45, 192); //窗口位置
290293
clk.deleteSprite();
291294
}
292295

@@ -299,7 +302,7 @@ void tempWin()
299302
clk.fillSprite(0x0000); //填充率
300303
clk.drawRoundRect(0, 0, 52, 6, 3, 0xFFFF); //空心圆角矩形 起始位x,y,长度,宽度,圆弧半径,颜色
301304
clk.fillRoundRect(1, 1, tempnum, 4, 2, tempcol); //实心圆角矩形
302-
clk.pushSprite(45, 192); //窗口位置
305+
clk.pushSprite(45, 222); //窗口位置
303306
clk.deleteSprite();
304307
}
305308

@@ -462,8 +465,10 @@ void Serial_set()
462465
tft.fillScreen(0x0000);
463466
LCD_reflash(); //屏幕刷新程序
464467
UpdateWeater_en = 1;
465-
TJpgDec.drawJpg(15, 183, temperature, sizeof(temperature)); //温度图标
466-
TJpgDec.drawJpg(15, 213, humidity, sizeof(humidity)); //湿度图标
468+
TJpgDec.drawJpg(15, 213, temperature, sizeof(temperature)); // 温度图标
469+
#if !SHOW_LUNAR
470+
TJpgDec.drawJpg(15, 183, humidity, sizeof(humidity)); // 湿度图标
471+
#endif
467472

468473
Serial.print("屏幕方向设置为:");
469474
Serial.println(RoSet);
@@ -766,15 +771,16 @@ void saveParamCallback()
766771
}
767772
#endif
768773

769-
// 获取农历日期 FIXME 这里要么请求失败-1,如果成功则会报错重启
774+
#if SHOW_LUNAR
775+
String lunarDate;
776+
// 获取农历日期
770777
void getLunarDate()
771778
{
779+
wifiClientSecure.setInsecure();
772780
String URL = "https://api.zhangnew.com/v1/lunar";
773-
HTTPClient httpClient; // 创建 HTTPClient 对象
774-
std::unique_ptr<BearSSL::WiFiClientSecure> client(new BearSSL::WiFiClientSecure);
775-
client->setInsecure(); // 因为指纹会随着证书更新而变化,这里直接忽略掉吧
776-
httpClient.begin(*client, URL); // 使用新方法
777-
int httpCode = httpClient.GET(); // 启动连接并发送HTTP请求
781+
HTTPClient httpClient; // 创建 HTTPClient 对象
782+
httpClient.begin(wifiClientSecure, URL); // 使用新方法
783+
int httpCode = httpClient.GET(); // 启动连接并发送HTTP请求
778784
log("正在获取农历日期");
779785
//如果服务器响应OK则从服务器获取响应体信息并通过串口输出
780786
if (httpCode == HTTP_CODE_OK)
@@ -784,7 +790,7 @@ void getLunarDate()
784790
deserializeJson(doc, str);
785791
JsonObject sk = doc.as<JsonObject>();
786792

787-
String lunarDate = sk["月日"].as<String>();
793+
lunarDate = sk["月日"].as<String>();
788794
log("农历日期获取成功 " + lunarDate);
789795
}
790796
else
@@ -795,6 +801,7 @@ void getLunarDate()
795801
//关闭ESP8266与服务器连接
796802
httpClient.end();
797803
}
804+
#endif
798805

799806
// 发送HTTP请求并且将服务器响应通过串口输出
800807
void getCityCode()
@@ -920,7 +927,7 @@ void weaterData(String *cityDZ, String *dataSK, String *dataFC)
920927
clk.setTextDatum(CC_DATUM);
921928
clk.setTextColor(TFT_WHITE, bgColor);
922929
clk.drawString(sk["temp"].as<String>() + "", 28, 13);
923-
clk.pushSprite(100, 184);
930+
clk.pushSprite(100, 214);
924931
clk.deleteSprite();
925932
tempnum = sk["temp"].as<int>();
926933
tempnum = tempnum + 10;
@@ -948,9 +955,9 @@ void weaterData(String *cityDZ, String *dataSK, String *dataFC)
948955
clk.setTextColor(TFT_WHITE, bgColor);
949956
clk.drawString(sk["SD"].as<String>(), 28, 13);
950957
// clk.drawString("100%",28,13);
951-
clk.pushSprite(100, 214);
958+
clk.pushSprite(100, 184);
952959
clk.deleteSprite();
953-
// String A = sk["SD"].as<String>();
960+
#if !SHOW_LUNAR
954961
huminum = atoi((sk["SD"].as<String>()).substring(0, 2).c_str());
955962

956963
if (huminum > 90)
@@ -964,6 +971,7 @@ void weaterData(String *cityDZ, String *dataSK, String *dataFC)
964971
else
965972
humicol = 0xF00F;
966973
humidityWin();
974+
#endif
967975

968976
// 城市名称
969977
clk.createSprite(94, 30);
@@ -1164,6 +1172,17 @@ void digitalClockDisplay(int reflash_en = 0)
11641172
clk.pushSprite(5, 150);
11651173
clk.deleteSprite();
11661174

1175+
#if SHOW_LUNAR
1176+
// 农历月日
1177+
clk.createSprite(95, 30);
1178+
clk.fillSprite(bgColor);
1179+
clk.setTextDatum(CC_DATUM);
1180+
clk.setTextColor(TFT_WHITE, bgColor);
1181+
clk.drawString(lunarDate, 49, 16);
1182+
clk.pushSprite(10, 182);
1183+
clk.deleteSprite();
1184+
#endif
1185+
11671186
clk.unloadFont();
11681187
/***日期****/
11691188
}
@@ -1292,7 +1311,9 @@ void WIFI_reflash_All()
12921311

12931312
updateNtpTime();
12941313
//其他需要联网的方法写在后面
1314+
#if SHOW_LUNAR
12951315
getLunarDate();
1316+
#endif
12961317

12971318
WiFi.forceSleepBegin(); // Wifi Off
12981319
log("WIFI sleep......");
@@ -1442,11 +1463,14 @@ void setup()
14421463

14431464
tft.fillScreen(TFT_BLACK); //清屏
14441465

1445-
TJpgDec.drawJpg(15, 183, temperature, sizeof(temperature)); //温度图标
1446-
TJpgDec.drawJpg(15, 213, humidity, sizeof(humidity)); //湿度图标
1466+
TJpgDec.drawJpg(15, 213, temperature, sizeof(temperature)); //温度图标
14471467

14481468
getCityWeater();
1469+
#if SHOW_LUNAR
14491470
getLunarDate();
1471+
#else
1472+
TJpgDec.drawJpg(15, 183, humidity, sizeof(humidity)); //湿度图标
1473+
#endif
14501474
#if DHT_EN
14511475
if (DHT_img_flag != 0)
14521476
IndoorTem();

src/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
#define ANIMATE_FPS 10 // 右下角动画 FPS
99
#define DEFAULT_UPDATE_TIME 1 // 默认联网更新周期(单位:分钟)
1010
#define EXISTS_BUTTON false // 是否有按键(默认否)
11+
#define SHOW_LUNAR true // 是否显示农历(代替湿度图标)
1112

1213
#define timeY 82 // 定义高度

0 commit comments

Comments
 (0)