]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/centralstation.cpp
Pass sensor events through blocks
[r2c2.git] / source / libr2c2 / centralstation.cpp
index 69bb8a9cf48c78745bf882f764cf0c7270087152..dd0cbcf58ef13709cd25989324090cd19a0cf5db 100644 (file)
@@ -90,7 +90,7 @@ unsigned CentralStation::get_protocol_speed_steps(const string &name) const
        {
        case MM: return 14;
        case MM_27: return 27;
-       case MFX: return 127;
+       case MFX: return 126;
        default: return 0;
        }
 }
@@ -121,7 +121,12 @@ void CentralStation::set_loco_speed(unsigned addr, unsigned speed)
 
        unsigned id = map_address(locos, loco_addr, addr);
        if(id)
+       {
+               Locomotive &loco = locos[id];
+               if(loco.protocol==MFX && speed)
+                       ++speed;
                command(format("set(%d, speedstep[%d])", id, speed));
+       }
 }
 
 void CentralStation::set_loco_reverse(unsigned addr, bool rev)
@@ -157,7 +162,7 @@ void CentralStation::add_turnout(unsigned addr, const TrackType &type)
                        cross = true;
        }
 
-       unsigned symbol;
+       unsigned symbol = Turnout::LEFT;
        if(cross)
                symbol = Turnout::DOUBLESLIP;
        else if(left && right)
@@ -245,15 +250,6 @@ bool CentralStation::get_sensor(unsigned addr) const
 
 void CentralStation::tick()
 {
-       Time::TimeStamp t = Time::now();
-       for(SensorMap::iterator i=sensors.begin(); i!=sensors.end(); ++i)
-               if(i->second.off_timeout && t>i->second.off_timeout)
-               {
-                       i->second.state = false;
-                       i->second.off_timeout = Time::TimeStamp();
-                       signal_sensor.emit(i->first, i->second.state);
-               }
-
        while(Message msg = receive())
        {
                if(msg.footer.code)
@@ -523,6 +519,8 @@ void CentralStation::process_object(unsigned id, const Message::AttribMap &attri
                        else if(i->first=="speedstep")
                        {
                                loco.speed = lexical_cast<unsigned>(i->second);
+                               if(loco.protocol==MFX && loco.speed)
+                                       --loco.speed;
                                speed_changed = true;
                        }
                        else if(i->first=="dir")
@@ -592,17 +590,11 @@ void CentralStation::process_object(unsigned id, const Message::AttribMap &attri
                                        unsigned addr = base*16+j+1;
                                        Sensor &sensor = sensors[addr];
                                        bool s = state&(1<<j);
-                                       if(s)
+                                       if(s!=sensor.state)
                                        {
-                                               sensor.off_timeout = Time::TimeStamp();
-                                               if(!sensor.state)
-                                               {
-                                                       sensor.state = true;
-                                                       signal_sensor.emit(addr, sensor.state);
-                                               }
+                                               sensor.state = s;
+                                               signal_sensor.emit(addr, sensor.state);
                                        }
-                                       else if(sensor.state)
-                                               sensor.off_timeout = Time::now()+700*Time::msec;
                                }
                        }
                }