Update GUIThread.cpp

This commit is contained in:
Ben V. Brown
2020-11-01 14:46:04 +11:00
parent 57b2505ad6
commit 9c712ee144

View File

@@ -7,22 +7,22 @@
extern "C" { extern "C" {
#include "FreeRTOSConfig.h" #include "FreeRTOSConfig.h"
} }
#include <MMA8652FC.hpp>
#include <gui.hpp>
#include <history.hpp>
#include "main.hpp"
#include <power.hpp>
#include "../../configuration.h" #include "../../configuration.h"
#include "Buttons.hpp" #include "Buttons.hpp"
#include "I2CBB.hpp"
#include "LIS2DH12.hpp" #include "LIS2DH12.hpp"
#include "Settings.h" #include "Settings.h"
#include "TipThermoModel.h" #include "TipThermoModel.h"
#include "Translation.h" #include "Translation.h"
#include "cmsis_os.h" #include "cmsis_os.h"
#include "main.hpp"
#include "stdlib.h" #include "stdlib.h"
#include "string.h" #include "string.h"
#include "unit.h" #include "unit.h"
#include "I2CBB.hpp" #include <MMA8652FC.hpp>
#include <gui.hpp>
#include <history.hpp>
#include <power.hpp>
// File local variables // File local variables
extern uint32_t currentTempTargetDegC; extern uint32_t currentTempTargetDegC;
extern TickType_t lastMovementTime; extern TickType_t lastMovementTime;
@@ -66,7 +66,7 @@ void gui_drawTipTemp(bool symbol) {
Temp = TipThermoModel::getTipInC(); Temp = TipThermoModel::getTipInC();
} }
OLED::printNumber(Temp, 3); // Draw the tip temp out finally OLED::printNumber(Temp, 3); // Draw the tip temp out finally
if (symbol) { if (symbol) {
if (OLED::getFont() == 0) { if (OLED::getFont() == 0) {
// Big font, can draw nice symbols // Big font, can draw nice symbols
@@ -96,7 +96,8 @@ static bool checkVoltageForExit() {
} }
uint16_t v = getInputVoltageX10(systemSettings.voltageDiv, 0); uint16_t v = getInputVoltageX10(systemSettings.voltageDiv, 0);
// Dont check for first 2 seconds while the ADC stabilizes and the DMA fills the buffer // Dont check for first 2 seconds while the ADC stabilizes and the DMA fills
// the buffer
if (xTaskGetTickCount() > (TICKS_SECOND * 2)) { if (xTaskGetTickCount() > (TICKS_SECOND * 2)) {
if ((v < lookupVoltageLevel())) { if ((v < lookupVoltageLevel())) {
currentTempTargetDegC = 0; currentTempTargetDegC = 0;
@@ -130,7 +131,7 @@ static void gui_drawBatteryIcon() {
// If <9V then show single digit, if not show duals // If <9V then show single digit, if not show duals
uint8_t V = getInputVoltageX10(systemSettings.voltageDiv, 0); uint8_t V = getInputVoltageX10(systemSettings.voltageDiv, 0);
if (V % 10 >= 5) if (V % 10 >= 5)
V = V / 10 + 1; // round up V = V / 10 + 1; // round up
else else
V = V / 10; V = V / 10;
if (V >= 10) { if (V >= 10) {
@@ -149,8 +150,8 @@ static void gui_drawBatteryIcon() {
// User is on a lithium battery // User is on a lithium battery
// we need to calculate which of the 10 levels they are on // we need to calculate which of the 10 levels they are on
uint8_t cellCount = systemSettings.cutoutSetting + 2; uint8_t cellCount = systemSettings.cutoutSetting + 2;
uint32_t cellV = getInputVoltageX10(systemSettings.voltageDiv, 0) uint32_t cellV =
/ cellCount; getInputVoltageX10(systemSettings.voltageDiv, 0) / cellCount;
// Should give us approx cell voltage X10 // Should give us approx cell voltage X10
// Range is 42 -> 33 = 9 steps therefore we will use battery 1-10 // Range is 42 -> 33 = 9 steps therefore we will use battery 1-10
if (cellV < 33) if (cellV < 33)
@@ -160,9 +161,8 @@ static void gui_drawBatteryIcon() {
cellV = 9; cellV = 9;
OLED::drawBattery(cellV + 1); OLED::drawBattery(cellV + 1);
} else } else
OLED::drawSymbol(15); // Draw the DC Logo OLED::drawSymbol(15); // Draw the DC Logo
#endif #endif
} }
static void gui_solderingTempAdjust() { static void gui_solderingTempAdjust() {
uint32_t lastChange = xTaskGetTickCount(); uint32_t lastChange = xTaskGetTickCount();
@@ -185,7 +185,8 @@ static void gui_solderingTempAdjust() {
return; return;
break; break;
case BUTTON_B_LONG: case BUTTON_B_LONG:
if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) { if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration >
PRESS_ACCEL_INTERVAL_MAX) {
if (systemSettings.ReverseButtonTempChangeEnabled) { if (systemSettings.ReverseButtonTempChangeEnabled) {
systemSettings.SolderingTemp += systemSettings.TempChangeLongStep; systemSettings.SolderingTemp += systemSettings.TempChangeLongStep;
} else } else
@@ -202,7 +203,8 @@ static void gui_solderingTempAdjust() {
systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep; systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep;
break; break;
case BUTTON_F_LONG: case BUTTON_F_LONG:
if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) { if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration >
PRESS_ACCEL_INTERVAL_MAX) {
if (systemSettings.ReverseButtonTempChangeEnabled) { if (systemSettings.ReverseButtonTempChangeEnabled) {
systemSettings.SolderingTemp -= systemSettings.TempChangeLongStep; systemSettings.SolderingTemp -= systemSettings.TempChangeLongStep;
} else } else
@@ -213,21 +215,25 @@ static void gui_solderingTempAdjust() {
break; break;
case BUTTON_F_SHORT: case BUTTON_F_SHORT:
if (systemSettings.ReverseButtonTempChangeEnabled) { if (systemSettings.ReverseButtonTempChangeEnabled) {
systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep; // add 10 systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep; // add 10
} else } else
systemSettings.SolderingTemp += systemSettings.TempChangeShortStep; // add 10 systemSettings.SolderingTemp += systemSettings.TempChangeShortStep; // add 10
break; break;
default: default:
break; break;
} }
if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) < PRESS_ACCEL_INTERVAL_MIN) { if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) <
autoRepeatAcceleration = PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN; PRESS_ACCEL_INTERVAL_MIN) {
autoRepeatAcceleration =
PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN;
} }
// constrain between 10-450 C // constrain between 10-450 C
#ifdef ENABLED_FAHRENHEIT_SUPPORT #ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF) { if (systemSettings.temperatureInF) {
if (systemSettings.SolderingTemp > 850) systemSettings.SolderingTemp = 850; if (systemSettings.SolderingTemp > 850)
if (systemSettings.SolderingTemp < 60) systemSettings.SolderingTemp = 60; systemSettings.SolderingTemp = 850;
if (systemSettings.SolderingTemp < 60)
systemSettings.SolderingTemp = 60;
} else } else
#endif #endif
{ {
@@ -238,7 +244,7 @@ static void gui_solderingTempAdjust() {
} }
if (xTaskGetTickCount() - lastChange > 2000) if (xTaskGetTickCount() - lastChange > 2000)
return; // exit if user just doesn't press anything for a bit return; // exit if user just doesn't press anything for a bit
#ifdef OLED_FLIP #ifdef OLED_FLIP
if (!OLED::getRotation()) { if (!OLED::getRotation()) {
@@ -298,13 +304,17 @@ static int gui_SolderingSleepingMode(bool stayOff) {
return 0; return 0;
} }
#ifdef MODEL_TS100 #ifdef POW_PD
if (checkVoltageForExit()) if (checkVoltageForExit())
return 1; // return non-zero on error return 1; // return non-zero on error
#endif #endif
#ifdef ENABLED_FAHRENHEIT_SUPPORT #ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF) { if (systemSettings.temperatureInF) {
currentTempTargetDegC = stayOff ? 0 : TipThermoModel::convertFtoC(min(systemSettings.SleepTemp, systemSettings.SolderingTemp)); currentTempTargetDegC =
stayOff
? 0
: TipThermoModel::convertFtoC(min(systemSettings.SleepTemp,
systemSettings.SolderingTemp));
} else } else
#endif #endif
{ {
@@ -360,7 +370,7 @@ static int gui_SolderingSleepingMode(bool stayOff) {
if (shouldShutdown()) { if (shouldShutdown()) {
// shutdown // shutdown
currentTempTargetDegC = 0; currentTempTargetDegC = 0;
return 1; // we want to exit soldering mode return 1; // we want to exit soldering mode
} }
} }
return 0; return 0;
@@ -394,19 +404,20 @@ static uint32_t getSleepTimeout() {
return 0; return 0;
} }
static bool shouldBeSleeping() { static bool shouldBeSleeping() {
//Return true if the iron should be in sleep mode // Return true if the iron should be in sleep mode
if (systemSettings.sensitivity && systemSettings.SleepTime) { if (systemSettings.sensitivity && systemSettings.SleepTime) {
if ((xTaskGetTickCount() - lastMovementTime) > getSleepTimeout() && (xTaskGetTickCount() - lastButtonTime) > getSleepTimeout()) { if ((xTaskGetTickCount() - lastMovementTime) > getSleepTimeout() && (xTaskGetTickCount() - lastButtonTime) > getSleepTimeout()) {
return true; return true;
} }
} }
#ifdef HALL_SENSOR #ifdef HALL_SENSOR
//If the hall effect sensor is enabled in the build, check if its over threshold, and if so then we force sleep // If the hall effect sensor is enabled in the build, check if its over
// threshold, and if so then we force sleep
if (lookupHallEffectThreshold()) { if (lookupHallEffectThreshold()) {
int16_t hallEffectStrength = getRawHallEffect(); int16_t hallEffectStrength = getRawHallEffect();
if (hallEffectStrength < 0) if (hallEffectStrength < 0)
hallEffectStrength = -hallEffectStrength; hallEffectStrength = -hallEffectStrength;
//Have absolute value of measure of magnetic field strength // Have absolute value of measure of magnetic field strength
if (hallEffectStrength > lookupHallEffectThreshold()) { if (hallEffectStrength > lookupHallEffectThreshold()) {
if (lastHallEffectSleepStart == 0) { if (lastHallEffectSleepStart == 0) {
lastHallEffectSleepStart = xTaskGetTickCount(); lastHallEffectSleepStart = xTaskGetTickCount();
@@ -442,7 +453,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
if (jumpToSleep) { if (jumpToSleep) {
if (gui_SolderingSleepingMode(jumpToSleep == 2)) { if (gui_SolderingSleepingMode(jumpToSleep == 2)) {
lastButtonTime = xTaskGetTickCount(); lastButtonTime = xTaskGetTickCount();
return; // If the function returns non-0 then exit return; // If the function returns non-0 then exit
} }
} }
for (;;) { for (;;) {
@@ -459,7 +470,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
OLED::setCursor(0, 0); OLED::setCursor(0, 0);
OLED::clearScreen(); OLED::clearScreen();
OLED::setFont(0); OLED::setFont(0);
OLED::print(UnlockingKeysString); OLED::print (UnlockingKeysString);
OLED::refresh(); OLED::refresh();
waitForButtonPressOrTimeout(1000); waitForButtonPressOrTimeout(1000);
break; break;
@@ -479,7 +490,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
OLED::setCursor(0, 0); OLED::setCursor(0, 0);
OLED::clearScreen(); OLED::clearScreen();
OLED::setFont(0); OLED::setFont(0);
OLED::print(WarningKeysLockedString); OLED::print (WarningKeysLockedString);
OLED::refresh(); OLED::refresh();
waitForButtonPressOrTimeout(500); waitForButtonPressOrTimeout(500);
break; break;
@@ -497,7 +508,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
return; return;
break; break;
case BUTTON_B_LONG: case BUTTON_B_LONG:
return; // exit on back long hold return; // exit on back long hold
break; break;
case BUTTON_F_LONG: case BUTTON_F_LONG:
// if boost mode is enabled turn it on // if boost mode is enabled turn it on
@@ -507,9 +518,9 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
case BUTTON_F_SHORT: case BUTTON_F_SHORT:
case BUTTON_B_SHORT: { case BUTTON_B_SHORT: {
uint16_t oldTemp = systemSettings.SolderingTemp; uint16_t oldTemp = systemSettings.SolderingTemp;
gui_solderingTempAdjust(); // goto adjust temp mode gui_solderingTempAdjust(); // goto adjust temp mode
if (oldTemp != systemSettings.SolderingTemp) { if (oldTemp != systemSettings.SolderingTemp) {
saveSettings(); // only save on change saveSettings(); // only save on change
} }
} }
break; break;
@@ -520,7 +531,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
OLED::setCursor(0, 0); OLED::setCursor(0, 0);
OLED::clearScreen(); OLED::clearScreen();
OLED::setFont(0); OLED::setFont(0);
OLED::print(LockingKeysString); OLED::print (LockingKeysString);
OLED::refresh(); OLED::refresh();
waitForButtonPressOrTimeout(1000); waitForButtonPressOrTimeout(1000);
} }
@@ -536,7 +547,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
// Draw in the screen details // Draw in the screen details
if (systemSettings.detailedSoldering) { if (systemSettings.detailedSoldering) {
OLED::setFont(1); OLED::setFont(1);
OLED::print(SolderingAdvancedPowerPrompt); // Power: OLED::print(SolderingAdvancedPowerPrompt); // Power:
OLED::printNumber(x10WattHistory.average() / 10, 2); OLED::printNumber(x10WattHistory.average() / 10, 2);
OLED::print(SymbolDot); OLED::print(SymbolDot);
OLED::printNumber(x10WattHistory.average() % 10, 1); OLED::printNumber(x10WattHistory.average() % 10, 1);
@@ -560,7 +571,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
// battery // battery
gui_drawBatteryIcon(); gui_drawBatteryIcon();
OLED::print(SymbolSpace); // Space out gap between battery <-> temp OLED::print(SymbolSpace); // Space out gap between battery <-> temp
gui_drawTipTemp(true); // Draw current tip temp gui_drawTipTemp(true); // Draw current tip temp
// We draw boost arrow if boosting, or else gap temp <-> heat // We draw boost arrow if boosting, or else gap temp <-> heat
// indicator // indicator
@@ -580,7 +591,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
OLED::drawSymbol(2); OLED::drawSymbol(2);
else else
OLED::print(SymbolSpace); OLED::print(SymbolSpace);
gui_drawTipTemp(true); // Draw current tip temp gui_drawTipTemp(true); // Draw current tip temp
OLED::print(SymbolSpace); // Space out gap between battery <-> temp OLED::print(SymbolSpace); // Space out gap between battery <-> temp
@@ -593,7 +604,8 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
if (boostModeOn) { if (boostModeOn) {
#ifdef ENABLED_FAHRENHEIT_SUPPORT #ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF) if (systemSettings.temperatureInF)
currentTempTargetDegC = TipThermoModel::convertFtoC(systemSettings.BoostTemp); currentTempTargetDegC =
TipThermoModel::convertFtoC(systemSettings.BoostTemp);
else else
#endif #endif
{ {
@@ -602,7 +614,8 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
} else { } else {
#ifdef ENABLED_FAHRENHEIT_SUPPORT #ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF) if (systemSettings.temperatureInF)
currentTempTargetDegC = TipThermoModel::convertFtoC(systemSettings.SolderingTemp); currentTempTargetDegC =
TipThermoModel::convertFtoC(systemSettings.SolderingTemp);
else else
#endif #endif
{ {
@@ -620,7 +633,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
if (shouldBeSleeping()) { if (shouldBeSleeping()) {
if (gui_SolderingSleepingMode(false)) { if (gui_SolderingSleepingMode(false)) {
return; // If the function returns non-0 then exit return; // If the function returns non-0 then exit
} }
} }
// slow down ui update rate // slow down ui update rate
@@ -632,14 +645,14 @@ void showDebugMenu(void) {
uint8_t screen = 0; uint8_t screen = 0;
ButtonState b; ButtonState b;
for (;;) { for (;;) {
OLED::clearScreen(); // Ensure the buffer starts clean OLED::clearScreen(); // Ensure the buffer starts clean
OLED::setCursor(0, 0); // Position the cursor at the 0,0 (top left) OLED::setCursor(0, 0); // Position the cursor at the 0,0 (top left)
OLED::setFont(1); // small font OLED::setFont(1); // small font
OLED::print(SymbolVersionNumber); // Print version number OLED::print(SymbolVersionNumber); // Print version number
OLED::setCursor(0, 8); // second line OLED::setCursor(0, 8); // second line
OLED::print(DebugMenu[screen]); OLED::print(DebugMenu[screen]);
switch (screen) { switch (screen) {
case 0: // Just prints date case 0: // Just prints date
break; break;
case 1: case 1:
// High water mark for GUI // High water mark for GUI
@@ -704,30 +717,30 @@ void showDebugMenu(void) {
uint8_t idleScreenBGF[sizeof(idleScreenBG)]; uint8_t idleScreenBGF[sizeof(idleScreenBG)];
/* StartGUITask function */ /* StartGUITask function */
void startGUITask(void const *argument __unused) { void startGUITask(void const *argument __unused) {
OLED::initialize(); // start up the LCD OLED::initialize(); // start up the LCD
uint8_t tempWarningState = 0; uint8_t tempWarningState = 0;
bool buttonLockout = false; bool buttonLockout = false;
bool tempOnDisplay = false; bool tempOnDisplay = false;
{ {
//Generate the flipped screen into ram for later use // Generate the flipped screen into ram for later use
//flipped is generated by flipping each row // flipped is generated by flipping each row
for (int row = 0; row < 2; row++) { for (int row = 0; row < 2; row++) {
for (int x = 0; x < 84; x++) { for (int x = 0; x < 84; x++) {
idleScreenBGF[(row * 84) + x] = idleScreenBG[(row * 84) + (83 - x)]; idleScreenBGF[(row * 84) + x] = idleScreenBG[(row * 84) + (83 - x)];
} }
} }
} }
getTipRawTemp(1); // reset filter getTipRawTemp(1); // reset filter
OLED::setRotation(systemSettings.OrientationMode & 1); OLED::setRotation(systemSettings.OrientationMode & 1);
uint32_t ticks = xTaskGetTickCount(); uint32_t ticks = xTaskGetTickCount();
ticks += 4000; // 4 seconds from now ticks += 4000; // 4 seconds from now
while (xTaskGetTickCount() < ticks) { while (xTaskGetTickCount() < ticks) {
if (showBootLogoIfavailable() == false) if (showBootLogoIfavailable() == false)
ticks = xTaskGetTickCount(); ticks = xTaskGetTickCount();
ButtonState buttons = getButtonState(); ButtonState buttons = getButtonState();
if (buttons) if (buttons)
ticks = xTaskGetTickCount(); // make timeout now so we will exit ticks = xTaskGetTickCount(); // make timeout now so we will exit
GUIDelay(); GUIDelay();
} }
@@ -786,18 +799,18 @@ void startGUITask(void const *argument __unused) {
saveSettings(); saveSettings();
break; break;
case BUTTON_F_SHORT: case BUTTON_F_SHORT:
gui_solderingMode(0); // enter soldering mode gui_solderingMode(0); // enter soldering mode
buttonLockout = true; buttonLockout = true;
break; break;
case BUTTON_B_SHORT: case BUTTON_B_SHORT:
enterSettingsMenu(); // enter the settings menu enterSettingsMenu(); // enter the settings menu
buttonLockout = true; buttonLockout = true;
break; break;
default: default:
break; break;
} }
currentTempTargetDegC = 0; // ensure tip is off currentTempTargetDegC = 0; // ensure tip is off
getInputVoltageX10(systemSettings.voltageDiv, 0); getInputVoltageX10(systemSettings.voltageDiv, 0);
uint32_t tipTemp = TipThermoModel::getTipInC(); uint32_t tipTemp = TipThermoModel::getTipInC();
@@ -807,7 +820,8 @@ void startGUITask(void const *argument __unused) {
// button presses) in a while. // button presses) in a while.
OLED::setDisplayState(OLED::DisplayState::ON); OLED::setDisplayState(OLED::DisplayState::ON);
if ((tipTemp < 50) && systemSettings.sensitivity && (((xTaskGetTickCount() - lastMovementTime) > MOVEMENT_INACTIVITY_TIME) && ((xTaskGetTickCount() - lastButtonTime) > BUTTON_INACTIVITY_TIME))) { if ((tipTemp < 50) && systemSettings.sensitivity && (((xTaskGetTickCount() - lastMovementTime) >
MOVEMENT_INACTIVITY_TIME) && ((xTaskGetTickCount() - lastButtonTime) > BUTTON_INACTIVITY_TIME))) {
OLED::setDisplayState(OLED::DisplayState::OFF); OLED::setDisplayState(OLED::DisplayState::OFF);
} }
@@ -862,12 +876,12 @@ void startGUITask(void const *argument __unused) {
OLED::setCursor(56, 0); OLED::setCursor(56, 0);
} else { } else {
OLED::fillArea(0, 0, 41, 16, 0); // clear the area OLED::fillArea(0, 0, 41, 16, 0); // clear the area
OLED::setCursor(0, 0); OLED::setCursor(0, 0);
} }
// draw in the temp // draw in the temp
if (!(systemSettings.coolingTempBlink && (xTaskGetTickCount() % 25 < 16))) if (!(systemSettings.coolingTempBlink && (xTaskGetTickCount() % 25 < 16)))
gui_drawTipTemp(false); // draw in the temp gui_drawTipTemp(false); // draw in the temp
} }
} }
OLED::refresh(); OLED::refresh();