From f9b685e891c80918f86774648a74242e71e23cc0 Mon Sep 17 00:00:00 2001 From: norbert-walter Date: Sat, 27 Apr 2024 00:05:13 +0200 Subject: [PATCH] Add touch sensitivity settimgs --- lib/obp60task/OBP60Extensions.cpp | 2 +- lib/obp60task/OBP60Extensions.h | 2 +- lib/obp60task/OBP60Hardware.h | 1 - lib/obp60task/OBP60Keypad.h | 22 +++++++++++++++------- lib/obp60task/OBPSensorTask.cpp | 2 +- lib/obp60task/config.json | 14 ++++++++++++++ lib/obp60task/obp60task.cpp | 9 +++++---- 7 files changed, 37 insertions(+), 15 deletions(-) diff --git a/lib/obp60task/OBP60Extensions.cpp b/lib/obp60task/OBP60Extensions.cpp index 1fe9a6a..6cd4395 100644 --- a/lib/obp60task/OBP60Extensions.cpp +++ b/lib/obp60task/OBP60Extensions.cpp @@ -264,7 +264,7 @@ void displayHeader(CommonData &commonData, GwApi::BoatValue *date, GwApi::BoatVa getdisplay().print("USB "); } double gpshdop = formatValue(hdop, commonData).value; - if(commonData.config->getString(commonData.config->useGPS) != "off" && gpshdop > 1.0){ + if(commonData.config->getString(commonData.config->useGPS) != "off" && gpshdop > 0.3){ getdisplay().print("GPS"); } // Save old telegram counter diff --git a/lib/obp60task/OBP60Extensions.h b/lib/obp60task/OBP60Extensions.h index add05ea..79e0b52 100644 --- a/lib/obp60task/OBP60Extensions.h +++ b/lib/obp60task/OBP60Extensions.h @@ -63,6 +63,6 @@ SunData calcSunsetSunrise(GwApi *api, double time, double date, double latitude, void batteryGraphic(uint x, uint y, float percent, int pcolor, int bcolor); // Battery graphic with fill level void solarGraphic(uint x, uint y, int pcolor, int bcolor); // Solar graphic with fill level -void generatorGraphic(uint x, uint y, int pcolor, int bcolor); // Generator graphic with fill level +void generatorGraphic(uint x, uint y, int pcolor, int bcolor); // Generator graphic with fill level #endif \ No newline at end of file diff --git a/lib/obp60task/OBP60Hardware.h b/lib/obp60task/OBP60Hardware.h index 3143b18..5219ded 100644 --- a/lib/obp60task/OBP60Hardware.h +++ b/lib/obp60task/OBP60Hardware.h @@ -61,7 +61,6 @@ #define MIN_VOLTAGE 10.0 // Min voltage for under voltage detection (then goto deep sleep) #define POWER_FAIL_TIME 2 // in [ms] Accept min voltage until 2 x 1ms (for under voltage gaps by engine start) // Touch buttons - #define TOUCHTHRESHOLD 50000// Touch sensitivity, lower values more sensitiv #define TP1 14 // Left outside #define TP2 13 #define TP3 12 diff --git a/lib/obp60task/OBP60Keypad.h b/lib/obp60task/OBP60Keypad.h index 0d6fa71..178f205 100644 --- a/lib/obp60task/OBP60Keypad.h +++ b/lib/obp60task/OBP60Keypad.h @@ -20,42 +20,50 @@ bool keylock = false; // Key lock after pressed key is valid (repeat protectio long starttime = 0; // Start time point for pressed key -int readKeypad() { +int readKeypad(uint thSensitivity) { + + // Touch sensor values + // 35000 - Not touched + // 50000 - Light toched with fingertip + // 70000 - Touched + // 170000 - Strong touched + uint32_t touchthreshold = (thSensitivity * -1200) + 170000; // thSensitivity 0...100% + int keystatus = 0; // Status of key [0...11], 0 = processed, 1...8 = key 1..8, 9 = right swipe , 10 = left swipe, 11 keys disabled keycode = 0; // Read key code - if(touchRead(14) > TOUCHTHRESHOLD){ // Touch pad 1 + if(touchRead(14) > touchthreshold){ // Touch pad 1 keypad[1] = 1; } else{ keypad[1] = 0; } - if(touchRead(13) > TOUCHTHRESHOLD){ // Touch pad 2 + if(touchRead(13) > touchthreshold){ // Touch pad 2 keypad[2] = 1; } else{ keypad[2] = 0; } - if(touchRead(12) > TOUCHTHRESHOLD){ // Touch pad 3 + if(touchRead(12) > touchthreshold){ // Touch pad 3 keypad[3] = 1; } else{ keypad[3] = 0; } - if(touchRead(11) > TOUCHTHRESHOLD){ // Touch pad 4 + if(touchRead(11) > touchthreshold){ // Touch pad 4 keypad[4] = 1; } else{ keypad[4] = 0; } - if(touchRead(10) > TOUCHTHRESHOLD){ // Touch pad 5 + if(touchRead(10) > touchthreshold){ // Touch pad 5 keypad[5] = 1; } else{ keypad[5] = 0; } - if(touchRead(9) > TOUCHTHRESHOLD){ // Touch pad 6 + if(touchRead(9) > touchthreshold){ // Touch pad 6 keypad[6] = 1; } else{ diff --git a/lib/obp60task/OBPSensorTask.cpp b/lib/obp60task/OBPSensorTask.cpp index f8b5d94..c461942 100644 --- a/lib/obp60task/OBPSensorTask.cpp +++ b/lib/obp60task/OBPSensorTask.cpp @@ -73,7 +73,7 @@ void sensorTask(void *param){ Timer1.start(); // Start Timer1 for undervoltage detection } Timer1.start(); // Start Timer2 for blinking LED - + // Direction settings for NMEA0183 String nmea0183Mode = api->getConfig()->getConfigItem(api->getConfig()->serialDirection, true)->asString(); api->getLogger()->logDebug(GwLog::LOG, "NMEA0183 Mode is: %s", nmea0183Mode); diff --git a/lib/obp60task/config.json b/lib/obp60task/config.json index 13d5ad6..fb2e479 100644 --- a/lib/obp60task/config.json +++ b/lib/obp60task/config.json @@ -567,6 +567,20 @@ "obp60":"true" } }, + { + "name": "tSensitivity", + "label": "Touch Sensitivity [%]", + "type": "number", + "default": "100", + "check": "checkMinMax", + "min": 0, + "max": 100, + "description": "Touch sensitivity [0...100%] for sensor buttons", + "category": "OBP60 Calibrations", + "capabilities": { + "obp60":"true" + } + }, { "name": "vOffset", "label": "VSensor Offset", diff --git a/lib/obp60task/obp60task.cpp b/lib/obp60task/obp60task.cpp index 45639db..1b2e431 100644 --- a/lib/obp60task/obp60task.cpp +++ b/lib/obp60task/obp60task.cpp @@ -83,20 +83,20 @@ typedef struct { int page0=0; QueueHandle_t queue; GwLog* logger = NULL; +// GwApi* api = NULL; + uint sensitivity = 100; } MyData; // Keyboard Task -//#################################################################################### -int readKeypad(); - void keyboardTask(void *param){ MyData *data=(MyData *)param; + int keycode = 0; data->logger->logDebug(GwLog::LOG,"Start keyboard task"); // Loop for keyboard task while (true){ - keycode = readKeypad(); + keycode = readKeypad(data->sensitivity); //send a key event if(keycode != 0){ xQueueSend(data->queue, &keycode, 0); @@ -382,6 +382,7 @@ void OBP60Task(GwApi *api){ allParameters.logger=api->getLogger(); allParameters.page0=3; allParameters.queue=xQueueCreate(10,sizeof(int)); + allParameters.sensitivity= api->getConfig()->getInt(GwConfigDefinitions::tSensitivity); xTaskCreate(keyboardTask,"keyboard",2000,&allParameters,configMAX_PRIORITIES-1,NULL); SharedData *shared=new SharedData(api); createSensorTask(shared);