]> git.tdb.fi Git - r2c2.git/commitdiff
Implement halt in the dummy driver
authorMikko Rasa <tdb@tdb.fi>
Tue, 8 Apr 2014 18:47:53 +0000 (21:47 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 8 Apr 2014 18:47:53 +0000 (21:47 +0300)
source/libr2c2/dummy.cpp
source/libr2c2/dummy.h

index cfee07417b3105b75c2eba5a1029f3056ead320a..c28a3e16e9ae9c3a25d3a87c8b560b62c7e28c51 100644 (file)
@@ -18,6 +18,18 @@ void Dummy::set_power(bool p)
        signal_power.emit(power);
 }
 
+void Dummy::halt(bool h)
+{
+       halted = h;
+       if(halted)
+       {
+               for(map<unsigned, LocoState>::iterator i=locos.begin(); i!=locos.end(); ++i)
+                       if(i->second.speed)
+                               set_loco_speed(i->first, 0);
+       }
+       signal_halt.emit(halted);
+}
+
 const char *Dummy::enumerate_protocols(unsigned i) const
 {
        if(i==0)
@@ -65,6 +77,9 @@ unsigned Dummy::get_turnout(unsigned addr) const
 
 void Dummy::set_loco_speed(unsigned addr, unsigned speed)
 {
+       if(speed && halted)
+               return;
+
        LocoState &loco = locos[addr];
        loco.speed = speed;
        signal_loco_speed.emit(addr, speed, loco.reverse);
index 6943413a8142d5500136ce259afd89bc2ba8ced9..f7b48cf2709ac6ede5ae0b0847997272caddad80 100644 (file)
@@ -25,6 +25,7 @@ private:
        };
 
        bool power;
+       bool halted;
        std::map<unsigned, TurnoutState> turnouts;
        std::map<unsigned, LocoState> locos;
        std::map<unsigned, bool> sensors;
@@ -35,8 +36,8 @@ public:
 
        virtual void set_power(bool);
        virtual bool get_power() const { return power; }
-       virtual void halt(bool) { }
-       virtual bool is_halted() const { return false; }
+       virtual void halt(bool);
+       virtual bool is_halted() const { return halted; }
 
        virtual const char *enumerate_protocols(unsigned) const;
        virtual unsigned get_protocol_speed_steps(const std::string &) const;