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);
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;
}