Funziona ma crasha con altri device

master
Pietro Brenna 2019-10-01 14:33:47 +02:00
parent 938bf47bc0
commit 78e0426f7c
3 changed files with 65 additions and 5 deletions

View File

@ -3,12 +3,43 @@ Created on 1 ott 2019
@author: Emanuele Trabattoni
'''
from evdev import InputDevice
from evdev import InputDevice, ecodes, categorize
from select import select
dev = InputDevice('/dev/input/by-id/usb-0581_0106-event-kbd')
#dev = InputDevice('/dev/input/by-id/usb-Chicony_USB_Keyboard-event-kbd')
dev.grab()
char_map = {
458782: 1,
458783: 2,
458784: 3,
458785: 4,
458786: 5,
458787: 6,
458788: 7,
458789: 8,
458790: 9,
458791: 0,
458792: "Invio"
}
def get_numero(dev):
stringa = ""
last = None
while True:
r,w,x = select([dev], [], [])
for event in dev.read():
print(event)
if event.code == 4 and event.type==4:
if last is None:
last = char_map[event.value]
if last != "Invio":
stringa += str(last)
else:
yield stringa
stringa = ""
else:
last = None
for x in get_numero(dev):
print(x[0:12])

14
poetry.lock generated 100644
View File

@ -0,0 +1,14 @@
[[package]]
category = "main"
description = "Bindings to the Linux input handling subsystem"
name = "evdev"
optional = false
python-versions = "*"
version = "1.2.0"
[metadata]
content-hash = "ca795258e78a1fd6410b3cbde59ffd58d74ce4734cabb0ea7fc7574961c75ab9"
python-versions = "^3.7"
[metadata.hashes]
evdev = ["b03f5e1be5b4a5327494a981b831d251a142b09e8778eda1a8b53eba91100166"]

15
pyproject.toml 100644
View File

@ -0,0 +1,15 @@
[tool.poetry]
name = "libbeepz"
version = "0.1.0"
description = ""
authors = ["Emanuele Trabattoni"]
[tool.poetry.dependencies]
python = "^3.7"
evdev = "^1.2"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"