From be65a94f7d2c7c574104a95b68a70a58c2f0052e Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 28 Nov 2023 15:49:31 +0700 Subject: [PATCH] fix captouch issue with incorrect send pin --- utility/CPlay_CapacitiveSensor.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/utility/CPlay_CapacitiveSensor.cpp b/utility/CPlay_CapacitiveSensor.cpp index cb12f79..3374b07 100644 --- a/utility/CPlay_CapacitiveSensor.cpp +++ b/utility/CPlay_CapacitiveSensor.cpp @@ -46,13 +46,13 @@ CPlay_CapacitiveSensor::CPlay_CapacitiveSensor(uint8_t sendPin, uint8_t receiveP if ((sendPin != 255) && (sendPin >= NUM_DIGITAL_PINS)) error = -3; if (receivePin >= NUM_DIGITAL_PINS) error = -2; #endif - if (sendPin != -1) { // sendpin to OUTPUT if we have one + if (sendPin != 255) { // sendpin to OUTPUT if we have one #ifdef ARDUINO_TEEONARDU_FLORA // terrible hack! - DDRD |= _BV(5); + DDRD |= _BV(5); #else - pinMode(sendPin, OUTPUT); + pinMode(sendPin, OUTPUT); #endif - } + } pinMode(receivePin, INPUT); // receivePin to INPUT @@ -63,13 +63,13 @@ CPlay_CapacitiveSensor::CPlay_CapacitiveSensor(uint8_t sendPin, uint8_t receiveP digitalWrite(sendPin, LOW); #endif - if (sendPin != -1) { - send_outport = portOutputRegister(digitalPinToPort(sendPin)); - send_mask = digitalPinToBitMask(sendPin); - } else { - send_outport = NULL; - send_mask = 0; - } + if (sendPin != 255) { + send_outport = portOutputRegister(digitalPinToPort(sendPin)); + send_mask = digitalPinToBitMask(sendPin); + } else { + send_outport = NULL; + send_mask = 0; + } recv_outport = portOutputRegister(digitalPinToPort(receivePin)); recv_inport = portInputRegister(digitalPinToPort(receivePin)); @@ -216,7 +216,7 @@ int CPlay_CapacitiveSensor::SenseOneCycle(void) } //Serial.print("SenseOneCycle(1): "); Serial.println(total); - if (total > CS_Timeout_Millis) { + if (total >= CS_Timeout_Millis) { return -2; // total variable over timeout } }