From ebd1a07f6d794a78acdfe14a35a44c5e27bea109 Mon Sep 17 00:00:00 2001 From: YiHui Liu Date: Mon, 10 Jan 2022 20:26:01 +0800 Subject: [PATCH] fix: usage of PROGMEM --- lib/image/image.cpp | 34 ++++++++++++++++++++-------------- lib/utils/utils.cpp | 14 +++++++++----- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/lib/image/image.cpp b/lib/image/image.cpp index 2fcb3ce..172cba5 100644 --- a/lib/image/image.cpp +++ b/lib/image/image.cpp @@ -28,13 +28,13 @@ void oledTitle(OLEDDisplay *display, String s, int16_t x, int16_t y) { void oledWebFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { // Title - oledTitle(display, "Fox Home", x, y); + oledTitle(display, F("Fox Home"), x, y); // Items display->setTextAlignment(TEXT_ALIGN_LEFT); - display->drawString(0+x, 16+y, "Today"); - display->drawString(0+x, 30+y, "Last Week"); - display->drawString(0+x, 44+y, "Last Month"); + display->drawString(0+x, 16+y, F("Today")); + display->drawString(0+x, 30+y, F("Last Week")); + display->drawString(0+x, 44+y, F("Last Month")); // Values display->setTextAlignment(TEXT_ALIGN_RIGHT); @@ -49,13 +49,13 @@ void oledMQTTFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, i void oledBilibiliFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { // Title - oledTitle(display, "BiliBili", x, y); + oledTitle(display, F("BiliBili"), x, y); // Items display->setTextAlignment(TEXT_ALIGN_LEFT); - display->drawString(0+x, 16+y, "Follower"); - display->drawString(0+x, 30+y, "View"); - display->drawString(0+x, 44+y, "Likes"); + display->drawString(0+x, 16+y, F("Follower")); + display->drawString(0+x, 30+y, F("View")); + display->drawString(0+x, 44+y, F("Likes")); // Values display->setTextAlignment(TEXT_ALIGN_RIGHT); @@ -66,11 +66,17 @@ void oledBilibiliFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t void oledOsFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { // Title - oledTitle(display, "INFO BOARD", x, y); - display->setTextAlignment(TEXT_ALIGN_LEFT); + oledTitle(display, F("INFO BOARD"), x, y); - // Version - display->drawString(0+x, 16+y, "Ver: " + Board.Version); - display->drawString(0+x, 30+y, "IP : " + Board.ip.toString()); - display->drawString(0+x, 44+y, "Mem: " + (String)(80.0-ESP.getFreeHeap()/1024.0) + "/80 kB"); + // Items + display->setTextAlignment(TEXT_ALIGN_LEFT); + display->drawString(0+x, 16+y, F("Ver: ")); + display->drawString(0+x, 30+y, F("IP : ")); + display->drawString(0+x, 44+y, F("Mem: ")); + + // Values + display->setTextAlignment(TEXT_ALIGN_RIGHT); + display->drawString(120+x, 16+y, Board.Version); + display->drawString(120+x, 30+y, Board.ip.toString()); + display->drawString(120+x, 44+y, (String)(ESP.getFreeHeap()) + " byte"); } \ No newline at end of file diff --git a/lib/utils/utils.cpp b/lib/utils/utils.cpp index 41bd54f..cf3888d 100644 --- a/lib/utils/utils.cpp +++ b/lib/utils/utils.cpp @@ -124,8 +124,8 @@ static String followerUrl = "http://api.bilibili.com/x/relation/stat?vmid=" + UI static String viewAndLikesUrl = "http://api.bilibili.com/x/space/upstat?mid=" + UID; static String webViewerUrl = "https://api.foolishfox.cn/data/board.json"; -static const char UserAgent[] PROGMEM = "UserAgent"; -static const char Cookie[] PROGMEM = "Cookie"; +const char UserAgent[] PROGMEM = "UserAgent"; +const char Cookie[] PROGMEM = "Cookie"; static WiFiClient client; std::unique_ptrclientSecure(new BearSSL::WiFiClientSecure); @@ -136,8 +136,10 @@ static void getFollower() { http.begin(client, followerUrl); int resCode = http.GET(); + if( resCode == 200 ) { String resBuffer = http.getString(); + Serial.println(resBuffer); DeserializationError error = deserializeJson(jsonBuffer, resBuffer); if( error ) { @@ -148,7 +150,7 @@ static void getFollower() { follower = jsonBuffer["data"]["follower"]; } else { - Serial.printf("[HTTP] GET Follower failed, error: %d\n", resCode); + Serial.printf_P(PSTR("[HTTP] GET Follower failed, error: %d\n"), resCode); } http.end(); @@ -165,6 +167,7 @@ static void getViewAndLikes() { int resCode = http.GET(); if( resCode == 200 ) { String resBuffer = http.getString(); + Serial.println(resBuffer); DeserializationError error = deserializeJson(jsonBuffer, resBuffer); if( error ) { @@ -176,7 +179,7 @@ static void getViewAndLikes() { likes = jsonBuffer["data"]["likes"]; view = jsonBuffer["data"]["archive"]["view"]; } else { - Serial.printf("[HTTP] GET View & Likes failed, error: %d\n", resCode); + Serial.printf_P(PSTR("[HTTP] GET View & Likes failed, error: %d\n"), resCode); } http.end(); @@ -190,6 +193,7 @@ static void getWebView() { int resCode = https.GET(); if( resCode == 200 ) { String resBuffer = https.getString(); + Serial.println(resBuffer); DeserializationError error = deserializeJson(jsonBuffer, resBuffer); if( error ) { @@ -202,7 +206,7 @@ static void getWebView() { weekView = jsonBuffer["week"]; monthView = jsonBuffer["month"]; } else { - Serial.printf("[HTTP] GET Web View failed, error: %d\n", resCode); + Serial.printf_P(PSTR("[HTTP] GET Web View failed, error: %d\n"), resCode); } https.end();