File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ class SensorMPR121: public Sensor {
68
68
// do not average the value
69
69
children.get ()->setValueProcessing (NONE);
70
70
// report immediately
71
- setReportTimerMode (IMMEDIATELY);
71
+ setReportTimerMode (IMMEDIATELY);
72
72
if (!_cap->begin (_i2c_addr)) debug (PSTR (LOG_SENSOR " %s: KO\n " ),_name);
73
73
// setup passcode array
74
74
_passcode.allocateBlocks (_passcode_length);
@@ -82,9 +82,9 @@ class SensorMPR121: public Sensor {
82
82
while (true ) {
83
83
// if a timer is set, leave the cycle if over
84
84
if (_wait_code_for_seconds > 0 && ((millis () - start_millis) > (unsigned long )_wait_code_for_seconds*1000 )) break ;
85
-
86
85
// Get the currently touched pads
87
86
_currtouched = _cap->touched ();
87
+ bool value_set = false ;
88
88
for (uint8_t i=0 ; i<12 ; i++) {
89
89
if ((_currtouched & _BV (i)) && !(_lasttouched & _BV (i)) ) {
90
90
// pad i touched
@@ -103,10 +103,13 @@ class SensorMPR121: public Sensor {
103
103
child->setValue (passcode);
104
104
// clear the passcode array
105
105
_passcode.clear ();
106
+ value_set = true ;
106
107
break ;
107
108
}
108
109
}
109
110
}
111
+ // value was captured, leave the while cycle
112
+ if (value_set) break ;
110
113
// reset state
111
114
_lasttouched = _currtouched;
112
115
wait (100 );
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ class SensorTTP: public Sensor {
30
30
int8_t _dv_pin = 3 ;
31
31
int8_t _rst_pin = 4 ;
32
32
int key = 0 ;
33
- int ziro = 0 ;
33
+ int count = 0 ;
34
34
List<int > _passcode;
35
35
int _passcode_length = 4 ;
36
36
@@ -109,19 +109,20 @@ class SensorTTP: public Sensor {
109
109
protected:
110
110
// Send 8 clock pulses and check each data bit as it arrives
111
111
int _fetchData () {
112
+ count = 0 ;
112
113
for (int i = 1 ; i < 9 ; i++) {
113
114
digitalWrite (_clock_pin,1 );
114
115
delayMicroseconds (1000 );
115
116
// If data bit, high, then that key was pressed.
116
117
if (digitalRead (_sdo_pin) == HIGH)
117
118
key=i;
118
119
else
119
- ziro ++;
120
+ count ++;
120
121
digitalWrite (_clock_pin,0 );
121
122
// Don't use delay(1) as it will mess up interrupts
122
123
delayMicroseconds (1000 );
123
124
}
124
- if (key > 0 && ziro == 7 ) return key;
125
+ if (key > 0 && count == 7 ) return key;
125
126
return 0 ;
126
127
};
127
128
};
You can’t perform that action at this time.
0 commit comments