From ae3700a0387cb96a96fe5f2527a3479c0297ddc2 Mon Sep 17 00:00:00 2001 From: Riccardo Rizzo Date: Mon, 17 May 2021 11:57:31 +0200 Subject: [PATCH 1/4] modified touch example and wrapper --- .../Custom_Sensitivity/Custom_Sensitivity.ino | 15 +-- .../Relays_control_Qtouch.ino | 6 +- examples/TouchPads/TouchTypes/TouchTypes.ino | 20 +-- .../Touch_and_LEDs/Touch_and_LEDs.ino | 22 ++-- examples/TouchPads/getTouch/getTouch.ino | 15 ++- src/Arduino_MKRIoTCarrier.cpp | 94 ++++++-------- src/Arduino_MKRIoTCarrier.h | 11 +- src/Arduino_MKRIoTCarrier_Qtouch.cpp | 115 +++++++----------- src/Arduino_MKRIoTCarrier_Qtouch.h | 49 ++++---- 9 files changed, 148 insertions(+), 199 deletions(-) diff --git a/examples/TouchPads/Custom_Sensitivity/Custom_Sensitivity.ino b/examples/TouchPads/Custom_Sensitivity/Custom_Sensitivity.ino index fa69855..481f64d 100644 --- a/examples/TouchPads/Custom_Sensitivity/Custom_Sensitivity.ino +++ b/examples/TouchPads/Custom_Sensitivity/Custom_Sensitivity.ino @@ -13,13 +13,14 @@ void setup() { Serial.begin(9600); while (!Serial); + carrier.begin(); //CARRIER_CASE = false; //Now we can set our custom touch threshold // First we update all the buttons with the new threshold // Then we overwrite individually one of them (they can be all set individually too) carrier.Buttons.updateConfig(threshold); - carrier.Button0.updateConfig(threshold_btn_0); - carrier.begin(); + carrier.Buttons.updateConfig(threshold_btn_0); + } void loop() { @@ -27,23 +28,23 @@ void loop() { carrier.Buttons.update(); // Verify your thresholds - if (carrier.Button0.getTouch()) { + if (carrier.Buttons.getTouch(TOUCH0)) { Serial.println("touching 0"); } - if (carrier.Button1.getTouch()) { + if (carrier.Buttons.getTouch(TOUCH1)) { Serial.println("touching 1"); } - if (carrier.Button2.getTouch()) { + if (carrier.Buttons.getTouch(TOUCH2)) { Serial.println("touching 2"); } - if (carrier.Button3.getTouch()) { + if (carrier.Buttons.getTouch(TOUCH3)) { Serial.println("touching 3"); } - if (carrier.Button4.getTouch()) { + if (carrier.Buttons.getTouch(4)) { Serial.println("touching 4"); } } diff --git a/examples/TouchPads/Relays_control_Qtouch/Relays_control_Qtouch.ino b/examples/TouchPads/Relays_control_Qtouch/Relays_control_Qtouch.ino index bce54d7..bc8ba9c 100644 --- a/examples/TouchPads/Relays_control_Qtouch/Relays_control_Qtouch.ino +++ b/examples/TouchPads/Relays_control_Qtouch/Relays_control_Qtouch.ino @@ -43,7 +43,7 @@ void loop() { //The LED changes to Green its going to be NC (Normally Closed) or Orange to NO (Normally Open) //Then the middle pad its going to upload the relay status, to confirm both new status - if (carrier.Button0.onTouchDown()) { + if (carrier.Buttons.onTouchDown(TOUCH0)) { newRelay2 = !newRelay2; if (newRelay2) { carrier.leds.setPixelColor(0, c_orange); @@ -53,7 +53,7 @@ void loop() { carrier.leds.show(); } - if (carrier.Button4.onTouchDown()) { + if (carrier.Buttons.onTouchDown(TOUCH3)) { newRelay1 = !newRelay1; if (newRelay1) { carrier.leds.setPixelColor(4, c_orange); @@ -63,7 +63,7 @@ void loop() { carrier.leds.show(); } - if (carrier.Button2.onTouchDown()) { + if (carrier.Buttons.onTouchDown(TOUCH1)) { carrier.leds.setPixelColor(2, c_orange); carrier.leds.show(); diff --git a/examples/TouchPads/TouchTypes/TouchTypes.ino b/examples/TouchPads/TouchTypes/TouchTypes.ino index af3d621..16df066 100644 --- a/examples/TouchPads/TouchTypes/TouchTypes.ino +++ b/examples/TouchPads/TouchTypes/TouchTypes.ino @@ -30,20 +30,20 @@ void loop() { // polling the sensor for new measure carrier.Buttons.update(); - if (carrier.Button0.onTouchDown()) { - Serial.println("Touched Down Button 1"); + if (carrier.Buttons.onTouchDown(TOUCH0)) { + Serial.println("Touched Down Button 0"); } - if (carrier.Button1.onTouchUp()) { - Serial.println("Release Touch Button 2"); + if (carrier.Buttons..onTouchUp(TOUCH1)) { + Serial.println("Release Touch Button 1"); } - if (carrier.Button2.onTouchChange()) { - Serial.println("Changed Touch Button 3"); + if (carrier.Buttons..onTouchChange(TOUCH2)) { + Serial.println("Changed Touch Button 2"); } - if (carrier.Button3.getTouch()) { - Serial.println("Touching Button 4"); + if (carrier.Buttons.getTouch(TOUCH3)) { + Serial.println("Touching Button 3"); } - if (carrier.Button4.getTouch()) { - Serial.println("Touching Button 5"); + if (carrier.Buttons.getTouch(TOUCH4)) { + Serial.println("Touching Button 4"); } delay(20); } diff --git a/examples/TouchPads/Touch_and_LEDs/Touch_and_LEDs.ino b/examples/TouchPads/Touch_and_LEDs/Touch_and_LEDs.ino index f270187..7301b8e 100644 --- a/examples/TouchPads/Touch_and_LEDs/Touch_and_LEDs.ino +++ b/examples/TouchPads/Touch_and_LEDs/Touch_and_LEDs.ino @@ -21,8 +21,8 @@ void loop() { //Different types of touches //When you first touch it - if (carrier.Button0.onTouchDown()) { - Serial.println("Touched Down Button 1"); + if (carrier.Buttons.onTouchDown(TOUCH0)) { + Serial.println("Touched Down Button 0"); carrier.leds.setPixelColor(0, 20, 20, 20); // 'Off' pixel at tail carrier.leds.show(); // Refresh strip delay(50); @@ -32,8 +32,8 @@ void loop() { } //When you release it - if (carrier.Button1.onTouchUp()) { - Serial.println("Release Touch Button 2"); + if (carrier.Buttons.onTouchUp(TOUCH1)) { + Serial.println("Release Touch Button 1"); carrier.leds.setPixelColor(1, 20, 20, 20); // 'Off' pixel at tail carrier.leds.show(); // Refresh strip delay(50); @@ -43,8 +43,8 @@ void loop() { } //When it detects a change, down or up - if (carrier.Button2.onTouchChange()) { - Serial.println("Changed Touch Button 3"); + if (carrier.Buttons.onTouchChange(TOUCH2)) { + Serial.println("Changed Touch Button 2"); carrier.leds.setPixelColor(2, 20, 20, 20); // 'Off' pixel at tail carrier.leds.show(); // Refresh strip delay(50); @@ -54,8 +54,8 @@ void loop() { } //Normal, if it is being pressed - if (carrier.Button3.getTouch()) { - Serial.println("Touching Button 4"); + if (carrier.Buttons.getTouch(TOUCH3)) { + Serial.println("Touching Button 3"); carrier.leds.setPixelColor(3, 20, 20, 20); // 'Off' pixel at tail carrier.leds.show(); // Refresh strip delay(5); @@ -64,8 +64,8 @@ void loop() { carrier.leds.show(); // Refresh strip } - if (carrier.Button4.getTouch()) { - Serial.println("Touching Button 5"); + if (carrier.Buttons.getTouch(TOUCH4)) { + Serial.println("Touching Button 4"); carrier.leds.setPixelColor(4, 20, 20, 20); // 'Off' pixel at tail carrier.leds.show(); // Refresh strip delay(5); @@ -77,4 +77,4 @@ void loop() { Serial.println(); delay(10); -} +} \ No newline at end of file diff --git a/examples/TouchPads/getTouch/getTouch.ino b/examples/TouchPads/getTouch/getTouch.ino index cbf4fdc..ff6a545 100644 --- a/examples/TouchPads/getTouch/getTouch.ino +++ b/examples/TouchPads/getTouch/getTouch.ino @@ -18,7 +18,6 @@ void setup() { Serial.begin(9600); while (!Serial); // Qtouch initialization - CARRIER_CASE = false; if (!carrier.begin()) { Serial.println("Error in sensors initialization!"); while (1); @@ -31,20 +30,20 @@ void loop() { carrier.Buttons.update(); // Checks if new data are available - if (carrier.Button0.getTouch()) { + if (carrier.Buttons.getTouch(TOUCH0)) { + Serial.println("Touching Button 0"); + } + if (carrier.Buttons.getTouch(TOUCH1)) { Serial.println("Touching Button 1"); } - if (carrier.Button1.getTouch()) { + if (carrier.Buttons.getTouch(TOUCH2)) { Serial.println("Touching Button 2"); } - if (carrier.Button2.getTouch()) { + if (carrier.Buttons.getTouch(TOUCH3)) { Serial.println("Touching Button 3"); } - if (carrier.Button3.getTouch()) { + if (carrier.Buttons.getTouch(TOUCH4)) { Serial.println("Touching Button 4"); } - if (carrier.Button4.getTouch()) { - Serial.println("Touching Button 5"); - } } diff --git a/src/Arduino_MKRIoTCarrier.cpp b/src/Arduino_MKRIoTCarrier.cpp index 8c8c452..52f13f7 100644 --- a/src/Arduino_MKRIoTCarrier.cpp +++ b/src/Arduino_MKRIoTCarrier.cpp @@ -24,70 +24,52 @@ //Define on the sketch to use it bool CARRIER_CASE = false; -MKRIoTCarrier::MKRIoTCarrier(){ - //Restart cleaner - //display.fillScreen(ST77XX_BLACK); - //leds.clear(); - //leds.show(); - +MKRIoTCarrier::MKRIoTCarrier() { } -int MKRIoTCarrier::begin(){ - //Display - display.init(240, 240); // Initialize ST7789 screen - pinMode(3,INPUT_PULLUP); // RESET fix - - //Default rotation to align it with the carrier - display.setRotation(2); - display.fillScreen(ST77XX_BLACK); - +int MKRIoTCarrier::begin() { + //Display + display.init(240, 240);//.begin(true); // Initialize ST7789 screen + pinMode(3,INPUT_PULLUP); // RESET fix - if(!Buttons.customSens){ + //Default rotation to align it with the carrier + display.setRotation(2); + display.fillScreen(ST77XX_BLACK); - if(CARRIER_CASE){ - TOUCH.setSensorsSensitivity(5u); - }else{ - TOUCH.setSensorsSensitivity(100u); - } - } - Buttons.begin(); //init buttons + Buttons.begin(); //init buttons - //init LEDs - leds.begin(); - leds.clear(); - leds.show(); + //init LEDs + leds.begin(); + leds.clear(); + leds.show(); - //PMIC init - PMIC.begin(); - PMIC.enableBoostMode(); - - //Sensors - uint8_t sensorsOK = !Light.begin() << 0 | !Pressure.begin() << 1 | !IMUmodule.begin() << 2 | !Env.begin() << 3 ; - //Serial.println(sensorsOK , BIN); + //PMIC init + PMIC.begin(); + PMIC.enableBoostMode(); - //If some of the sensors are not connected - if(sensorsOK > 0 ){ - Serial.println("Error detected!"); - if(sensorsOK & 0b0001){ - Serial.println("Ambient light sensor is not connected!"); - } - if(sensorsOK & 0b0010){ - Serial.println("Pressure sensor is not connected!"); - } - if(sensorsOK & 0b0100){ - Serial.println("IMU is not connected"); - } - if(sensorsOK & 0b1000){ - Serial.println("Environmental sensor is not connected!"); - } + //Sensors + uint8_t sensorsOK = !Light.begin() << 0 | !Pressure.begin() << 1 | !IMUmodule.begin() << 2 | !Env.begin() << 3; - //while (true); - return false; + //If some of the sensors are not connected + if(sensorsOK > 0 ){ + Serial.println("Error detected!"); + if(sensorsOK & 0b0001){ + Serial.println("Ambient light sensor is not connected!"); + } + if(sensorsOK & 0b0010){ + Serial.println("Pressure sensor is not connected!"); + } + if(sensorsOK & 0b0100){ + Serial.println("IMU is not connected"); + } + if(sensorsOK & 0b1000){ + Serial.println("Environmental sensor is not connected!"); } + return false; + } - //Its OK if the SD card is not plugged in - if(!SD.begin(SD_CS)){ - Serial.println("Sd card not detected"); - } - return true; + if(!SD.begin(SD_CS)) { + Serial.println("Sd card not detected"); + } + return true; } diff --git a/src/Arduino_MKRIoTCarrier.h b/src/Arduino_MKRIoTCarrier.h index bdd102f..c89f6ab 100644 --- a/src/Arduino_MKRIoTCarrier.h +++ b/src/Arduino_MKRIoTCarrier.h @@ -89,7 +89,7 @@ enum { }; class MKRIoTCarrier{ - public: + public: MKRIoTCarrier(); int begin(); @@ -108,18 +108,13 @@ class MKRIoTCarrier{ MKRIoTCarrier_Buzzer Buzzer = MKRIoTCarrier_Buzzer(BUZZER); //Buzzer, pin 6 //Buttons - MKRIoTCarrier_Qtouch_Manager Buttons = MKRIoTCarrier_Qtouch_Manager(); - MKRIoTCarrier_Qtouch Button0 = MKRIoTCarrier_Qtouch(0, &Buttons); - MKRIoTCarrier_Qtouch Button1 = MKRIoTCarrier_Qtouch(1, &Buttons); - MKRIoTCarrier_Qtouch Button2 = MKRIoTCarrier_Qtouch(2, &Buttons); - MKRIoTCarrier_Qtouch Button3 = MKRIoTCarrier_Qtouch(3, &Buttons); - MKRIoTCarrier_Qtouch Button4 = MKRIoTCarrier_Qtouch(4, &Buttons); + MKRIoTCarrierQtouch Buttons = MKRIoTCarrierQtouch(); //Display Adafruit_ST7789 display = Adafruit_ST7789(&SPI, TFT_CS, TFT_DC, -1); //RGB LEDs Adafruit_DotStar leds = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG); - private: + private: }; #endif diff --git a/src/Arduino_MKRIoTCarrier_Qtouch.cpp b/src/Arduino_MKRIoTCarrier_Qtouch.cpp index 2740b80..c8328ba 100644 --- a/src/Arduino_MKRIoTCarrier_Qtouch.cpp +++ b/src/Arduino_MKRIoTCarrier_Qtouch.cpp @@ -22,96 +22,71 @@ #include "Arduino_MCHPTouch.h" //Individual pad -MKRIoTCarrier_Qtouch::MKRIoTCarrier_Qtouch(int padIndex, MKRIoTCarrier_Qtouch_Manager * pManager){ - _padIndex = padIndex; - _pManager = pManager; +MKRIoTCarrierQtouch::MKRIoTCarrierQtouch() { } -bool MKRIoTCarrier_Qtouch::getTouch(){ - bool getState = _pManager->t_state[_padIndex]; - _saveToHistory(getState); - - return(getState); +bool MKRIoTCarrierQtouch::getTouch(touchButtons padIndex) { + if(_available) { + return TOUCH.read(padIndex); + } + return false; } -void MKRIoTCarrier_Qtouch::_saveToHistory(bool newEntry){ - //Serial.println(_padIndex); - for (int i = 10; i>0; i--){ - _touches[i] = _touches[i -1]; - /* Serial.print(i); - Serial.print(" = "); - Serial.println( _touches[i]);*/ +bool MKRIoTCarrierQtouch::onTouchDown(touchButtons padIndex) { + if(_available) { + if(getTouch(padIndex) && _touchesPrev[padIndex] == 0) { + _touchesPrev[padIndex] = 1; + return true; } - _touches[0] = newEntry; - /* - Serial.print(0); - Serial.print(" = "); - Serial.println( _touches[0]);*/ + _touchesPrev[padIndex] = getTouch(padIndex); + } + return false; } -bool MKRIoTCarrier_Qtouch::onTouchDown(){ - getTouch(); - //Serial.print(_touches[0]); - //Serial.print(_touches[1]); - //Serial.println(); - if(_touches[0] && !_touches[1]){ - return true; - }else{ - return false; - } -} -bool MKRIoTCarrier_Qtouch::onTouchUp(){ - getTouch(); - //Serial.print(_touches[0]); - //Serial.print(_touches[1]); - //Serial.println(); - if(!_touches[0] && _touches[1]){ - return true; - }else{ - return false; +bool MKRIoTCarrierQtouch::onTouchUp(touchButtons padIndex) { + if(_available) { + if(!getTouch(padIndex) && _touchesPrev[padIndex] == 1) { + _touchesPrev[padIndex] = 0; + return true; } + _touchesPrev[padIndex] = getTouch(padIndex); + } + return false; } -bool MKRIoTCarrier_Qtouch::onTouchChange(){ - getTouch(); - //Serial.print(_touches[0]); - //Serial.print(_touches[1]); - //Serial.println(); - if(_touches[0] != _touches[1]){ + +bool MKRIoTCarrierQtouch::onTouchChange(touchButtons padIndex) { + if(_available) { + if(_touchesPrev[padIndex] != getTouch(padIndex)){ + _touchesPrev[padIndex] = getTouch(padIndex); return true; - }else{ - return false; } + } + return false; } -void MKRIoTCarrier_Qtouch::updateConfig(int newSens){ - TOUCH.setSensorsSensitivity(newSens, _padIndex); - //TOUCH.begin(); - _pManager->customSens = true; +void MKRIoTCarrierQtouch::updateConfig(int newSens, touchButtons padIndex) { + TOUCH.setSensorsSensitivity(newSens, padIndex); + customSens = true; } //Manager -bool MKRIoTCarrier_Qtouch_Manager::begin(){ - return TOUCH.begin(); +bool MKRIoTCarrierQtouch::begin() { + return TOUCH.begin(); } -MKRIoTCarrier_Qtouch_Manager::MKRIoTCarrier_Qtouch_Manager(){ -} -void MKRIoTCarrier_Qtouch_Manager::update(){ - TOUCH .poll(); - if(TOUCH.available()){ - t_state[0] = TOUCH.read(0); - t_state[1] = TOUCH.read(1); - t_state[2] = TOUCH.read(2); - t_state[3] = TOUCH.read(3); - t_state[4] = TOUCH.read(4); - } +bool MKRIoTCarrierQtouch::update() { + TOUCH.poll(); + if(TOUCH.available()) { + _available = true; + return true; + } + _available = false; + return false; } -void MKRIoTCarrier_Qtouch_Manager::updateConfig(int newSens){ - TOUCH.setSensorsSensitivity(newSens); - //TOUCH.setSernsorsHysteresis(newHyst); - //TOUCH.begin(); - customSens = true; +void MKRIoTCarrierQtouch::updateConfig(int newSens) { + TOUCH.setSensorsSensitivity(newSens); + customSens = true; } diff --git a/src/Arduino_MKRIoTCarrier_Qtouch.h b/src/Arduino_MKRIoTCarrier_Qtouch.h index 42c79f9..05a1fe3 100644 --- a/src/Arduino_MKRIoTCarrier_Qtouch.h +++ b/src/Arduino_MKRIoTCarrier_Qtouch.h @@ -24,42 +24,39 @@ #include "Arduino.h" #include "Arduino_MCHPTouch.h" -//manager -class MKRIoTCarrier_Qtouch_Manager{ - public: - MKRIoTCarrier_Qtouch_Manager(); - - bool begin(); - void update(); +typedef enum { + TOUCH1 = 0, + TOUCH2, + TOUCH3, + TOUCH4, + TOUCH5 +} touchButtons; - int t_state[5]; +class MKRIoTCarrierQtouch{ + public: + MKRIoTCarrierQtouch(); + bool begin(); + bool update(); //Set touch settings - void updateConfig(int newSens); - bool customSens = false; + void updateConfig(int newSens, touchButtons padIndex); -}; - -class MKRIoTCarrier_Qtouch{ - public: - MKRIoTCarrier_Qtouch(int padIndex, MKRIoTCarrier_Qtouch_Manager * pManager); //Individual - - bool getTouch(); - bool onTouchDown(); - bool onTouchUp(); - bool onTouchChange(); + bool getTouch(touchButtons _padIndex); + bool onTouchDown(touchButtons _padIndex); + bool onTouchUp(touchButtons _padIndex); + bool onTouchChange(touchButtons _padIndex); void updateConfig(int newSens); - private: - MKRIoTCarrier_Qtouch_Manager * _pManager; - int _padIndex; + bool customSens = false; - bool _touches[10]; //To know last touches + private: + int _padIndex; + bool _available = false; - void _saveToHistory(bool newEntry); + bool _touchesPrev[5] = {0, 0, 0, 0, 0}; //To know last touches - //Cfg + //Config bool setOnChange = false; //Touch on change bool setOnNormal = false; //Allways read bool setOnUp = false; //When the pad is not being touched From bb99f46e3cc5b26633905d9c46575575d5d5ad94 Mon Sep 17 00:00:00 2001 From: Riccardo Rizzo Date: Thu, 27 May 2021 12:00:05 +0200 Subject: [PATCH 2/4] added Backward compatibility for previous software version --- .../Custom_Sensitivity/Custom_Sensitivity.ino | 2 +- examples/TouchPads/TouchTypes/TouchTypes.ino | 4 ++-- src/Arduino_MKRIoTCarrier.h | 9 ++++++- src/Arduino_MKRIoTCarrier_Qtouch.cpp | 24 +++++++++++++++++-- src/Arduino_MKRIoTCarrier_Qtouch.h | 20 ++++++++++------ 5 files changed, 46 insertions(+), 13 deletions(-) diff --git a/examples/TouchPads/Custom_Sensitivity/Custom_Sensitivity.ino b/examples/TouchPads/Custom_Sensitivity/Custom_Sensitivity.ino index 481f64d..30daac7 100644 --- a/examples/TouchPads/Custom_Sensitivity/Custom_Sensitivity.ino +++ b/examples/TouchPads/Custom_Sensitivity/Custom_Sensitivity.ino @@ -44,7 +44,7 @@ void loop() { Serial.println("touching 3"); } - if (carrier.Buttons.getTouch(4)) { + if (carrier.Buttons.getTouch(TOUCH4)) { Serial.println("touching 4"); } } diff --git a/examples/TouchPads/TouchTypes/TouchTypes.ino b/examples/TouchPads/TouchTypes/TouchTypes.ino index 16df066..94bb3e3 100644 --- a/examples/TouchPads/TouchTypes/TouchTypes.ino +++ b/examples/TouchPads/TouchTypes/TouchTypes.ino @@ -33,10 +33,10 @@ void loop() { if (carrier.Buttons.onTouchDown(TOUCH0)) { Serial.println("Touched Down Button 0"); } - if (carrier.Buttons..onTouchUp(TOUCH1)) { + if (carrier.Buttons.onTouchUp(TOUCH1)) { Serial.println("Release Touch Button 1"); } - if (carrier.Buttons..onTouchChange(TOUCH2)) { + if (carrier.Buttons.onTouchChange(TOUCH2)) { Serial.println("Changed Touch Button 2"); } if (carrier.Buttons.getTouch(TOUCH3)) { diff --git a/src/Arduino_MKRIoTCarrier.h b/src/Arduino_MKRIoTCarrier.h index c89f6ab..000d850 100644 --- a/src/Arduino_MKRIoTCarrier.h +++ b/src/Arduino_MKRIoTCarrier.h @@ -18,7 +18,7 @@ */ -#ifndef ARDUINO_MKRIoTCarrier_h +ifndef ARDUINO_MKRIoTCarrier_h #define ARDUINO_MKRIoTCarrier_h #include @@ -110,6 +110,13 @@ class MKRIoTCarrier{ //Buttons MKRIoTCarrierQtouch Buttons = MKRIoTCarrierQtouch(); + + MKRIoTCarrierQtouch Button0 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH0); + MKRIoTCarrierQtouch Button1 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH1); + MKRIoTCarrierQtouch Button2 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH2); + MKRIoTCarrierQtouch Button3 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH3); + MKRIoTCarrierQtouch Button4 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH4); + //Display Adafruit_ST7789 display = Adafruit_ST7789(&SPI, TFT_CS, TFT_DC, -1); diff --git a/src/Arduino_MKRIoTCarrier_Qtouch.cpp b/src/Arduino_MKRIoTCarrier_Qtouch.cpp index c8328ba..99a9d62 100644 --- a/src/Arduino_MKRIoTCarrier_Qtouch.cpp +++ b/src/Arduino_MKRIoTCarrier_Qtouch.cpp @@ -25,6 +25,11 @@ MKRIoTCarrierQtouch::MKRIoTCarrierQtouch() { } +//Individual pad +MKRIoTCarrierQtouch::MKRIoTCarrierQtouch(touchButtons padIndex) { + _padID = padIndex; +} + bool MKRIoTCarrierQtouch::getTouch(touchButtons padIndex) { if(_available) { return TOUCH.read(padIndex); @@ -32,6 +37,10 @@ bool MKRIoTCarrierQtouch::getTouch(touchButtons padIndex) { return false; } +bool MKRIoTCarrierQtouch::getTouch() { + return getTouch(_padID); +} + bool MKRIoTCarrierQtouch::onTouchDown(touchButtons padIndex) { if(_available) { if(getTouch(padIndex) && _touchesPrev[padIndex] == 0) { @@ -43,6 +52,10 @@ bool MKRIoTCarrierQtouch::onTouchDown(touchButtons padIndex) { return false; } +bool MKRIoTCarrierQtouch::onTouchDown() { + return onTouchDown(_padID); +} + bool MKRIoTCarrierQtouch::onTouchUp(touchButtons padIndex) { if(_available) { if(!getTouch(padIndex) && _touchesPrev[padIndex] == 1) { @@ -54,6 +67,10 @@ bool MKRIoTCarrierQtouch::onTouchUp(touchButtons padIndex) { return false; } +bool MKRIoTCarrierQtouch::onTouchUp() { + return onTouchUp(_padID); +} + bool MKRIoTCarrierQtouch::onTouchChange(touchButtons padIndex) { if(_available) { if(_touchesPrev[padIndex] != getTouch(padIndex)){ @@ -64,6 +81,9 @@ bool MKRIoTCarrierQtouch::onTouchChange(touchButtons padIndex) { return false; } +bool MKRIoTCarrierQtouch::onTouchChange() { + return onTouchChange(_padID); +} void MKRIoTCarrierQtouch::updateConfig(int newSens, touchButtons padIndex) { TOUCH.setSensorsSensitivity(newSens, padIndex); @@ -80,10 +100,10 @@ bool MKRIoTCarrierQtouch::update() { TOUCH.poll(); if(TOUCH.available()) { _available = true; - return true; + return _available; } _available = false; - return false; + return _available; } void MKRIoTCarrierQtouch::updateConfig(int newSens) { diff --git a/src/Arduino_MKRIoTCarrier_Qtouch.h b/src/Arduino_MKRIoTCarrier_Qtouch.h index 05a1fe3..584cda4 100644 --- a/src/Arduino_MKRIoTCarrier_Qtouch.h +++ b/src/Arduino_MKRIoTCarrier_Qtouch.h @@ -24,35 +24,41 @@ #include "Arduino.h" #include "Arduino_MCHPTouch.h" +static bool _available = false; + typedef enum { - TOUCH1 = 0, + TOUCH0 = 0, + TOUCH1, TOUCH2, TOUCH3, - TOUCH4, - TOUCH5 + TOUCH4 } touchButtons; class MKRIoTCarrierQtouch{ public: MKRIoTCarrierQtouch(); + MKRIoTCarrierQtouch(touchButtons padIndex); bool begin(); bool update(); //Set touch settings void updateConfig(int newSens, touchButtons padIndex); - + void updateConfig(int newSens); bool getTouch(touchButtons _padIndex); + bool getTouch() __attribute__((deprecated)); bool onTouchDown(touchButtons _padIndex); + bool onTouchDown() __attribute__((deprecated)); bool onTouchUp(touchButtons _padIndex); + bool onTouchUp() __attribute__((deprecated)); bool onTouchChange(touchButtons _padIndex); - - void updateConfig(int newSens); + bool onTouchChange() __attribute__((deprecated)); bool customSens = false; private: + touchButtons _padID; int _padIndex; - bool _available = false; + bool _touchesPrev[5] = {0, 0, 0, 0, 0}; //To know last touches From 912f715f847de72122a2af8d9281354439a6c923 Mon Sep 17 00:00:00 2001 From: Riccardo Rizzo <37290960+Rocketct@users.noreply.github.com> Date: Thu, 27 May 2021 12:15:44 +0200 Subject: [PATCH 3/4] Update Arduino_MKRIoTCarrier.h --- src/Arduino_MKRIoTCarrier.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arduino_MKRIoTCarrier.h b/src/Arduino_MKRIoTCarrier.h index 000d850..2f2bd10 100644 --- a/src/Arduino_MKRIoTCarrier.h +++ b/src/Arduino_MKRIoTCarrier.h @@ -18,7 +18,7 @@ */ -ifndef ARDUINO_MKRIoTCarrier_h +#ifndef ARDUINO_MKRIoTCarrier_h #define ARDUINO_MKRIoTCarrier_h #include From fc1bf7df73b47f8bd3d514f998fdb2c65d42884b Mon Sep 17 00:00:00 2001 From: Riccardo Rizzo <37290960+Rocketct@users.noreply.github.com> Date: Thu, 27 May 2021 12:16:05 +0200 Subject: [PATCH 4/4] Update Arduino_MKRIoTCarrier.h --- src/Arduino_MKRIoTCarrier.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arduino_MKRIoTCarrier.h b/src/Arduino_MKRIoTCarrier.h index 2f2bd10..46d5e38 100644 --- a/src/Arduino_MKRIoTCarrier.h +++ b/src/Arduino_MKRIoTCarrier.h @@ -115,7 +115,7 @@ class MKRIoTCarrier{ MKRIoTCarrierQtouch Button1 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH1); MKRIoTCarrierQtouch Button2 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH2); MKRIoTCarrierQtouch Button3 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH3); - MKRIoTCarrierQtouch Button4 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH4); + MKRIoTCarrierQtouch Button4 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH4); //Display Adafruit_ST7789 display = Adafruit_ST7789(&SPI, TFT_CS, TFT_DC, -1);