mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-28 18:47:40 +00:00
Fix #207 adjust OLED Brightness by attachDuringLongPress
adjust the OLED Brightness by "attachDuringLongPress" from "OneButton". It will cycle trough 0 to 254 as long as the button is pressed
This commit is contained in:
parent
f1da6469a3
commit
ec10e784e1
@ -136,6 +136,9 @@ Periodic ledPeriodic(ledBlinker);
|
|||||||
void userButtonPressed() {
|
void userButtonPressed() {
|
||||||
powerFSM.trigger(EVENT_PRESS);
|
powerFSM.trigger(EVENT_PRESS);
|
||||||
}
|
}
|
||||||
|
void userButtonPressedLong(){
|
||||||
|
screen.adjustBrightness();
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef NO_ESP32
|
#ifndef NO_ESP32
|
||||||
void initWifi()
|
void initWifi()
|
||||||
@ -197,10 +200,12 @@ void setup()
|
|||||||
#ifdef BUTTON_PIN
|
#ifdef BUTTON_PIN
|
||||||
userButton = OneButton(BUTTON_PIN, true, true);
|
userButton = OneButton(BUTTON_PIN, true, true);
|
||||||
userButton.attachClick(userButtonPressed);
|
userButton.attachClick(userButtonPressed);
|
||||||
|
userButton.attachDuringLongPress(userButtonPressedLong);
|
||||||
#endif
|
#endif
|
||||||
#ifdef BUTTON_PIN_ALT
|
#ifdef BUTTON_PIN_ALT
|
||||||
userButtonAlt = OneButton(BUTTON_PIN_ALT, true, true);
|
userButtonAlt = OneButton(BUTTON_PIN_ALT, true, true);
|
||||||
userButtonAlt.attachClick(userButtonPressed);
|
userButtonAlt.attachClick(userButtonPressed);
|
||||||
|
userButton.attachDuringLongPress(userButtonPressedLong);
|
||||||
#endif
|
#endif
|
||||||
#ifdef LED_PIN
|
#ifdef LED_PIN
|
||||||
pinMode(LED_PIN, OUTPUT);
|
pinMode(LED_PIN, OUTPUT);
|
||||||
|
@ -514,6 +514,9 @@ void Screen::setup()
|
|||||||
// Store a pointer to Screen so we can get to it from static functions.
|
// Store a pointer to Screen so we can get to it from static functions.
|
||||||
ui.getUiState()->userData = this;
|
ui.getUiState()->userData = this;
|
||||||
|
|
||||||
|
// Set the utf8 conversion function
|
||||||
|
dispdev.setFontTableLookupFunction(customFontTableLookup);
|
||||||
|
|
||||||
// Add frames.
|
// Add frames.
|
||||||
static FrameCallback bootFrames[] = {drawBootScreen};
|
static FrameCallback bootFrames[] = {drawBootScreen};
|
||||||
static const int bootFrameCount = sizeof(bootFrames) / sizeof(bootFrames[0]);
|
static const int bootFrameCount = sizeof(bootFrames) / sizeof(bootFrames[0]);
|
||||||
@ -720,9 +723,24 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *fields[] = {channelStr, nullptr};
|
const char *fields[] = {channelStr, nullptr};
|
||||||
uint32_t yo = drawRows(display, x, y + 12, fields);
|
uint32_t yo = drawRows(display, x, y + FONT_HEIGHT, fields);
|
||||||
|
|
||||||
display->drawLogBuffer(x, yo);
|
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
|
} // namespace meshtastic
|
||||||
|
35
src/screen.h
35
src/screen.h
@ -117,6 +117,10 @@ class Screen : public PeriodicTask
|
|||||||
/// Handles a button press.
|
/// Handles a button press.
|
||||||
void onPress() { enqueueCmd(CmdItem{.cmd = Cmd::ON_PRESS}); }
|
void onPress() { enqueueCmd(CmdItem{.cmd = Cmd::ON_PRESS}); }
|
||||||
|
|
||||||
|
// Implementation to Adjust Brightness
|
||||||
|
void adjustBrightness();
|
||||||
|
int brightness = 150;
|
||||||
|
|
||||||
/// Starts showing the Bluetooth PIN screen.
|
/// Starts showing the Bluetooth PIN screen.
|
||||||
//
|
//
|
||||||
// Switches over to a static frame showing the Bluetooth pairing screen
|
// Switches over to a static frame showing the Bluetooth pairing screen
|
||||||
@ -149,6 +153,37 @@ class Screen : public PeriodicTask
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Overrides the default utf8 character conversion, to replace empty space with question marks
|
||||||
|
static char customFontTableLookup(const uint8_t ch) {
|
||||||
|
// UTF-8 to font table index converter
|
||||||
|
// Code form http://playground.arduino.cc/Main/Utf8ascii
|
||||||
|
static uint8_t LASTCHAR;
|
||||||
|
static bool SKIPREST; // Only display a single unconvertable-character symbol per sequence of unconvertable characters
|
||||||
|
|
||||||
|
if (ch < 128) { // Standard ASCII-set 0..0x7F handling
|
||||||
|
LASTCHAR = 0;
|
||||||
|
SKIPREST = false;
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t last = LASTCHAR; // get last char
|
||||||
|
LASTCHAR = ch;
|
||||||
|
|
||||||
|
switch (last) { // conversion depnding on first UTF8-character
|
||||||
|
case 0xC2: { SKIPREST = false; return (uint8_t) ch; }
|
||||||
|
case 0xC3: { SKIPREST = false; return (uint8_t) (ch | 0xC0); }
|
||||||
|
}
|
||||||
|
|
||||||
|
// We want to strip out prefix chars for two-byte char formats
|
||||||
|
if (ch == 0xC2 || ch == 0xC3 || ch == 0x82) return (uint8_t) 0;
|
||||||
|
|
||||||
|
// If we already returned an unconvertable-character symbol for this unconvertable-character sequence, return NULs for the rest of it
|
||||||
|
if (SKIPREST) return (uint8_t) 0;
|
||||||
|
SKIPREST = true;
|
||||||
|
|
||||||
|
return (uint8_t) 191; // otherwise: return ¿ if character can't be converted (note that the font map we're using doesn't stick to standard EASCII codes)
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a handle to the DebugInfo screen.
|
/// Returns a handle to the DebugInfo screen.
|
||||||
//
|
//
|
||||||
// Use this handle to set things like battery status, user count, GPS status, etc.
|
// Use this handle to set things like battery status, user count, GPS status, etc.
|
||||||
|
Loading…
Reference in New Issue
Block a user