1
0
forked from me/IronOS

Edit sleep mode settings to be autostart aware

Fixes #696
This commit is contained in:
Ben V. Brown
2020-12-31 10:11:20 +11:00
parent 7f81fbbe7a
commit 29863ebf6c
2 changed files with 27 additions and 28 deletions

View File

@@ -32,7 +32,7 @@ extern TickType_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 shouldBeSleeping(bool inAutoStart = false);
static bool shouldShutdown(); 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)
@@ -301,17 +301,12 @@ static bool shouldShutdown() {
} }
return false; return false;
} }
static int gui_SolderingSleepingMode(bool stayOff) { static int gui_SolderingSleepingMode(bool stayOff, bool autoStarted) {
// Drop to sleep temperature and display until movement or button press // Drop to sleep temperature and display until movement or button press
for (;;) { for (;;) {
// user moved or pressed a button, go back to soldering // user moved or pressed a button, go back to soldering
//If in the first two seconds we disable this to let accelerometer warm up //If in the first two seconds we disable this to let accelerometer warm up
if (xTaskGetTickCount() > TICKS_SECOND * 2) {
if (!shouldBeSleeping()) {
return 0;
}
}
#ifdef POW_DC #ifdef POW_DC
if (checkVoltageForExit()) if (checkVoltageForExit())
@@ -372,6 +367,9 @@ static int gui_SolderingSleepingMode(bool stayOff) {
OLED::refresh(); OLED::refresh();
GUIDelay(); GUIDelay();
if (!shouldBeSleeping(autoStarted)) {
return 0;
}
if (shouldShutdown()) { if (shouldShutdown()) {
// shutdown // shutdown
currentTempTargetDegC = 0; currentTempTargetDegC = 0;
@@ -408,13 +406,21 @@ static uint32_t getSleepTimeout() {
} }
return 0; return 0;
} }
static bool shouldBeSleeping() { static bool shouldBeSleeping(bool inAutoStart) {
// 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 (inAutoStart) {
//In auto start we are asleep until movement
if (lastMovementTime == 0 && lastButtonTime == 0) {
return true;
}
}
if (lastMovementTime > 0 || lastButtonTime > 0) {
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 // If the hall effect sensor is enabled in the build, check if its over
@@ -457,7 +463,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
bool buttonsLocked = false; bool buttonsLocked = false;
if (jumpToSleep) { if (jumpToSleep) {
if (gui_SolderingSleepingMode(jumpToSleep == 2)) { if (gui_SolderingSleepingMode(jumpToSleep == 2, true) == 1) {
lastButtonTime = xTaskGetTickCount(); lastButtonTime = xTaskGetTickCount();
return; // If the function returns non-0 then exit return; // If the function returns non-0 then exit
} }
@@ -636,7 +642,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
#endif #endif
if (shouldBeSleeping()) { if (shouldBeSleeping()) {
if (gui_SolderingSleepingMode(false)) { if (gui_SolderingSleepingMode(false, false)) {
return; // If the function returns non-0 then exit return; // If the function returns non-0 then exit
} }
} }
@@ -789,16 +795,8 @@ void startGUITask(void const *argument __unused) {
} }
if (systemSettings.autoStartMode) { if (systemSettings.autoStartMode) {
// jump directly to the autostart mode // jump directly to the autostart mode
if (systemSettings.autoStartMode == 1) { gui_solderingMode(systemSettings.autoStartMode - 1);
gui_solderingMode(0);
buttonLockout = true; buttonLockout = true;
} else if (systemSettings.autoStartMode == 2) {
gui_solderingMode(1);
buttonLockout = true;
} else if (systemSettings.autoStartMode == 3) {
gui_solderingMode(2);
buttonLockout = true;
}
} }
for (;;) { for (;;) {

View File

@@ -27,7 +27,7 @@ void detectAccelerometerVersion() {
#ifdef ACCEL_MMA #ifdef ACCEL_MMA
if (MMA8652FC::detect()) { if (MMA8652FC::detect()) {
PCBVersion = 1; PCBVersion = 1;
if(!MMA8652FC::initalize()) { if (!MMA8652FC::initalize()) {
PCBVersion = 99; PCBVersion = 99;
} }
} else } else
@@ -36,7 +36,7 @@ void detectAccelerometerVersion() {
if (LIS2DH12::detect()) { if (LIS2DH12::detect()) {
PCBVersion = 2; PCBVersion = 2;
// Setup the ST Accelerometer // Setup the ST Accelerometer
if(!LIS2DH12::initalize()) { if (!LIS2DH12::initalize()) {
PCBVersion = 99; PCBVersion = 99;
} }
} else } else
@@ -58,7 +58,7 @@ void detectAccelerometerVersion() {
} }
} }
inline void readAccelerometer(int16_t& tx, int16_t& ty, int16_t& tz, Orientation &rotation) { inline void readAccelerometer(int16_t &tx, int16_t &ty, int16_t &tz, Orientation &rotation) {
#ifdef ACCEL_LIS #ifdef ACCEL_LIS
if (PCBVersion == 2) { if (PCBVersion == 2) {
LIS2DH12::getAxisReadings(tx, ty, tz); LIS2DH12::getAxisReadings(tx, ty, tz);
@@ -82,12 +82,13 @@ inline void readAccelerometer(int16_t& tx, int16_t& ty, int16_t& tz, Orientation
} }
} }
void startMOVTask(void const *argument __unused) { void startMOVTask(void const *argument __unused) {
osDelay(10);//Make oled init happen first osDelay(1); //Make oled init happen first
postRToSInit(); postRToSInit();
OLED::setRotation(systemSettings.OrientationMode & 1); OLED::setRotation(systemSettings.OrientationMode & 1);
detectAccelerometerVersion(); detectAccelerometerVersion();
lastMovementTime = 0;
if ((systemSettings.autoStartMode == 2 || systemSettings.autoStartMode == 3)) if ((systemSettings.autoStartMode == 2 || systemSettings.autoStartMode == 3))
osDelay(2000); osDelay(2 * TICKS_SECOND);
lastMovementTime = 0; lastMovementTime = 0;
int16_t datax[MOVFilter] = { 0 }; int16_t datax[MOVFilter] = { 0 };