]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/sensor.cpp
Refer to things in the driver with abstract ids instead of addresses
[r2c2.git] / source / libr2c2 / sensor.cpp
index 618a06b7b609c6ac8a930bc62c197bb4ac2db768..ecd06473fb4bdf2234a2c149f19d0b3ae1af849e 100644 (file)
@@ -9,6 +9,7 @@ namespace R2C2 {
 Sensor::Sensor(Layout &l):
        layout(l),
        address(0),
+       id(0),
        invert(false),
        state(INACTIVE)
 {
@@ -28,11 +29,13 @@ Sensor::~Sensor()
 void Sensor::set_address(unsigned a)
 {
        Driver *driver = (layout.has_driver() ? &layout.get_driver() : 0);
-       if(driver && address)
-               driver->remove_sensor(address);
+       if(driver && id)
+               driver->remove_sensor(id);
        address = a;
        if(driver && address)
-               driver->add_sensor(address);
+               id = driver->add_sensor(address);
+       else
+               id = 0;
 }
 
 void Sensor::tick(const Time::TimeDelta &dt)
@@ -52,9 +55,9 @@ void Sensor::tick(const Time::TimeDelta &dt)
        }
 }
 
-void Sensor::event(unsigned a, bool s)
+void Sensor::event(unsigned i, bool s)
 {
-       if(a==address)
+       if(i==id)
        {
                if(s!=invert && state<MAYBE_ACTIVE)
                {