9 Sensor::Sensor(Layout &l):
16 if(layout.has_driver())
17 layout.get_driver().signal_sensor.connect(sigc::mem_fun(this, &Sensor::event));
24 if(layout.has_driver() && address)
25 layout.get_driver().remove_sensor(address);
29 void Sensor::set_address(unsigned a)
31 Driver *driver = (layout.has_driver() ? &layout.get_driver() : 0);
33 driver->remove_sensor(id);
36 id = driver->add_sensor(address);
41 void Sensor::tick(const Time::TimeDelta &dt)
43 if(state_confirm_timeout)
45 state_confirm_timeout -= dt;
46 if(state_confirm_timeout<=Time::zero)
48 if(state==MAYBE_INACTIVE)
50 else if(state==MAYBE_ACTIVE)
52 state_confirm_timeout = Time::zero;
53 signal_state_changed.emit(state);
58 void Sensor::event(unsigned i, bool s)
62 if(s!=invert && state<MAYBE_ACTIVE)
65 state_confirm_timeout = 300*Time::msec;
66 signal_state_changed.emit(state);
68 else if(s==invert && state>MAYBE_INACTIVE)
70 state = MAYBE_INACTIVE;
71 state_confirm_timeout = 700*Time::msec;
72 signal_state_changed.emit(state);