Skip to content

Commit

Permalink
Refactor logging
Browse files Browse the repository at this point in the history
In KeyboardAdapter, ItemCommand, ItemInput, ItemInputCharset, ItemList, and ItemRangeBase classes.

- Removed redundant printLog calls for various actions.
- Updated logging to use the LOG macro for consistency.
  • Loading branch information
forntoh committed Oct 23, 2024
1 parent 3cfaf98 commit 92dec87
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 87 deletions.
2 changes: 1 addition & 1 deletion src/ItemCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ItemCommand : public MenuItem {
if (callback != NULL) {
callback();
}
printLog(F("ItemCommand::enter"), text);
LOG(F("ItemCommand::enter"), text);
}
};

Expand Down
16 changes: 8 additions & 8 deletions src/ItemInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class ItemInput : public MenuItem {
bool setValue(char* value) {
if (this->value != value) {
this->value = value;
printLog(F("ItemInput::setValue"), value);
LOG(F("ItemInput::setValue"), value);
return true;
}
return false;
Expand Down Expand Up @@ -178,7 +178,7 @@ class ItemInput : public MenuItem {
draw(renderer);
renderer->drawBlinker();
// Log
printLog(F("ItemInput::enterEditMode"), value);
LOG(F("ItemInput::enterEditMode"), value);
};
void back(MenuRenderer* renderer) {
renderer->clearBlinker();
Expand All @@ -191,7 +191,7 @@ class ItemInput : public MenuItem {
callback(value);
}
// Log
printLog(F("ItemInput::exitEditMode"), value);
LOG(F("ItemInput::exitEditMode"), value);
};
void left(MenuRenderer* renderer) {
if (cursor == 0) {
Expand All @@ -208,7 +208,7 @@ class ItemInput : public MenuItem {
renderer->moveCursor(cursorCol, renderer->getCursorRow());
renderer->drawBlinker();
// Log
printLog(F("ItemInput::left"), value);
LOG(F("ItemInput::left"), value);
};
/**
* @brief Moves the cursor to the right within the input value.
Expand All @@ -229,7 +229,7 @@ class ItemInput : public MenuItem {
renderer->moveCursor(cursorCol, renderer->getCursorRow());
renderer->drawBlinker();
// Log
printLog(F("ItemInput::right"), value);
LOG(F("ItemInput::right"), value);
}
/**
* @brief Handles the backspace action for the input field.
Expand All @@ -250,7 +250,7 @@ class ItemInput : public MenuItem {
renderer->moveCursor(cursorCol, renderer->getCursorRow());
renderer->drawBlinker();
// Log
printLog(F("ItemInput::backspace"), value);
LOG(F("ItemInput::backspace"), value);
}
/**
* @brief Types a character into the current input value at the cursor position.
Expand Down Expand Up @@ -287,7 +287,7 @@ class ItemInput : public MenuItem {
draw(renderer);
renderer->drawBlinker();
// Log
printLog(F("ItemInput::typeChar"), character);
LOG(F("ItemInput::typeChar"), character);
}
/**
* @brief Clear the value of the input field
Expand All @@ -297,7 +297,7 @@ class ItemInput : public MenuItem {
draw(renderer);
renderer->drawBlinker();
// Log
printLog(F("ItemInput::clear"), value);
LOG(F("ItemInput::clear"), value);
}
};

Expand Down
8 changes: 4 additions & 4 deletions src/ItemInputCharset.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ class ItemInputCharset : public ItemInput {
initCharEdit();
}
showPreviousChar(renderer);
printLog(F("ItemInputCharset::up"), charset[charsetPosition]);
LOG(F("ItemInputCharset::up"), charset[charsetPosition]);
return true;
case DOWN:
if (!charEdit) {
initCharEdit();
}
showNextChar(renderer);
printLog(F("ItemInputCharset::down"), charset[charsetPosition]);
LOG(F("ItemInputCharset::down"), charset[charsetPosition]);
return true;
case LEFT:
if (charEdit) {
Expand Down Expand Up @@ -124,7 +124,7 @@ class ItemInputCharset : public ItemInput {
renderer->draw(' ');
}
renderer->moveCursor(cursorCol, renderer->getCursorRow());
printLog(F("ItemInputCharset::abortCharEdit"));
LOG(F("ItemInputCharset::abortCharEdit"));
}
/**
* @brief Commit char edit mode.
Expand All @@ -140,7 +140,7 @@ class ItemInputCharset : public ItemInput {
value = buf;
}
abortCharEdit(renderer);
printLog(F("ItemInputCharset::commitCharEdit"), charset[charsetPosition]);
LOG(F("ItemInputCharset::commitCharEdit"), charset[charsetPosition]);
ItemInput::right(renderer);
}
/**
Expand Down
8 changes: 4 additions & 4 deletions src/ItemList.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ItemList : public MenuItem {
if (callback != NULL) {
callback(itemIndex);
}
printLog(F("ItemList::exitEditMode"), getValue());
LOG(F("ItemList::exitEditMode"), getValue());
return true;
case UP:
selectNext(renderer);
Expand All @@ -115,7 +115,7 @@ class ItemList : public MenuItem {
case ENTER:
renderer->setEditMode(true);
draw(renderer);
printLog(F("ItemList::enterEditMode"), getValue());
LOG(F("ItemList::enterEditMode"), getValue());
return true;
default:
return false;
Expand All @@ -129,7 +129,7 @@ class ItemList : public MenuItem {
if (previousIndex != itemIndex) {
draw(renderer);
}
printLog(F("ItemList::selectPrevious"), getValue());
LOG(F("ItemList::selectPrevious"), getValue());
};

void selectNext(MenuRenderer* renderer) {
Expand All @@ -138,7 +138,7 @@ class ItemList : public MenuItem {
if (previousIndex != itemIndex) {
draw(renderer);
}
printLog(F("ItemList::selectNext"), getValue());
LOG(F("ItemList::selectNext"), getValue());
};
};

Expand Down
8 changes: 4 additions & 4 deletions src/ItemRangeBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ItemRangeBase : public MenuItem {
return false;
}
currentValue += step;
printLog(F("ItemRangeBase::increment"), currentValue);
LOG(F("ItemRangeBase::increment"), currentValue);
return true;
}

Expand All @@ -75,7 +75,7 @@ class ItemRangeBase : public MenuItem {
return false;
}
currentValue -= step;
printLog(F("ItemRangeBase::decrement"), currentValue);
LOG(F("ItemRangeBase::decrement"), currentValue);
return true;
}

Expand Down Expand Up @@ -122,7 +122,7 @@ class ItemRangeBase : public MenuItem {
if (callback != NULL && !commitOnChange) {
callback(currentValue);
}
printLog(F("ItemRangeBase::exitEditMode"), currentValue);
LOG(F("ItemRangeBase::exitEditMode"), currentValue);
return true;
case UP:
if (increment()) {
Expand All @@ -148,7 +148,7 @@ class ItemRangeBase : public MenuItem {
case ENTER:
renderer->setEditMode(true);
draw(renderer);
printLog(F("ItemRangeBase::enterEditMode"), currentValue);
LOG(F("ItemRangeBase::enterEditMode"), currentValue);
return true;
default:
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/ItemSubMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ItemSubMenu : public MenuItem {
}
}
void changeScreen(LcdMenu* menu) {
printLog(F("ItemSubMenu::changeScreen"), text);
LOG(F("ItemSubMenu::changeScreen"), text);
screen->setParent(menu->getScreen());
menu->setScreen(screen);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ItemToggle.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class ItemToggle : public MenuItem {
if (callback != NULL) {
callback(enabled);
}
printLog(F("ItemToggle::toggle"), enabled ? textOn : textOff);
LOG(F("ItemToggle::toggle"), enabled ? textOn : textOff);
draw(renderer);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/LcdMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ MenuScreen* LcdMenu::getScreen() {
}

void LcdMenu::setScreen(MenuScreen* screen) {
printLog(F("LcdMenu::setScreen"));
LOG(F("LcdMenu::setScreen"));
this->screen = screen;
renderer.display->clear();
this->screen->draw(&renderer);
Expand Down
10 changes: 5 additions & 5 deletions src/MenuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@ bool MenuScreen::process(LcdMenu* menu, const unsigned char command) {
if (parent != NULL) {
menu->setScreen(parent);
}
printLog(F("MenuScreen::back"));
LOG(F("MenuScreen::back"));
return true;
case RIGHT:
if (renderer->cursorCol >= renderer->maxCols - 1) {
renderer->viewShift++;
draw(renderer);
}
printLog(F("MenuScreen::right"), renderer->viewShift);
LOG(F("MenuScreen::right"), renderer->viewShift);
return true;
case LEFT:
if (renderer->viewShift > 0) {
renderer->viewShift--;
draw(renderer);
}
printLog(F("MenuScreen::left"), renderer->viewShift);
LOG(F("MenuScreen::left"), renderer->viewShift);
return true;
default:
return false;
Expand All @@ -94,15 +94,15 @@ void MenuScreen::up(MenuRenderer* renderer) {
if (--cursor < view) view--;
draw(renderer);
}
printLog(F("MenuScreen:up"), cursor);
LOG(F("MenuScreen:up"), cursor);
}

void MenuScreen::down(MenuRenderer* renderer) {
if (cursor < itemCount - 1) {
if (++cursor > view + renderer->maxRows - 1) view++;
draw(renderer);
}
printLog(F("MenuScreen:down"), cursor);
LOG(F("MenuScreen:down"), cursor);
}

void MenuScreen::reset(MenuRenderer* renderer) {
Expand Down
23 changes: 7 additions & 16 deletions src/input/KeyboardAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ class KeyboardAdapter : public InputInterface {
void handleIdle() {
switch (lastChar) {
case CR: // Received single `\r`
printLog(F("Call ENTER from idle"));
// LOG(F("Call ENTER from idle"));
menu->process(ENTER);
break;
case ESC: // Received single `ESC`
printLog(F("Call BACK from idle"));
// LOG(F("Call BACK from idle"));
menu->process(BACK);
break;
}
Expand All @@ -155,11 +155,9 @@ class KeyboardAdapter : public InputInterface {
switch (command) {
case BS: // 8. On Win
case DEL: // 127. On Mac
printLog(F("Call BACKSPACE"));
menu->process(BACKSPACE);
break;
case LF: // 10, \n
printLog(F("Call ENTER"));
menu->process(ENTER);
break;
case CR: // 13, \r
Expand All @@ -169,7 +167,6 @@ class KeyboardAdapter : public InputInterface {
codeSet = CodeSet::C1;
break;
default:
printLog(F("Call default"), (uint8_t)command);
menu->process(command);
break;
}
Expand All @@ -189,42 +186,37 @@ class KeyboardAdapter : public InputInterface {
if (command >= C2_CSI_TERMINAL_MIN && command <= C2_CSI_TERMINAL_MAX) {
switch (command) {
case 'A':
printLog(F("Call UP"));
menu->process(UP);
break;
case 'B':
printLog(F("Call DOWN"));
menu->process(DOWN);
break;
case 'C':
printLog(F("Call RIGHT"));
menu->process(RIGHT);
break;
case 'D':
printLog(F("Call LEFT"));
menu->process(LEFT);
break;
case 'F':
printLog(F("End"));
LOG(F("End"));
break;
case 'H':
printLog(F("Home"));
LOG(F("Home"));
break;
case '~':
if (csiBufferCursor > 0) {
switch (csiBuffer[0] - '0') {
case 2: // Insert
printLog(F("Insert"));
LOG(F("Insert"));
break;
case 3: // Delete
printLog(F("Call CLEAR"));
menu->process(CLEAR);
break;
case 5: // PgUp
printLog(F("PgUp"));
LOG(F("PgUp"));
break;
case 6: // PgDn
printLog(F("PgDn"));
LOG(F("PgDn"));
break;
}
}
Expand Down Expand Up @@ -254,7 +246,6 @@ class KeyboardAdapter : public InputInterface {
return;
}
unsigned char command = stream->read();
printLog(F("KEY"), command);
handleReceived(command);
}
};
2 changes: 1 addition & 1 deletion src/renderer/MenuRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class MenuRenderer {
if (millis() != startTime + DISPLAY_TIMEOUT) {
return;
}
printLog(F("MenuRenderer::timeout"));
LOG(F("MenuRenderer::timeout"));
display->hide();
}

Expand Down
Loading

0 comments on commit 92dec87

Please sign in to comment.