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
1.2-legacy
Professr 2020-06-22 12:03:26 -07:00 zatwierdzone przez Marlon Spangenberg
rodzic f1da6469a3
commit ec10e784e1
3 zmienionych plików z 59 dodań i 1 usunięć

Wyświetl plik

@ -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);

Wyświetl plik

@ -514,6 +514,9 @@ void Screen::setup()
// Store a pointer to Screen so we can get to it from static functions.
ui.getUiState()->userData = this;
// Set the utf8 conversion function
dispdev.setFontTableLookupFunction(customFontTableLookup);
// Add frames.
static FrameCallback bootFrames[] = {drawBootScreen};
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};
uint32_t yo = drawRows(display, x, y + 12, fields);
uint32_t yo = drawRows(display, x, y + FONT_HEIGHT, fields);
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

Wyświetl plik

@ -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
@ -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.
//
// Use this handle to set things like battery status, user count, GPS status, etc.