]> git.tdb.fi Git - r2c2.git/commitdiff
Add a set_sensor function to the Driver interface
authorMikko Rasa <tdb@tdb.fi>
Mon, 5 Apr 2010 13:35:46 +0000 (13:35 +0000)
committerMikko Rasa <tdb@tdb.fi>
Mon, 5 Apr 2010 13:35:46 +0000 (13:35 +0000)
Bring back the simulation mode in Engineer

source/engineer/engineer.cpp
source/libmarklin/driver.h
source/libmarklin/dummy.cpp
source/libmarklin/dummy.h
source/libmarklin/intellibox.h

index ea5139d5b2e9d9e94cc7ebbdd2455bf72f959c2d..4a35c8e0cd381bc6307f24e828c8352d68152239 100644 (file)
@@ -74,6 +74,7 @@ Engineer::Engineer(int argc, char **argv):
 
        layout.signal_train_added.connect(sigc::mem_fun(this, &Engineer::train_added));
        layout.signal_block_reserved.connect(sigc::mem_fun(this, &Engineer::block_reserved));
+       layout.get_driver().signal_sensor.connect(sigc::mem_fun(this, &Engineer::sensor_event));
        if(FS::exists("engineer.state"))
                DataFile::load(layout, "engineer.state");
 
@@ -83,8 +84,6 @@ Engineer::Engineer(int argc, char **argv):
                server->use_event_dispatcher(event_disp);
        }
 
-       layout.get_driver().signal_sensor.connect(sigc::mem_fun(this, &Engineer::sensor_event));
-
        // Setup 3D view
        DataFile::load(arrow_mesh, "arrow.mesh");
 
@@ -241,14 +240,11 @@ void Engineer::button_press(int x, int y, unsigned btn, unsigned)
                                        track.set_active_path(i);
                                }
                        }
-                       /*else if(simulate)
+                       else if(options.simulate)
                        {
-                               if(unsigned sid=track->get_track().get_sensor_id())
-                               {
-                                       Sensor &sensor = control.get_sensor(sid);
-                                       control.signal_sensor_event.emit(sid, !sensor.get_state());
-                               }
-                       }*/
+                               if(unsigned sid=track.get_sensor_id())
+                                       layout.get_driver().set_sensor(sid, !layout.get_driver().get_sensor(sid));
+                       }
                }
        }
 }
index 1a5084d09a0156947d3a72ce0dd21cad87d359cd..9cab5cf9ebe4f97b48933b511d28d274fffb6aeb 100644 (file)
@@ -40,6 +40,7 @@ public:
        virtual bool get_turnout(unsigned) const = 0;
 
        virtual void add_sensor(unsigned) = 0;
+       virtual void set_sensor(unsigned, bool) = 0;
        virtual bool get_sensor(unsigned) const = 0;
 
        virtual void tick() = 0;
index 99e97933879accb2eacf4e3994451d66914a89ee..b8478a2fe95c10e7f27843a531f658f26df72c04 100644 (file)
@@ -62,4 +62,21 @@ void Dummy::set_loco_function(unsigned addr, unsigned func, bool state)
        signal_loco_function.emit(addr, func, state);
 }
 
+void Dummy::set_sensor(unsigned addr, bool state)
+{
+       if(sensors[addr]!=state)
+       {
+               sensors[addr] = state;
+               signal_sensor.emit(addr, state);
+       }
+}
+
+bool Dummy::get_sensor(unsigned addr) const
+{
+       map<unsigned, bool>::const_iterator i = sensors.find(addr);
+       if(i!=sensors.end())
+               return i->second;
+       return false;
+}
+
 } // namespace Marklin
index dab38ec157ea1b5cb7b2ad8518bef52d81efe3dc..3004c8bd1a8f768841bb42bb3df53db757726b3e 100644 (file)
@@ -25,6 +25,7 @@ private:
        bool power;
        std::map<unsigned, bool> turnouts;
        std::map<unsigned, LocoState> locos;
+       std::map<unsigned, bool> sensors;
 
 public:
        Dummy();
@@ -42,7 +43,8 @@ public:
        virtual bool get_turnout(unsigned) const;
 
        virtual void add_sensor(unsigned) { }
-       virtual bool get_sensor(unsigned) const { return false; }
+       virtual void set_sensor(unsigned, bool);
+       virtual bool get_sensor(unsigned) const;
 
        virtual void tick() { }
        virtual void flush() { }
index 9f42aa223f75184571e8f91ca55c6bd6546ee99e..a6b7cda966a50141026af672311b3ab07936e1b3 100644 (file)
@@ -122,6 +122,7 @@ public:
        virtual bool get_turnout(unsigned) const;
 
        virtual void add_sensor(unsigned);
+       virtual void set_sensor(unsigned, bool) { }
        virtual bool get_sensor(unsigned) const;
 
        virtual void tick();