Skip to content

Commit

Permalink
refactored, interrupt type
Browse files Browse the repository at this point in the history
  • Loading branch information
fbiego committed Aug 13, 2021
1 parent 817f395 commit 69cf0dd
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 41 deletions.
22 changes: 12 additions & 10 deletions CST816S.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ void IRAM_ATTR CST816S::handleISR(void) {

/*!
@brief initialize the touch screen
@param interrupt
type of interrupt FALLING, RISING..
*/
void CST816S::begin() {
void CST816S::begin(int interrupt) {
Wire.begin(_sda, _scl);

pinMode(_irq, INPUT);
Expand All @@ -90,7 +92,7 @@ void CST816S::begin() {
delay(5);
i2c_read(CST816S_ADDRESS, 0xA7, data.versionInfo, 3);

attachInterrupt(_irq, std::bind(&CST816S::handleISR, this), RISING);
attachInterrupt(_irq, std::bind(&CST816S::handleISR, this), interrupt);
}

/*!
Expand Down Expand Up @@ -122,28 +124,28 @@ void CST816S::sleep() {
*/
String CST816S::gesture() {
switch (data.gestureID) {
case CST816S_NONE:
case NONE:
return "NONE";
break;
case CST816S_SWIPE_DOWN:
case SWIPE_DOWN:
return "SWIPE DOWN";
break;
case CST816S_SWIPE_UP:
case SWIPE_UP:
return "SWIPE UP";
break;
case CST816S_SWIPE_LEFT:
case SWIPE_LEFT:
return "SWIPE LEFT";
break;
case CST816S_SWIPE_RIGHT:
case SWIPE_RIGHT:
return "SWIPE RIGHT";
break;
case CST816S_SINGLE_CLICK:
case SINGLE_CLICK:
return "SINGLE CLICK";
break;
case CST816S_DOUBLE_CLICK:
case DOUBLE_CLICK:
return "DOUBLE CLICK";
break;
case CST816S_LONG_PRESS:
case LONG_PRESS:
return "LONG PRESS";
break;
default:
Expand Down
23 changes: 13 additions & 10 deletions CST816S.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,20 @@

#include <Arduino.h>

#define CST816S_NONE 0x00
#define CST816S_SWIPE_DOWN 0x01
#define CST816S_SWIPE_UP 0x02
#define CST816S_SWIPE_LEFT 0x03
#define CST816S_SWIPE_RIGHT 0x04
#define CST816S_SINGLE_CLICK 0x05
#define CST816S_DOUBLE_CLICK 0x0B
#define CST816S_LONG_PRESS 0x0C

#define CST816S_ADDRESS 0x15

enum GESTURE {
NONE = 0x00,
SWIPE_DOWN = 0x01,
SWIPE_UP = 0x02,
SWIPE_LEFT = 0x03,
SWIPE_RIGHT = 0x04,
SINGLE_CLICK = 0x05,
DOUBLE_CLICK = 0x0B,
LONG_PRESS = 0x0C

};

struct data_struct {
byte gestureID; // Gesture ID
byte points; // Number of touch points
Expand All @@ -54,7 +57,7 @@ class CST816S {

public:
CST816S(int sda, int scl, int rst, int irq);
void begin();
void begin(int interrupt = FALLING);
void sleep();
bool available();
data_struct data;
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# CST816S
An Arduino library for the Hynitron CST816S capacitive touch screen IC

[![arduino-library-badge](https://www.ardu-badge.com/badge/CST816S.svg?)](https://www.arduinolibraries.info/libraries/cst816-s)
An Arduino library for the CST816S capacitive touch screen IC
20 changes: 8 additions & 12 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ available KEYWORD2
sleep KEYWORD2
begin KEYWORD2
gesture KEYWORD2
version KEYWORD2
versionInfo KEYWORD2
gestureID KEYWORD2
points KEYWORD2

CST816S_NONE LITERAL2
CST816S_SWIPE_DOWN LITERAL2
CST816S_SWIPE_UP LITERAL2
CST816S_SWIPE_LEFT LITERAL2
CST816S_SWIPE_RIGHT LITERAL2
CST816S_SINGLE_CLICK LITERAL2
CST816S_DOUBLE_CLICK LITERAL2
CST816S_LONG_PRESS LITERAL2
NONE LITERAL1
SWIPE_DOWN LITERAL1
SWIPE_UP LITERAL1
SWIPE_LEFT LITERAL1
SWIPE_RIGHT LITERAL1
SINGLE_CLICK LITERAL1
DOUBLE_CLICK LITERAL1
LONG_PRESS LITERAL1
6 changes: 3 additions & 3 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "CST816S",
"version": "1.0.0",
"keywords": "Arduino, ESP32, Touch, Hynitron, CST816S, I2C, TouchScreen",
"description": "An Arduino library for the Hynitron CST816S capacitive touch screen IC",
"version": "1.1.0",
"keywords": "Arduino, ESP32, Touch, Hynitron, CST816S, I2C",
"description": "An Arduino library for the CST816S capacitive touch screen IC",
"repository":
{
"type": "git",
Expand Down
6 changes: 3 additions & 3 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name=CST816S
version=1.0.0
version=1.1.0
author=fbiego
maintainer=fbiego
sentence=Capacitive touch screen library
paragraph=An Arduino library for the Hynitron CST816S capacitive touch screen IC
category=Sensors
paragraph=An Arduino library for the CST816S capacitive touch screen IC
category=Other
url=https://github.com/fbiego/CST816S
architectures=*
includes=CST816S.h
Expand Down

0 comments on commit 69cf0dd

Please sign in to comment.