Initial hotpluggable keyboard handling (#9540)

* Added a new plugin external-keyboard. It listens to USB events. When keyboard is plugged in or plugged out, it updates device and input configuration accordingly.
* Added new fake events UsbDevicePlugIn and UsbDevicePlugOut that are emitted when a device is connected to a book reader that plays the role of USB host. The usage of the existing events UsbPlugIn and UsbPlugOut has not changed - they are used when a reader is connected to a host. The koreader-base has a related PR for those events.
* Did a small refactoring of initialization for the modules FocusManager and InputText. They check device keyboard capabilities on their when the module is first loaded and store it. Some of the initialization code has been extracted into functions, so that we can re-initialize them when keyboard is (dis)connected.
* Initial implementation centered around text input, and tested with USB keyboards on devices with OTG support.
* Said OTG shenanigans are so far supported on devices with debugfs & the chipidea driver, or sunxi devices.
This commit is contained in:
Borys Lykah
2022-10-29 14:46:35 -06:00
committed by GitHub
parent c36a2929ac
commit 9b2201a438
10 changed files with 626 additions and 20 deletions

View File

@@ -176,6 +176,14 @@ local Input = {
},
},
fake_event_set = {
IntoSS = true, OutOfSS = true,
UsbPlugIn = true, UsbPlugOut = true,
Charging = true, NotCharging = true,
WakeupFromSuspend = true, ReadyToSuspend = true,
UsbDevicePlugIn = true, UsbDevicePlugOut = true,
},
-- NOTE: When looking at the device in Portrait mode, that's assuming PgBack is on TOP, and PgFwd on the BOTTOM
rotation_map = {
[framebuffer.ORIENTATION_PORTRAIT] = {},
@@ -194,6 +202,7 @@ local Input = {
Ctrl = false,
Shift = false,
Sym = false,
Meta = false,
},
-- repeat state:
@@ -256,6 +265,8 @@ function Input:init()
self.event_map[10021] = "NotCharging"
self.event_map[10030] = "WakeupFromSuspend"
self.event_map[10031] = "ReadyToSuspend"
self.event_map[10040] = "UsbDevicePlugIn"
self.event_map[10041] = "UsbDevicePlugOut"
-- user custom event map
local custom_event_map_location = string.format(
@@ -527,11 +538,7 @@ function Input:handleKeyBoardEv(ev)
keycode = self.rotation_map[self.device.screen:getRotationMode()][keycode]
end
-- fake events
if keycode == "IntoSS" or keycode == "OutOfSS"
or keycode == "UsbPlugIn" or keycode == "UsbPlugOut"
or keycode == "Charging" or keycode == "NotCharging"
or keycode == "WakeupFromSuspend" or keycode == "ReadyToSuspend" then
if self.fake_event_set[keycode] then
return keycode
end
@@ -638,11 +645,7 @@ function Input:handlePowerManagementOnlyEv(ev)
return keycode
end
-- Fake events
if keycode == "IntoSS" or keycode == "OutOfSS"
or keycode == "UsbPlugIn" or keycode == "UsbPlugOut"
or keycode == "Charging" or keycode == "NotCharging"
or keycode == "WakeupFromSuspend" or keycode == "ReadyToSuspend" then
if self.fake_event_set[keycode] then
return keycode
end