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 MOVTaskHandle;
extern osThreadId PIDTaskHandle;
static bool shouldBeSleeping();
static bool shouldBeSleeping(bool inAutoStart = false);
static bool shouldShutdown();
#define MOVEMENT_INACTIVITY_TIME (60 * configTICK_RATE_HZ)
#define BUTTON_INACTIVITY_TIME (60 * configTICK_RATE_HZ)
@@ -301,17 +301,12 @@ static bool shouldShutdown() {
}
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
for (;;) {
// 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 (xTaskGetTickCount() > TICKS_SECOND * 2) {
if (!shouldBeSleeping()) {
return 0;
}
}
#ifdef POW_DC
if (checkVoltageForExit())
@@ -372,6 +367,9 @@ static int gui_SolderingSleepingMode(bool stayOff) {
OLED::refresh();
GUIDelay();
if (!shouldBeSleeping(autoStarted)) {
return 0;
}
if (shouldShutdown()) {
// shutdown
currentTempTargetDegC = 0;
@@ -408,11 +406,19 @@ static uint32_t getSleepTimeout() {
}
return 0;
}
static bool shouldBeSleeping() {
// Return true if the iron should be in sleep mode
static bool shouldBeSleeping(bool inAutoStart) {
// Return true if the iron should be in sleep mode
if (systemSettings.sensitivity && systemSettings.SleepTime) {
if ((xTaskGetTickCount() - lastMovementTime) > getSleepTimeout() && (xTaskGetTickCount() - lastButtonTime) > getSleepTimeout()) {
return true;
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()) {
return true;
}
}
}
@@ -457,7 +463,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
bool buttonsLocked = false;
if (jumpToSleep) {
if (gui_SolderingSleepingMode(jumpToSleep == 2)) {
if (gui_SolderingSleepingMode(jumpToSleep == 2, true) == 1) {
lastButtonTime = xTaskGetTickCount();
return; // If the function returns non-0 then exit
}
@@ -636,7 +642,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
#endif
if (shouldBeSleeping()) {
if (gui_SolderingSleepingMode(false)) {
if (gui_SolderingSleepingMode(false, false)) {
return; // If the function returns non-0 then exit
}
}
@@ -789,16 +795,8 @@ void startGUITask(void const *argument __unused) {
}
if (systemSettings.autoStartMode) {
// jump directly to the autostart mode
if (systemSettings.autoStartMode == 1) {
gui_solderingMode(0);
buttonLockout = true;
} else if (systemSettings.autoStartMode == 2) {
gui_solderingMode(1);
buttonLockout = true;
} else if (systemSettings.autoStartMode == 3) {
gui_solderingMode(2);
buttonLockout = true;
}
gui_solderingMode(systemSettings.autoStartMode - 1);
buttonLockout = true;
}
for (;;) {

View File

@@ -27,7 +27,7 @@ void detectAccelerometerVersion() {
#ifdef ACCEL_MMA
if (MMA8652FC::detect()) {
PCBVersion = 1;
if(!MMA8652FC::initalize()) {
if (!MMA8652FC::initalize()) {
PCBVersion = 99;
}
} else
@@ -36,7 +36,7 @@ void detectAccelerometerVersion() {
if (LIS2DH12::detect()) {
PCBVersion = 2;
// Setup the ST Accelerometer
if(!LIS2DH12::initalize()) {
if (!LIS2DH12::initalize()) {
PCBVersion = 99;
}
} 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
if (PCBVersion == 2) {
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) {
osDelay(10);//Make oled init happen first
osDelay(1); //Make oled init happen first
postRToSInit();
OLED::setRotation(systemSettings.OrientationMode & 1);
detectAccelerometerVersion();
lastMovementTime = 0;
if ((systemSettings.autoStartMode == 2 || systemSettings.autoStartMode == 3))
osDelay(2000);
osDelay(2 * TICKS_SECOND);
lastMovementTime = 0;
int16_t datax[MOVFilter] = { 0 };