]> git.tdb.fi Git - r2c2.git/commitdiff
Support inverted sensors that give low output when active
authorMikko Rasa <tdb@tdb.fi>
Mon, 8 Jul 2013 17:17:03 +0000 (20:17 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 8 Jul 2013 20:17:40 +0000 (23:17 +0300)
source/libr2c2/sensor.cpp
source/libr2c2/sensor.h

index 8a65d3dedf20f52419d130bfd1612f5bb3cc2a30..47e05f6068076063acc1e711fd97b480e66e406d 100644 (file)
@@ -9,6 +9,7 @@ namespace R2C2 {
 Sensor::Sensor(Layout &l):
        layout(l),
        address(0),
 Sensor::Sensor(Layout &l):
        layout(l),
        address(0),
+       invert(false),
        state(INACTIVE)
 {
        if(layout.has_driver())
        state(INACTIVE)
 {
        if(layout.has_driver())
@@ -43,13 +44,13 @@ void Sensor::event(unsigned a, bool s)
 {
        if(a==address)
        {
 {
        if(a==address)
        {
-               if(s && state<MAYBE_ACTIVE)
+               if(s!=invert && state<MAYBE_ACTIVE)
                {
                        state = MAYBE_ACTIVE;
                        state_confirm_timeout = 300*Time::msec;
                        signal_state_changed.emit(state);
                }
                {
                        state = MAYBE_ACTIVE;
                        state_confirm_timeout = 300*Time::msec;
                        signal_state_changed.emit(state);
                }
-               else if(!s && state>MAYBE_INACTIVE)
+               else if(s==invert && state>MAYBE_INACTIVE)
                {
                        state = MAYBE_INACTIVE;
                        state_confirm_timeout = 700*Time::msec;
                {
                        state = MAYBE_INACTIVE;
                        state_confirm_timeout = 700*Time::msec;
index d3f472dbeef11370690360a20dd4d24be56d8a7b..f1525bf4d6a377d7e2b3fd6c1e07d462a9982ebf 100644 (file)
@@ -25,6 +25,7 @@ public:
 protected:
        Layout &layout;
        unsigned address;
 protected:
        Layout &layout;
        unsigned address;
+       bool invert;
        State state;
        Msp::Time::TimeDelta state_confirm_timeout;
 
        State state;
        Msp::Time::TimeDelta state_confirm_timeout;