Pull out sleep and shutdown control into their own functions
This commit is contained in:
@@ -25,15 +25,15 @@ extern "C" {
|
|||||||
#include "I2CBB.hpp"
|
#include "I2CBB.hpp"
|
||||||
// File local variables
|
// File local variables
|
||||||
extern uint32_t currentTempTargetDegC;
|
extern uint32_t currentTempTargetDegC;
|
||||||
extern uint8_t accelInit;
|
extern TickType_t lastMovementTime;
|
||||||
extern uint32_t lastMovementTime;
|
|
||||||
extern osThreadId GUITaskHandle;
|
extern osThreadId GUITaskHandle;
|
||||||
extern osThreadId MOVTaskHandle;
|
extern osThreadId MOVTaskHandle;
|
||||||
extern osThreadId PIDTaskHandle;
|
extern osThreadId PIDTaskHandle;
|
||||||
|
static bool shouldBeSleeping();
|
||||||
|
static bool shouldShutdown();
|
||||||
#define MOVEMENT_INACTIVITY_TIME (60 * configTICK_RATE_HZ)
|
#define MOVEMENT_INACTIVITY_TIME (60 * configTICK_RATE_HZ)
|
||||||
#define BUTTON_INACTIVITY_TIME (60 * configTICK_RATE_HZ)
|
#define BUTTON_INACTIVITY_TIME (60 * configTICK_RATE_HZ)
|
||||||
|
static TickType_t lastHallEffectSleepStart = 0;
|
||||||
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;
|
||||||
@@ -272,19 +272,33 @@ static void gui_solderingTempAdjust() {
|
|||||||
GUIDelay();
|
GUIDelay();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static bool shouldShutdown() {
|
||||||
|
if (systemSettings.ShutdownTime) { // only allow shutdown exit if time > 0
|
||||||
|
if (lastMovementTime) {
|
||||||
|
if (((TickType_t) (xTaskGetTickCount() - lastMovementTime)) > (TickType_t) (systemSettings.ShutdownTime * TICKS_MIN)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (lastHallEffectSleepStart) {
|
||||||
|
if (((TickType_t) (xTaskGetTickCount() - lastHallEffectSleepStart)) > (TickType_t) (systemSettings.ShutdownTime * TICKS_MIN)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
static int gui_SolderingSleepingMode(bool stayOff) {
|
static int gui_SolderingSleepingMode(bool stayOff) {
|
||||||
// Drop to sleep temperature and display until movement or button press
|
// Drop to sleep temperature and display until movement or button press
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ButtonState buttons = getButtonState();
|
// user moved or pressed a button, go back to soldering
|
||||||
if (buttons)
|
if (!shouldBeSleeping()) {
|
||||||
return 0;
|
return 0;
|
||||||
if ((xTaskGetTickCount() > 1000) && ((accelInit && (xTaskGetTickCount() - lastMovementTime < 1000)) || (xTaskGetTickCount() - lastButtonTime < 1000)))
|
}
|
||||||
return 0; // user moved or pressed a button, go back to soldering
|
|
||||||
#ifdef MODEL_TS100
|
#ifdef MODEL_TS100
|
||||||
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) {
|
||||||
@@ -338,15 +352,14 @@ static int gui_SolderingSleepingMode(bool stayOff) {
|
|||||||
OLED::drawSymbol(1);
|
OLED::drawSymbol(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (systemSettings.ShutdownTime) // only allow shutdown exit if time > 0
|
|
||||||
if (lastMovementTime)
|
|
||||||
if (((uint32_t) (xTaskGetTickCount() - lastMovementTime)) > (uint32_t) (systemSettings.ShutdownTime * 60 * 1000)) {
|
|
||||||
// shutdown
|
|
||||||
currentTempTargetDegC = 0;
|
|
||||||
return 1; // we want to exit soldering mode
|
|
||||||
}
|
|
||||||
OLED::refresh();
|
OLED::refresh();
|
||||||
GUIDelay();
|
GUIDelay();
|
||||||
|
if (shouldShutdown()) {
|
||||||
|
// shutdown
|
||||||
|
currentTempTargetDegC = 0;
|
||||||
|
return 1; // we want to exit soldering mode
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -380,12 +393,29 @@ static uint32_t getSleepTimeout() {
|
|||||||
}
|
}
|
||||||
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 ((xTaskGetTickCount() - lastMovementTime) > getSleepTimeout() && (xTaskGetTickCount() - lastButtonTime) > getSleepTimeout()) {
|
if (systemSettings.sensitivity && systemSettings.SleepTime) {
|
||||||
return true;
|
if ((xTaskGetTickCount() - lastMovementTime) > getSleepTimeout() && (xTaskGetTickCount() - lastButtonTime) > getSleepTimeout()) {
|
||||||
|
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()) {
|
||||||
|
int16_t hallEffectStrength = getRawHallEffect();
|
||||||
|
if (hallEffectStrength < 0)
|
||||||
|
hallEffectStrength = -hallEffectStrength;
|
||||||
|
//Have absolute value of measure of magnetic field strength
|
||||||
|
if (hallEffectStrength > lookupHallEffectThreshold()) {
|
||||||
|
if (lastHallEffectSleepStart == 0) {
|
||||||
|
lastHallEffectSleepStart = xTaskGetTickCount();
|
||||||
|
}
|
||||||
|
if ((xTaskGetTickCount() - lastHallEffectSleepStart) > TICKS_SECOND) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
lastHallEffectSleepStart = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -531,12 +561,11 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (systemSettings.sensitivity && systemSettings.SleepTime)
|
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
|
||||||
GUIDelay();
|
GUIDelay();
|
||||||
}
|
}
|
||||||
@@ -598,7 +627,7 @@ void showDebugMenu(void) {
|
|||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
// Print PCB ID number
|
// Print PCB ID number
|
||||||
OLED::printNumber(PCBVersion, 1);
|
OLED::printNumber(PCBVersion, 2);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -654,14 +683,6 @@ void startGUITask(void const *argument __unused) {
|
|||||||
OLED::refresh();
|
OLED::refresh();
|
||||||
waitForButtonPressOrTimeout(10000);
|
waitForButtonPressOrTimeout(10000);
|
||||||
}
|
}
|
||||||
if (getHallSensorFitted()) {
|
|
||||||
OLED::clearScreen();
|
|
||||||
OLED::setFont(1);
|
|
||||||
OLED::setCursor(0, 0);
|
|
||||||
OLED::printNumber(5000, 4, 0);
|
|
||||||
OLED::refresh();
|
|
||||||
waitForButtonPressOrTimeout(10000);
|
|
||||||
}
|
|
||||||
if (systemSettings.autoStartMode) {
|
if (systemSettings.autoStartMode) {
|
||||||
// jump directly to the autostart mode
|
// jump directly to the autostart mode
|
||||||
if (systemSettings.autoStartMode == 1) {
|
if (systemSettings.autoStartMode == 1) {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
#include "task.h"
|
#include "task.h"
|
||||||
#define MOVFilter 8
|
#define MOVFilter 8
|
||||||
uint8_t accelInit = 0;
|
uint8_t accelInit = 0;
|
||||||
uint32_t lastMovementTime = 0;
|
TickType_t lastMovementTime = 0;
|
||||||
void detectAccelerometerVersion() {
|
void detectAccelerometerVersion() {
|
||||||
#ifdef ACCEL_MMA
|
#ifdef ACCEL_MMA
|
||||||
if (MMA8652FC::detect()) {
|
if (MMA8652FC::detect()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user