]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/train.cpp
Emit signals from loco status command only when all data has been gathered
[r2c2.git] / source / libr2c2 / train.cpp
index 0cbe306234c09b11a9535f1e21fe71673e4bed2e..0eaf1e9a0ec91fb62e6947ff15ae2a38851d378e 100644 (file)
@@ -76,7 +76,7 @@ Train::Train(Layout &l, const VehicleType &t, unsigned a, const string &p):
 
        layout.add_train(*this);
 
-       layout.get_driver().add_loco(address, protocol);
+       layout.get_driver().add_loco(address, protocol, loco_type);
        layout.get_driver().signal_loco_speed.connect(sigc::mem_fun(this, &Train::loco_speed_event));
        layout.get_driver().signal_loco_function.connect(sigc::mem_fun(this, &Train::loco_func_event));
 
@@ -186,10 +186,7 @@ void Train::set_function(unsigned func, bool state)
 {
        if(!loco_type.get_functions().count(func))
                throw InvalidParameterValue("Invalid function");
-       if(func<5)
-               layout.get_driver().set_loco_function(address, func, state);
-       else
-               layout.get_driver().set_loco_function(address+1, func-4, state);
+       layout.get_driver().set_loco_function(address, func, state);
 }
 
 float Train::get_control(const string &ctrl) const
@@ -678,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;
        }
@@ -690,10 +689,8 @@ void Train::loco_speed_event(unsigned addr, unsigned speed, bool)
 
 void Train::loco_func_event(unsigned addr, unsigned func, bool state)
 {
-       if(addr==address || (addr==address+1 && loco_type.get_max_function()>4))
+       if(addr==address)
        {
-               if(addr==address+1)
-                       func += 4;
                if(state)
                        functions |= 1<<func;
                else