forked from mirror/joycontrol
error message for disconnect
This commit is contained in:
+10
-1
@@ -1,6 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import time
|
|
||||||
from asyncio import BaseTransport, BaseProtocol
|
from asyncio import BaseTransport, BaseProtocol
|
||||||
from typing import Optional, Union, Tuple, Text
|
from typing import Optional, Union, Tuple, Text
|
||||||
|
|
||||||
@@ -93,6 +92,11 @@ class ControllerProtocol(BaseProtocol):
|
|||||||
reply_send = False
|
reply_send = False
|
||||||
if reader.done():
|
if reader.done():
|
||||||
data = await reader
|
data = await reader
|
||||||
|
if not data:
|
||||||
|
# disconnect happened
|
||||||
|
logger.error('No data received (most likely due to a disconnect).')
|
||||||
|
break
|
||||||
|
|
||||||
reader = asyncio.ensure_future(self.transport.read())
|
reader = asyncio.ensure_future(self.transport.read())
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -115,6 +119,11 @@ class ControllerProtocol(BaseProtocol):
|
|||||||
await self.write(input_report)
|
await self.write(input_report)
|
||||||
|
|
||||||
async def report_received(self, data: Union[bytes, Text], addr: Tuple[str, int]) -> None:
|
async def report_received(self, data: Union[bytes, Text], addr: Tuple[str, int]) -> None:
|
||||||
|
if not data:
|
||||||
|
# disconnect happened
|
||||||
|
logger.error('No data received (most likely due to a disconnect).')
|
||||||
|
return
|
||||||
|
|
||||||
self._data_received.set()
|
self._data_received.set()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class InputReport:
|
|||||||
https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/bluetooth_hid_notes.md
|
https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/bluetooth_hid_notes.md
|
||||||
"""
|
"""
|
||||||
def __init__(self, data=None):
|
def __init__(self, data=None):
|
||||||
if data is None:
|
if not data:
|
||||||
# TODO: not enough space for NFC/IR data input report
|
# TODO: not enough space for NFC/IR data input report
|
||||||
self.data = [0x00] * 51
|
self.data = [0x00] * 51
|
||||||
# all input reports are prepended with 0xA1
|
# all input reports are prepended with 0xA1
|
||||||
@@ -212,7 +212,7 @@ class OutputReportID(Enum):
|
|||||||
|
|
||||||
class OutputReport:
|
class OutputReport:
|
||||||
def __init__(self, data=None):
|
def __init__(self, data=None):
|
||||||
if data is None:
|
if not data:
|
||||||
data = 50 * [0x00]
|
data = 50 * [0x00]
|
||||||
data[0] = 0xA2
|
data[0] = 0xA2
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user