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");
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");
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));
+ }
}
}
}
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;
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
bool power;
std::map<unsigned, bool> turnouts;
std::map<unsigned, LocoState> locos;
+ std::map<unsigned, bool> sensors;
public:
Dummy();
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() { }
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();