Cleanup LCD on/off commands into buffer

This commit is contained in:
Ben V. Brown
2018-05-06 20:06:16 +10:00
parent 1fef2fb53a
commit 771f0a1b9e
5 changed files with 36 additions and 63 deletions

View File

@@ -32,7 +32,7 @@ void FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
//RToS is active, run threading
//Get the mutex so we can use the I2C port
//Wait up to 1 second for the mutex
if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) 1000 ) == pdTRUE) {
if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) portMAX_DELAY ) == pdTRUE) {
if (HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData,
Size, 5000) != HAL_OK) {
NVIC_SystemReset();
@@ -57,7 +57,7 @@ void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
//RToS is active, run threading
//Get the mutex so we can use the I2C port
//Wait up to 1 second for the mutex
if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) 1000 ) == pdTRUE) {
if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) portMAX_DELAY ) == pdTRUE) {
if (HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize,
pData, Size, 5000) != HAL_OK) {
NVIC_SystemReset();
@@ -86,7 +86,7 @@ void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t* pData, uint16_t Size) {
//RToS is active, run threading
//Get the mutex so we can use the I2C port
//Wait up to 1 second for the mutex
if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) 1000 ) == pdTRUE) {
if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) portMAX_DELAY ) == pdTRUE) {
if (HAL_I2C_Master_Transmit_DMA(i2c, DevAddress, pData, Size)
!= HAL_OK) {
NVIC_SystemReset();

View File

@@ -49,8 +49,8 @@ OLED::OLED(FRToSI2C* i2cHandle) {
currentFont = FONT_12;
fontWidth = 12;
inLeftHandedMode = false;
firstStripPtr = &screenBuffer[15];
secondStripPtr = &screenBuffer[15 + 96];
firstStripPtr = &screenBuffer[16 + 1];
secondStripPtr = &screenBuffer[16 + 1 + 96];
fontHeight = 16;
fontWidth = 12;
displayOffset = 0;
@@ -70,22 +70,24 @@ void OLED::initialize() {
//Write out the buffer to the OLEd & call any rendering objects
void OLED::refresh() {
screenBuffer[0] = 0x80;
screenBuffer[1] = 0x21;
screenBuffer[1] = displayOnOffState ? 0xAF : 0xAE;
screenBuffer[2] = 0x80;
screenBuffer[3] = inLeftHandedMode ? 0 : 32; //display is shifted by 32 in left handed mode as driver ram is 128 wide
screenBuffer[3] = 0x21;
screenBuffer[4] = 0x80;
screenBuffer[5] = inLeftHandedMode ? 95 : 0x7F; //End address of the ram segment we are writing to (96 wide)
screenBuffer[6] = 0x80; /*Set COM Scan direction*/
screenBuffer[7] = inLeftHandedMode ? 0xC8 : 0xC0;
screenBuffer[8] = 0x80; //Set pages to rollover after 2
screenBuffer[9] = 0x22;
screenBuffer[10] = 0x80;
screenBuffer[11] = 0x00; //start page 0
screenBuffer[5] = inLeftHandedMode ? 0 : 32; //display is shifted by 32 in left handed mode as driver ram is 128 wide
screenBuffer[6] = 0x80;
screenBuffer[7] = inLeftHandedMode ? 95 : 0x7F; //End address of the ram segment we are writing to (96 wide)
screenBuffer[8] = 0x80; /*Set COM Scan direction*/
screenBuffer[9] = inLeftHandedMode ? 0xC8 : 0xC0;
screenBuffer[10] = 0x80; //Set pages to rollover after 2
screenBuffer[11] = 0x22;
screenBuffer[12] = 0x80;
screenBuffer[13] = 0x01;
screenBuffer[14] = 0x40; //start of data marker
screenBuffer[13] = 0x00; //start page 0
screenBuffer[14] = 0x80;
screenBuffer[15] = 0x01;
screenBuffer[16] = 0x40; //start of data marker
i2c->Transmit( DEVICEADDR_OLED, screenBuffer, 14 + 96 * 2 + 1);
i2c->Transmit( DEVICEADDR_OLED, screenBuffer, 16 + (96 * 2) + 1);
}
@@ -150,16 +152,7 @@ void OLED::drawChar(char c, char PrecursorCommand) {
}
void OLED::displayOnOff(bool on) {
if (on != displayOnOffState) {
uint8_t data[6] = { 0x80, 0X8D, 0x80, 0X14, 0x80, 0XAF }; //on
if (!on) {
data[3] = 0x10;
data[5] = 0xAE;
}
i2c->Transmit( DEVICEADDR_OLED, data, 6);
displayOnOffState = on;
}
displayOnOffState = on;
}
void OLED::setRotation(bool leftHanded) {
@@ -172,7 +165,8 @@ void OLED::setRotation(bool leftHanded) {
OLED_Setup_Array[11] = 0xC0;
OLED_Setup_Array[19] = 0xA0;
}
i2c->Transmit( DEVICEADDR_OLED, (uint8_t*) OLED_Setup_Array, configLength);
i2c->Transmit( DEVICEADDR_OLED, (uint8_t*) OLED_Setup_Array,
configLength);
inLeftHandedMode = leftHanded;
}
}
@@ -340,7 +334,7 @@ void OLED::fillArea(int16_t x, int8_t y, uint8_t wide, uint8_t height,
}
void OLED::drawFilledRect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
bool clear) {
bool clear) {
//Draw this in 3 sections
//This is basically a N wide version of vertical line

View File

@@ -587,6 +587,10 @@ void showVersion(void) {
case 5:
lcd.print("Time: ");
lcd.printNumber(xTaskGetTickCount() / 100, 5);
break;
case 6:
lcd.print("Move: ");
lcd.printNumber(lastMovementTime / 100, 5);
break;
}
@@ -597,7 +601,7 @@ void showVersion(void) {
return;
else if (b == BUTTON_F_SHORT) {
screen++;
screen = screen % 6;
screen = screen % 7;
}
}
}
@@ -605,29 +609,6 @@ void showVersion(void) {
/* StartGUITask function */
void startGUITask(void const *argument) {
i2cDev.FRToSInit();
/*
* Main program states:
*
* * Soldering (gui_solderingMode)
* -> Main loop where we draw temp, and animations
* --> User presses buttons and they goto the temperature adjust screen
* ---> Display the current setpoint temperature
* ---> Use buttons to change forward and back on temperature
* ---> Both buttons or timeout for exiting
* --> Long hold front button to enter boost mode
* ---> Just temporarily sets the system into the alternate temperature for
* PID control
* --> Long hold back button to exit
* --> Double button to exit
* * Settings Menu (gui_settingsMenu)
* -> Show setting name
* --> If no button press for > 3 Seconds, scroll description
* -> If user presses back button, adjust the setting
* -> Currently the same as 1.x (future to make more depth based)
*/
uint8_t animationStep = 0;
uint8_t tempWarningState = 0;
bool buttonLockout = false;
@@ -727,7 +708,6 @@ void startGUITask(void const *argument) {
lcd.displayOnOff(false); // turn lcd off when no movement
} else
lcd.displayOnOff(true); // turn lcd on
} else
lcd.displayOnOff(true); // turn lcd on - disabled motion sleep
} else
@@ -787,7 +767,6 @@ void startGUITask(void const *argument) {
}
lcd.refresh();
animationStep++;
GUIDelay();
}
}