From 32005a56429aaacd1d536cee0db971021a04eb5f Mon Sep 17 00:00:00 2001 From: hogthrob Date: Sat, 22 Jun 2019 07:29:40 +0200 Subject: [PATCH] Reduce stack usage: Make logo stored in flash, fix oled (#33) This way the OLED display does not overwrite useful data since the stack on the F072RB in mbed is just 1k and the logog is also 1k. Also fixed minor issue in OLED display code (refactoring not done). --- lib/Adafruit_GFX/Adafruit_SSD1306.cpp | 14 ++++++++------ src/uext/uext_oled.cpp | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/Adafruit_GFX/Adafruit_SSD1306.cpp b/lib/Adafruit_GFX/Adafruit_SSD1306.cpp index c4ced13..aff42ec 100644 --- a/lib/Adafruit_GFX/Adafruit_SSD1306.cpp +++ b/lib/Adafruit_GFX/Adafruit_SSD1306.cpp @@ -149,11 +149,8 @@ void Adafruit_SSD1306::clearDisplay(void) std::fill(buffer.begin(),buffer.end(),0); } -void Adafruit_SSD1306::splash(void) -{ - - #ifndef NO_SPLASH_ADAFRUIT - uint8_t logoLibreSolar[64 * 128 / 8] = +#ifndef NO_SPLASH_ADAFRUIT +static const uint8_t logoLibreSolar[64 * 128 / 8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -220,13 +217,18 @@ void Adafruit_SSD1306::splash(void) 0x0C, 0x0C, 0x00, 0x08, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x0C, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x0C, 0x00, 0x00, 0x00, 0x00 }; +#endif + +void Adafruit_SSD1306::splash(void) +{ +#ifndef NO_SPLASH_ADAFRUIT std::copy( &logoLibreSolar[0] , &logoLibreSolar[0] + sizeof(logoLibreSolar) , buffer.begin() ); /* - uint8_t adaFruitLogo[64 * 128 / 8] = + const uint8_t adaFruitLogo[64 * 128 / 8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/src/uext/uext_oled.cpp b/src/uext/uext_oled.cpp index 306c6f2..daf970f 100644 --- a/src/uext/uext_oled.cpp +++ b/src/uext/uext_oled.cpp @@ -130,11 +130,11 @@ void uext_process_1s() oled.printf("%5.1fV", ls_bus.voltage); // load data - tmp = ls_bus.voltage * load.current; + tmp = ls_bus.voltage * load.bus->current; oled.setTextCursor(90, 18); oled.printf("%5.1fW", (abs(tmp) < 0.1) ? 0 : tmp); // remove negative zeros oled.setTextCursor(90, 26); - oled.printf("%5.1fA\n", (abs(load.current) < 0.1) ? 0 : load.current); + oled.printf("%5.1fA\n", (abs(load.bus->current) < 0.1) ? 0 : load.bus->current); oled.setTextCursor(0, 36); oled.printf("Day +%5.0fWh -%5.0fWh", hs_bus.dis_energy_Wh, fabs(load_bus.chg_energy_Wh));