]> git.tdb.fi Git - r2c2.git/commitdiff
Emit signals from loco status command only when all data has been gathered
authorMikko Rasa <tdb@tdb.fi>
Wed, 24 Nov 2010 07:01:47 +0000 (07:01 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 24 Nov 2010 07:01:47 +0000 (07:01 +0000)
Force Driver's reverse bit to sync with Train

source/libr2c2/intellibox.cpp
source/libr2c2/train.cpp

index 84d576ba99ac8821ae797b62d13380adffb38dbb..4e6bb763d7e278a745a16fc200cfb8cdf406da63 100644 (file)
@@ -622,24 +622,22 @@ void Intellibox::process_reply(const Time::TimeStamp &t)
 
                        unsigned speed = (data[0]<=1 ? 0 : data[0]*2/19+1);
                        bool reverse = !(data[1]&0x20);
-                       if(speed!=loco.speed || reverse!=loco.reverse)
-                       {
-                               loco.speed = speed;
-                               loco.reverse = reverse;
-                               signal_loco_speed.emit(addr, loco.speed, loco.reverse);
-                       }
+                       bool speed_changed = (speed!=loco.speed || reverse!=loco.reverse);
+
+                       loco.speed = speed;
+                       loco.reverse = reverse;
 
                        unsigned funcs = (data[1]&0xF)<<1;
                        if(data[1]&0x10)
                                funcs |= 1;
-                       if(funcs!=loco.funcs)
-                       {
-                               unsigned changed = loco.funcs^funcs;
-                               loco.funcs = funcs;
-                               for(unsigned i=0; i<5; ++i)
-                                       if(changed&(1<<i))
-                                               signal_loco_function.emit(addr, i, loco.funcs&(1<<i));
-                       }
+                       unsigned funcs_changed = loco.funcs^funcs;
+                       loco.funcs = funcs;
+
+                       if(speed_changed)
+                               signal_loco_speed.emit(addr, loco.speed, loco.reverse);
+                       for(unsigned i=0; i<5; ++i)
+                               if(funcs_changed&(1<<i))
+                                       signal_loco_function.emit(addr, i, loco.funcs&(1<<i));
                }
                else
                        error(cmd, err);
index 28976838fcf7da9c699ed11b8b461cdab566fd41..0eaf1e9a0ec91fb62e6947ff15ae2a38851d378e 100644 (file)
@@ -675,11 +675,13 @@ void Train::control_changed(const Controller::Control &ctrl)
        signal_control_changed.emit(ctrl.name, ctrl.value);
 }
 
-void Train::loco_speed_event(unsigned addr, unsigned speed, bool)
+void Train::loco_speed_event(unsigned addr, unsigned speed, bool rev)
 {
        if(addr==address)
        {
                current_speed_step = speed;
+               if(rev!=reverse)
+                       layout.get_driver().set_loco_reverse(address, reverse);
                speed_changing = false;
                pure_speed = false;
        }