From f7cc0d3ccf3ea83029c5cdae88bfcecf902bfe90 Mon Sep 17 00:00:00 2001 From: 217heidai <217heidai@gmail.com> Date: Tue, 11 Jun 2024 16:27:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20BTC=E3=80=81ETH=E3=80=81BN?= =?UTF-8?q?B=20=E9=87=91=E9=A2=9D=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/datetime.ino | 2 +- src/display.ino | 57 ++++++++++++++++++++++++++++++++++++++++++-- src/eInkCalendar.ino | 20 ++++++++++++---- src/hitokoto.ino | 4 ++++ src/test.ino | 12 +++++----- src/wifi.ino | 1 + 6 files changed, 82 insertions(+), 14 deletions(-) diff --git a/src/datetime.ino b/src/datetime.ino index 9370fa9..4411bc3 100644 --- a/src/datetime.ino +++ b/src/datetime.ino @@ -151,8 +151,8 @@ extern bool isNeedRefresh(void) } //正常时间下的刷新规则 - //if((((stTime.hour - stTime_LastUpdate.hour)>= REFRESH_FREQUENCY) || (stTime.day != stTime_LastUpdate.day)) && ((stTime.hour > REFRESH_TIME_START) && (stTime.hour < REFRESH_TIME_END))) //距离上次刷新超过REFRESH_FREQUENCY小时,或者日期发生变化 if(((stTime.hour - stTime_LastUpdate.hour)>= REFRESH_FREQUENCY) || (stTime.day != stTime_LastUpdate.day)) //距离上次刷新超过REFRESH_FREQUENCY小时,或者日期发生变化 + //if((((stTime.hour - stTime_LastUpdate.hour)>= REFRESH_FREQUENCY) || (stTime.day != stTime_LastUpdate.day)) && ((stTime.hour > REFRESH_TIME_START) && (stTime.hour < REFRESH_TIME_END))) //距离上次刷新超过REFRESH_FREQUENCY小时,或者日期发生变化,且在允许的刷新时间范围内 { isRefresh = true; goto END; diff --git a/src/display.ino b/src/display.ino index a2b3298..4bb1b05 100644 --- a/src/display.ino +++ b/src/display.ino @@ -82,11 +82,11 @@ static bool RefreshDate(void) { sprintf(disp, "%s", stDate.holiday); } - if(strlen(disp)==0 && strlen(stDate.term)) + if((strlen(disp)==0 && strlen(stDate.term)) || (stDate.isWorkday && strlen(stDate.term))) { sprintf(disp, "%s", stDate.term); } - if(strlen(disp)==0 && strlen(stDate.lunar_festival)) + if((strlen(disp)==0 && strlen(stDate.lunar_festival)) || (stDate.isWorkday && strlen(stDate.lunar_festival))) { sprintf(disp, "%s", stDate.lunar_festival); } @@ -350,6 +350,58 @@ static bool RefreshHitokoto(void) return true; } +static bool RefreshCoin(void) +{ + CryptoCoin stCryptoCoin; + uint16_t dataWidth; + uint16_t start_x = 1; + char disp[120]; + int i = 0; + + for (i=0; i= MAX_TRY_COUNT) + { + return true; // 加密货币价格获取失败不影响 + } + + u8g2Fonts.setFont(chinese_city_gb2312); + if (strlen(stCryptoCoin.price_btc)) + { + //btc + sprintf(disp, "BTC"); + u8g2Fonts.drawUTF8(start_x, SCREEN_HEIGTH/2 - FONT_SIZE_CHINESE_SPACING*2, disp); + sprintf(disp, "%s", stCryptoCoin.price_btc); + dataWidth = u8g2Fonts.getUTF8Width(disp); + u8g2Fonts.drawUTF8(start_x, SCREEN_HEIGTH/2 - FONT_SIZE_CHINESE_SPACING, disp); + //eth + if (strlen(stCryptoCoin.price_eth)) + { + sprintf(disp, "ETH"); + u8g2Fonts.drawUTF8(start_x, SCREEN_HEIGTH/2, disp); + sprintf(disp, "%s", stCryptoCoin.price_eth); + u8g2Fonts.drawUTF8(start_x + dataWidth - u8g2Fonts.getUTF8Width(disp), SCREEN_HEIGTH/2 + FONT_SIZE_CHINESE_SPACING, disp); + } + //BNB + if (strlen(stCryptoCoin.price_bnb)) + { + sprintf(disp, "BNB"); + u8g2Fonts.drawUTF8(start_x, SCREEN_HEIGTH/2 + FONT_SIZE_CHINESE_SPACING*2, disp); + sprintf(disp, "%s", stCryptoCoin.price_bnb); + u8g2Fonts.drawUTF8(start_x + dataWidth - u8g2Fonts.getUTF8Width(disp), SCREEN_HEIGTH/2 + FONT_SIZE_CHINESE_SPACING*3, disp); + } + } + + return true; +} + + static bool RefreshBattery(void) { //电量百分比 @@ -397,6 +449,7 @@ extern void display_MainPage(void) if(!RefreshDate()) return;//刷新日期 if(!RefreshWeather()) return;//刷新天气 if(!RefreshHitokoto()) return;//刷新一言 + if(!RefreshCoin()) return;//刷新加密货币 if(!RefreshBattery()) return;//刷新电量 } while (display.nextPage()); diff --git a/src/eInkCalendar.ino b/src/eInkCalendar.ino index 4fdd0cf..b035dfb 100644 --- a/src/eInkCalendar.ino +++ b/src/eInkCalendar.ino @@ -65,14 +65,16 @@ static const char *url_Date = "https://api.heidai.space/date"; // 天气,修改location为所在城市拼音,首字母大写,可以用浏览器打开链接测试下 static const char *url_Weather = "https://api.heidai.space/weather/?location=Shanghai"; // 一言,max为返回句子的最大字数 -static const char *url_Hitokoto = "https://api.heidai.space/hitokoto/?max=30"; +static const char *url_Hitokoto = "https://api.heidai.space/hitokoto/?max=28"; +// 加密货币 +static const char *url_Coin = "https://api.heidai.space/coin"; // 刷新间隔 -#define REFRESH_FREQUENCY 4 //每x小时刷新 -#define REFRESH_TIME_START 7 //刷新屏幕的时间范围,8点以后刷新 -#define REFRESH_TIME_END 20 //刷新屏幕的时间范围,20点前刷新 +#define REFRESH_FREQUENCY 1 //每x小时刷新 +#define REFRESH_TIME_START 7 //刷新屏幕的时间范围,8点以后刷新 +#define REFRESH_TIME_END 20 //刷新屏幕的时间范围,20点前刷新 // 休眠时间 -#define SLEEP_TIME 60 //60分钟 +#define SLEEP_TIME (REFRESH_FREQUENCY * 60) // 是否为夜间 bool gisNight = false; @@ -128,6 +130,14 @@ typedef struct _Hitokoto { char from[64]; //出自 } Hitokoto; +//加密货币 +typedef struct _CryptoCoin { + char price_btc[20]; //BTC 价格 + char price_eth[20]; //ETH 价格 + char price_bnb[20]; //BNB 价格 + char price_doge[20]; //DOGE 价格 +} CryptoCoin; + static const char DefaultHitokoto[] = "Talk is cheap. Show me the code."; //默认信息 static const char DefaultHitokotoFrom[] = "Linus Torvalds"; diff --git a/src/hitokoto.ino b/src/hitokoto.ino index 3492fa5..c6d3226 100644 --- a/src/hitokoto.ino +++ b/src/hitokoto.ino @@ -19,6 +19,10 @@ static bool ParseHitokoto(String content, Hitokoto *pstHitokoto) { strcpy(pstHitokoto->hitokoto, json["hitokoto"]); } + else if(!json["poetry"].isNull()) + { + strcpy(pstHitokoto->hitokoto, json["poetry"]); + } else { json.clear(); diff --git a/src/test.ino b/src/test.ino index af65631..aaf63e7 100644 --- a/src/test.ino +++ b/src/test.ino @@ -4,24 +4,24 @@ extern void display_test_str(void) //中文字体测试 String str = "2023年07月04日 星期二 上海"; const char* character = str.c_str(); - display.setPartialWindow(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH/2); //设置刷新区域 + u8g2Fonts.setFont(chinese_city_gb2312); + dataWidth = u8g2Fonts.getUTF8Width(character); + display.setPartialWindow((SCREEN_WIDTH - dataWidth)/2, 0, dataWidth, FONT_SIZE_CHINESE_SPACING * 3); //设置刷新区域 display.firstPage(); do { - u8g2Fonts.setFont(chinese_city_gb2312); - dataWidth = u8g2Fonts.getUTF8Width(character); u8g2Fonts.drawUTF8((SCREEN_WIDTH - dataWidth)/2, FONT_SIZE_CHINESE_SPACING, character); u8g2Fonts.drawUTF8((SCREEN_WIDTH - dataWidth)/2, FONT_SIZE_CHINESE_SPACING * 2, character); u8g2Fonts.drawUTF8((SCREEN_WIDTH - dataWidth)/2, FONT_SIZE_CHINESE_SPACING * 3, character); } while (display.nextPage()); - display.setPartialWindow(0, SCREEN_HEIGTH/2, SCREEN_WIDTH, SCREEN_HEIGTH/2); //设置刷新区域 + u8g2Fonts.setFont(u8g2_mfxinran_16_number); + dataWidth = u8g2Fonts.getUTF8Width(character); + display.setPartialWindow((SCREEN_WIDTH - dataWidth)/2, SCREEN_HEIGTH/2, dataWidth, SCREEN_HEIGTH/2 + FONT_SIZE_CHINESE_LARGE_SPACING * 3); //设置刷新区域 display.firstPage(); do { - u8g2Fonts.setFont(u8g2_mfxinran_16_number); - dataWidth = u8g2Fonts.getUTF8Width(character); u8g2Fonts.drawUTF8((SCREEN_WIDTH - dataWidth)/2, SCREEN_HEIGTH/2 + FONT_SIZE_CHINESE_LARGE_SPACING, character); u8g2Fonts.drawUTF8((SCREEN_WIDTH - dataWidth)/2, SCREEN_HEIGTH/2 + FONT_SIZE_CHINESE_LARGE_SPACING * 2, character); u8g2Fonts.drawUTF8((SCREEN_WIDTH - dataWidth)/2, SCREEN_HEIGTH/2 + FONT_SIZE_CHINESE_LARGE_SPACING * 3, character); diff --git a/src/wifi.ino b/src/wifi.ino index ec12532..27913ae 100644 --- a/src/wifi.ino +++ b/src/wifi.ino @@ -33,6 +33,7 @@ extern String callHttps(const char *url) client.setInsecure(); //不检验证书 client.setBufferSizes(512, 256); //缓存大小 + client.setTimeout(20000); //超时时间20s https.setReuse(false); //是否keep-alive delay(1);