2025-01-12 18:08:57 +01:00
|
|
|
#include "graphics/DeviceScreen.h"
|
2024-03-19 21:08:28 +01:00
|
|
|
#include "Arduino.h"
|
2025-01-12 18:08:57 +01:00
|
|
|
#include "graphics/common/ViewFactory.h"
|
|
|
|
|
#include "util/ILog.h"
|
2024-02-24 17:19:27 +01:00
|
|
|
|
2025-02-17 14:55:14 +01:00
|
|
|
#if defined(ARDUINO_ARCH_ESP32)
|
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
|
#include "freertos/semphr.h"
|
|
|
|
|
|
|
|
|
|
static SemaphoreHandle_t xSemaphore = nullptr;
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-03-08 11:45:41 +01:00
|
|
|
DeviceScreen &DeviceScreen::create(void)
|
|
|
|
|
{
|
2024-04-15 14:54:47 +02:00
|
|
|
return *new DeviceScreen(nullptr);
|
2024-02-24 17:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
2024-04-15 14:54:47 +02:00
|
|
|
DeviceScreen &DeviceScreen::create(const DisplayDriverConfig *cfg)
|
2024-03-08 11:45:41 +01:00
|
|
|
{
|
2025-08-16 18:28:05 +02:00
|
|
|
ILOG_DEBUG("creating DeviceScreen %dx%d ...", cfg ? cfg->width() : 0, cfg ? cfg->height() : 0);
|
2024-04-15 14:54:47 +02:00
|
|
|
return *new DeviceScreen(cfg);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-20 22:08:37 +02:00
|
|
|
DeviceScreen &DeviceScreen::create(DisplayDriverConfig &&cfg)
|
|
|
|
|
{
|
|
|
|
|
return *new DeviceScreen(std::move(cfg));
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-15 14:54:47 +02:00
|
|
|
DeviceScreen::DeviceScreen(const DisplayDriverConfig *cfg)
|
|
|
|
|
{
|
|
|
|
|
if (cfg) {
|
|
|
|
|
gui = ViewFactory::create(*cfg);
|
|
|
|
|
} else {
|
|
|
|
|
gui = ViewFactory::create();
|
|
|
|
|
}
|
2025-02-17 14:55:14 +01:00
|
|
|
#if defined(ARDUINO_ARCH_ESP32)
|
|
|
|
|
xSemaphore = xSemaphoreCreateMutex();
|
|
|
|
|
if (!xSemaphore)
|
|
|
|
|
ILOG_ERROR("DeviceScreen: xSemaphoreCreateMutex() failed");
|
|
|
|
|
#endif
|
2024-03-08 11:45:41 +01:00
|
|
|
}
|
|
|
|
|
|
2024-04-20 22:08:37 +02:00
|
|
|
DeviceScreen::DeviceScreen(DisplayDriverConfig &&cfg)
|
|
|
|
|
{
|
|
|
|
|
gui = ViewFactory::create(cfg);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-08 11:45:41 +01:00
|
|
|
void DeviceScreen::init(IClientBase *client)
|
|
|
|
|
{
|
2024-10-17 09:06:42 +02:00
|
|
|
ILOG_DEBUG("DeviceScreen::init()...");
|
2024-03-08 11:45:41 +01:00
|
|
|
gui->init(client);
|
2024-02-24 17:19:27 +01:00
|
|
|
|
2024-09-06 01:48:21 +02:00
|
|
|
// #ifdef TFT_BL
|
|
|
|
|
// digitalWrite(TFT_BL, HIGH);
|
|
|
|
|
// pinMode(TFT_BL, OUTPUT);
|
|
|
|
|
// #endif
|
2024-02-24 17:19:27 +01:00
|
|
|
|
|
|
|
|
#ifdef VTFT_CTRL
|
2024-03-08 11:45:41 +01:00
|
|
|
digitalWrite(VTFT_CTRL, LOW);
|
|
|
|
|
pinMode(VTFT_CTRL, OUTPUT);
|
2024-02-24 17:19:27 +01:00
|
|
|
#endif
|
2024-10-17 09:06:42 +02:00
|
|
|
ILOG_DEBUG("DeviceScreen::init() done.");
|
2024-02-24 17:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
2024-03-08 11:45:41 +01:00
|
|
|
void DeviceScreen::task_handler(void)
|
|
|
|
|
{
|
|
|
|
|
gui->task_handler();
|
|
|
|
|
}
|
2025-02-17 14:55:14 +01:00
|
|
|
|
|
|
|
|
#if defined(ARDUINO_ARCH_ESP32)
|
|
|
|
|
int DeviceScreen::prepareSleep(void *)
|
|
|
|
|
{
|
|
|
|
|
if (xSemaphore)
|
|
|
|
|
return xSemaphoreTake(xSemaphore, pdMS_TO_TICKS(1000)) == pdTRUE ? 0 : 1;
|
|
|
|
|
else
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int DeviceScreen::wakeUp(esp_sleep_wakeup_cause_t cause)
|
|
|
|
|
{
|
|
|
|
|
if (xSemaphore)
|
|
|
|
|
return xSemaphoreGive(xSemaphore) == pdTRUE ? 0 : 1;
|
|
|
|
|
else
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief synchronisation point: here we sleep after prepareSleep() was called
|
|
|
|
|
*/
|
2025-05-22 18:07:39 +02:00
|
|
|
void DeviceScreen::sleep(uint32_t sleepTime)
|
2025-02-17 14:55:14 +01:00
|
|
|
{
|
2025-05-22 18:07:39 +02:00
|
|
|
#if defined(ARCH_ESP32)
|
2025-02-17 14:55:14 +01:00
|
|
|
if (xSemaphore && xSemaphoreTake(xSemaphore, portMAX_DELAY) == pdTRUE)
|
|
|
|
|
xSemaphoreGive(xSemaphore);
|
2025-05-22 18:07:39 +02:00
|
|
|
vTaskDelay((TickType_t)sleepTime); // yield, do not remove
|
2025-02-17 14:55:14 +01:00
|
|
|
#endif
|
|
|
|
|
}
|