1
0
forked from me/IronOS

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;
@@ -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;
@@ -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)
@@ -162,7 +163,6 @@ static void gui_drawBatteryIcon() {
} 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
@@ -220,14 +222,18 @@ static void gui_solderingTempAdjust() {
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
{ {
@@ -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
{ {
@@ -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();
@@ -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;
@@ -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);
} }
@@ -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
{ {
@@ -710,8 +723,8 @@ void startGUITask(void const *argument __unused) {
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)];
@@ -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);
} }