From b8cf48e87dee01be817accdff3928f6f455e2542 Mon Sep 17 00:00:00 2001 From: Sergey Ko Date: Mon, 10 Jun 2024 18:58:41 -0600 Subject: [PATCH] TEST: fix: clearing an object of non-trivial type 'class OLEDMenuItem'; use assignment or value-initialization instead [-Wclass-memaccess] --- .vscode/settings.json | 3 +- README.md | 10 +++++++ src/OLEDMenuManager.cpp | 65 ++++++++++++++++++++++++++++++++--------- src/OLEDMenuManager.h | 15 +++++++--- src/menu.cpp | 4 ++- src/options.h | 2 +- src/video.cpp | 6 ++-- 7 files changed, 81 insertions(+), 24 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index dd3ec86..3b26ab9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,7 +8,8 @@ "string": "cpp", "typeinfo": "cpp", "random": "cpp", - "*.html.tpl": "html" + "*.html.tpl": "html", + "new": "cpp" }, "editor.tabSize": 4, "editor.insertSpaces": true, diff --git a/README.md b/README.md index f6e4501..174bbf8 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ Development threads: - [Slots vs Presets](#slots-vs-presets) - [Vocabulary](#vocabulary) - [How-to switch GBS-Control to upload mode?](#how-to-switch-gbs-control-to-upload-mode) +- [TODO:](#todo) - [Additional information](#additional-information) - [Old documentation](#old-documentation) @@ -294,6 +295,15 @@ The following diagram represents the structure of system and user configurations ESP8266 version of the factory built GBSC, boots into firmware upload mode by pressing the knob button while the device is off and connecting it to a computer with USB cable. +## TODO: + +- [ ] Full height doesn't work +- [ ] Invert Sync issue +- [ ] PassThrough doesn't work +- [ ] preferScalingRgbhv doesn't work (?) +- [ ] feature request #553 +- [ ] creation/destruction OLEDMenuItem procedure + ## Additional information See [/doc/developer_guide.md](./doc/DEVELOPER_GUIDE.md). diff --git a/src/OLEDMenuManager.cpp b/src/OLEDMenuManager.cpp index fd8b6fd..daa98a0 100644 --- a/src/OLEDMenuManager.cpp +++ b/src/OLEDMenuManager.cpp @@ -10,12 +10,26 @@ * * @param display */ -OLEDMenuManager::OLEDMenuManager(SSD1306Wire *display) - : display(display) - , rootItem(registerItem(nullptr, 0, nullptr)) +OLEDMenuManager::OLEDMenuManager(SSD1306Wire * _display) { + display = _display; + // allocate memory for menu items list + allItems = new OLEDMenuItem * [OLED_MENU_MAX_ITEMS_NUM]; + uint8_t i = 0; + while(i < OLED_MENU_MAX_ITEMS_NUM) { + allItems[i] = nullptr; + i++; + } +} + +/** + * @brief initializer does what constructor can NOT do + * + */ +void OLEDMenuManager::init() { + rootItem = registerItem(nullptr, 0, nullptr); pushItem(rootItem); - randomSeed(millis()); // does this work? + // randomSeed(millis()); // does this work? } /** @@ -26,21 +40,36 @@ OLEDMenuManager::OLEDMenuManager(SSD1306Wire *display) OLEDMenuItem *OLEDMenuManager::allocItem() { int i = 0; - OLEDMenuItem *newItem = nullptr; + OLEDMenuItem * newItem = nullptr; + auto lambdaAllocItem = [&newItem]() { + newItem = new OLEDMenuItem(); + newItem->used = true; + }; while (i < OLED_MENU_MAX_ITEMS_NUM) { - if (!this->allItems[i].used) { - // FIXME - memset(&this->allItems[i], 0, sizeof(OLEDMenuItem)); - newItem = &this->allItems[i]; - newItem->used = true; + if(this->allItems[i] == nullptr) { + lambdaAllocItem(); + break; + } + else if (!this->allItems[i]->used) + { + delete this->allItems[i]; + lambdaAllocItem(); break; } + // if (!this->allItems[i].used) { + // // FIXME + // memset(&this->allItems[i], 0, sizeof(OLEDMenuItem)); + // newItem = &this->allItems[i]; + // newItem->used = true; + // break; + // } i++; } - if (!newItem) { - char msg[40]; - sprintf(msg, PSTR("Maximum number of items reached: %d"), OLED_MENU_MAX_ITEMS_NUM); - panicAndDisable(msg); + if (newItem == nullptr) { + // char msg[40]; + _DBGF(PSTR("reached max. menu items: %d"), OLED_MENU_MAX_ITEMS_NUM); + // sprintf(msg, PSTR("Maximum number of items reached: %d"), OLED_MENU_MAX_ITEMS_NUM); + // panicAndDisable(msg); } return newItem; } @@ -67,6 +96,8 @@ OLEDMenuItem *OLEDMenuManager::registerItem( OLEDDISPLAY_TEXT_ALIGNMENT alignment) { OLEDMenuItem *newItem = allocItem(); + if(newItem == nullptr) + goto register_image_item_end; if (alignment == OLEDDISPLAY_TEXT_ALIGNMENT::TEXT_ALIGN_CENTER_BOTH) { alignment = OLEDDISPLAY_TEXT_ALIGNMENT::TEXT_ALIGN_CENTER; @@ -85,6 +116,8 @@ OLEDMenuItem *OLEDMenuManager::registerItem( itemUnderCursor = rootItem->subItems[0]; } } + +register_image_item_end: return newItem; } @@ -108,6 +141,9 @@ OLEDMenuItem *OLEDMenuManager::registerItem( OLEDDISPLAY_TEXT_ALIGNMENT alignment) { OLEDMenuItem *newItem = allocItem(); + if(newItem == nullptr) + goto register_text_item_end; + newItem->str = string; if (font == nullptr) { font = DejaVu_Sans_Mono_12; @@ -128,6 +164,7 @@ OLEDMenuItem *OLEDMenuManager::registerItem( itemUnderCursor = rootItem->subItems[0]; } } +register_text_item_end: return newItem; } diff --git a/src/OLEDMenuManager.h b/src/OLEDMenuManager.h index d5c3a4b..5d50e4d 100644 --- a/src/OLEDMenuManager.h +++ b/src/OLEDMenuManager.h @@ -8,6 +8,7 @@ #include "OLEDMenuItem.h" #include "OLEDMenuTranslations.h" #include "options.h" +#include "wserial.h" #define IMAGE_ITEM(name) name##_WIDTH, name##_HEIGHT, name #define CENTER_IMAGE(name) (OLED_MENU_WIDTH - name##_WIDTH) / 2, (OLED_MENU_HEIGHT - name##_HEIGHT) / 2, name##_WIDTH, name##_HEIGHT, name @@ -29,9 +30,10 @@ enum class OLEDMenuNav class OLEDMenuManager { private: - OLEDDisplay *const display; - OLEDMenuItem allItems[OLED_MENU_MAX_ITEMS_NUM]; - OLEDMenuItem *itemStack[OLED_MENU_MAX_DEPTH]; + OLEDDisplay * display = nullptr; + // OLEDMenuItem allItems[OLED_MENU_MAX_ITEMS_NUM]; + OLEDMenuItem ** allItems; + OLEDMenuItem * itemStack[OLED_MENU_MAX_DEPTH]; uint8_t itemSP; OLEDMenuItem *itemUnderCursor; // null means the status bar is currently selected OLEDMenuState state; @@ -119,13 +121,18 @@ class OLEDMenuManager public: OLEDMenuManager(SSD1306Wire *display); + ~OLEDMenuManager() { + delete[] allItems; + allItems = NULL; + } OLEDMenuItem *allocItem(); OLEDMenuItem *registerItem(OLEDMenuItem *parent, uint16_t tag, uint16_t imageWidth, uint16_t imageHeight, const uint8_t *xbmImage, MenuItemHandler handler = nullptr, OLEDDISPLAY_TEXT_ALIGNMENT alignment = TEXT_ALIGN_CENTER); OLEDMenuItem *registerItem(OLEDMenuItem *parent, uint16_t tag, const char *string, MenuItemHandler handler = nullptr, const uint8_t *font = nullptr, OLEDDISPLAY_TEXT_ALIGNMENT alignment = TEXT_ALIGN_CENTER); + void init(); void tick(OLEDMenuNav btn); void goBack(bool preserveCursor = true); void goMain(bool preserveCursor = true); - OLEDMenuItem *const rootItem; + OLEDMenuItem * rootItem = nullptr; void clearSubItems(OLEDMenuItem *item) { diff --git a/src/menu.cpp b/src/menu.cpp index 87a04d7..867897b 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -3,7 +3,7 @@ # File: menu.cpp # # File Created: Thursday, 2nd May 2024 11:31:34 pm # # Author: # -# Last Modified: Sunday, 2nd June 2024 5:26:25 pm # +# Last Modified: Monday, 10th June 2024 6:34:38 pm # # Modified By: Sergey Ko # ########################################################################### # CHANGELOG: # @@ -824,6 +824,8 @@ void IRAM_ATTR isrRotaryEncoderPushForNewMenu() * */ void menuInit() { + oledMenu.init(); + #if USE_NEW_OLED_MENU attachInterrupt(digitalPinToInterrupt(PIN_CLK), isrRotaryEncoderRotateForNewMenu, FALLING); diff --git a/src/options.h b/src/options.h index 8640593..58cb89b 100644 --- a/src/options.h +++ b/src/options.h @@ -22,7 +22,7 @@ #define WEBSOCK_HBEAT_INTVAL 1500UL #define WEBSOCK_HBEAT_PONG_TOUT 1500UL #define WEBSOCK_HBEAT_DISCONN_CNT 5 -#define WEBSOCK_HBEAT_DEV_INTVAL 500UL +#define WEBSOCK_HBEAT_DEV_INTVAL 300UL #define WEBSOCK_HBEAT_DEV_PONG_TOUT 1000UL #define WEBSOCK_HBEAT_DEV_DISCONN_CNT 3 #define THIS_DEVICE_MASTER diff --git a/src/video.cpp b/src/video.cpp index edcff64..0b20f5f 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -3,7 +3,7 @@ # File: video.cpp # # File Created: Thursday, 2nd May 2024 4:07:57 pm # # Author: # -# Last Modified: Monday, 10th June 2024 4:04:57 pm # +# Last Modified: Monday, 10th June 2024 4:55:33 pm # # Modified By: Sergey Ko # ##################################################################################### # CHANGELOG: # @@ -1693,7 +1693,7 @@ void setOutModeHdBypass(bool regsInitialized) GBS::PAD_SYNC_OUT_ENZ::write(0); // enable sync out delay(200); optimizePhaseSP(); - _WSN(F("pass-through on")); + _WSN(F("output mode HD bypass")); } /** @@ -4236,7 +4236,7 @@ void runSyncWatcher() } if (newVideoModeCounter != 0) { // apply new mode - _WSF(PSTR(" %d \n"), vidModeReadout); + _WSF(PSTR(" %d (%d -> %d)\n"), vidModeReadout, rto->videoStandardInput, detectedVideoMode); // _WS("Old: "); _WS(rto->videoStandardInput); // _WS(" New: "); _WSN(detectedVideoMode); rto->videoIsFrozen = false;