mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-14 02:00:32 +08:00
refactoring
This commit is contained in:
parent
1a7208f6db
commit
bf510f4ff3
11
genmap.py
11
genmap.py
@ -61,7 +61,7 @@ class _X11Key:
|
|||||||
class _KeyMapping:
|
class _KeyMapping:
|
||||||
web_name: str
|
web_name: str
|
||||||
serial_code: int
|
serial_code: int
|
||||||
usb_name: str
|
arduino_name: str
|
||||||
otg_key: _OtgKey
|
otg_key: _OtgKey
|
||||||
ps2_key: _Ps2Key
|
ps2_key: _Ps2Key
|
||||||
at1_code: int
|
at1_code: int
|
||||||
@ -114,7 +114,7 @@ def _read_keymap_csv(path: str) -> List[_KeyMapping]:
|
|||||||
keymap.append(_KeyMapping(
|
keymap.append(_KeyMapping(
|
||||||
web_name=row["web_name"],
|
web_name=row["web_name"],
|
||||||
serial_code=int(row["serial_code"]),
|
serial_code=int(row["serial_code"]),
|
||||||
usb_name=row["usb_name"],
|
arduino_name=row["arduino_name"],
|
||||||
otg_key=_parse_otg_key(row["otg_key"]),
|
otg_key=_parse_otg_key(row["otg_key"]),
|
||||||
ps2_key=_parse_ps2_key(row["ps2_key"]),
|
ps2_key=_parse_ps2_key(row["ps2_key"]),
|
||||||
at1_code=int(row["at1_code"], 16),
|
at1_code=int(row["at1_code"], 16),
|
||||||
@ -135,16 +135,19 @@ def _render_keymap(keymap: List[_KeyMapping], template_path: str, out_path: str)
|
|||||||
def main() -> None:
|
def main() -> None:
|
||||||
# https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code/code_values
|
# https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code/code_values
|
||||||
# https://github.com/NicoHood/HID/blob/master/src/KeyboardLayouts/ImprovedKeylayouts.h
|
# https://github.com/NicoHood/HID/blob/master/src/KeyboardLayouts/ImprovedKeylayouts.h
|
||||||
|
# https://github.com/Harvie/ps2dev/blob/master/src/ps2dev.h
|
||||||
# https://gist.github.com/MightyPork/6da26e382a7ad91b5496ee55fdc73db2
|
# https://gist.github.com/MightyPork/6da26e382a7ad91b5496ee55fdc73db2
|
||||||
# https://github.com/qemu/keycodemapdb/blob/master/data/keymaps.csv
|
# https://github.com/qemu/keycodemapdb/blob/master/data/keymaps.csv
|
||||||
|
# Hut1_12v2.pdf
|
||||||
|
|
||||||
# Fields list:
|
# Fields list:
|
||||||
# - Web
|
# - Web
|
||||||
# - Serial code
|
# - Serial code
|
||||||
# - Arduino key
|
# - Arduino name
|
||||||
# - OTG code (^ for mod)
|
# - OTG code (^ for mod)
|
||||||
|
# - PS/2 key
|
||||||
# - AT set1
|
# - AT set1
|
||||||
# -X11 keysyms (^ for shift)
|
# - X11 keysyms (^ for shift)
|
||||||
|
|
||||||
assert len(sys.argv) == 4, f"{sys.argv[0]} <keymap.csv> <template> <out>"
|
assert len(sys.argv) == 4, f"{sys.argv[0]} <keymap.csv> <template> <out>"
|
||||||
|
|
||||||
|
|||||||
@ -40,7 +40,7 @@ INLINE void keymapPs2(uint8_t code, Ps2KeyType *ps2_type, uint8_t *ps2_code) {
|
|||||||
|
|
||||||
switch (code) {
|
switch (code) {
|
||||||
% for km in sorted(keymap, key=operator.attrgetter("serial_code")):
|
% for km in sorted(keymap, key=operator.attrgetter("serial_code")):
|
||||||
case ${km.serial_code}: *ps2_type = PS2_KEY_TYPE_${km.ps2_key.type.upper()}; *ps2_code = ${km.ps2_key.code}; return; // ${km.usb_name}
|
case ${km.serial_code}: *ps2_type = PS2_KEY_TYPE_${km.ps2_key.type.upper()}; *ps2_code = ${km.ps2_key.code}; return; // ${km.arduino_name}
|
||||||
% endfor
|
% endfor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,7 @@
|
|||||||
INLINE KeyboardKeycode keymapUsb(uint8_t code) {
|
INLINE KeyboardKeycode keymapUsb(uint8_t code) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
% for km in sorted(keymap, key=operator.attrgetter("serial_code")):
|
% for km in sorted(keymap, key=operator.attrgetter("serial_code")):
|
||||||
case ${km.serial_code}: return ${km.usb_name};
|
case ${km.serial_code}: return ${km.arduino_name};
|
||||||
% endfor
|
% endfor
|
||||||
default: return KEY_ERROR_UNDEFINED;
|
default: return KEY_ERROR_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
web_name,serial_code,usb_name,otg_key,ps2_key,at1_code,x11_names
|
web_name,serial_code,arduino_name,otg_key,ps2_key,at1_code,x11_names
|
||||||
KeyA,1,KEY_A,0x04,reg:0x1c,0x1e,"^XK_A,XK_a"
|
KeyA,1,KEY_A,0x04,reg:0x1c,0x1e,"^XK_A,XK_a"
|
||||||
KeyB,2,KEY_B,0x05,reg:0x32,0x30,"^XK_B,XK_b"
|
KeyB,2,KEY_B,0x05,reg:0x32,0x30,"^XK_B,XK_b"
|
||||||
KeyC,3,KEY_C,0x06,reg:0x21,0x2e,"^XK_C,XK_c"
|
KeyC,3,KEY_C,0x06,reg:0x21,0x2e,"^XK_C,XK_c"
|
||||||
|
|||||||
|
@ -24,7 +24,7 @@ fake_rpi.RPi.GPIO
|
|||||||
|
|
||||||
_KeyMapping.web_name
|
_KeyMapping.web_name
|
||||||
_KeyMapping.serial_code
|
_KeyMapping.serial_code
|
||||||
_KeyMapping.usb_name
|
_KeyMapping.arduino_name
|
||||||
_KeyMapping.otg_key
|
_KeyMapping.otg_key
|
||||||
_KeyMapping.ps2_key
|
_KeyMapping.ps2_key
|
||||||
_KeyMapping.at1_code
|
_KeyMapping.at1_code
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user