Files

114 lines
3.1 KiB
C++
Raw Permalink Normal View History

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"
#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;
#if LV_USE_LIBINPUT
2025-01-12 18:08:57 +01:00
#include "input/LinuxInputDriver.h"
static LinuxInputDriver *linuxInputDriver = nullptr;
#else
#if defined(INPUTDRIVER_ENCODER_TYPE)
2025-01-12 18:08:57 +01:00
#include "input/EncoderInputDriver.h"
static EncoderInputDriver *encoderDriver = nullptr;
#endif
#if defined(INPUTDRIVER_MATRIX_TYPE)
2025-01-12 18:08:57 +01:00
#include "input/KeyMatrixInputDriver.h"
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
#endif
2024-02-24 17:19:27 +01:00
#include "lvgl.h"
#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
#if LV_USE_LIBINPUT
2024-05-28 14:43:15 +02:00
if (cfg)
linuxInputDriver = new LinuxInputDriver(cfg->keyboard(), cfg->pointer());
// else
// linuxInputDriver = InputDriver::instance();
2024-05-26 15:16:36 +02:00
#else
#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
#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-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();
#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();
#endif
if (inputdriver)
inputdriver->init();
2024-11-13 21:42:09 +00:00
displaydriver->printConfig();
2024-02-24 17:19:27 +01: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)
{
#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();
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()
{
delete inputdriver;
}