From 33f2aac271120d6f3a141ba2722fd16ee459bf4d Mon Sep 17 00:00:00 2001 From: norbert-walter Date: Sat, 12 Feb 2022 19:21:49 +0100 Subject: [PATCH] Wrong keycode function --- lib/obp60task/OBP60Keypad.h | 3 +- lib/obp60task/obp60task.cpp | 57 +++++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/lib/obp60task/OBP60Keypad.h b/lib/obp60task/OBP60Keypad.h index a4123d1..b93b7bc 100644 --- a/lib/obp60task/OBP60Keypad.h +++ b/lib/obp60task/OBP60Keypad.h @@ -17,7 +17,6 @@ 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 -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; // Disable all keys @@ -27,6 +26,8 @@ long starttime = 0; // Start time point for pressed key int readKeypad() { + int keystatus = 0; // Status of key [0...11], 0 = processed, 1...8 = key 1..8, 9 = right swipe , 10 = left swipe, 11 keys disabled + noInterrupts(); pinMode(TTP_SDO, INPUT); pinMode(TTP_SCL, OUTPUT); diff --git a/lib/obp60task/obp60task.cpp b/lib/obp60task/obp60task.cpp index a980681..4d1f540 100644 --- a/lib/obp60task/obp60task.cpp +++ b/lib/obp60task/obp60task.cpp @@ -14,7 +14,7 @@ #include // GxEPD lip for SPI display communikation #include // GxEPD lip for SPI #include "OBP60ExtensionPort.h" // Functions lib for extension board -#include "OBP60Keypad.h" // Functions lib for keypad +#include "OBP60Keypad.h" // Functions for keypad // True type character sets #include "Ubuntu_Bold8pt7b.h" @@ -157,34 +157,28 @@ void OBP60Init(GwApi *api){ typedef struct { int page0=0; QueueHandle_t queue; + GwLog* logger = NULL; } MyData; // Keyboard Task //####################################### +int readKeypad(); + void keyboardTask(void *param){ MyData *data=(MyData *)param; - int page=data->page0; + int keycode = 0; + data->logger->logDebug(GwLog::LOG,"Start keyboard task"); // Loop for keyboard task while (true){ - //send a key event - xQueueSend(data->queue, &page, 0); -/* - delay(10000); - page+=1; -*/ - readKeypad(); + keycode = readKeypad(); + //send a key event + if(keycode != 0){ + xQueueSend(data->queue, &keycode, 0); + data->logger->logDebug(GwLog::LOG,"Send keycode: %d", keycode); + } + 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); } @@ -325,6 +319,7 @@ void OBP60Task(GwApi *api){ numPages=config->getInt(config->visiblePages,1); if (numPages < 1) numPages=1; if (numPages >= MAX_PAGE_NUMBER) numPages=MAX_PAGE_NUMBER; + LOG_DEBUG(GwLog::LOG,"Number of pages %d",numPages); String configPrefix="page"; for (int i=0;i< numPages;i++){ String prefix=configPrefix+String(i+1); //e.g. page1 @@ -361,6 +356,7 @@ void OBP60Task(GwApi *api){ //now we have prepared the page data //we start a separate task that will fetch our keys... MyData allParameters; + allParameters.logger=api->getLogger(); allParameters.page0=3; allParameters.queue=xQueueCreate(10,sizeof(int)); xTaskCreate(keyboardTask,"keyboard",2000,&allParameters,0,NULL); @@ -374,16 +370,29 @@ void OBP60Task(GwApi *api){ while (true){ delay(1000); //check if there is a keyboard message - int keyboardMessage=-1; + int keyboardMessage=0; if (xQueueReceive(allParameters.queue,&keyboardMessage,0)){ - LOG_DEBUG(GwLog::LOG,"new page from keyboard %d",keyboardMessage); + LOG_DEBUG(GwLog::LOG,"new key from keyboard %d",keyboardMessage); + Page *currentPage=pages[pageNumber].page; if (currentPage ){ keyboardMessage=currentPage->handleKey(keyboardMessage); } - if (keyboardMessage >= 0 && keyboardMessage < numPages){ - - pageNumber=keyboardMessage; + if (keyboardMessage > 0) + { + // Decoding all key codes + if (keyboardMessage == 9) + { + pageNumber++; + if (pageNumber >= numPages) + pageNumber = 0; + } + if (keyboardMessage == 10) + { + pageNumber--; + if (pageNumber < 0) + pageNumber = numPages - 1; + } } LOG_DEBUG(GwLog::LOG,"set pagenumber to %d",pageNumber); }