Skip to content

Commit c67ff6e

Browse files
committed
更新时钟显示方法,降低性能占用
1 parent 9cbfe69 commit c67ff6e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+6773
-40
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
.vscode/c_cpp_properties.json
44
.vscode/launch.json
55
.vscode/ipch
6+
.test/

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ lib_deps =
2020
fastled/FastLED@^3.4.0
2121
2222
ivanseidel/[email protected]+sha.1a4e504c5f
23-
upload_speed = 1500000
23+
upload_speed = 3000000

src/Animate/Animate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ void imgAnim(const uint8_t **Animate_value, uint32_t *Animate_size)
3030
if (Animate_key >= 31)
3131
Animate_key = -1;
3232
#endif
33-
}
33+
}

src/SmallDesktopDisplay.cpp

Lines changed: 72 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
*
1313
*
1414
* 引 脚 分 配:SCK GPIO14
15-
* MOSI GPIO13
16-
* RES GPIO2
17-
* DC GPIO0
18-
* LCDBL GPIO5
15+
* MOSI GPIO13
16+
* RES GPIO2
17+
* DC GPIO0
18+
* LCDBL GPIO5
1919
*
2020
* 增加DHT11温湿度传感器,传感器接口为 GPIO 12
2121
*
@@ -40,7 +40,6 @@
4040
#include <StaticThreadController.h> //协程控制
4141

4242
#include "config.h" //配置文件
43-
#include "number/number.h" //数字字库
4443
#include "weatherNum/weatherNum.h" //天气图库
4544
#include "Animate/Animate.h" //动画模块
4645
#include "wifiReFlash/wifiReFlash.h" //WIFI功能模块
@@ -70,15 +69,16 @@ Button2 Button_sw1 = Button2(4);
7069
/* *****************************************************************
7170
* 字库、图片库
7271
* *****************************************************************/
73-
#include "font/ZdyLwFont_20.h" //字体库
74-
#include "img/temperature.h" //温度图标
75-
#include "img/humidity.h" //湿度图标
72+
#include "font/ZdyLwFont_20.h" //字体库
73+
#include "font/timeClockFont.h" //字体库
74+
#include "img/temperature.h" //温度图标
75+
#include "img/humidity.h" //湿度图标
7676

7777
//函数声明
7878
void sendNTPpacket(IPAddress &address); //向NTP服务器发送请求
7979
time_t getNtpTime(); //从NTP获取时间
8080

81-
void digitalClockDisplay(int reflash_en);
81+
// void digitalClockDisplay(int reflash_en);
8282
void printDigits(int digits);
8383
String num2str(int digits);
8484
void LCD_reflash();
@@ -119,7 +119,7 @@ struct config_type
119119
};
120120
//---------------修改此处""内的信息--------------------
121121
//如开启WEB配网则可不用设置这里的参数,前一个为wifi ssid,后一个为密码
122-
config_type wificonf = {{"HUAWEI-0G17LY"}, {"19990823"}};
122+
config_type wificonf = {{"WiFi名"}, {"密码"}};
123123

124124
//天气更新时间 X 分钟
125125
unsigned int updateweater_time = 1;
@@ -151,7 +151,6 @@ time_t prevDisplay = 0; //显示时间显示记录
151151
int Amimate_reflash_Time = 0; //更新时间记录
152152

153153
/*** Component objects ***/
154-
Number dig;
155154
WeatherNum wrat;
156155

