Skip to content

Commit

Permalink
Fix MainPage wasting memory in display()
Browse files Browse the repository at this point in the history
  • Loading branch information
andreock committed Sep 7, 2024
1 parent 5e8412b commit 2c02dfc
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 64 deletions.
2 changes: 1 addition & 1 deletion lib/UI/pages/Page.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Page {
uint8_t lower_limit = 0;
uint8_t position_increment = 0;
uint8_t current_position = 0;
Grid *grid;
Grid *grid = nullptr;
Gui *gui;
Page(uint8_t _position_limit, uint8_t _lower_limit,
uint8_t _position_increment, GFXForms *_screen, Gui *_gui) {
Expand Down
109 changes: 55 additions & 54 deletions lib/UI/pages/main_page/MainPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,63 +32,64 @@ MainPage::~MainPage() {}
void section_not_ready() { LOG_ERROR("Section not ready"); }
void MainPage::display() {
current_position = 0;

wifi = new RectText(screen, english_words->at(WIFI_HOME_KEY),
if(wifi == nullptr && SubGhz == nullptr && NFC == nullptr && IR == nullptr && net_attacks == nullptr && settings == nullptr && grid == nullptr) {
wifi = new RectText(screen, english_words->at(WIFI_HOME_KEY),
HOME_TEXT_SIZE, HOME_TEXT_COLOR, HOME_ICON_HEIGHT,
HOME_ICON_RADIUS, HOME_ICON_COLOR, init_wifi_ui);
#ifndef CONFIG_IDF_TARGET_ESP32S2
ble = new RectText(screen, english_words->at(BLE_HOME_KEY), HOME_TEXT_SIZE,
HOME_TEXT_COLOR, HOME_ICON_HEIGHT, HOME_ICON_RADIUS,
HOME_ICON_COLOR, init_ble_ui);
#endif
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
badusb = new RectText(screen, english_words->at(BADUSB_HOME_KEY),
HOME_TEXT_SIZE, HOME_TEXT_COLOR, HOME_ICON_HEIGHT,
HOME_ICON_RADIUS, HOME_ICON_COLOR, init_badusb_ui);
#endif
SubGhz = new RectText(screen, english_words->at(SUBGHZ_HOME_KEY),
HOME_TEXT_SIZE, HOME_TEXT_COLOR, HOME_ICON_HEIGHT,
HOME_ICON_RADIUS, HOME_ICON_COLOR, init_subghz_ui);
NFC = new RectText(screen, english_words->at(NFC_HOME_KEY), HOME_TEXT_SIZE,
HOME_TEXT_COLOR, HOME_ICON_HEIGHT, HOME_ICON_RADIUS,
HOME_ICON_COLOR, init_nfc_ui);
IR = new RectText(screen, english_words->at(IR_HOME_KEY), HOME_TEXT_SIZE,
HOME_TEXT_COLOR, HOME_ICON_HEIGHT, HOME_ICON_RADIUS,
HOME_ICON_COLOR, section_not_ready);
net_attacks = new RectText(screen, english_words->at(NET_ATTACKS_HOME_KEY),
HOME_TEXT_SIZE, HOME_TEXT_COLOR,
HOME_ICON_HEIGHT, HOME_ICON_RADIUS,
HOME_ICON_COLOR, init_network_attacks_ui);
settings =
new RectText(screen, english_words->at(SETTINGS_HOME_KEY),
HOME_TEXT_SIZE, HOME_TEXT_COLOR, HOME_ICON_HEIGHT,
HOME_ICON_RADIUS, HOME_ICON_COLOR, init_wifi_ui);
#ifndef CONFIG_IDF_TARGET_ESP32S2
ble = new RectText(screen, english_words->at(BLE_HOME_KEY), HOME_TEXT_SIZE,
HOME_TEXT_COLOR, HOME_ICON_HEIGHT, HOME_ICON_RADIUS,
HOME_ICON_COLOR, init_ble_ui);
#endif
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
badusb = new RectText(screen, english_words->at(BADUSB_HOME_KEY),
HOME_TEXT_SIZE, HOME_TEXT_COLOR, HOME_ICON_HEIGHT,
HOME_ICON_RADIUS, HOME_ICON_COLOR, init_badusb_ui);
#endif
SubGhz = new RectText(screen, english_words->at(SUBGHZ_HOME_KEY),
HOME_TEXT_SIZE, HOME_TEXT_COLOR, HOME_ICON_HEIGHT,
HOME_ICON_RADIUS, HOME_ICON_COLOR, init_subghz_ui);
NFC = new RectText(screen, english_words->at(NFC_HOME_KEY), HOME_TEXT_SIZE,
HOME_TEXT_COLOR, HOME_ICON_HEIGHT, HOME_ICON_RADIUS,
HOME_ICON_COLOR, init_nfc_ui);
IR = new RectText(screen, english_words->at(IR_HOME_KEY), HOME_TEXT_SIZE,
HOME_TEXT_COLOR, HOME_ICON_HEIGHT, HOME_ICON_RADIUS,
HOME_ICON_COLOR, section_not_ready);
net_attacks = new RectText(screen, english_words->at(NET_ATTACKS_HOME_KEY),
HOME_TEXT_SIZE, HOME_TEXT_COLOR,
HOME_ICON_HEIGHT, HOME_ICON_RADIUS,
HOME_ICON_COLOR, init_network_attacks_ui);
settings =
new RectText(screen, english_words->at(SETTINGS_HOME_KEY),
HOME_TEXT_SIZE, HOME_TEXT_COLOR, HOME_ICON_HEIGHT,
HOME_ICON_RADIUS, HOME_ICON_COLOR, section_not_ready);
HOME_ICON_RADIUS, HOME_ICON_COLOR, section_not_ready);

grid = new Grid(screen, 2, 4);

grid = new Grid(screen, 2, 4);
grid->add(wifi);
#ifndef CONFIG_IDF_TARGET_ESP32S2
grid->add(ble);
#endif
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
grid->add(badusb);
#endif
grid->add(SubGhz);
grid->add(NFC);
grid->add(IR);
grid->add(net_attacks);
// grid->add(settings);
grid->set_pos(0, 10);
grid->set_space_between(10);
grid->set_padding(0, 20);
text = new Text(screen, HOME_INFO_COLOR,
String(english_words->at(VERSION_KEY)) + String(VERSION));
text->set_size(2);
text->set_wrap(true);
text->set_pos(5, 200);
// Text battery_level = Text(screen, HOME_INFO_COLOR, "Battery: 0%", 2U, true);
// battery_level.set_pos(5, 220);
}

grid->add(wifi);
#ifndef CONFIG_IDF_TARGET_ESP32S2
grid->add(ble);
#endif
#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
grid->add(badusb);
#endif
grid->add(SubGhz);
grid->add(NFC);
grid->add(IR);
grid->add(net_attacks);
// grid->add(settings);
grid->set_pos(0, 10);
grid->set_space_between(10);
grid->set_padding(0, 20);
text = new Text(screen, HOME_INFO_COLOR,
String(english_words->at(VERSION_KEY)) + String(VERSION));
text->set_size(2);
text->set_wrap(true);
text->set_pos(5, 200);
// Text battery_level = Text(screen, HOME_INFO_COLOR, "Battery: 0%", 2U, true);

// battery_level.set_pos(5, 220);
grid->display();
grid->set_selected(lower_limit, true);
text->display();
Expand Down
18 changes: 9 additions & 9 deletions lib/UI/pages/main_page/MainPage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@

class MainPage : public Page {
private:
RectText *wifi;
RectText *ble;
RectText *badusb;
RectText *SubGhz;
RectText *NFC;
RectText *IR;
RectText *net_attacks;
RectText *settings;
Text *text;
RectText *wifi = nullptr;
RectText *ble = nullptr;
RectText *badusb = nullptr;
RectText *SubGhz = nullptr;
RectText *NFC = nullptr;
RectText *IR = nullptr;
RectText *net_attacks = nullptr;
RectText *settings = nullptr;
Text *text = nullptr;
int read_bat_level();
// Text *battery_level;
public:
Expand Down

0 comments on commit 2c02dfc

Please sign in to comment.