inputs: idle: implement an idletimer
This commit is contained in:
parent
e43b594637
commit
0d3bcb4267
41
src/inputs/Idle.cpp
Normal file
41
src/inputs/Idle.cpp
Normal 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
12
src/inputs/Idle.h
Normal 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;
|
||||
};
|
Loading…
Reference in New Issue
Block a user