@@ -65,18 +65,18 @@ void CommonIO::SetValues(bool RelayOFF, bool Invert, uint8_t Type, uint8_t Pin1,
6565 break ;
6666 // Touch button
6767 case 5 :
68- _SensorPin = Pin1; ReadReference ( );
68+ _SensorPin = Pin1; _ReadReference (_SensorPin );
6969 break ;
7070 // Touch button + digital button + output
7171 case 6 :
72- _SensorPin = Pin1; ReadReference ( );
72+ _SensorPin = Pin1; _ReadReference (_SensorPin );
7373 _SensorPin2 = Pin2; pinMode (_SensorPin2, INPUT_PULLUP);
7474 _RelayPin = Pin3; pinMode (_RelayPin, OUTPUT);
7575 digitalWrite (_RelayPin, _RelayOFF);
7676 break ;
7777 // Touch button + output
7878 case 7 :
79- _SensorPin = Pin1; ReadReference ( );
79+ _SensorPin = Pin1; _ReadReference (_SensorPin );
8080 _RelayPin = Pin2; pinMode (_RelayPin, OUTPUT);
8181 digitalWrite (_RelayPin, _RelayOFF);
8282 break ;
@@ -86,12 +86,25 @@ void CommonIO::SetValues(bool RelayOFF, bool Invert, uint8_t Type, uint8_t Pin1,
8686}
8787
8888/* *
89- * @brief reads reference value for touch buttons
89+ * @brief public function to call _ReadReference()
9090 *
9191 */
9292void CommonIO::ReadReference () {
9393
94- _TouchReference = ADCTouch.read (_SensorPin, 500 ); // ADCTouch.read(pin, number of samples)
94+ uint8_t InputPin;
95+
96+ if (SensorType == 5 || SensorType == 6 || SensorType == 7 ) InputPin = _SensorPin;
97+
98+ _ReadReference (InputPin);
99+ }
100+
101+ /* *
102+ * @brief reads reference value for touch buttons
103+ *
104+ */
105+ void CommonIO::_ReadReference (uint8_t InputPin) {
106+
107+ _TouchReference = ADCTouch.read (InputPin, 512 ); // ADCTouch.read(pin, number of samples)
95108}
96109
97110/* *
@@ -119,7 +132,7 @@ void CommonIO::CheckInput(uint16_t LongpressDuration, uint8_t DebounceValue) {
119132 uint32_t StartTime = millis ();
120133
121134 do {
122- Reading = _ReadDigital (DebounceValue);
135+ Reading = _ReadDigital (DebounceValue, _SensorPin );
123136
124137 if (SensorType == 0 || SensorType == 1 ) {
125138 if (State != Reading) {
@@ -167,10 +180,10 @@ void CommonIO::CheckInput2(uint8_t Threshold, uint16_t LongpressDuration, uint8_
167180 uint32_t StartTime = millis ();
168181
169182 do {
170- Reading = _ReadAnalog (Threshold);
183+ Reading = _ReadAnalog (Threshold, _SensorPin );
171184
172185 if (SensorType == 6 && !Reading) {
173- Reading = _ReadDigital (DebounceValue);
186+ Reading = _ReadDigital (DebounceValue, _SensorPin2 );
174187 }
175188
176189 if (!Shortpress && Reading) {
@@ -195,10 +208,10 @@ void CommonIO::CheckInput3(uint8_t Threshold, uint8_t DebounceValue, bool Monost
195208 bool Shortpress = false ;
196209
197210 do {
198- Reading = _ReadAnalog (Threshold);
211+ Reading = _ReadAnalog (Threshold, _SensorPin );
199212
200213 if (SensorType == 6 && !Reading) {
201- Reading = _ReadDigital (DebounceValue);
214+ Reading = _ReadDigital (DebounceValue, _SensorPin2 );
202215 }
203216
204217 if (Monostable) {
@@ -227,15 +240,15 @@ void CommonIO::CheckInput3(uint8_t Threshold, uint8_t DebounceValue, bool Monost
227240 * @return true if input state is true
228241 * @return false if input state is false
229242 */
230- bool CommonIO::_ReadDigital (uint8_t DebounceValue) {
243+ bool CommonIO::_ReadDigital (uint8_t DebounceValue, uint8_t InputPin ) {
231244
232245 bool DigitalReading;
233246 bool PreviousReading = false ;
234247 bool InputState = false ;
235248 uint32_t StartTime = millis ();
236249
237250 do {
238- DigitalReading = (_Invert ? digitalRead (_SensorPin ) : !digitalRead (_SensorPin ));
251+ DigitalReading = (_Invert ? digitalRead (InputPin ) : !digitalRead (InputPin ));
239252
240253 if (DigitalReading && !PreviousReading) {
241254 StartTime = millis ();
@@ -267,12 +280,12 @@ bool CommonIO::_ReadDigital(uint8_t DebounceValue) {
267280 * @return true if touch was sensed
268281 * @return false if touch was not sensed
269282 */
270- bool CommonIO::_ReadAnalog (uint8_t Threshold) {
283+ bool CommonIO::_ReadAnalog (uint8_t Threshold, uint8_t InputPin ) {
271284
272285 int TouchValue;
273286 bool ButtonState = false ;
274287
275- TouchValue = ADCTouch.read (_SensorPin , 64 );
288+ TouchValue = ADCTouch.read (InputPin , 64 );
276289 TouchValue -= _TouchReference;
277290 TouchDiagnosisValue = TouchValue;
278291
0 commit comments