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 {
6868 // do not average the value
6969 children.get ()->setValueProcessing (NONE);
7070 // report immediately
71- setReportTimerMode (IMMEDIATELY);
71+ setReportTimerMode (IMMEDIATELY);
7272 if (!_cap->begin (_i2c_addr)) debug (PSTR (LOG_SENSOR " %s: KO\n " ),_name);
7373 // setup passcode array
7474 _passcode.allocateBlocks (_passcode_length);
@@ -82,9 +82,9 @@ class SensorMPR121: public Sensor {
8282 while (true ) {
8383 // if a timer is set, leave the cycle if over
8484 if (_wait_code_for_seconds > 0 && ((millis () - start_millis) > (unsigned long )_wait_code_for_seconds*1000 )) break ;
85-
8685 // Get the currently touched pads
8786 _currtouched = _cap->touched ();
87+ bool value_set = false ;
8888 for (uint8_t i=0 ; i<12 ; i++) {
8989 if ((_currtouched & _BV (i)) && !(_lasttouched & _BV (i)) ) {
9090 // pad i touched
@@ -103,10 +103,13 @@ class SensorMPR121: public Sensor {
103103 child->setValue (passcode);
104104 // clear the passcode array
105105 _passcode.clear ();
106+ value_set = true ;
106107 break ;
107108 }
108109 }
109110 }
111+ // value was captured, leave the while cycle
112+ if (value_set) break ;
110113 // reset state
111114 _lasttouched = _currtouched;
112115 wait (100 );
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ class SensorTTP: public Sensor {
3030 int8_t _dv_pin = 3 ;
3131 int8_t _rst_pin = 4 ;
3232 int key = 0 ;
33- int ziro = 0 ;
33+ int count = 0 ;
3434 List<int > _passcode;
3535 int _passcode_length = 4 ;
3636
@@ -109,19 +109,20 @@ class SensorTTP: public Sensor {
109109protected:
110110 // Send 8 clock pulses and check each data bit as it arrives
111111 int _fetchData () {
112+ count = 0 ;
112113 for (int i = 1 ; i < 9 ; i++) {
113114 digitalWrite (_clock_pin,1 );
114115 delayMicroseconds (1000 );
115116 // If data bit, high, then that key was pressed.
116117 if (digitalRead (_sdo_pin) == HIGH)
117118 key=i;
118119 else
119- ziro ++;
120+ count ++;
120121 digitalWrite (_clock_pin,0 );
121122 // Don't use delay(1) as it will mess up interrupts
122123 delayMicroseconds (1000 );
123124 }
124- if (key > 0 && ziro == 7 ) return key;
125+ if (key > 0 && count == 7 ) return key;
125126 return 0 ;
126127 };
127128};
You can’t perform that action at this time.
0 commit comments