Skip to content

Commit

Permalink
TEST: fix: clearing an object of non-trivial type 'class OLEDMenuItem…
Browse files Browse the repository at this point in the history
…'; use assignment or value-initialization instead [-Wclass-memaccess]
  • Loading branch information
way5 committed Jun 11, 2024
1 parent be6c7eb commit b8cf48e
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"string": "cpp",
"typeinfo": "cpp",
"random": "cpp",
"*.html.tpl": "html"
"*.html.tpl": "html",
"new": "cpp"
},
"editor.tabSize": 4,
"editor.insertSpaces": true,
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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).
Expand Down
65 changes: 51 additions & 14 deletions src/OLEDMenuManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}

/**
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -85,6 +116,8 @@ OLEDMenuItem *OLEDMenuManager::registerItem(
itemUnderCursor = rootItem->subItems[0];
}
}

register_image_item_end:
return newItem;
}

Expand All @@ -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;
Expand All @@ -128,6 +164,7 @@ OLEDMenuItem *OLEDMenuManager::registerItem(
itemUnderCursor = rootItem->subItems[0];
}
}
register_text_item_end:
return newItem;
}

Expand Down
15 changes: 11 additions & 4 deletions src/OLEDMenuManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
4 changes: 3 additions & 1 deletion src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: #
Expand Down Expand Up @@ -824,6 +824,8 @@ void IRAM_ATTR isrRotaryEncoderPushForNewMenu()
*
*/
void menuInit() {
oledMenu.init();

#if USE_NEW_OLED_MENU

attachInterrupt(digitalPinToInterrupt(PIN_CLK), isrRotaryEncoderRotateForNewMenu, FALLING);
Expand Down
2 changes: 1 addition & 1 deletion src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: #
Expand Down Expand Up @@ -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"));
}

/**
Expand Down Expand Up @@ -4236,7 +4236,7 @@ void runSyncWatcher()
}
if (newVideoModeCounter != 0) {
// apply new mode
_WSF(PSTR(" %d <stable>\n"), vidModeReadout);
_WSF(PSTR(" %d <stable> (%d -> %d)\n"), vidModeReadout, rto->videoStandardInput, detectedVideoMode);
// _WS("Old: "); _WS(rto->videoStandardInput);
// _WS(" New: "); _WSN(detectedVideoMode);
rto->videoIsFrozen = false;
Expand Down

0 comments on commit b8cf48e

Please sign in to comment.