]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/dummy.cpp
Rename the project to R²C²
[r2c2.git] / source / libr2c2 / dummy.cpp
diff --git a/source/libr2c2/dummy.cpp b/source/libr2c2/dummy.cpp
new file mode 100644 (file)
index 0000000..814dce4
--- /dev/null
@@ -0,0 +1,94 @@
+/* $Id$
+
+This file is part of R²C²
+Copyright © 2010  Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
+#include "dummy.h"
+
+using namespace std;
+
+namespace R2C2 {
+
+Dummy::Dummy():
+       power(true)
+{ }
+
+void Dummy::set_power(bool p)
+{
+       power = p;
+       signal_power.emit(power);
+}
+
+const char *Dummy::enumerate_protocols(unsigned i) const
+{
+       if(i==0)
+               return "dummy";
+       return 0;
+}
+
+unsigned Dummy::get_protocol_speed_steps(const string &) const
+{
+       return 0;
+}
+
+void Dummy::add_turnout(unsigned addr)
+{
+       turnouts[addr];
+}
+
+void Dummy::set_turnout(unsigned addr, bool state)
+{
+       if(turnouts[addr]!=state)
+       {
+               turnouts[addr] = state;
+               signal_turnout.emit(addr, state);
+       }
+}
+
+bool Dummy::get_turnout(unsigned addr) const
+{
+       map<unsigned, bool>::const_iterator i = turnouts.find(addr);
+       if(i!=turnouts.end())
+               return i->second;
+       return false;
+}
+
+void Dummy::set_loco_speed(unsigned addr, unsigned speed)
+{
+       LocoState &loco = locos[addr];
+       loco.speed = speed;
+       signal_loco_speed.emit(addr, speed, loco.reverse);
+}
+
+void Dummy::set_loco_reverse(unsigned addr, bool rev)
+{
+       LocoState &loco = locos[addr];
+       loco.reverse = rev;
+       signal_loco_speed.emit(addr, loco.speed, rev);
+}
+
+void Dummy::set_loco_function(unsigned addr, unsigned func, bool state)
+{
+       signal_loco_function.emit(addr, func, state);
+}
+
+void Dummy::set_sensor(unsigned addr, bool state)
+{
+       if(sensors[addr]!=state)
+       {
+               sensors[addr] = state;
+               signal_sensor.emit(addr, state);
+       }
+}
+
+bool Dummy::get_sensor(unsigned addr) const
+{
+       map<unsigned, bool>::const_iterator i = sensors.find(addr);
+       if(i!=sensors.end())
+               return i->second;
+       return false;
+}
+
+} // namespace R2C2