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