From 9eb905506cfe360623c1b8d4b4d292f72fe94575 Mon Sep 17 00:00:00 2001 From: norbert-walter Date: Sat, 12 Feb 2022 17:57:41 +0100 Subject: [PATCH] Page forwarding via key active --- lib/obp60task/OBP60Keypad.h | 27 +++++++++------------------ lib/obp60task/obp60task.cpp | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/obp60task/OBP60Keypad.h b/lib/obp60task/OBP60Keypad.h index c1cf81c..a4123d1 100644 --- a/lib/obp60task/OBP60Keypad.h +++ b/lib/obp60task/OBP60Keypad.h @@ -16,23 +16,17 @@ int keyposition[9] = {0, 3, 5, 7, 8, 6, 4, 2, 1}; // Position of key in raw da int keypad[9]; // Raw data array from TTP229 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 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 keycode2 = 0; // Keycode of very short pressed key [0...8], 0 = nothing touched +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 keycodeold2 = 0; // Old keycode for short pressed key -bool keyoff = false; // Key switch off -int swipedelay = 500; // Delay after swipe in [ms] +bool keyoff = false; // Disable all keys int keydelay = 250; // Delay after key pressed in [ms] 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 -String readKeypad() { +int readKeypad() { noInterrupts(); pinMode(TTP_SDO, INPUT); pinMode(TTP_SCL, OUTPUT); @@ -70,7 +64,6 @@ String readKeypad() { } // Detect a very short keynumber (10ms) if (millis() > starttime + 10 && keycode == keycodeold && keylock == true) { - keystatus = String(keycode) + "vs"; // Process only valid keys if(keycode == 1 || keycode == 6){ keycode2 = keycode; @@ -87,7 +80,7 @@ String readKeypad() { } // Detect a short keynumber (200ms) if (keyoff == false && millis() > starttime + 200 && keycode == keycodeold && keylock == true) { - keystatus = String(keycode) + "s"; + keystatus = keycode; keycode = 0; keycodeold = 0; keycode2 = 0; @@ -110,10 +103,10 @@ String readKeypad() { keyoff = !keyoff; if(keyoff == true){ - keystatus = "off"; + keystatus = 11; } else{ - keystatus = "on"; + keystatus = 0; } } @@ -124,8 +117,7 @@ String readKeypad() { keycodeold = 0; keycode2 = 0; keycodeold2 = 0; - swipedir = 1; - keystatus = "r"; + keystatus = 9; buzzer(TONE3, buzPower, 150); buzzer(TONE4, buzPower, 150); } @@ -137,8 +129,7 @@ String readKeypad() { keycodeold = 0; keycode2 = 0; keycodeold2 = 0; - swipedir = -1; - keystatus = "l"; + keystatus = 10; buzzer(TONE4, buzPower, 150); buzzer(TONE3, buzPower, 150); } diff --git a/lib/obp60task/obp60task.cpp b/lib/obp60task/obp60task.cpp index 9b3a669..a980681 100644 --- a/lib/obp60task/obp60task.cpp +++ b/lib/obp60task/obp60task.cpp @@ -164,6 +164,7 @@ typedef struct { void keyboardTask(void *param){ MyData *data=(MyData *)param; int page=data->page0; + // Loop for keyboard task while (true){ //send a key event @@ -173,8 +174,17 @@ void keyboardTask(void *param){ page+=1; */ readKeypad(); - delay(20); - if (page>=MAX_PAGE_NUMBER) page=0; + delay(20); // TP229-BSF working in 8 key mode with 64Hz update rate (15.6ms) + 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); }