From: Mikko Rasa Date: Tue, 30 Mar 2010 11:26:02 +0000 (+0000) Subject: Generate loco events from the Dummy driver X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=43638fd7170c5c8290212c38c3eaf623b8c1b415;p=r2c2.git Generate loco events from the Dummy driver Don't emit a turnout event if the turnout was already in the correct setting --- diff --git a/source/libmarklin/dummy.cpp b/source/libmarklin/dummy.cpp index 1a7dd36..99e9793 100644 --- a/source/libmarklin/dummy.cpp +++ b/source/libmarklin/dummy.cpp @@ -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 diff --git a/source/libmarklin/dummy.h b/source/libmarklin/dummy.h index 96b62a8..dab38ec 100644 --- a/source/libmarklin/dummy.h +++ b/source/libmarklin/dummy.h @@ -16,8 +16,15 @@ namespace Marklin { class Dummy: public Driver { private: + struct LocoState + { + unsigned speed; + bool reverse; + }; + bool power; std::map turnouts; + std::map 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);