diff --git a/lib/UI/pages/Page.hpp b/lib/UI/pages/Page.hpp index 775ddfc..64f56be 100644 --- a/lib/UI/pages/Page.hpp +++ b/lib/UI/pages/Page.hpp @@ -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) { diff --git a/lib/UI/pages/main_page/MainPage.cpp b/lib/UI/pages/main_page/MainPage.cpp index 9601ac0..7adb23f 100644 --- a/lib/UI/pages/main_page/MainPage.cpp +++ b/lib/UI/pages/main_page/MainPage.cpp @@ -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(); diff --git a/lib/UI/pages/main_page/MainPage.hpp b/lib/UI/pages/main_page/MainPage.hpp index 877cb7a..daa7ac9 100644 --- a/lib/UI/pages/main_page/MainPage.hpp +++ b/lib/UI/pages/main_page/MainPage.hpp @@ -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: