inputs: idle: implement an idletimer

This commit is contained in:
Torrie Fischer 2023-12-23 11:11:49 +01:00
parent e43b594637
commit 0d3bcb4267
2 changed files with 53 additions and 0 deletions

41
src/inputs/Idle.cpp Normal file
View File

@ -0,0 +1,41 @@
#include "Idle.h"
#include "../Static.h"
IdleTimer::IdleTimer()
: InputSource("IdleTimer"),
m_idleTime(60), m_secondsRemaining(0)
{
}
InputEvent
IdleTimer::read()
{
EVERY_N_SECONDS(1) {
if (m_secondsRemaining > 0) {
m_secondsRemaining -= 1;
if (m_secondsRemaining == 0) {
return InputEvent::IdleStart;
}
}
}
return InputEvent::None;
}
void
IdleTimer::handleEvent(const InputEvent& evt)
{
switch(evt.intent) {
case InputEvent::IdleStart:
m_secondsRemaining = 0;
break;
case InputEvent::IdleStop:
m_secondsRemaining = m_idleTime;
break;
default:
break;
}
}
STATIC_ALLOC(IdleTimer);
STATIC_TASK(IdleTimer);

12
src/inputs/Idle.h Normal file
View File

@ -0,0 +1,12 @@
#pragma once
#include <Figments.h>
class IdleTimer : public InputSource {
public:
IdleTimer();
void handleEvent(const InputEvent& evt);
virtual InputEvent read() override;
private:
uint16_t m_idleTime;
uint16_t m_secondsRemaining;
};