Skip to content

Commit e58b609

Browse files
committed
aioble/client.py: Make read/write events work for descriptors.
Descriptors were missing common initialisation for events shared with characteristics. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
1 parent 765f14b commit e58b609

File tree

1 file changed

+25
-28
lines changed

1 file changed

+25
-28
lines changed

micropython/bluetooth/aioble/aioble/client.py

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,29 @@ def _start_discovery(connection, uuid=None):
193193

194194

195195
class BaseClientCharacteristic:
196+
def __init__(self, value_handle, properties, uuid):
197+
# Used for read/write/notify ops.
198+
self._value_handle = value_handle
199+
200+
# Which operations are supported.
201+
self.properties = properties
202+
203+
# Allows comparison to a known uuid.
204+
self.uuid = uuid
205+
206+
if properties & _FLAG_READ:
207+
# Fired for each read result and read done IRQ.
208+
self._read_event = None
209+
self._read_data = None
210+
# Used to indicate that the read is complete.
211+
self._read_status = None
212+
213+
if (properties & _FLAG_WRITE) or (properties & _FLAG_WRITE_NO_RESPONSE):
214+
# Fired for the write done IRQ.
215+
self._write_event = None
216+
# Used to indicate that the write is complete.
217+
self._write_status = None
218+
196219
# Register this value handle so events can find us.
197220
def _register_with_connection(self):
198221
self._connection()._characteristics[self._value_handle] = self
@@ -292,27 +315,8 @@ def __init__(self, service, end_handle, value_handle, properties, uuid):
292315
# past the value handle (enough for two descriptors without risking
293316
# going into the next characteristic).
294317
self._end_handle = end_handle if end_handle > value_handle else value_handle + 2
295-
# Used for read/write/notify ops.
296-
self._value_handle = value_handle
297-
298-
# Which operations are supported.
299-
self.properties = properties
300318

301-
# Allows comparison to a known uuid.
302-
self.uuid = uuid
303-
304-
if properties & _FLAG_READ:
305-
# Fired for each read result and read done IRQ.
306-
self._read_event = None
307-
self._read_data = None
308-
# Used to indicate that the read is complete.
309-
self._read_status = None
310-
311-
if (properties & _FLAG_WRITE) or (properties & _FLAG_WRITE_NO_RESPONSE):
312-
# Fired for the write done IRQ.
313-
self._write_event = None
314-
# Used to indicate that the write is complete.
315-
self._write_status = None
319+
super().__init__(value_handle, properties, uuid)
316320

317321
if properties & _FLAG_NOTIFY:
318322
# Fired when a notification arrives.
@@ -437,14 +441,7 @@ class ClientDescriptor(BaseClientCharacteristic):
437441
def __init__(self, characteristic, dsc_handle, uuid):
438442
self.characteristic = characteristic
439443

440-
# Allows comparison to a known uuid.
441-
self.uuid = uuid
442-
443-
# Used for read/write.
444-
self._value_handle = dsc_handle
445-
446-
# Default flags
447-
self.properties = _FLAG_READ | _FLAG_WRITE_NO_RESPONSE
444+
super().__init__(dsc_handle, _FLAG_READ | _FLAG_WRITE_NO_RESPONSE, uuid)
448445

449446
def __str__(self):
450447
return "Descriptor: {} {} {}".format(self._value_handle, self.properties, self.uuid)

0 commit comments

Comments
 (0)