]> git.tdb.fi Git - r2c2.git/commitdiff
Generate loco events from the Dummy driver
authorMikko Rasa <tdb@tdb.fi>
Tue, 30 Mar 2010 11:26:02 +0000 (11:26 +0000)
committerMikko Rasa <tdb@tdb.fi>
Tue, 30 Mar 2010 11:26:02 +0000 (11:26 +0000)
Don't emit a turnout event if the turnout was already in the correct setting

source/libmarklin/dummy.cpp
source/libmarklin/dummy.h

index 1a7dd365ca2a2a2598425531e684ae0803fb7854..99e97933879accb2eacf4e3994451d66914a89ee 100644 (file)
@@ -28,8 +28,11 @@ void Dummy::add_turnout(unsigned addr)
 
 void Dummy::set_turnout(unsigned addr, bool state)
 {
-       turnouts[addr] = state;
-       signal_turnout.emit(addr, state);
+       if(turnouts[addr]!=state)
+       {
+               turnouts[addr] = state;
+               signal_turnout.emit(addr, state);
+       }
 }
 
 bool Dummy::get_turnout(unsigned addr) const
@@ -40,4 +43,23 @@ bool Dummy::get_turnout(unsigned addr) const
        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);
+}
+
 } // namespace Marklin
index 96b62a89d3bf5cf2e55edc3c14752e45fc7a9c25..dab38ec157ea1b5cb7b2ad8518bef52d81efe3dc 100644 (file)
@@ -16,8 +16,15 @@ namespace Marklin {
 class Dummy: public Driver
 {
 private:
+       struct LocoState
+       {
+               unsigned speed;
+               bool reverse;
+       };
+
        bool power;
        std::map<unsigned, bool> turnouts;
+       std::map<unsigned, LocoState> locos;
 
 public:
        Dummy();
@@ -26,9 +33,9 @@ public:
        virtual bool get_power() const { return power; }
 
        virtual void add_loco(unsigned) { }
-       virtual void set_loco_speed(unsigned, unsigned) { }
-       virtual void set_loco_reverse(unsigned, bool) { }
-       virtual void set_loco_function(unsigned, unsigned, bool) { }
+       virtual void set_loco_speed(unsigned, unsigned);
+       virtual void set_loco_reverse(unsigned, bool);
+       virtual void set_loco_function(unsigned, unsigned, bool);
 
        virtual void add_turnout(unsigned);
        virtual void set_turnout(unsigned, bool);