]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/dummy.cpp
Strip Id tags and copyright notices from files
[r2c2.git] / source / libr2c2 / dummy.cpp
1 #include "dummy.h"
2
3 using namespace std;
4
5 namespace R2C2 {
6
7 Dummy::Dummy():
8         power(true)
9 { }
10
11 void Dummy::set_power(bool p)
12 {
13         power = p;
14         signal_power.emit(power);
15 }
16
17 const char *Dummy::enumerate_protocols(unsigned i) const
18 {
19         if(i==0)
20                 return "dummy";
21         return 0;
22 }
23
24 unsigned Dummy::get_protocol_speed_steps(const string &) const
25 {
26         return 0;
27 }
28
29 void Dummy::add_turnout(unsigned addr, const TrackType &)
30 {
31         turnouts[addr];
32 }
33
34 void Dummy::set_turnout(unsigned addr, unsigned state)
35 {
36         if(turnouts[addr]!=state)
37         {
38                 turnouts[addr] = state;
39                 signal_turnout.emit(addr, state);
40         }
41 }
42
43 unsigned Dummy::get_turnout(unsigned addr) const
44 {
45         map<unsigned, unsigned>::const_iterator i = turnouts.find(addr);
46         if(i!=turnouts.end())
47                 return i->second;
48         return false;
49 }
50
51 void Dummy::set_loco_speed(unsigned addr, unsigned speed)
52 {
53         LocoState &loco = locos[addr];
54         loco.speed = speed;
55         signal_loco_speed.emit(addr, speed, loco.reverse);
56 }
57
58 void Dummy::set_loco_reverse(unsigned addr, bool rev)
59 {
60         LocoState &loco = locos[addr];
61         loco.reverse = rev;
62         signal_loco_speed.emit(addr, loco.speed, rev);
63 }
64
65 void Dummy::set_loco_function(unsigned addr, unsigned func, bool state)
66 {
67         signal_loco_function.emit(addr, func, state);
68 }
69
70 void Dummy::set_sensor(unsigned addr, bool state)
71 {
72         if(sensors[addr]!=state)
73         {
74                 sensors[addr] = state;
75                 signal_sensor.emit(addr, state);
76         }
77 }
78
79 bool Dummy::get_sensor(unsigned addr) const
80 {
81         map<unsigned, bool>::const_iterator i = sensors.find(addr);
82         if(i!=sensors.end())
83                 return i->second;
84         return false;
85 }
86
87 } // namespace R2C2