From 3a80436344ede8a8877f26f0ed9099ab27c400bc Mon Sep 17 00:00:00 2001 From: George McLaughlin Date: Sat, 28 Sep 2024 22:25:37 -0500 Subject: [PATCH 1/2] Add register details and new functions with examples - Updated README with detailed CST816S register information, including descriptions, addresses, default values, and configuration options. - Added `enable_double_click()` function to enable double-click gesture detection, with an example demonstrating double-click counting. - Renamed and added `enable_auto_standby(uint16_t milliseconds)` function to dynamically set the auto standby delay, with an example showcasing its use. - Enhanced documentation and examples to improve usability and functionality of the CST816S touch controller. --- CST816S.cpp | 18 +++++++++++ CST816S.h | 2 ++ README.md | 41 +++++++++++++++++++++++++- examples/auto_standby/auto_standby.ino | 19 ++++++++++++ examples/double_click/double_click.ino | 20 +++++++++++++ 5 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 examples/auto_standby/auto_standby.ino create mode 100644 examples/double_click/double_click.ino diff --git a/CST816S.cpp b/CST816S.cpp index 674bc07..44fed92 100644 --- a/CST816S.cpp +++ b/CST816S.cpp @@ -70,6 +70,24 @@ void IRAM_ATTR CST816S::handleISR(void) { } +/*! + @brief enable double click +*/ +void CST816S::enable_double_click(void) { + byte enableDoubleTap = 0x01; // Set EnDClick (bit 0) to enable double-tap + i2c_write(CST816S_ADDRESS, 0xEC, &enableDoubleTap, 1); +} + +/*! + @brief Enable auto standby mode with a specified delay. + @param milliseconds + Time in milliseconds before entering standby mode. +*/ +void CST816S::enable_auto_standby(uint16_t milliseconds) { + byte standbyTime = min(milliseconds / 1000, 255); // Convert milliseconds to seconds, max value 255 + i2c_write(CST816S_ADDRESS, 0xF9, &standbyTime, 1); +} + /*! @brief initialize the touch screen @param interrupt diff --git a/CST816S.h b/CST816S.h index 81bab88..6044916 100644 --- a/CST816S.h +++ b/CST816S.h @@ -58,6 +58,8 @@ class CST816S { public: CST816S(int sda, int scl, int rst, int irq); void begin(int interrupt = RISING); + void enable_double_click(); + void enable_auto_standby(uint16_t milliseconds); void sleep(); bool available(); data_struct data; diff --git a/README.md b/README.md index e4f0b4c..17486a7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,43 @@ # CST816S An Arduino library for the CST816S capacitive touch screen IC - [![arduino-library-badge](https://www.ardu-badge.com/badge/CST816S.svg?)](https://www.arduinolibraries.info/libraries/cst816-s) \ No newline at end of file + [![arduino-library-badge](https://www.ardu-badge.com/badge/CST816S.svg?)](https://www.arduinolibraries.info/libraries/cst816-s) + + ## Register Information + + The following information was extracted from (this document)[https://www.waveshare.com/w/upload/c/c2/CST816S_register_declaration.pdf] provided by Waveshare. + + | Register Name | Address | Bit Description | Default Value | Configuration Options | +|-------------------|---------|-------------------------------------------------------|---------------|----------------------------------------------------------------| +| GestureID | 0x01 | Gesture code for detected gestures | N/A | 0x00: None, 0x01: Slide Up, 0x02: Slide Down, 0x0B: Double Click | +| FingerNum | 0x02 | Number of fingers detected | N/A | 0: No finger, 1: One finger | +| XposH | 0x03 | High 4 bits of X coordinate | N/A | - | +| XposL | 0x04 | Low 8 bits of X coordinate | N/A | - | +| YposH | 0x05 | High 4 bits of Y coordinate | N/A | - | +| YposL | 0x06 | Low 8 bits of Y coordinate | N/A | - | +| BPC0H | 0xB0 | High 8 bits of BPC0 value | N/A | - | +| BPC0L | 0xB1 | Low 8 bits of BPC0 value | N/A | - | +| BPC1H | 0xB2 | High 8 bits of BPC1 value | N/A | - | +| BPC1L | 0xB3 | Low 8 bits of BPC1 value | N/A | - | +| ChipID | 0xA7 | Chip model identifier | N/A | - | +| ProjID | 0xA8 | Project number | N/A | - | +| FwVersion | 0xA9 | Firmware version number | N/A | - | +| MotionMask | 0xEC | Enable gesture actions like double-click | 0x00 | Bit 0: EnDClick (enable double-click), Bit 1: EnConUD | +| IrqPluseWidth | 0xED | Interrupt pulse width (0.1 ms units) | 10 | 1-200 | +| NorScanPer | 0xEE | Normal scan period (10 ms units) | 1 | 1-30 | +| MotionSlAngle | 0xEF | Gesture detection sliding angle control | N/A | - | +| LpScanRaw1H | 0xF0 | High 8 bits of low-power scan channel 1 reference | N/A | - | +| LpScanRaw1L | 0xF1 | Low 8 bits of low-power scan channel 1 reference | N/A | - | +| LpScanRaw2H | 0xF2 | High 8 bits of low-power scan channel 2 reference | N/A | - | +| LpScanRaw2L | 0xF3 | Low 8 bits of low-power scan channel 2 reference | N/A | - | +| LpAutoWakeTime | 0xF4 | Auto recalibration time in low-power mode | 5 minutes | 1-5 minutes | +| LpScanTH | 0xF5 | Low-power scan wake threshold | 48 | 1-255 | +| LpScanWin | 0xF6 | Low-power scan range | 3 | 0-3 | +| LpScanFreq | 0xF7 | Low-power scan frequency | 7 | 1-255 | +| LpScanIdac | 0xF8 | Low-power scan current | N/A | 1-255 | +| AutoSleepTime | 0xF9 | Time in seconds before entering standby mode | 2 seconds | 1-255 seconds | +| IrqCtl | 0xFA | Control of interrupt behavior | N/A | EnTest, EnTouch, EnChange, EnMotion | +| AutoReset | 0xFB | Auto-reset time with no valid gesture detected | 5 seconds | 0-5 seconds (0 to disable) | +| LongPressTime | 0xFC | Time for long press to trigger reset | 10 seconds | 0-10 seconds (0 to disable) | +| IOCtl | 0xFD | IO control settings including soft reset | N/A | SOFT_RST, IIC_OD, En1v8 | +| DisAutoSleep | 0xFE | Disable auto sleep mode | 0 | Non-zero value disables auto sleep mode | diff --git a/examples/auto_standby/auto_standby.ino b/examples/auto_standby/auto_standby.ino new file mode 100644 index 0000000..7359af8 --- /dev/null +++ b/examples/auto_standby/auto_standby.ino @@ -0,0 +1,19 @@ +#include + +CST816S touch(21, 22, 5, 4); // sda, scl, rst, irq + +void setup() { + Serial.begin(115200); + touch.begin(); + touch.enable_auto_standby(5000); // Set auto standby mode to 5000 milliseconds (5 seconds) + Serial.println("Auto standby enabled for 5 seconds of inactivity."); +} + +void loop() { + // Check for touch events to reset inactivity timer + if (touch.available()) { + Serial.println("Touch detected, reset standby timer."); + } + // Standby mode will activate automatically based on inactivity + delay(100); // Small delay to avoid excessive loop cycles +} diff --git a/examples/double_click/double_click.ino b/examples/double_click/double_click.ino new file mode 100644 index 0000000..d96cd15 --- /dev/null +++ b/examples/double_click/double_click.ino @@ -0,0 +1,20 @@ +#include + +CST816S touch(21, 22, 5, 4); // sda, scl, rst, irq +int doubleClickCount = 0; // Counter for double clicks + +void setup() { + Serial.begin(115200); + touch.begin(); + touch.enable_double_click(); // Enable double-click detection +} + +void loop() { + if (touch.available()) { + if (touch.gesture() == "DOUBLE CLICK") { + doubleClickCount++; + Serial.print("Double Click Count: "); + Serial.println(doubleClickCount); + } + } +} From 98f3781e65963872b2071243945f5e3a391e560e Mon Sep 17 00:00:00 2001 From: George McLaughlin Date: Sat, 28 Sep 2024 22:28:44 -0500 Subject: [PATCH 2/2] Increment version --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index cf90651..9b17891 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=CST816S -version=1.1.1 +version=1.2.0 author=fbiego maintainer=fbiego sentence=Capacitive touch screen library