]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/dummy.cpp
Add framework for generating simple meshes for vehicles
[r2c2.git] / source / libmarklin / dummy.cpp
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #include "dummy.h"
9
10 using namespace std;
11
12 namespace Marklin {
13
14 Dummy::Dummy():
15         power(true)
16 { }
17
18 void Dummy::set_power(bool p)
19 {
20         power = p;
21         signal_power.emit(power);
22 }
23
24 void Dummy::add_turnout(unsigned addr)
25 {
26         turnouts[addr];
27 }
28
29 void Dummy::set_turnout(unsigned addr, bool state)
30 {
31         if(turnouts[addr]!=state)
32         {
33                 turnouts[addr] = state;
34                 signal_turnout.emit(addr, state);
35         }
36 }
37
38 bool Dummy::get_turnout(unsigned addr) const
39 {
40         map<unsigned, bool>::const_iterator i = turnouts.find(addr);
41         if(i!=turnouts.end())
42                 return i->second;
43         return false;
44 }
45
46 void Dummy::set_loco_speed(unsigned addr, unsigned speed)
47 {
48         LocoState &loco = locos[addr];
49         loco.speed = speed;
50         signal_loco_speed.emit(addr, speed, loco.reverse);
51 }
52
53 void Dummy::set_loco_reverse(unsigned addr, bool rev)
54 {
55         LocoState &loco = locos[addr];
56         loco.reverse = rev;
57         signal_loco_speed.emit(addr, loco.speed, rev);
58 }
59
60 void Dummy::set_loco_function(unsigned addr, unsigned func, bool state)
61 {
62         signal_loco_function.emit(addr, func, state);
63 }
64
65 void Dummy::set_sensor(unsigned addr, bool state)
66 {
67         if(sensors[addr]!=state)
68         {
69                 sensors[addr] = state;
70                 signal_sensor.emit(addr, state);
71         }
72 }
73
74 bool Dummy::get_sensor(unsigned addr) const
75 {
76         map<unsigned, bool>::const_iterator i = sensors.find(addr);
77         if(i!=sensors.end())
78                 return i->second;
79         return false;
80 }
81
82 } // namespace Marklin