#include "Screen/BaseMenuScreen.h" #include "Config.h" #include "Buzzer.h" void BaseMenuScreen::setEnableMenuScroll(bool value) { if (value != mEnableMenuScroll) { mEnableMenuScroll = value; printScrollIndicators(); } } void BaseMenuScreen::onShow() { printTitle(); printScrollIndicators(); printValue(); } void BaseMenuScreen::onHide() { } void BaseMenuScreen::printTitle() { LiquidCrystal* display = getDisplay(); const char* title = getTitle(); uint8_t titleLength = strlen(title); uint8_t maxWidth = LCDWidth - 2; display->setCursor(1, 0); if (titleLength >= maxWidth) { // Title too long, cut off char* character = (char*)title; for (uint8_t i = 0; i < maxWidth; i++) { display->write(byte(*character)); character++; } } else { // Center title uint8_t offset = (maxWidth - titleLength) / 2; for (uint8_t i = 0; i < offset; i++) display->write(' '); display->print(title); offset += titleLength; while (offset < LCDWidth - 2) { display->print(' '); offset++; } } } void BaseMenuScreen::printScrollIndicators() { LiquidCrystal* display = getDisplay(); display->setCursor(0, 0); if (hasPrevious()) display->write(getEnableMenuScroll() ? LCDCharArrowLeft : LCDCharArrowLeftHollow); else display->write(' '); display->setCursor(LCDWidth - 1, 0); if (hasNext()) display->write(getEnableMenuScroll() ? LCDCharArrowRight : LCDCharArrowRightHollow); else display->write(' '); } void BaseMenuScreen::printValue() { LiquidCrystal* display = getDisplay(); display->setCursor(0, 1); for (uint8_t x = 0; x < LCDWidth; x++) display->write(' '); } void BaseMenuScreen::onEncoder(long lastPosition, long newPosition) { if (mEnableMenuScroll) { if (newPosition > lastPosition) { if (hasNext()) { buzzSelect(); gotoNext(); } } else { if (hasPrevious()) { buzzSelect(); gotoPrevious(); } } } }