forked from mirror/joycontrol
move hid stuff to extra module
This commit is contained in:
@@ -2,28 +2,9 @@ import asyncio
|
||||
import logging
|
||||
from contextlib import contextmanager
|
||||
|
||||
import hid
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AsyncHID(hid.Device):
|
||||
def __init__(self, *args, loop=asyncio.get_event_loop(), **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self._loop = loop
|
||||
|
||||
self._write_lock = asyncio.Lock()
|
||||
self._read_lock = asyncio.Lock()
|
||||
|
||||
async def read(self, size, timeout=None):
|
||||
async with self._read_lock:
|
||||
return await self._loop.run_in_executor(None, hid.Device.read, self, size, timeout)
|
||||
|
||||
async def write(self, data):
|
||||
async with self._write_lock:
|
||||
return await self._loop.run_in_executor(None, hid.Device.write, self, data)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def get_output(path=None, open_flags='wb', default=None):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user