Added Touch Multitask example

This commit is contained in:
lewisxhe
2020-10-13 09:34:54 +08:00
parent 0c2f8ef2cf
commit f35ee0aae0
2 changed files with 85 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
/*
* The example shows that calling TTGOClass objects in multitasking must
* implement a mutex lock,otherwise it will cause panic
* Copyright 2020 Lewis he
*/
#include "config.h"
TTGOClass *ttgo = nullptr;
char buf[128];
int16_t x, y;
static SemaphoreHandle_t xSemaphores = NULL;
void touch_task(void *args)
{
for (;;) {
if ( xSemaphoreTake( xSemaphores, ( TickType_t ) 10 ) == pdTRUE ) {
if (ttgo->getTouch(x, y)) {
sprintf(buf, "[task] x:%03d y:%03d", x, y);
ttgo->tft->drawString(buf, 60, 40);
Serial.println(buf);
}
xSemaphoreGive( xSemaphores );
}
delay(20);
}
}
void touch_task1(void *args)
{
for (;;) {
if ( xSemaphoreTake( xSemaphores, ( TickType_t ) 10 ) == pdTRUE ) {
if (ttgo->getTouch(x, y)) {
sprintf(buf, "[task1] x:%03d y:%03d", x, y);
ttgo->tft->drawString(buf, 60, 60);
Serial.println(buf);
}
xSemaphoreGive( xSemaphores );
}
delay(20);
}
}
void setup()
{
Serial.begin(115200);
ttgo = TTGOClass::getWatch();
ttgo->begin();
ttgo->openBL();
ttgo->tft->fillScreen(TFT_BLACK);
ttgo->tft->setTextFont(2);
ttgo->tft->setTextColor(TFT_WHITE, TFT_BLACK);
ttgo->tft->drawString("Touch task test", 62, 20);
xSemaphores = xSemaphoreCreateMutex();
xTaskCreate(touch_task, "touch", 2048, NULL, 5, NULL);
xTaskCreate(touch_task1, "touch1", 2048, NULL, 5, NULL);
}
void loop()
{
if ( xSemaphoreTake( xSemaphores, ( TickType_t ) 10 ) == pdTRUE ) {
if (ttgo->getTouch(x, y)) {
sprintf(buf, "[loop] x:%03d y:%03d", x, y);
ttgo->tft->drawString(buf, 60, 80);
Serial.println(buf);
}
xSemaphoreGive( xSemaphores );
}
delay(20);
}

View File

@@ -0,0 +1,12 @@
// => Hardware select
// #define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line
// #define LILYGO_WATCH_2020_V1 // To use T-Watch2020 V1, please uncomment this line
// #define LILYGO_WATCH_2020_V2 // To use T-Watch2020 V2, please uncomment this line
// NOT SUPPORT ...
//// #define LILYGO_WATCH_2019_NO_TOUCH
//// #define LILYGO_WATCH_BLOCK
// NOT SUPPORT ...
#include <LilyGoWatch.h>