diff --git a/src/main.cpp b/src/main.cpp index fde93df0..667c1069 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -136,6 +136,9 @@ Periodic ledPeriodic(ledBlinker); void userButtonPressed() { powerFSM.trigger(EVENT_PRESS); } +void userButtonPressedLong(){ + screen.adjustBrightness(); +} #ifndef NO_ESP32 void initWifi() @@ -197,10 +200,12 @@ void setup() #ifdef BUTTON_PIN userButton = OneButton(BUTTON_PIN, true, true); userButton.attachClick(userButtonPressed); + userButton.attachDuringLongPress(userButtonPressedLong); #endif #ifdef BUTTON_PIN_ALT userButtonAlt = OneButton(BUTTON_PIN_ALT, true, true); userButtonAlt.attachClick(userButtonPressed); + userButton.attachDuringLongPress(userButtonPressedLong); #endif #ifdef LED_PIN pinMode(LED_PIN, OUTPUT); diff --git a/src/screen.cpp b/src/screen.cpp index d0fb8f46..bb690a49 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -732,4 +732,19 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 display->drawLogBuffer(x, yo); } +//adjust Brightness cycle trough 1 to 254 as long as attachDuringLongPress is true +void Screen::adjustBrightness(){ + if (brightness == 254) + { + brightness = 0; + } else { + brightness++; + } + int width = brightness / 1.984375; + dispdev.drawRect( 0, 30, 128, 4); + dispdev.fillRect(0, 30, width, 4); + dispdev.display(); + dispdev.setBrightness(brightness); +} + } // namespace meshtastic diff --git a/src/screen.h b/src/screen.h index 95ca0a60..6d4d8b37 100644 --- a/src/screen.h +++ b/src/screen.h @@ -117,6 +117,10 @@ class Screen : public PeriodicTask /// Handles a button press. void onPress() { enqueueCmd(CmdItem{.cmd = Cmd::ON_PRESS}); } + // Implementation to Adjust Brightness + void adjustBrightness(); + int brightness = 150; + /// Starts showing the Bluetooth PIN screen. // // Switches over to a static frame showing the Bluetooth pairing screen