diff --git a/src/core/menu_items/OthersMenu.cpp b/src/core/menu_items/OthersMenu.cpp index 50cff0e6..b102f1e6 100644 --- a/src/core/menu_items/OthersMenu.cpp +++ b/src/core/menu_items/OthersMenu.cpp @@ -24,22 +24,22 @@ void OthersMenu::optionsMenu() { #ifdef MIC_SPM1423 {"Mic Spectrum", [=]() { mic_test(); }}, #endif - {"BadUSB", [=]() { usb_setup(); }}, + {"BadUSB", [=]() { usb_setup(); }}, #ifdef HAS_KEYBOARD_HID - {"USB Keyboard", [=]() { usb_keyboard(); }}, + {"USB Keyboard", [=]() { usb_keyboard(); }}, #endif #ifdef HAS_RGB_LED - {"LED Control", [=]() { ledrgb_setup(); }}, // IncursioHack - {"LED FLash", [=]() { ledrgb_flash(); }}, // IncursioHack + {"LED Control", [=]() { ledrgb_setup(); }}, // IncursioHack + {"LED FLash", [=]() { ledrgb_flash(); }}, // IncursioHack #endif #ifndef LITE_VERSION - {"Openhaystack", [=]() { openhaystack_setup(); }}, + {"Openhaystack", [=]() { openhaystack_setup(); }}, #endif #if !defined(CORE) && !defined(CORE2) - {"Interpreter", [=]() { run_bjs_script(); }}, + {"Interpreter", [=]() { run_bjs_script(); }}, #endif {"Timer", [=]() { Timer(); }}, - {"Main Menu", [=]() { backToMenu(); }}, + {"Main Menu", [=]() { backToMenu(); }}, }; delay(200); diff --git a/src/modules/others/timer.cpp b/src/modules/others/timer.cpp index 7438975c..e94a1cf6 100644 --- a/src/modules/others/timer.cpp +++ b/src/modules/others/timer.cpp @@ -16,58 +16,18 @@ Timer::Timer() { setup(); } -void Timer::loop() { - unsigned long startMillis = millis(); - unsigned long currentMillis; - unsigned long elapsedMillis; - - char timeString[9]; +Timer::~Timer() { tft.fillScreen(bruceConfig.bgColor); - - for (;;) { - currentMillis = millis(); - elapsedMillis = currentMillis - startMillis; - - unsigned long remainingMillis = duration + 1000 - elapsedMillis; - - int seconds = (remainingMillis / 1000) % 60; - int minutes = (remainingMillis / 60000) % 60; - int hours = (remainingMillis / 3600000); - - snprintf(timeString, sizeof(timeString), "%02d:%02d:%02d", hours, minutes, seconds); - - tft.setTextColor(bruceConfig.priColor, bruceConfig.bgColor); - drawMainBorder(false); - tft.setTextSize(4); - tft.drawCentreString(timeString, WIDTH / 2, HEIGHT / 2 - 13, 1); - - if (checkEscPress()) { - duration = 0; - tft.fillScreen(bruceConfig.bgColor); - returnToMenu = true; - break; - } - - if (elapsedMillis >= duration) { - tft.fillScreen(bruceConfig.bgColor); - _tone(2000, 1000); - returnToMenu = true; - break; - } - - delay(DELAY_VALUE); - } + backToMenu(); } + void Timer::setup() { - int hours = 0; int minutes = 0; int seconds = 0; int settingMode = 0; - int underlineHeight = HEIGHT / 3 * 2; - int underlineWidth = WIDTH / 5; char timeString[9]; @@ -75,25 +35,18 @@ void Timer::setup() { delay(DELAY_VALUE); - for (;;) { + while (true) { snprintf(timeString, sizeof(timeString), "%02d:%02d:%02d", hours, minutes, seconds); - tft.setTextColor(bruceConfig.priColor, bruceConfig.bgColor); - tft.setTextSize(2); drawMainBorderWithTitle("Set a timer", false); - tft.setTextSize(4); - tft.drawCentreString(timeString, WIDTH / 2, HEIGHT / 2 - 13, 1); - - if (settingMode == 0) { - tft.drawLine(WIDTH / 10 * 7, underlineHeight, WIDTH / 10 * 7 + underlineWidth, underlineHeight, bruceConfig.bgColor); - tft.drawLine(WIDTH / 10, underlineHeight, WIDTH / 10 + underlineWidth, underlineHeight, bruceConfig.priColor); - } else if (settingMode == 1) { - tft.drawLine(WIDTH / 10, underlineHeight, WIDTH / 10 + underlineWidth, underlineHeight, bruceConfig.bgColor); - tft.drawLine(WIDTH / 10 * 4, underlineHeight, WIDTH / 10 * 4 + underlineWidth, underlineHeight, bruceConfig.priColor); - } else if (settingMode == 2) { - tft.drawLine(WIDTH / 10 * 4, underlineHeight, WIDTH / 10 * 4 + underlineWidth, underlineHeight, bruceConfig.bgColor); - tft.drawLine(WIDTH / 10 * 7, underlineHeight, WIDTH / 10 * 7 + underlineWidth, underlineHeight, bruceConfig.priColor); - } + tft.setTextSize(fontSize); + tft.drawCentreString(timeString, timerX, timerY, 1); + + clearUnderline(); + + if (settingMode == 0) underlineHours(); + else if (settingMode == 1) underlineMinutes(); + else if (settingMode == 2) underlineSeconds(); if (checkNextPress()) { if (settingMode == 0 && ++hours > 99) { @@ -118,15 +71,91 @@ void Timer::setup() { if (checkSelPress()) { if (++settingMode > 2 && (hours > 0 || minutes > 0 || seconds > 0)) { duration = (hours * 3600 + minutes * 60 + seconds) * 1000; - loop(); break; } - if (settingMode > 2 && hours == 0 && minutes == 0 && seconds == 0) { - settingMode = 0; - } + if (settingMode > 2) settingMode = 0; } delay(DELAY_VALUE); } + + return loop(); +} + + +void Timer::loop() { + unsigned long startMillis = millis(); + unsigned long currentMillis; + unsigned long elapsedMillis; + + char timeString[9]; + + tft.fillScreen(bruceConfig.bgColor); + + while (true) { + currentMillis = millis(); + elapsedMillis = currentMillis - startMillis; + + unsigned long remainingMillis = duration + 1000 - elapsedMillis; + + int seconds = (remainingMillis / 1000) % 60; + int minutes = (remainingMillis / 60000) % 60; + int hours = (remainingMillis / 3600000); + + snprintf(timeString, sizeof(timeString), "%02d:%02d:%02d", hours, minutes, seconds); + + drawMainBorder(false); + + tft.setTextSize(4); + tft.setTextColor(bruceConfig.priColor, bruceConfig.bgColor); + tft.drawCentreString(timeString, timerX, timerY, 1); + + if (checkEscPress()) { + break; + } + + if (elapsedMillis >= duration) { + _tone(2000, 1000); + break; + } + + delay(DELAY_VALUE); + } +} + + +void Timer::clearUnderline() { + tft.drawLine( + BORDER_PAD_X, underlineY, + WIDTH - BORDER_PAD_X, underlineY, + bruceConfig.bgColor + ); +} + + +void Timer::underlineHours() { + tft.drawLine( + timerX - (4 * LW * fontSize), underlineY, + timerX - (2 * LW * fontSize), underlineY, + bruceConfig.priColor + ); +} + + +void Timer::underlineMinutes() { + tft.drawLine( + timerX - (LW * fontSize), underlineY, + timerX + (LW * fontSize), underlineY, + bruceConfig.priColor + ); +} + + +void Timer::underlineSeconds() { + tft.drawLine( + timerX + (2 * LW * fontSize), underlineY, + timerX + (4 * LW * fontSize), underlineY, + bruceConfig.priColor + ); } diff --git a/src/modules/others/timer.h b/src/modules/others/timer.h index 983c7523..1f1a7aa2 100644 --- a/src/modules/others/timer.h +++ b/src/modules/others/timer.h @@ -9,11 +9,21 @@ class Timer { private: + int fontSize = 4; int duration = 0; + int timerX = WIDTH / 2; + int timerY = HEIGHT / 2; + int underlineY = timerY + (fontSize + 1) * LH; + + void clearUnderline(); + void underlineHours(); + void underlineMinutes(); + void underlineSeconds(); public: Timer(); + ~Timer(); void setup(); void loop();