Page forwarding via key active

This commit is contained in:
norbert-walter 2022-02-12 17:57:41 +01:00
parent df87a6121e
commit 9eb905506c
2 changed files with 21 additions and 20 deletions

View File

@ -17,22 +17,16 @@ int keypad[9]; // Raw data array from TTP229
int key; // Value of key [0|1], 0 = touched, 1 = not touched int key; // Value of key [0|1], 0 = touched, 1 = not touched
int keycode = 0; // Keycode of pressed key [0...8], 0 = nothing touched int keycode = 0; // Keycode of pressed key [0...8], 0 = nothing touched
int keycode2 = 0; // Keycode of very short pressed key [0...8], 0 = nothing touched int keycode2 = 0; // Keycode of very short pressed key [0...8], 0 = nothing touched
String keystatus = "0"; // Status of key (0 = processed, 1s...8s, 1l...8l, left, right unprocessed) int keystatus = 0; // Status of key [0...11], 0 = processed, 1...8 = key 1..8, 9 = right swipe , 10 = left swipe, 11 keys disabled
int keycodeold = 0; // Old keycode int keycodeold = 0; // Old keycode
int keycodeold2 = 0; // Old keycode for short pressed key int keycodeold2 = 0; // Old keycode for short pressed key
bool keyoff = false; // Key switch off bool keyoff = false; // Disable all keys
int swipedelay = 500; // Delay after swipe in [ms]
int keydelay = 250; // Delay after key pressed in [ms] int keydelay = 250; // Delay after key pressed in [ms]
bool keylock = false; // Key lock after pressed key is valid (repeat protection by conginous pressing) bool keylock = false; // Key lock after pressed key is valid (repeat protection by conginous pressing)
int repeatnum; // Actual number of key detections for a pressed key
int shortpress = 5; // number of key detections after that the key is valid (n * 40ms) for short pessing
int longpress = 25; // number of key detections after that the key is valid (n * 40ms) for long pessing
int swipedir = 0; // Swipe direction 0 = nothing, -1 = left, +1 = right
long starttime = 0; // Start time point for pressed key long starttime = 0; // Start time point for pressed key
String readKeypad() { int readKeypad() {
noInterrupts(); noInterrupts();
pinMode(TTP_SDO, INPUT); pinMode(TTP_SDO, INPUT);
pinMode(TTP_SCL, OUTPUT); pinMode(TTP_SCL, OUTPUT);
@ -70,7 +64,6 @@ String readKeypad() {
} }
// Detect a very short keynumber (10ms) // Detect a very short keynumber (10ms)
if (millis() > starttime + 10 && keycode == keycodeold && keylock == true) { if (millis() > starttime + 10 && keycode == keycodeold && keylock == true) {
keystatus = String(keycode) + "vs";
// Process only valid keys // Process only valid keys
if(keycode == 1 || keycode == 6){ if(keycode == 1 || keycode == 6){
keycode2 = keycode; keycode2 = keycode;
@ -87,7 +80,7 @@ String readKeypad() {
} }
// Detect a short keynumber (200ms) // Detect a short keynumber (200ms)
if (keyoff == false && millis() > starttime + 200 && keycode == keycodeold && keylock == true) { if (keyoff == false && millis() > starttime + 200 && keycode == keycodeold && keylock == true) {
keystatus = String(keycode) + "s"; keystatus = keycode;
keycode = 0; keycode = 0;
keycodeold = 0; keycodeold = 0;
keycode2 = 0; keycode2 = 0;
@ -110,10 +103,10 @@ String readKeypad() {
keyoff = !keyoff; keyoff = !keyoff;
if(keyoff == true){ if(keyoff == true){
keystatus = "off"; keystatus = 11;
} }
else{ else{
keystatus = "on"; keystatus = 0;
} }
} }
@ -124,8 +117,7 @@ String readKeypad() {
keycodeold = 0; keycodeold = 0;
keycode2 = 0; keycode2 = 0;
keycodeold2 = 0; keycodeold2 = 0;
swipedir = 1; keystatus = 9;
keystatus = "r";
buzzer(TONE3, buzPower, 150); buzzer(TONE3, buzPower, 150);
buzzer(TONE4, buzPower, 150); buzzer(TONE4, buzPower, 150);
} }
@ -137,8 +129,7 @@ String readKeypad() {
keycodeold = 0; keycodeold = 0;
keycode2 = 0; keycode2 = 0;
keycodeold2 = 0; keycodeold2 = 0;
swipedir = -1; keystatus = 10;
keystatus = "l";
buzzer(TONE4, buzPower, 150); buzzer(TONE4, buzPower, 150);
buzzer(TONE3, buzPower, 150); buzzer(TONE3, buzPower, 150);
} }

View File

@ -164,6 +164,7 @@ typedef struct {
void keyboardTask(void *param){ void keyboardTask(void *param){
MyData *data=(MyData *)param; MyData *data=(MyData *)param;
int page=data->page0; int page=data->page0;
// Loop for keyboard task // Loop for keyboard task
while (true){ while (true){
//send a key event //send a key event
@ -173,8 +174,17 @@ void keyboardTask(void *param){
page+=1; page+=1;
*/ */
readKeypad(); readKeypad();
delay(20); delay(20); // TP229-BSF working in 8 key mode with 64Hz update rate (15.6ms)
if (page>=MAX_PAGE_NUMBER) page=0; if(keystatus == 9){
page+=1;
keystatus = 0;
}
if(keystatus == 10){
page-=1;
keystatus = 0;
}
if(page >= MAX_PAGE_NUMBER) page = 0;
if(page < 0) page = MAX_PAGE_NUMBER - 1;
} }
vTaskDelete(NULL); vTaskDelete(NULL);
} }