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