Files
meshtastic-device-ui/source/input/I2CKeyboardInputDriver.cpp
T
2025-01-12 18:08:57 +01:00

79 lines
2.6 KiB
C++

#ifdef INPUTDRIVER_I2C_KBD_TYPE
#include "input/I2CKeyboardInputDriver.h"
#include "util/ILog.h"
#include <Arduino.h>
#include <Wire.h>
I2CKeyboardInputDriver::I2CKeyboardInputDriver(void) {}
void I2CKeyboardInputDriver::init(void)
{
keyboard = lv_indev_create();
lv_indev_set_type(keyboard, LV_INDEV_TYPE_KEYPAD);
lv_indev_set_read_cb(keyboard, keyboard_read);
if (!inputGroup) {
inputGroup = lv_group_create();
lv_group_set_default(inputGroup);
}
lv_indev_set_group(keyboard, inputGroup);
}
/******************************************************************
LV_KEY_NEXT: Focus on the next object
LV_KEY_PREV: Focus on the previous object
LV_KEY_ENTER: Triggers LV_EVENT_PRESSED, LV_EVENT_CLICKED, or LV_EVENT_LONG_PRESSED etc. events
LV_KEY_UP: Increase value or move upwards
LV_KEY_DOWN: Decrease value or move downwards
LV_KEY_RIGHT: Increase value or move to the right
LV_KEY_LEFT: Decrease value or move to the left
LV_KEY_ESC: Close or exit (E.g. close a Drop down list)
LV_KEY_DEL: Delete (E.g. a character on the right in a Text area)
LV_KEY_BACKSPACE: Delete a character on the left (E.g. in a Text area)
LV_KEY_HOME: Go to the beginning/top (E.g. in a Text area)
LV_KEY_END: Go to the end (E.g. in a Text area)
LV_KEY_UP = 17, // 0x11
LV_KEY_DOWN = 18, // 0x12
LV_KEY_RIGHT = 19, // 0x13
LV_KEY_LEFT = 20, // 0x14
LV_KEY_ESC = 27, // 0x1B
LV_KEY_DEL = 127, // 0x7F
LV_KEY_BACKSPACE = 8, // 0x08
LV_KEY_ENTER = 10, // 0x0A, '\n'
LV_KEY_NEXT = 9, // 0x09, '\t'
LV_KEY_PREV = 11, // 0x0B, '
LV_KEY_HOME = 2, // 0x02, STX
LV_KEY_END = 3, // 0x03, ETX
*******************************************************************/
void I2CKeyboardInputDriver::keyboard_read(lv_indev_t *indev, lv_indev_data_t *data)
{
char keyValue = 0;
Wire.requestFrom(INPUTDRIVER_I2C_KBD_TYPE, 1);
if (Wire.available() > 0) {
keyValue = Wire.read();
if (keyValue != (char)0x00) {
data->state = LV_INDEV_STATE_PRESSED;
ILOG_DEBUG("key press value: %d", (int)keyValue);
switch (keyValue) {
case 0x0D:
keyValue = LV_KEY_ENTER;
break;
default:
break;
}
} else {
data->state = LV_INDEV_STATE_RELEASED;
}
}
data->key = (uint32_t)keyValue;
}
void I2CKeyboardInputDriver::task_handler(void) {}
I2CKeyboardInputDriver::~I2CKeyboardInputDriver(void) {}
#endif