157156
uint32_t targetTime = 0;
@@ -346,7 +345,6 @@ void Serial_set()
346345
String incomingByte = "";
347346
if (Serial.available() > 0)
348347
{
349-
350348
while (Serial.available() > 0) //监测串口缓存,当有数据输入时,循环赋值给incomingByte
351349
{
352350
incomingByte += char(Serial.read()); //读取单个字符值,转换为字符,并按顺序一个个赋值给incomingByte
@@ -1000,34 +998,74 @@ void scrollBanner()
1000998
// }
1001999
}
10021000

1003-
unsigned char Hour_sign = 60;
1004-
unsigned char Minute_sign = 60;
1005-
unsigned char Second_sign = 60;
1006-
// 时钟刷新,输入1强制刷新
1007-
void digitalClockDisplay(int reflash_en = 0)
1001+
// 用快速线方法绘制数字
1002+
void drawLineFont(uint32_t _x, uint32_t _y, uint32_t _num, uint32_t _size, uint32_t _color)
10081003
{
1009-
int now_hour = hour(); //获取小时
1010-
int now_minu = minute(); //获取分钟
1011-
int now_seco = second(); //获取秒针
1004+
uint32_t fontSize;
1005+
const LineAtom *fontOne;
1006+
// 小号(9*14)
1007+
if (_size == 1)
1008+
{
1009+
fontOne = smallLineFont[_num];
1010+
fontSize = smallLineFont_size[_num];
1011+
// 绘制前清理字体绘制区域
1012+
tft.fillRect(_x, _y, 9, 14, TFT_BLACK);
1013+
}
1014+
// 中号(18*30)
1015+
else if (_size == 2)
1016+
{
1017+
fontOne = middleLineFont[_num];
1018+
fontSize = middleLineFont_size[_num];
1019+
// 绘制前清理字体绘制区域
1020+
tft.fillRect(_x, _y, 18, 30, TFT_BLACK);
1021+
}
1022+
// 大号(36*90)
1023+
else if (_size == 3)
1024+
{
1025+
fontOne = largeLineFont[_num];
1026+
fontSize = largeLineFont_size[_num];
1027+
// 绘制前清理字体绘制区域
1028+
tft.fillRect(_x, _y, 36, 90, TFT_BLACK);
1029+
}
1030+
else
1031+
return;
1032+
1033+
for (uint32_t i = 0; i < fontSize; i++)
1034+
{
1035+
tft.drawFastHLine(fontOne[i].xValue + _x, fontOne[i].yValue + _y, fontOne[i].lValue, _color);
1036+
}
1037+
}
10121038

1013-
int timey = 82;
1014-
if ((now_hour != Hour_sign) || (reflash_en == 1)) //时钟刷新
1039+
int Hour_sign = 60;
1040+
int Minute_sign = 60;
1041+
int Second_sign = 60;
1042+
// 日期刷新
1043+
void digitalClockDisplay(int reflash_en = 0)
1044+
{
1045+
// 时钟刷新,输入1强制刷新
1046+
int now_hour = hour(); //获取小时
1047+
int now_minute = minute(); //获取分钟
1048+
int now_second = second(); //获取秒针
1049+
//小时刷新
1050+
if ((now_hour != Hour_sign) || (reflash_en == 1))
10151051
{
1016-
dig.printfW3660(20, timey, now_hour / 10);
1017-
dig.printfW3660(60, timey, now_hour % 10);
1052+
drawLineFont(20, timeY, now_hour / 10, 3, SD_FONT_WHITE);
1053+
drawLineFont(60, timeY, now_hour % 10, 3, SD_FONT_WHITE);
10181054
Hour_sign = now_hour;
10191055
}
1020-
if ((now_minu != Minute_sign) || (reflash_en == 1)) //分钟刷新
1056+
//分钟刷新
1057+
if ((now_minute != Minute_sign) || (reflash_en == 1))
10211058
{
1022-
dig.printfO3660(101, timey, now_minu / 10);
1023-
dig.printfO3660(141, timey, now_minu % 10);
1024-
Minute_sign = now_minu;
1059+
drawLineFont(101, timeY, now_minute / 10, 3, SD_FONT_YELLOW);
1060+
drawLineFont(141, timeY, now_minute % 10, 3, SD_FONT_YELLOW);
1061+
Minute_sign = now_minute;
10251062
}
1026-
if ((now_seco != Second_sign) || (reflash_en == 1)) //分钟刷新
1063+
//秒针刷新
1064+
if ((now_second != Second_sign) || (reflash_en == 1)) //分钟刷新
10271065
{
1028-
dig.printfW1830(182, timey + 30, now_seco / 10);
1029-
dig.printfW1830(202, timey + 30, now_seco % 10);
1030-
Second_sign = now_seco;
1066+
drawLineFont(182, timeY + 30, now_second / 10, 2, SD_FONT_WHITE);
1067+
drawLineFont(202, timeY + 30, now_second % 10, 2, SD_FONT_WHITE);
1068+
Second_sign = now_second;
10311069
}
10321070

10331071
if (reflash_en == 1)
@@ -1139,7 +1177,8 @@ void wifi_reset(Button2 &btn)
11391177
void reflashTime()
11401178
{
11411179
prevDisplay = now();
1142-
digitalClockDisplay(1);
1180+
// timeClockDisplay(1);
1181+
digitalClockDisplay();
11431182
prevTime = 0;
11441183
}
11451184

@@ -1332,7 +1371,6 @@ void setup()
13321371

13331372
reflash_Animate.setInterval(TMS / 10); //设置帧率
13341373
reflash_openWifi.onRun(refresh_AnimatedImage);
1335-
13361374
controller.run();
13371375
}
13381376

src/config.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
#define Animate_Choice 2 //动图选择:1,太空人图片 2,胡桃
2-
#define TMS 1000 //一千毫秒
3-
#define WM_EN 1 // WEB配网使能标志位----WEB配网打开后会默认关闭smartconfig功能
4-
#define DHT_EN 0 //设定DHT11温湿度传感器使能标志
1+
#define Animate_Choice 2 //动图选择:1,太空人图片 2,胡桃
2+
#define TMS 1000 //一千毫秒
3+
#define WM_EN 1 // WEB配网使能标志位----WEB配网打开后会默认关闭smartconfig功能
4+
#define DHT_EN 0 //设定DHT11温湿度传感器使能标志
5+
#define SD_FONT_YELLOW 0xD404 // 黄色字体颜色
6+
#define SD_FONT_WHITE 0xFFFF // 黄色字体颜色
7+
8+
#define timeY 82 // 定义高度

0 commit comments

Comments
 (0)