From da6b780941c95123fd3d665b4d21d994521c1f7a Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Tue, 22 Nov 2022 18:25:55 +1100 Subject: [PATCH] Create shouldDeviceShutdown.cpp --- .../utils/shouldDeviceShutdown.cpp | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 source/Core/Threads/OperatingModes/utils/shouldDeviceShutdown.cpp diff --git a/source/Core/Threads/OperatingModes/utils/shouldDeviceShutdown.cpp b/source/Core/Threads/OperatingModes/utils/shouldDeviceShutdown.cpp new file mode 100644 index 00000000..541a2669 --- /dev/null +++ b/source/Core/Threads/OperatingModes/utils/shouldDeviceShutdown.cpp @@ -0,0 +1,24 @@ +#include "OperatingModeUtilities.h" + +extern TickType_t lastMovementTime; +extern TickType_t lastHallEffectSleepStart; +#include "Buttons.hpp" + +bool shouldShutdown(void) { + if (getSettingValue(SettingsOptions::ShutdownTime)) { // only allow shutdown exit if time > 0 + if (lastMovementTime) { + if (((TickType_t)(xTaskGetTickCount() - lastMovementTime)) > (TickType_t)(getSettingValue(SettingsOptions::ShutdownTime) * TICKS_MIN)) { + return true; + } + } + if (lastHallEffectSleepStart) { + if (((TickType_t)(xTaskGetTickCount() - lastHallEffectSleepStart)) > (TickType_t)(getSettingValue(SettingsOptions::ShutdownTime) * TICKS_MIN)) { + return true; + } + } + } + if (getButtonState() == BUTTON_B_LONG) { // allow also if back button is pressed long + return true; + } + return false; +}