From: Mikko Rasa Date: Tue, 8 Apr 2014 18:47:53 +0000 (+0300) Subject: Implement halt in the dummy driver X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=73d4dc248a97c11538e83bed6dddf486785804e1;p=r2c2.git Implement halt in the dummy driver --- diff --git a/source/libr2c2/dummy.cpp b/source/libr2c2/dummy.cpp index cfee074..c28a3e1 100644 --- a/source/libr2c2/dummy.cpp +++ b/source/libr2c2/dummy.cpp @@ -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::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); diff --git a/source/libr2c2/dummy.h b/source/libr2c2/dummy.h index 6943413..f7b48cf 100644 --- a/source/libr2c2/dummy.h +++ b/source/libr2c2/dummy.h @@ -25,6 +25,7 @@ private: }; bool power; + bool halted; std::map turnouts; std::map locos; std::map 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;