-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from georgemclaughlin/1.3.0
Updated auto sleep functionality and added user interrupt
- Loading branch information
Showing
9 changed files
with
253 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
MIT License | ||
Copyright (c) 2021 Felix Biego | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
|
||
#include <CST816S.h> | ||
|
||
CST816S touch(21, 22, 5, 4); // sda, scl, rst, irq | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
touch.begin(); | ||
|
||
// Print version information | ||
Serial.print("Touch Firmware Version: "); | ||
Serial.print(touch.data.version); | ||
Serial.print("\t"); | ||
Serial.print(touch.data.versionInfo[0]); | ||
Serial.print("-"); | ||
Serial.print(touch.data.versionInfo[1]); | ||
Serial.print("-"); | ||
Serial.println(touch.data.versionInfo[2]); | ||
|
||
// Disable auto sleep to keep the device active (useful during debugging or testing) | ||
touch.disable_auto_sleep(); | ||
Serial.println("Auto sleep disabled"); | ||
|
||
// Optionally, set a custom auto sleep time (e.g., 10 seconds) | ||
touch.set_auto_sleep_time(10); | ||
Serial.println("Auto sleep timeout set to 10 seconds"); | ||
|
||
// Setting the auto sleep time does not automatically reenable auto sleep | ||
touch.enable_auto_sleep(); | ||
} | ||
|
||
void loop() { | ||
if (touch.available()) { | ||
Serial.print("Gesture: "); | ||
Serial.print(touch.gesture()); | ||
Serial.print("\tPoints: "); | ||
Serial.print(touch.data.points); | ||
Serial.print("\tEvent: "); | ||
Serial.print(touch.data.event); | ||
Serial.print("\tX: "); | ||
Serial.print(touch.data.x); | ||
Serial.print("\tY: "); | ||
Serial.println(touch.data.y); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
MIT License | ||
Copyright (c) 2021 Felix Biego | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
|
||
#include <CST816S.h> | ||
|
||
CST816S touch(21, 22, 5, 4); // sda, scl, rst, irq | ||
|
||
// Flag to indicate a touch interrupt has occurred | ||
volatile bool touchEventFlag = false; | ||
|
||
// Interrupt function to set the flag | ||
void IRAM_ATTR onTouchInterrupt() { | ||
touchEventFlag = true; | ||
} | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
touch.begin(); | ||
touch.attachUserInterrupt(onTouchInterrupt); | ||
touch.enable_double_click(); // Enable double-click detection | ||
} | ||
|
||
void loop() { | ||
// Check if the interrupt flag has been set by the interrupt handler | ||
if (touchEventFlag) { | ||
touchEventFlag = false; // Clear the flag | ||
|
||
// Check if there’s touch data available | ||
if (touch.available()) { | ||
// Check if the gesture is a double touch | ||
if (touch.gesture() == "DOUBLE CLICK") { | ||
Serial.println("Double touch detected!"); | ||
} else { | ||
Serial.println("Touch event detected, but not a double touch."); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.