X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fdummy.cpp;h=a8efac3a1d71204f3b0d861843b482db41911f98;hb=44b821894e355d62188f955b0bf29c24fa16d910;hp=9ccb1bcceb94f6fe9630b8ad04e328a5feffcec8;hpb=73e4a36bbf828e07b83a779b696875e1f80045cc;p=r2c2.git diff --git a/source/libr2c2/dummy.cpp b/source/libr2c2/dummy.cpp index 9ccb1bc..a8efac3 100644 --- a/source/libr2c2/dummy.cpp +++ b/source/libr2c2/dummy.cpp @@ -7,22 +7,10 @@ using namespace Msp; namespace R2C2 { -Dummy::Dummy(const string ¶ms): - power(true) -{ - vector opts = split(params, ':'); - for(vector::const_iterator i=opts.begin(); i!=opts.end(); ++i) - { - string::size_type equals = i->find('='); - if(equals!=string::npos) - { - string name = i->substr(0, equals); - string value = i->substr(equals+1); - if(name=="turnout_delay") - turnout_delay = lexical_cast(value)*Time::msec; - } - } -} +Dummy::Dummy(const Options &opts): + power(true), + turnout_delay(opts.get("turnout_delay", 0.0f)*Time::sec) +{ } void Dummy::set_power(bool p) { @@ -30,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) @@ -77,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);