Plaquette
 
Loading...
Searching...
No Matches
Alarm.h
1/*
2 * Alarm.h
3 *
4 * (c) 2015 Sofian Audry :: info(@)sofianaudry(.)com
5 * (c) 2015 Thomas O Fredericks :: tof(@)t-o-f(.)info
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef PQ_ALARM_H_
22#define PQ_ALARM_H_
23
24#include "PqCore.h"
25#include "AbstractTimer.h"
26
27namespace pq {
28
32class Alarm : public DigitalSource, public AbstractTimer {
33public:
39
46
48 virtual bool finished() { return rose(); }
49
51 virtual void onFinish(EventCallback callback) { onEvent(callback, EVENT_FINISH); }
52
54 virtual void setTime(float time);
55
56protected:
57 virtual void begin();
58 virtual void step();
59
61 virtual bool eventTriggered(EventType eventType) {
62 switch (eventType) {
63 case EVENT_FINISH: return finished();
64 default: return DigitalSource::eventTriggered(eventType);
65 }
66 }
67
68 // Returns current absolute time (in seconds).
69 virtual float _time() const;
70};
71
72}
73
74#endif
Definition AbstractTimer.h:29
virtual float duration() const
Returns duration.
Definition AbstractTimer.h:45
Chronometer class which becomes "on" after a given duration.
Definition Alarm.h:32
virtual bool finished()
Returns true iff the alarm just finished its process this step.
Definition Alarm.h:48
virtual void onFinish(EventCallback callback)
Registers event callback on finish event.
Definition Alarm.h:51
virtual bool eventTriggered(EventType eventType)
Returns true iff an event of a certain type has been triggered.
Definition Alarm.h:61
virtual void setTime(float time)
Set alarm at specific time.
Definition Alarm.cpp:51
A digital source that contains a true/false value.
Definition PqCore.h:462
virtual bool eventTriggered(EventType eventType)
Returns true iff an event of a certain type has been triggered.
Definition PqCore.h:509
virtual bool rose()
Returns true if the value rose.
Definition PqCore.h:479
The main Plaquette static class containing all the units.
Definition PqCore.h:60
static Engine & primary()
Returns the main instance of Plaquette.
Definition PqCore.cpp:31
virtual void onEvent(EventCallback callback, EventType eventType)
Registers event callback.
Definition PqCore.cpp:246
Engine * engine() const
Returns the engine that owns this unit.
Definition PqCore.h:382