]> git.tdb.fi Git - r2c2.git/commitdiff
Handle separate speed and reverse controls correctly in remote
authorMikko Rasa <tdb@tdb.fi>
Wed, 27 Oct 2010 07:18:19 +0000 (07:18 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 27 Oct 2010 07:18:19 +0000 (07:18 +0000)
source/network/train.cpp
source/remote/trainpanel.cpp

index 6a0c3a8b8fa99006c56275e9382618f05998b962..4b6c8e86e1233955d3d4d04b19b6e1d27c522670 100644 (file)
@@ -32,6 +32,12 @@ void NetTrain::set_control(const string &c, float v)
        client.send(pkt);
 }
 
+float NetTrain::get_control(const string &c) const
+{
+       map<string, float>::const_iterator i = controls.find(c);
+       return i!=controls.end() ? i->second : 0;
+}
+
 void NetTrain::set_function(unsigned i, bool set)
 {
        TrainFunctionPacket pkt;
index 45435d56fa1ebd4d8a65748a0843aecc1c00fa1b..b170edc5ff8e4df910fae410f32543b525d61069 100644 (file)
@@ -84,10 +84,11 @@ void TrainPanel::control_changed(const string &control, float value)
 {
        if(control=="speed")
        {
-               // XXX It would be better to make the LocoType give us the catalogue
-               scl_speed->set_value(abs(value)*3.6/remote.get_catalogue().get_scale());
-               chk_reverse->set_active(value<0);
+               // XXX It would be better to make the VehicleType give us the catalogue
+               scl_speed->set_value(value*3.6/remote.get_catalogue().get_scale());
        }
+       else if(control=="reverse")
+               chk_reverse->set_active(value);
 }
 
 void TrainPanel::function_changed(unsigned func, bool set)
@@ -111,14 +112,18 @@ void TrainPanel::route_changed(const string &route)
 void TrainPanel::ui_speed_changed()
 {
        float speed = scl_speed->get_value()/3.6*remote.get_catalogue().get_scale();
-       if(chk_reverse->get_active())
-               speed = -speed;
        train.set_control("speed", speed);
 }
 
 void TrainPanel::ui_reverse_changed()
 {
-       train.set_control("speed", 0);
+       if(train.get_control("speed"))
+       {
+               train.set_control("speed", 0);
+               chk_reverse->set_active(train.get_control("reverse"));
+       }
+       else
+               train.set_control("reverse", chk_reverse->get_active());
 }
 
 void TrainPanel::ui_function_changed(unsigned func)