mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Merge pull request #499 from agatti/guicleanup
Refactor OLED on/off mechanism.
This commit is contained in:
@@ -26,8 +26,14 @@ extern "C" {
|
||||
#define OLED_WIDTH 96
|
||||
#define FRAMEBUFFER_START 17
|
||||
|
||||
class OLED {
|
||||
class OLED {
|
||||
public:
|
||||
|
||||
enum DisplayState : bool {
|
||||
OFF = false,
|
||||
ON = true
|
||||
};
|
||||
|
||||
static void initialize(); // Startup the I2C coms (brings screen out of reset etc)
|
||||
|
||||
// Draw the buffer out to the LCD using the DMA Channel
|
||||
@@ -38,11 +44,11 @@ public:
|
||||
//or we need to goto double buffering
|
||||
}
|
||||
|
||||
// Turn the screen on or not
|
||||
static void displayOnOff(bool on) {
|
||||
displayOnOffState = on;
|
||||
screenBuffer[1] = on ? 0xAF : 0xAE;
|
||||
static void setDisplayState(DisplayState state) {
|
||||
displayState = state;
|
||||
screenBuffer[1] = (state == ON) ? 0xAF : 0xAE;
|
||||
}
|
||||
|
||||
static void setRotation(bool leftHanded); // Set the rotation for the screen
|
||||
// Get the current rotation of the LCD
|
||||
static bool getRotation() {
|
||||
@@ -96,7 +102,7 @@ private:
|
||||
static uint8_t* firstStripPtr; // Pointers to the strips to allow for buffer having extra content
|
||||
static uint8_t* secondStripPtr; //Pointers to the strips
|
||||
static bool inLeftHandedMode; // Whether the screen is in left or not (used for offsets in GRAM)
|
||||
static bool displayOnOffState; // If the display is on or not
|
||||
static DisplayState displayState;
|
||||
static uint8_t fontWidth, fontHeight;
|
||||
static int16_t cursor_x, cursor_y;
|
||||
static uint8_t displayOffset;
|
||||
|
||||
@@ -26,6 +26,11 @@ extern osThreadId GUITaskHandle;
|
||||
extern osThreadId MOVTaskHandle;
|
||||
extern osThreadId PIDTaskHandle;
|
||||
|
||||
// TODO: express time constants in terms of dividends of portTICK_RATE_MS
|
||||
|
||||
#define MOVEMENT_INACTIVITY_TIME 6000
|
||||
#define BUTTON_INACTIVITY_TIME 6000
|
||||
|
||||
static uint16_t min(uint16_t a, uint16_t b) {
|
||||
if (a > b)
|
||||
return b;
|
||||
@@ -714,7 +719,7 @@ void startGUITask(void const *argument __unused) {
|
||||
for (;;) {
|
||||
ButtonState buttons = getButtonState();
|
||||
if (buttons != BUTTON_NONE) {
|
||||
OLED::displayOnOff(true); // turn lcd on
|
||||
OLED::setDisplayState(OLED::DisplayState::ON);
|
||||
OLED::setFont(0);
|
||||
}
|
||||
if (tempWarningState == 2)
|
||||
@@ -760,17 +765,17 @@ void startGUITask(void const *argument __unused) {
|
||||
getInputVoltageX10(systemSettings.voltageDiv, 0);
|
||||
uint16_t tipTemp = tipMeasurementToC(getTipRawTemp(0));
|
||||
|
||||
if (tipTemp < 50) {
|
||||
if (systemSettings.sensitivity) {
|
||||
if ((xTaskGetTickCount() - lastMovementTime) > 6000
|
||||
&& (xTaskGetTickCount() - lastButtonTime) > 6000) {
|
||||
OLED::displayOnOff(false); // turn lcd off when no movement
|
||||
} else
|
||||
OLED::displayOnOff(true); // turn lcd on
|
||||
} else
|
||||
OLED::displayOnOff(true); // turn lcd on - disabled motion sleep
|
||||
} else
|
||||
OLED::displayOnOff(true); // turn lcd on when temp > 50C
|
||||
// Preemptively turn the display on. Turn it off if and only if
|
||||
// the tip temperature is below 50 degrees C *and* motion sleep
|
||||
// detection is enabled *and* there has been no activity (movement or
|
||||
// button presses) in a while.
|
||||
OLED::setDisplayState(OLED::DisplayState::ON);
|
||||
|
||||
if ((tipTemp < 50) && systemSettings.sensitivity &&
|
||||
(((xTaskGetTickCount() - lastMovementTime) > MOVEMENT_INACTIVITY_TIME) &&
|
||||
((xTaskGetTickCount() - lastButtonTime) > BUTTON_INACTIVITY_TIME))) {
|
||||
OLED::setDisplayState(OLED::DisplayState::OFF);
|
||||
}
|
||||
|
||||
// Clear the lcd buffer
|
||||
OLED::clearScreen();
|
||||
|
||||
@@ -18,7 +18,7 @@ uint8_t* OLED::firstStripPtr; // Pointers to the strips to allow for buffer
|
||||
uint8_t* OLED::secondStripPtr; // Pointers to the strips
|
||||
bool OLED::inLeftHandedMode; // Whether the screen is in left or not (used for
|
||||
// offsets in GRAM)
|
||||
bool OLED::displayOnOffState; // If the display is on or not
|
||||
OLED::DisplayState OLED::displayState;
|
||||
uint8_t OLED::fontWidth, OLED::fontHeight;
|
||||
int16_t OLED::cursor_x, OLED::cursor_y;
|
||||
uint8_t OLED::displayOffset;
|
||||
@@ -70,16 +70,18 @@ void OLED::initialize() {
|
||||
secondStripPtr = &screenBuffer[FRAMEBUFFER_START + OLED_WIDTH];
|
||||
fontHeight = 16;
|
||||
displayOffset = 0;
|
||||
displayOnOffState = true;
|
||||
memcpy(&screenBuffer[0], &REFRESH_COMMANDS[0], sizeof(REFRESH_COMMANDS));
|
||||
|
||||
HAL_Delay(50);
|
||||
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_SET);
|
||||
HAL_Delay(50);
|
||||
// Send the setup settings
|
||||
FRToSI2C::Transmit(DEVICEADDR_OLED, (uint8_t*) OLED_Setup_Array,
|
||||
sizeof(OLED_Setup_Array));
|
||||
displayOnOff(true);
|
||||
|
||||
// Set the display to be ON once the settings block is sent and send the
|
||||
// initialisation data to the OLED.
|
||||
|
||||
setDisplayState(DisplayState::ON);
|
||||
FRToSI2C::Transmit(DEVICEADDR_OLED, &OLED_Setup_Array[0],
|
||||
sizeof(OLED_Setup_Array));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user