2025-01-12 18:08:57 +01:00
|
|
|
#include "graphics/DeviceGUI.h"
|
|
|
|
|
#include "graphics/driver/DisplayDriver.h"
|
|
|
|
|
#include "graphics/driver/DisplayDriverConfig.h"
|
2025-08-22 20:12:09 +02:00
|
|
|
#include "input/I2CKeyboardScanner.h"
|
2025-01-12 18:08:57 +01:00
|
|
|
#include "input/InputDriver.h"
|
2025-05-22 18:07:39 +02:00
|
|
|
#include <thread>
|
2025-01-12 18:08:57 +01:00
|
|
|
|
2025-08-22 20:12:09 +02:00
|
|
|
#include "input/I2CKeyboardInputDriver.h"
|
|
|
|
|
static I2CKeyboardInputDriver *keyboardDriver = nullptr;
|
|
|
|
|
|
2024-05-26 11:32:21 +02:00
|
|
|
#if LV_USE_LIBINPUT
|
2025-01-12 18:08:57 +01:00
|
|
|
#include "input/LinuxInputDriver.h"
|
2024-06-27 14:56:14 +02:00
|
|
|
static LinuxInputDriver *linuxInputDriver = nullptr;
|
2024-05-26 11:32:21 +02:00
|
|
|
#else
|
2024-06-27 14:56:14 +02:00
|
|
|
#if defined(INPUTDRIVER_ENCODER_TYPE)
|
2025-01-12 18:08:57 +01:00
|
|
|
#include "input/EncoderInputDriver.h"
|
2024-06-27 14:56:14 +02:00
|
|
|
static EncoderInputDriver *encoderDriver = nullptr;
|
|
|
|
|
#endif
|
|
|
|
|
#if defined(INPUTDRIVER_MATRIX_TYPE)
|
2025-01-12 18:08:57 +01:00
|
|
|
#include "input/KeyMatrixInputDriver.h"
|
2024-06-27 14:56:14 +02:00
|
|
|
static KeyMatrixInputDriver *keyMatrixDriver = nullptr;
|
|
|
|
|
#endif
|
2024-12-01 12:43:41 +01:00
|
|
|
#if defined(INPUTDRIVER_BUTTON_TYPE)
|
2025-01-12 18:08:57 +01:00
|
|
|
#include "input/ButtonInputDriver.h"
|
2024-12-01 12:43:41 +01:00
|
|
|
static ButtonInputDriver *buttonDriver = nullptr;
|
|
|
|
|
#endif
|
2024-05-26 11:32:21 +02:00
|
|
|
#endif
|
2024-02-24 17:19:27 +01:00
|
|
|
#include "lvgl.h"
|
2024-06-27 14:56:14 +02:00
|
|
|
#include "ui.h"
|
2025-01-12 18:08:57 +01:00
|
|
|
#include "util/ILog.h"
|
2024-02-24 17:19:27 +01:00
|
|
|
|
2024-05-28 14:43:15 +02:00
|
|
|
DeviceGUI::DeviceGUI(const DisplayDriverConfig *cfg, DisplayDriver *driver) : displaydriver(driver), inputdriver(nullptr)
|
2024-05-25 01:08:29 +02:00
|
|
|
{
|
2025-08-22 20:12:09 +02:00
|
|
|
|
2024-05-26 11:32:21 +02:00
|
|
|
#if LV_USE_LIBINPUT
|
2024-05-28 14:43:15 +02:00
|
|
|
if (cfg)
|
2024-06-27 14:56:14 +02:00
|
|
|
linuxInputDriver = new LinuxInputDriver(cfg->keyboard(), cfg->pointer());
|
|
|
|
|
// else
|
|
|
|
|
// linuxInputDriver = InputDriver::instance();
|
2024-05-26 15:16:36 +02:00
|
|
|
#else
|
2024-06-27 14:56:14 +02:00
|
|
|
#if defined(INPUTDRIVER_ENCODER_TYPE)
|
|
|
|
|
encoderDriver = new EncoderInputDriver;
|
|
|
|
|
#endif
|
|
|
|
|
#if defined(INPUTDRIVER_MATRIX_TYPE)
|
|
|
|
|
keyMatrixDriver = new KeyMatrixInputDriver;
|
|
|
|
|
#endif
|
2024-12-01 12:43:41 +01:00
|
|
|
#if defined(INPUTDRIVER_BUTTON_TYPE)
|
|
|
|
|
buttonDriver = new ButtonInputDriver;
|
|
|
|
|
#endif
|
2024-06-27 14:56:14 +02:00
|
|
|
#endif
|
|
|
|
|
if (!inputdriver)
|
|
|
|
|
inputdriver = InputDriver::instance();
|
2024-05-25 01:08:29 +02:00
|
|
|
}
|
2024-03-07 16:21:28 +01:00
|
|
|
|
2024-03-08 11:45:41 +01:00
|
|
|
void DeviceGUI::init(IClientBase *client)
|
|
|
|
|
{
|
2024-10-17 09:06:42 +02:00
|
|
|
ILOG_DEBUG("Display driver init...");
|
2024-04-15 14:54:47 +02:00
|
|
|
displaydriver->init(this);
|
2024-06-27 14:56:14 +02:00
|
|
|
|
2024-10-17 09:06:42 +02:00
|
|
|
ILOG_DEBUG("Input driver init...");
|
2025-08-22 20:12:09 +02:00
|
|
|
I2CKeyboardScanner scanner;
|
|
|
|
|
keyboardDriver = scanner.scan();
|
|
|
|
|
if (keyboardDriver)
|
|
|
|
|
keyboardDriver->init();
|
2024-06-27 14:56:14 +02:00
|
|
|
#if LV_USE_LIBINPUT
|
|
|
|
|
if (linuxInputDriver)
|
|
|
|
|
linuxInputDriver->init();
|
|
|
|
|
#endif
|
|
|
|
|
#if defined(INPUTDRIVER_ENCODER_TYPE)
|
|
|
|
|
if (encoderDriver)
|
|
|
|
|
encoderDriver->init();
|
|
|
|
|
#endif
|
|
|
|
|
#if defined(INPUTDRIVER_MATRIX_TYPE)
|
|
|
|
|
if (keyMatrixDriver)
|
|
|
|
|
keyMatrixDriver->init();
|
2024-12-01 12:43:41 +01:00
|
|
|
#endif
|
|
|
|
|
#if defined(INPUTDRIVER_BUTTON_TYPE)
|
|
|
|
|
if (buttonDriver)
|
|
|
|
|
buttonDriver->init();
|
2024-06-27 14:56:14 +02:00
|
|
|
#endif
|
2024-05-26 11:32:21 +02:00
|
|
|
if (inputdriver)
|
|
|
|
|
inputdriver->init();
|
2024-06-27 14:56:14 +02:00
|
|
|
|
2024-11-13 21:42:09 +00:00
|
|
|
displaydriver->printConfig();
|
2024-02-24 17:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
2025-05-22 18:07:39 +02:00
|
|
|
/**
|
|
|
|
|
* Linux: measure how long it takes to call displaydriver->task_handler().
|
|
|
|
|
* Then tell the lvgl library how long it took via lv_tick_inc().
|
|
|
|
|
*/
|
2024-03-08 11:45:41 +01:00
|
|
|
void DeviceGUI::task_handler(void)
|
|
|
|
|
{
|
2025-05-22 18:07:39 +02:00
|
|
|
#if defined(ARCH_PORTDUINO)
|
|
|
|
|
int ms = 10;
|
|
|
|
|
auto start = std::chrono::high_resolution_clock::now();
|
2024-03-08 11:45:41 +01:00
|
|
|
displaydriver->task_handler();
|
2025-05-22 18:07:39 +02:00
|
|
|
auto stop = std::chrono::high_resolution_clock::now();
|
|
|
|
|
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(stop - start);
|
|
|
|
|
if (duration.count() < ms) {
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(ms - duration.count()));
|
|
|
|
|
lv_tick_inc(ms);
|
|
|
|
|
} else {
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
|
|
|
lv_tick_inc(duration.count() + 1);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
displaydriver->task_handler();
|
|
|
|
|
#endif
|
2024-03-08 11:45:41 +01:00
|
|
|
};
|
2024-03-10 09:28:49 +01:00
|
|
|
|
2024-05-26 15:16:36 +02:00
|
|
|
DeviceGUI::~DeviceGUI()
|
|
|
|
|
{
|
2024-05-26 11:32:21 +02:00
|
|
|
delete inputdriver;
|
|
|
|
|
}
|