Skip to content

Commit

Permalink
memory optimization, only three tabs in memory at the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausMu committed Mar 10, 2024
1 parent 4227372 commit b98a06e
Show file tree
Hide file tree
Showing 32 changed files with 1,121 additions and 1,087 deletions.
70 changes: 62 additions & 8 deletions Platformio/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,83 @@ board_build.f_cpu = 240000000L
board_build.partitions = huge_app.csv
upload_speed = 1000000
lib_deps =
sparkfun/SparkFun LIS3DH Arduino Library@^1.0.3
crankyoldgit/IRremoteESP8266@^2.8.4
bodmer/TFT_eSPI@^2.5.23
adafruit/Adafruit FT6206 Library@^1.0.6
lvgl/lvgl@^8.3.4
bodmer/TFT_eSPI@^2.5.23
sparkfun/SparkFun LIS3DH Arduino Library@^1.0.3
crankyoldgit/IRremoteESP8266@^2.8.4
knolleary/PubSubClient@^2.8
h2zero/NimBLE-Arduino@^1.4.1
;chris--a/Keypad@^3.1.1
;t-vk/ESP32 BLE Keyboard@^0.3.2
build_flags =
-D DISABLE_ALL_LIBRARY_WARNINGS=1 ; for TFT_eSPI
-D USE_NIMBLE=1 ; for BLE Keyboard
-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
-D LV_CONF_PATH=../../../../src/gui_general_and_keys/lv_conf.h
;-- OMOTE -----------------------------------------------------------------
-D ENABLE_WIFI_AND_MQTT=1
-D ENABLE_BLUETOOTH=1
;-- Arduino log -----------------------------------------------------------
;-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
;-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_ERROR
;-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_WARN
-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO
;-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
;-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
;-- lvgl ------------------------------------------------------------------
; lvgl variant 1:
; Don't use lv_conf.h. Tweak params via platfom.ini. See lv_conf_internal.h line 31. Don't change this line.
-D LV_CONF_SKIP=1
; use millis() from "Arduino.h" to tell the elapsed time in milliseconds
-D LV_TICK_CUSTOM=1
; dynamic memory. Takes as much as it gets from heap (DRAM). Needs approx. 25%-30% more memory than static memory.
;-D LV_MEM_CUSTOM=1
; static memory, will be allocated in static DRAM
-D LV_MEM_CUSTOM=0
-D LV_MEM_SIZE="(32U * 1024U)"
; fonts and theme
-D LV_FONT_MONTSERRAT_10=1
-D LV_FONT_MONTSERRAT_12=1
-D LV_FONT_MONTSERRAT_16=1
-D LV_FONT_MONTSERRAT_24=1
-D LV_THEME_DEFAULT_DARK=1
; don't build examples
-D LV_BUILD_EXAMPLES=0
; Enable the log module
-D LV_USE_LOG=1
-D LV_LOG_PRINTF=1
;-D LV_LOG_LEVEL=LV_LOG_LEVEL_TRACE
;-D LV_LOG_LEVEL=LV_LOG_LEVEL_INFO
;-D LV_LOG_LEVEL=LV_LOG_LEVEL_WARN
-D LV_LOG_LEVEL=LV_LOG_LEVEL_ERROR
;-D LV_LOG_LEVEL=LV_LOG_LEVEL_USER
;-D LV_LOG_LEVEL=LV_LOG_LEVEL_NONE
; trace really gives a lot of messages ...
;-D LV_LOG_LEVEL=LV_LOG_LEVEL_TRACE
; ---
; Enable asserts if an operation is failed or an invalid data is found.
; If LV_USE_LOG is enabled an error message will be printed on failure*/
; /*Check if the styles are properly initialized. (Very fast, recommended)*/
-D LV_USE_ASSERT_STYLE=1
; /*Check the integrity of `lv_mem` after critical operations. (Slow)*/
;-D LV_USE_ASSERT_MEM_INTEGRITY=1
; /*Check the object's type and existence (e.g. not deleted). (Slow)*/
;-D LV_USE_ASSERT_OBJ=1
; ---------
; lvgl variant 2:
; or define where lv_conf.h is, relative to the `lvgl` folder
;-D LV_CONF_PATH=../../../../src/gui_general_and_keys/lv_conf.h
;-- TFT_eSPI --------------------------------------------------------------
-D DISABLE_ALL_LIBRARY_WARNINGS=1
; The following lines replace the TFT_eSPI User_setup.h-file
-D USER_SETUP_LOADED=1
-D ILI9341_DRIVER=1
-D TFT_WIDTH=240
-D TFT_HEIGHT=320
;-D TFT_MISO
-D TFT_MOSI=23
-D TFT_SCLK=18
-D TFT_CS=5
-D TFT_DC=9
-D TFT_RST=-1
-D SPI_FREQUENCY=40000000 ; 40MHz default, some displays might support 80MHz
-D SPI_TOUCH_FREQUENCY=2500000
; TFT_eSPI fonts are disabled by default
;-D LOAD_GLCD=1
;-D LOAD_FONT2=1
Expand All @@ -52,3 +104,5 @@ build_flags =
;-D LOAD_FONT8=1
;-D LOAD_GFXFF=1
;-D SMOOTH_FONT=1
;-- for BLE Keyboard. Don't change this line! -----------------------------
-D USE_NIMBLE=1
2 changes: 1 addition & 1 deletion Platformio/src/commandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void executeCommandWithData(std::string command, commandData commandData, std::s
break;
}

