diff --git a/source/Core/Drivers/Font.h b/source/Core/Drivers/Font.h index 9a752bce..12feb288 100644 --- a/source/Core/Drivers/Font.h +++ b/source/Core/Drivers/Font.h @@ -145,6 +145,14 @@ const uint8_t disconnectedTipIcon[] = { // }; +// 16 x 16 +const uint8_t brightnessIcon[] + = {0x80, 0x86, 0x8E, 0x9C, 0x18, 0xC0, 0xE0, 0xEF, 0xEF, 0xE0, 0xC0, 0x18, 0x9C, 0x8E, 0x86, 0x80, 0x01, 0x61, 0x71, 0x39, 0x18, 0x03, 0x07, 0xF7, 0xF7, 0x07, 0x03, 0x18, 0x39, 0x71, 0x61, 0x01}; + +// 24 x 16 +const uint8_t invertDisplayIcon[] = {0xFE, 0x01, 0x79, 0x25, 0x79, 0x01, 0xFE, 0x00, 0x20, 0x20, 0x20, 0x20, 0xDF, 0x07, 0x8F, 0xDF, 0xFF, 0x01, 0xFE, 0x86, 0xDA, 0x86, 0xFE, 0x01, + 0x7F, 0x80, 0xA4, 0xBE, 0xA0, 0x80, 0x7F, 0x00, 0x04, 0x0E, 0x1F, 0x04, 0xFB, 0xFB, 0xFB, 0xFB, 0xFF, 0x80, 0x7F, 0x5B, 0x41, 0x5F, 0x7F, 0x80}; + /* * 16x16 icons * 32 * 3 = Frame size * Frame count diff --git a/source/Core/Drivers/OLED.cpp b/source/Core/Drivers/OLED.cpp index b3559360..85ed90a8 100644 --- a/source/Core/Drivers/OLED.cpp +++ b/source/Core/Drivers/OLED.cpp @@ -46,7 +46,7 @@ I2C_CLASS::I2C_REG OLED_Setup_Array[] = { {0x80, 0xDA, 0}, /*Set VCOM Pins hardware config*/ {0x80, 0x02, 0}, /*Combination 2*/ {0x80, 0x81, 0}, /*Contrast*/ - {0x80, 0x33, 0}, /*^51*/ + {0x80, 0x00, 0}, /*^0*/ {0x80, 0xD9, 0}, /*Set pre-charge period*/ {0x80, 0xF1, 0}, /*Pre charge period*/ {0x80, 0xDB, 0}, /*Adjust VCOMH regulator ouput*/ @@ -362,6 +362,17 @@ void OLED::setRotation(bool leftHanded) { screenBuffer[9] = inLeftHandedMode ? 0xC8 : 0xC0; } +void OLED::setContrast(uint8_t contrast) { + OLED_Setup_Array[15].val = contrast; + I2C_CLASS::writeRegistersBulk(DEVICEADDR_OLED, &OLED_Setup_Array[14], 2); +} + +void OLED::setInverseDisplay(bool inverse) { + uint8_t normalInverseCmd = inverse ? 0xA7 : 0xA6; + OLED_Setup_Array[21].val = normalInverseCmd; + I2C_CLASS::I2C_RegisterWrite(DEVICEADDR_OLED, 0x80, normalInverseCmd); +} + // print a string to the current cursor location void OLED::print(const char *const str, FontStyle fontStyle) { const uint8_t *next = reinterpret_cast(str); diff --git a/source/Core/Drivers/OLED.hpp b/source/Core/Drivers/OLED.hpp index 83e8914d..b1568b6b 100644 --- a/source/Core/Drivers/OLED.hpp +++ b/source/Core/Drivers/OLED.hpp @@ -62,6 +62,8 @@ public: static void setRotation(bool leftHanded); // Set the rotation for the screen // Get the current rotation of the LCD static bool getRotation() { return inLeftHandedMode; } + static void setContrast(uint8_t contrast); + static void setInverseDisplay(bool inverted); static int16_t getCursorX() { return cursor_x; } static void print(const char *string, FontStyle fontStyle); // Draw a string to the current location, with selected font static void printWholeScreen(const char *string); diff --git a/source/Core/Src/gui.cpp b/source/Core/Src/gui.cpp index 9e9a518f..641933c7 100644 --- a/source/Core/Src/gui.cpp +++ b/source/Core/Src/gui.cpp @@ -84,6 +84,10 @@ static bool settings_displayPowerPulseWait(void); static bool settings_setPowerPulseWait(void); static bool settings_displayPowerPulseDuration(void); static bool settings_setPowerPulseDuration(void); +static bool settings_displayBrightnessLevel(void); +static bool settings_setBrightnessLevel(void); +static bool settings_displayInvertColor(void); +static bool settings_setInvertColor(void); #ifdef HALL_SENSOR static bool settings_displayHallEffect(void); static bool settings_setHallEffect(void); @@ -217,6 +221,8 @@ const menuitem UIMenu[] = { {SETTINGS_DESC(SettingsItemIndex::ReverseButtonTempChange), settings_setReverseButtonTempChangeEnabled, settings_displayReverseButtonTempChangeEnabled}, /* Reverse Temp change buttons + - */ {SETTINGS_DESC(SettingsItemIndex::AnimSpeed), settings_setAnimationSpeed, settings_displayAnimationSpeed}, /*Animation Speed adjustment */ {SETTINGS_DESC(SettingsItemIndex::AnimLoop), settings_setAnimationLoop, settings_displayAnimationLoop}, /*Animation Loop switch */ + {0, settings_setBrightnessLevel, settings_displayBrightnessLevel}, /*Brightness Level*/ + {0, settings_setInvertColor, settings_displayInvertColor}, /*Invert screen colour*/ {0, nullptr, nullptr} // end of menu marker. DO NOT REMOVE }; const menuitem PowerSavingMenu[] = { @@ -966,6 +972,41 @@ static bool settings_displayPowerPulseDuration(void) { } } +static uint8_t brightness = 0x00; + +static bool settings_displayBrightnessLevel(void) { + OLED::drawArea(0, 0, 16, 16, brightnessIcon); + OLED::setCursor(5 * FONT_12_WIDTH - 2, 0); + OLED::printNumber(brightness, 3, FontStyle::LARGE); + return false; +} + +static bool settings_setBrightnessLevel(void) { + if (brightness > (0xFF - 0x08 + 1)) { + brightness = 0; + } else if (brightness == 0) { + brightness = 7; + } else { + brightness += 0x08; + } + OLED::setContrast(brightness); + return brightness == 0xFF; +} + +static bool invertColor = false; + +static bool settings_displayInvertColor(void) { + OLED::drawArea(0, 0, 24, 16, invertDisplayIcon); + OLED::setCursor(7 * FONT_12_WIDTH - 2, 0); + OLED::drawCheckbox(invertColor); + return false; +} +static bool settings_setInvertColor(void) { + invertColor = !invertColor; + OLED::setInverseDisplay(invertColor); + return invertColor; +} + #ifdef HALL_SENSOR static bool settings_displayHallEffect(void) { printShortDescription(SettingsItemIndex::HallEffSensitivity, 7);