Skip to content

Commit bb99f46

Browse files
committed
added Backward compatibility for previous software version
1 parent ae3700a commit bb99f46

File tree

5 files changed

+46
-13
lines changed

5 files changed

+46
-13
lines changed

examples/TouchPads/Custom_Sensitivity/Custom_Sensitivity.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void loop() {
4444
Serial.println("touching 3");
4545
}
4646

47-
if (carrier.Buttons.getTouch(4)) {
47+
if (carrier.Buttons.getTouch(TOUCH4)) {
4848
Serial.println("touching 4");
4949
}
5050
}

examples/TouchPads/TouchTypes/TouchTypes.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ void loop() {
3333
if (carrier.Buttons.onTouchDown(TOUCH0)) {
3434
Serial.println("Touched Down Button 0");
3535
}
36-
if (carrier.Buttons..onTouchUp(TOUCH1)) {
36+
if (carrier.Buttons.onTouchUp(TOUCH1)) {
3737
Serial.println("Release Touch Button 1");
3838
}
39-
if (carrier.Buttons..onTouchChange(TOUCH2)) {
39+
if (carrier.Buttons.onTouchChange(TOUCH2)) {
4040
Serial.println("Changed Touch Button 2");
4141
}
4242
if (carrier.Buttons.getTouch(TOUCH3)) {

src/Arduino_MKRIoTCarrier.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020

21-
#ifndef ARDUINO_MKRIoTCarrier_h
21+
ifndef ARDUINO_MKRIoTCarrier_h
2222
#define ARDUINO_MKRIoTCarrier_h
2323

2424
#include <Arduino.h>
@@ -110,6 +110,13 @@ class MKRIoTCarrier{
110110
//Buttons
111111
MKRIoTCarrierQtouch Buttons = MKRIoTCarrierQtouch();
112112

113+
114+
MKRIoTCarrierQtouch Button0 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH0);
115+
MKRIoTCarrierQtouch Button1 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH1);
116+
MKRIoTCarrierQtouch Button2 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH2);
117+
MKRIoTCarrierQtouch Button3 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH3);
118+
MKRIoTCarrierQtouch Button4 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH4);
119+
113120
//Display
114121
Adafruit_ST7789 display = Adafruit_ST7789(&SPI, TFT_CS, TFT_DC, -1);
115122

src/Arduino_MKRIoTCarrier_Qtouch.cpp

+22-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,22 @@
2525
MKRIoTCarrierQtouch::MKRIoTCarrierQtouch() {
2626
}
2727

28+
//Individual pad
29+
MKRIoTCarrierQtouch::MKRIoTCarrierQtouch(touchButtons padIndex) {
30+
_padID = padIndex;
31+
}
32+
2833
bool MKRIoTCarrierQtouch::getTouch(touchButtons padIndex) {
2934
if(_available) {
3035
return TOUCH.read(padIndex);
3136
}
3237
return false;
3338
}
3439

40+
bool MKRIoTCarrierQtouch::getTouch() {
41+
return getTouch(_padID);
42+
}
43+
3544
bool MKRIoTCarrierQtouch::onTouchDown(touchButtons padIndex) {
3645
if(_available) {
3746
if(getTouch(padIndex) && _touchesPrev[padIndex] == 0) {
@@ -43,6 +52,10 @@ bool MKRIoTCarrierQtouch::onTouchDown(touchButtons padIndex) {
4352
return false;
4453
}
4554

55+
bool MKRIoTCarrierQtouch::onTouchDown() {
56+
return onTouchDown(_padID);
57+
}
58+
4659
bool MKRIoTCarrierQtouch::onTouchUp(touchButtons padIndex) {
4760
if(_available) {
4861
if(!getTouch(padIndex) && _touchesPrev[padIndex] == 1) {
@@ -54,6 +67,10 @@ bool MKRIoTCarrierQtouch::onTouchUp(touchButtons padIndex) {
5467
return false;
5568
}
5669

70+
bool MKRIoTCarrierQtouch::onTouchUp() {
71+
return onTouchUp(_padID);
72+
}
73+
5774
bool MKRIoTCarrierQtouch::onTouchChange(touchButtons padIndex) {
5875
if(_available) {
5976
if(_touchesPrev[padIndex] != getTouch(padIndex)){
@@ -64,6 +81,9 @@ bool MKRIoTCarrierQtouch::onTouchChange(touchButtons padIndex) {
6481
return false;
6582
}
6683

84+
bool MKRIoTCarrierQtouch::onTouchChange() {
85+
return onTouchChange(_padID);
86+
}
6787

6888
void MKRIoTCarrierQtouch::updateConfig(int newSens, touchButtons padIndex) {
6989
TOUCH.setSensorsSensitivity(newSens, padIndex);
@@ -80,10 +100,10 @@ bool MKRIoTCarrierQtouch::update() {
80100
TOUCH.poll();
81101
if(TOUCH.available()) {
82102
_available = true;
83-
return true;
103+
return _available;
84104
}
85105
_available = false;
86-
return false;
106+
return _available;
87107
}
88108

89109
void MKRIoTCarrierQtouch::updateConfig(int newSens) {

src/Arduino_MKRIoTCarrier_Qtouch.h

+13-7
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,41 @@
2424
#include "Arduino.h"
2525
#include "Arduino_MCHPTouch.h"
2626

27+
static bool _available = false;
28+
2729
typedef enum {
28-
TOUCH1 = 0,
30+
TOUCH0 = 0,
31+
TOUCH1,
2932
TOUCH2,
3033
TOUCH3,
31-
TOUCH4,
32-
TOUCH5
34+
TOUCH4
3335
} touchButtons;
3436

3537
class MKRIoTCarrierQtouch{
3638
public:
3739
MKRIoTCarrierQtouch();
40+
MKRIoTCarrierQtouch(touchButtons padIndex);
3841
bool begin();
3942
bool update();
4043

4144
//Set touch settings
4245
void updateConfig(int newSens, touchButtons padIndex);
43-
46+
void updateConfig(int newSens);
4447
bool getTouch(touchButtons _padIndex);
48+
bool getTouch() __attribute__((deprecated));
4549
bool onTouchDown(touchButtons _padIndex);
50+
bool onTouchDown() __attribute__((deprecated));
4651
bool onTouchUp(touchButtons _padIndex);
52+
bool onTouchUp() __attribute__((deprecated));
4753
bool onTouchChange(touchButtons _padIndex);
48-
49-
void updateConfig(int newSens);
54+
bool onTouchChange() __attribute__((deprecated));
5055

5156
bool customSens = false;
5257

5358
private:
59+
touchButtons _padID;
5460
int _padIndex;
55-
bool _available = false;
61+
5662

5763
bool _touchesPrev[5] = {0, 0, 0, 0, 0}; //To know last touches
5864

0 commit comments

Comments
 (0)