#ifdef ENABLE_WIFI_AND_MQTT
#if ENABLE_WIFI_AND_MQTT == 1
case MQTT: {
auto current = commandData.commandPayloads.begin();
std::string topic = *current;
Expand Down
5 changes: 1 addition & 4 deletions Platformio/src/commandHandler.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#ifndef __COMMANDHANDLER_H__
#define __COMMANDHANDLER_H__

#define ENABLE_WIFI_AND_MQTT // Comment out to disable WiFi
#define ENABLE_BLUETOOTH // Comment out to disable Bluetooth

#include <Arduino.h>
#include <string>
#include <list>
Expand Down Expand Up @@ -104,7 +101,7 @@ enum commandHandlers {
IR_SONY,
IR_RC5,
IR_DENON,
#ifdef ENABLE_WIFI_AND_MQTT
#if ENABLE_WIFI_AND_MQTT == 1
MQTT,
#endif
#ifdef ENABLE_KEYBOARD_BLE
Expand Down
24 changes: 8 additions & 16 deletions Platformio/src/device_appleTV/gui_appleTV.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <lvgl.h>
#include "device_appleTV/device_appleTV.h"
#include "device_appleTV/gui_appleTV.h"
#include "gui_general_and_keys/guiBase.h"
#include "gui_general_and_keys/guiRegistry.h"
#include "hardware/tft.h"
Expand All @@ -17,11 +18,9 @@ static void appleKey_event_cb(lv_event_t* e) {
Serial.println(50 + (int)e->user_data);
}

void init_gui_tab_appleTV(lv_obj_t* tabview) {
void create_tab_content_appleTV(lv_obj_t* tab) {

lv_obj_t* tab = lv_tabview_add_tab(tabview, "Apple TV");

// Add content to the Apple TV tab (3)
// Add content to the Apple TV tab
// Add a nice apple tv logo
lv_obj_t* appleImg = lv_img_create(tab);
lv_img_set_src(appleImg, &appleTvIcon);
Expand Down Expand Up @@ -52,22 +51,15 @@ void init_gui_tab_appleTV(lv_obj_t* tabview) {
lv_obj_set_style_img_recolor(appleImg, lv_color_white(), LV_PART_MAIN);
lv_obj_set_style_img_recolor_opa(appleImg, LV_OPA_COVER, LV_PART_MAIN);
lv_obj_align(appleImg, LV_ALIGN_CENTER, 0, 0);

}

void init_gui_pageIndicator_appleTV(lv_obj_t* panel) {
// Create actual (non-clickable) buttons for every tab
lv_obj_t* btn = lv_btn_create(panel);
lv_obj_clear_flag(btn, LV_OBJ_FLAG_CLICKABLE);
lv_obj_set_size(btn, 150, lv_pct(100));
lv_obj_t* label = lv_label_create(btn);
lv_label_set_text_fmt(label, "Apple TV");
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_style_shadow_width(btn, 0, LV_PART_MAIN);
lv_obj_set_style_bg_color(btn, color_primary, LV_PART_MAIN);
void notify_tab_before_delete_appleTV(void) {
// remember to set all pointers to lvgl objects to NULL if they might be accessed from outside.
// They must check if object is NULL and must not use it if so

}

void register_gui_appleTV(void){
register_gui(& init_gui_tab_appleTV, & init_gui_pageIndicator_appleTV);
register_gui(std::string(tabName_appleTV), & create_tab_content_appleTV, & notify_tab_before_delete_appleTV);
}
1 change: 1 addition & 0 deletions Platformio/src/device_appleTV/gui_appleTV.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <lvgl.h>

const char * const tabName_appleTV = "Apple TV";
void register_gui_appleTV(void);

#endif /*__GUI_APPLETV_H__*/
6 changes: 3 additions & 3 deletions Platformio/src/device_keyboard_ble/device_keyboard_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ bool blinkBluetoothLabelIsOn = false;

void update_keyboard_ble_status() {
if (bleKeyboard.isConnected()) {
lv_label_set_text(BluetoothLabel, LV_SYMBOL_BLUETOOTH);
if (BluetoothLabel != NULL) {lv_label_set_text(BluetoothLabel, LV_SYMBOL_BLUETOOTH);}
bleKeyboard.setBatteryLevel(battery_percentage);

} else {
if(millis() - blinkBluetoothLabelLastChange >= 1000){
blinkBluetoothLabelIsOn = !blinkBluetoothLabelIsOn;
if (blinkBluetoothLabelIsOn) {
lv_label_set_text(BluetoothLabel, LV_SYMBOL_BLUETOOTH);
if (BluetoothLabel != NULL) {lv_label_set_text(BluetoothLabel, LV_SYMBOL_BLUETOOTH);}
} else {
lv_label_set_text(BluetoothLabel, "");
if (BluetoothLabel != NULL) {lv_label_set_text(BluetoothLabel, "");}
}
blinkBluetoothLabelLastChange = millis();
}
Expand Down
6 changes: 2 additions & 4 deletions Platformio/src/device_keyboard_ble/device_keyboard_ble.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@

#ifdef ENABLE_KEYBOARD_BLE

#include "commandHandler.h"

#if defined(ENABLE_KEYBOARD_BLE) && !defined(ENABLE_BLUETOOTH)
static_assert(false, "You have to use \"#define ENABLE_BLUETOOTH\" in \"commandHandler.h\" when having \"#define ENABLE_KEYBOARD_BLE\"");
#if defined(ENABLE_KEYBOARD_BLE) && !(ENABLE_BLUETOOTH == 1)
static_assert(false, "You have to use \"-D ENABLE_BLUETOOTH=1\" in \"platformio.ini\" when having \"#define ENABLE_KEYBOARD_BLE\"");
#endif

#include <BleKeyboard.h>
Expand Down
6 changes: 2 additions & 4 deletions Platformio/src/device_keyboard_mqtt/device_keyboard_mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@

// if you activate the MQTT keyboard, consider changing the mapping of the keyboard commands to the MQTT keyboard in file "commandHandler.h"

#include "commandHandler.h"

#if defined(ENABLE_KEYBOARD_MQTT) && !defined(ENABLE_WIFI_AND_MQTT)
static_assert(false, "You have to use \"#define ENABLE_WIFI_AND_MQTT\" in \"commandHandler.h\" when having \"#define ENABLE_KEYBOARD_MQTT\"");
#if defined(ENABLE_KEYBOARD_MQTT) && !(ENABLE_WIFI_AND_MQTT == 1)
static_assert(false, "You have to use \"-D ENABLE_WIFI_AND_MQTT=1\" in \"platformio.ini\" when having \"#define ENABLE_KEYBOARD_MQTT\"");
#endif

#define KEYBOARD_MQTT_UP "Keyboard_mqtt_up"
Expand Down
Loading

0 comments on commit b98a06e

Please sign in to comment.