May-26-2021, 10:46 AM
I'm using asyncio library to read input from a Infra Red remote control.
This is python 3.7 branch on an Orange Pi Zero, using the built in IR receiver as
the event loop.
The problem is asyncio is so fast that a single keypress will often read multiple times.
Is there any way to read a single event, or perhaps wait 50 milliseconds ?
Below is the python Code
IRC Code 5
IRC Code 5
IRC Code 2
IRC Code 4
So sometimes a single keypress i.e. 2 or 4 is displayed, but mostly it will report multiple
reads as button 5 has been reported twice.
Wanted Output:
IRC Code 5
IRC Code 2
IRC Code 4
I would like some way to catch just one keypress.
I've tried to slow down event loop reading with multiple
await asyncio.sleep(0.1)
lines, but Im still reading same key twice.
Thanks in advance for any help
This is python 3.7 branch on an Orange Pi Zero, using the built in IR receiver as
the event loop.
The problem is asyncio is so fast that a single keypress will often read multiple times.
Is there any way to read a single event, or perhaps wait 50 milliseconds ?
Below is the python Code
import asyncio from evdev import InputDevice irr = InputDevice('/dev/input/event0') # Receive keypress from IRR and store as 'code' async def rec_code(): await asyncio.sleep(0.1) async for event in irr.async_read_loop(): if event.type == 4: global code await asyncio.sleep(0.2) # small delay to prevent two keypresses code = event.value await asyncio.sleep(0.2) # small delay to prevent two keypresses print("IRC Code ",code) async def delay5(): while True: await asyncio.sleep(5) print("5 sec delay") # Create asyncio loop run two independent timer loops and IR receiver function loop= asyncio.get_event_loop() loop.create_task(delay5()) loop.create_task(rec_code()) loop.run_forever()Below is the output:
IRC Code 5
IRC Code 5
IRC Code 2
IRC Code 4
So sometimes a single keypress i.e. 2 or 4 is displayed, but mostly it will report multiple
reads as button 5 has been reported twice.
Wanted Output:
IRC Code 5
IRC Code 2
IRC Code 4
I would like some way to catch just one keypress.
I've tried to slow down event loop reading with multiple
await asyncio.sleep(0.1)
lines, but Im still reading same key twice.
Thanks in advance for any help