kopia lustrzana https://github.com/micropython/micropython-lib
Merge 2117b6fd8f
into 68e0dfce0a
commit
dd2819ab87
|
@ -6,7 +6,7 @@ from micropython import const
|
|||
import asyncio
|
||||
|
||||
from .core import ble, log_error, register_irq_handler
|
||||
from .device import DeviceConnection
|
||||
from .device import DeviceConnection, DeviceDisconnectedError
|
||||
|
||||
|
||||
_IRQ_L2CAP_ACCEPT = const(22)
|
||||
|
@ -180,6 +180,7 @@ class L2CAPChannel:
|
|||
# Use connection.l2cap_accept() instead of calling this directly.
|
||||
async def accept(connection, psm, mtu, timeout_ms):
|
||||
global _listening
|
||||
try:
|
||||
|
||||
channel = L2CAPChannel(connection)
|
||||
|
||||
|
@ -192,6 +193,10 @@ async def accept(connection, psm, mtu, timeout_ms):
|
|||
with connection.timeout(timeout_ms):
|
||||
await channel._event.wait()
|
||||
return channel
|
||||
except ValueError as ex:
|
||||
if ex.value == 'Not connected':
|
||||
raise DeviceDisconnectedError()
|
||||
raise
|
||||
|
||||
|
||||
# Use connection.l2cap_connect() instead of calling this directly.
|
||||
|
@ -199,6 +204,7 @@ async def connect(connection, psm, mtu, timeout_ms):
|
|||
if _listening:
|
||||
raise ValueError("Can't connect while listening")
|
||||
|
||||
try:
|
||||
channel = L2CAPChannel(connection)
|
||||
|
||||
with connection.timeout(timeout_ms):
|
||||
|
@ -212,3 +218,8 @@ async def connect(connection, psm, mtu, timeout_ms):
|
|||
return channel
|
||||
else:
|
||||
raise L2CAPConnectionError(channel._status)
|
||||
|
||||
except ValueError as ex:
|
||||
if ex.value == 'Not connected':
|
||||
raise DeviceDisconnectedError()
|
||||
raise
|
Ładowanie…
Reference in New Issue