]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/centralstation.cpp
Add driver for my custom Arduino-based control device
[r2c2.git] / source / libr2c2 / centralstation.cpp
index ee5aaeea4fe573e3b47f948e7154958c69b7f03d..2138e10702ee27497e70a641edc8fbd12d9d20ab 100644 (file)
@@ -111,6 +111,13 @@ void CentralStation::add_loco(unsigned addr, const string &proto_name, const Veh
                command(format("request(%d, view, control, force)", id));
 }
 
+void CentralStation::remove_loco(unsigned addr)
+{
+       unsigned id = map_address(locos, loco_addr, addr);
+       if(id)
+               command(format("release(%d, view, control)", id));
+}
+
 void CentralStation::set_loco_speed(unsigned addr, unsigned speed)
 {
        if(speed && halted)
@@ -150,14 +157,14 @@ void CentralStation::add_turnout(unsigned addr, const TrackType &type)
        const vector<TrackPart> &parts = type.get_parts();
        for(vector<TrackPart>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
        {
-               TrackPoint start = i->get_point(0);
-               TrackPoint end = i->get_point(i->get_length());
-               if(end.dir>start.dir+0.01 || end.dir<start.dir-0.01)
+               OrientedPoint start = i->get_point(0);
+               OrientedPoint end = i->get_point(i->get_length());
+               if(abs(end.rotation-start.rotation).radians()<0.01)
                {
-                       (end.dir>start.dir ? left : right) = true;
+                       (end.rotation>start.rotation ? left : right) = true;
                        straight &= ~(1<<i->get_path());
                }
-               else if(start.dir<-0.01 || start.dir>0.01)
+               else if(abs(start.rotation).radians()>0.01)
                        cross = true;
        }
 
@@ -175,6 +182,11 @@ void CentralStation::add_turnout(unsigned addr, const TrackType &type)
        turnout.bits = type.get_state_bits();
 }
 
+void CentralStation::remove_turnout(unsigned addr)
+{
+       remove_accessory(addr);
+}
+
 void CentralStation::set_turnout(unsigned addr, unsigned state)
 {
        set_accessory_state(addr, MagnetAccessory::TURNOUT, state);
@@ -190,6 +202,11 @@ void CentralStation::add_signal(unsigned addr, const SignalType &)
        add_accessory(addr, MagnetAccessory::SIGNAL, MagnetAccessory::SEMAPHORE_HOME);
 }
 
+void CentralStation::remove_signal(unsigned addr)
+{
+       remove_accessory(addr);
+}
+
 void CentralStation::set_signal(unsigned addr, unsigned state)
 {
        set_accessory_state(addr, MagnetAccessory::SIGNAL, state);
@@ -230,6 +247,13 @@ CentralStation::MagnetAccessory &CentralStation::add_accessory(unsigned addr, Ma
        }
 }
 
+void CentralStation::remove_accessory(unsigned addr)
+{
+       unsigned id = map_address(accessories, accessory_addr, addr);
+       if(id)
+               command(format("release(%d, view, control)", id));
+}
+
 void CentralStation::set_accessory_state(unsigned addr, MagnetAccessory::Type type, unsigned state)
 {
        unsigned id = map_address(accessories, accessory_addr, addr);
@@ -285,6 +309,10 @@ void CentralStation::add_sensor(unsigned addr)
        }
 }
 
+void CentralStation::remove_sensor(unsigned)
+{
+}
+
 bool CentralStation::get_sensor(unsigned addr) const
 {
        SensorMap::const_iterator i = sensors.find(addr);