diff --git a/examples/BasicUnit/TouchMultitask/TouchMultitask.ino b/examples/BasicUnit/TouchMultitask/TouchMultitask.ino new file mode 100644 index 0000000..3438a71 --- /dev/null +++ b/examples/BasicUnit/TouchMultitask/TouchMultitask.ino @@ -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); +} diff --git a/examples/BasicUnit/TouchMultitask/config.h b/examples/BasicUnit/TouchMultitask/config.h new file mode 100644 index 0000000..cc06805 --- /dev/null +++ b/examples/BasicUnit/TouchMultitask/config.h @@ -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 \ No newline at end of file