feat: option to automatically power off radio after inactivity (#3414)

This commit is contained in:
Paul Tapper
2024-08-28 15:31:25 +10:00
committed by GitHub
parent 1852c8c673
commit af9ba9cef7
41 changed files with 1042 additions and 927 deletions
+25 -2
View File
@@ -40,6 +40,7 @@
#include "switches.h"
#include "inactivity_timer.h"
#include "input_mapping.h"
#include "trainer.h"
#include "tasks.h"
#include "tasks/mixer_task.h"
@@ -1648,6 +1649,25 @@ uint32_t pwrPressedDuration()
inline tmr10ms_t getTicks() { return g_tmr10ms; }
#endif
bool pwrOffDueToInactivity()
{
uint8_t inactivityLimit = g_eeGeneral.pwrOffIfInactive;
static tmr10ms_t lastConnectedTime = 0;
tmr10ms_t currentTime = get_tmr10ms();
if (TELEMETRY_STREAMING() ||
(usbPlugged() && getSelectedUsbMode() != USB_UNSELECTED_MODE) ||
isTrainerValid())
lastConnectedTime = currentTime;
bool inactivityShutdown =
inactivityLimit && inactivity.counter > 60u * inactivityLimit &&
(currentTime - lastConnectedTime) / 100u > 60u * inactivityLimit;
return inactivityShutdown;
}
uint32_t pwrCheck()
{
const char * message = nullptr;
@@ -1660,11 +1680,14 @@ uint32_t pwrCheck()
static uint8_t pwr_check_state = PWR_CHECK_ON;
bool inactivityShutdown = pwrOffDueToInactivity();
if (pwr_check_state == PWR_CHECK_OFF) {
return e_power_off;
}
else if (pwrPressed()) {
inactivityTimerReset(ActivitySource::Keys);
else if (pwrPressed() || inactivityShutdown) {
if (!inactivityShutdown)
inactivityTimerReset(ActivitySource::Keys);
if (TELEMETRY_STREAMING()) {
message = STR_MODEL_STILL_POWERED;