]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/sensor.h
13aaca3fe8e9a060e94db659372ecfc3433cf13e
[r2c2.git] / source / libr2c2 / sensor.h
1 #ifndef LIBR2C2_SENSOR_H_
2 #define LIBR2C2_SENSOR_H_
3
4 #include <sigc++/signal.h>
5 #include <msp/time/timedelta.h>
6
7 namespace R2C2 {
8
9 class Block;
10 class Layout;
11
12 class Sensor: public sigc::trackable
13 {
14 public:
15         enum State
16         {
17                 INACTIVE,
18                 MAYBE_INACTIVE,
19                 MAYBE_ACTIVE,
20                 ACTIVE
21         };
22
23         sigc::signal<void, State> signal_state_changed;
24
25 protected:
26         Layout &layout;
27         unsigned address;
28         bool invert;
29         State state;
30         Msp::Time::TimeDelta state_confirm_timeout;
31
32         Sensor(Layout &);
33 public:
34         virtual ~Sensor();
35
36         virtual void set_address(unsigned);
37         unsigned get_address() const { return address; }
38         State get_state() const { return state; }
39         virtual Block *get_block() const { return 0; }
40
41         void tick(const Msp::Time::TimeDelta &);
42
43 private:
44         void event(unsigned, bool);
45 };
46
47 } // namespace R2C2
48
49 #endif