Remove device.py

This commit is contained in:
redphx 2022-04-29 11:12:10 +07:00
parent a3872b1f38
commit e42599bc73
3 changed files with 2 additions and 91 deletions

View file

@ -11,8 +11,8 @@ from enum import Enum
import aiohttp
import hid
from aiohttp import WSMsgType, web
from pyjoycon import ButtonEventJoyCon, JoyCon
from pyjoycon.constants import JOYCON_PRODUCT_IDS, JOYCON_VENDOR_ID
from pycon import ButtonEventJoyCon, JoyCon
from pycon.constants import JOYCON_PRODUCT_IDS, JOYCON_VENDOR_ID
from joydance import JoyDance, PairingState
from joydance.constants import (DEFAULT_CONFIG, JOYDANCE_VERSION,

View file

@ -1,20 +1,9 @@
from .device import (get_device_ids, get_ids_of_type, get_L_id, get_L_ids,
get_R_id, get_R_ids, is_id_L)
from .event import ButtonEventJoyCon
from .joycon import JoyCon
from .wrappers import PythonicJoyCon # as JoyCon
__version__ = "0.2.4"
__all__ = [
"ButtonEventJoyCon",
"JoyCon",
"PythonicJoyCon",
"get_L_id",
"get_L_ids",
"get_R_id",
"get_R_ids",
"get_device_ids",
"get_ids_of_type",
"is_id_L",
]

View file

@ -1,78 +0,0 @@
import hid
from .constants import (JOYCON_L_PRODUCT_ID, JOYCON_PRODUCT_IDS,
JOYCON_R_PRODUCT_ID, JOYCON_VENDOR_ID)
def get_device_ids(debug=False):
"""
returns a list of tuples like `(vendor_id, product_id, serial_number)`
"""
devices = hid.enumerate(0, 0)
out = []
for device in devices:
vendor_id = device["vendor_id"]
product_id = device["product_id"]
product_string = device["product_string"]
serial = device.get('serial') or device.get("serial_number")
if vendor_id != JOYCON_VENDOR_ID:
continue
if product_id not in JOYCON_PRODUCT_IDS:
continue
if not product_string:
continue
out.append((vendor_id, product_id, serial))
if debug:
print(product_string)
print(f"\tvendor_id is {vendor_id!r}")
print(f"\tproduct_id is {product_id!r}")
print(f"\tserial is {serial!r}")
return out
def is_id_L(id):
return id[1] == JOYCON_L_PRODUCT_ID
def get_ids_of_type(lr, **kw):
"""
returns a list of tuples like `(vendor_id, product_id, serial_number)`
arg: lr : str : put `R` or `L`
"""
if lr.lower() == "l":
product_id = JOYCON_L_PRODUCT_ID
else:
product_id = JOYCON_R_PRODUCT_ID
return [i for i in get_device_ids(**kw) if i[1] == product_id]
def get_R_ids(**kw):
"""returns a list of tuple like `(vendor_id, product_id, serial_number)`"""
return get_ids_of_type("R", **kw)
def get_L_ids(**kw):
"""returns a list of tuple like `(vendor_id, product_id, serial_number)`"""
return get_ids_of_type("L", **kw)
def get_R_id(**kw):
"""returns a tuple like `(vendor_id, product_id, serial_number)`"""
ids = get_R_ids(**kw)
if not ids:
return (None, None, None)
return ids[0]
def get_L_id(**kw):
"""returns a tuple like `(vendor_id, product_id, serial_number)`"""
ids = get_L_ids(**kw)
if not ids:
return (None, None, None)
return ids[0]