Skip to content

Commit

Permalink
增加 BTC、ETH、BNB 金额显示
Browse files Browse the repository at this point in the history
  • Loading branch information
217heidai committed Jun 11, 2024
1 parent 45ffe23 commit f7cc0d3
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/datetime.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
57 changes: 55 additions & 2 deletions src/display.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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; i++)
{
memset(&stCryptoCoin, 0, sizeof(stCryptoCoin));
if(GetCoin(&stCryptoCoin))
{
break;
}
}
if (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)
{
//电量百分比
Expand Down Expand Up @@ -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());
Expand Down
20 changes: 15 additions & 5 deletions src/eInkCalendar.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";

Expand Down
4 changes: 4 additions & 0 deletions src/hitokoto.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions src/test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/wifi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f7cc0d3

Please sign in to comment.