From 7c2c26d4159bcd8f864dec6c94c8ed5598eef332 Mon Sep 17 00:00:00 2001 From: Yihui Xiong Date: Wed, 19 Aug 2020 18:31:32 +0800 Subject: [PATCH 1/5] add timeout to start_advertising --- adafruit_ble/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/adafruit_ble/__init__.py b/adafruit_ble/__init__.py index 6250f9c..26cbac1 100755 --- a/adafruit_ble/__init__.py +++ b/adafruit_ble/__init__.py @@ -162,7 +162,7 @@ def __init__(self, adapter=None): self._current_advertisement = None self._connection_cache = {} - def start_advertising(self, advertisement, scan_response=None, interval=0.1): + def start_advertising(self, advertisement, scan_response=None, interval=0.1, timeout=0): """ Starts advertising the given advertisement. @@ -170,6 +170,8 @@ def start_advertising(self, advertisement, scan_response=None, interval=0.1): If ``None``, a default scan response will be generated that includes `BLERadio.name` and `BLERadio.tx_power`. :param float interval: advertising interval, in seconds + :param int timeout: advertising timeout in seconds. + If 0, no timeout. """ advertisement_bytes = bytes(advertisement) scan_response_bytes = b"" @@ -184,6 +186,7 @@ def start_advertising(self, advertisement, scan_response=None, interval=0.1): scan_response=scan_response_bytes, connectable=advertisement.connectable, interval=interval, + timeout=timeout, ) def stop_advertising(self): From 96b102e1debbf5df485c8d1f27652a1d7bdabed5 Mon Sep 17 00:00:00 2001 From: Yihui Xiong Date: Wed, 19 Aug 2020 18:36:48 +0800 Subject: [PATCH 2/5] add advertising property --- adafruit_ble/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/adafruit_ble/__init__.py b/adafruit_ble/__init__.py index 26cbac1..055199c 100755 --- a/adafruit_ble/__init__.py +++ b/adafruit_ble/__init__.py @@ -324,3 +324,8 @@ def tx_power(self, value): def address_bytes(self): """The device address, as a ``bytes()`` object of length 6.""" return self._adapter.address.address_bytes + + @property + def advertising(self): + """The adverstising state""" + return self._adapter.advertising From 41fb23f8ae23705889dba900319bea47f32ca7a4 Mon Sep 17 00:00:00 2001 From: Yihui Xiong Date: Wed, 19 Aug 2020 18:41:43 +0800 Subject: [PATCH 3/5] add report property to get keyboard leds info --- adafruit_ble/services/standard/hid.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/adafruit_ble/services/standard/hid.py b/adafruit_ble/services/standard/hid.py index 4149992..96192b3 100755 --- a/adafruit_ble/services/standard/hid.py +++ b/adafruit_ble/services/standard/hid.py @@ -241,6 +241,10 @@ def __init__(self, service, report_id, usage_page, usage, *, max_length): initial_value=struct.pack(" Date: Wed, 19 Aug 2020 19:22:26 +0800 Subject: [PATCH 4/5] updated --- adafruit_ble/__init__.py | 9 ++++++--- adafruit_ble/services/standard/hid.py | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/adafruit_ble/__init__.py b/adafruit_ble/__init__.py index 055199c..471e9f2 100755 --- a/adafruit_ble/__init__.py +++ b/adafruit_ble/__init__.py @@ -162,7 +162,9 @@ def __init__(self, adapter=None): self._current_advertisement = None self._connection_cache = {} - def start_advertising(self, advertisement, scan_response=None, interval=0.1, timeout=0): + def start_advertising( + self, advertisement, scan_response=None, interval=0.1, timeout=None + ): """ Starts advertising the given advertisement. @@ -171,7 +173,7 @@ def start_advertising(self, advertisement, scan_response=None, interval=0.1, tim `BLERadio.name` and `BLERadio.tx_power`. :param float interval: advertising interval, in seconds :param int timeout: advertising timeout in seconds. - If 0, no timeout. + If None, no timeout. """ advertisement_bytes = bytes(advertisement) scan_response_bytes = b"" @@ -181,6 +183,7 @@ def start_advertising(self, advertisement, scan_response=None, interval=0.1, tim scan_response.tx_power = self.tx_power if scan_response: scan_response_bytes = bytes(scan_response) + timeout = 0 if timeout is None else timeout self._adapter.start_advertising( advertisement_bytes, scan_response=scan_response_bytes, @@ -327,5 +330,5 @@ def address_bytes(self): @property def advertising(self): - """The adverstising state""" + """The advertising state""" return self._adapter.advertising diff --git a/adafruit_ble/services/standard/hid.py b/adafruit_ble/services/standard/hid.py index 96192b3..595ea82 100755 --- a/adafruit_ble/services/standard/hid.py +++ b/adafruit_ble/services/standard/hid.py @@ -243,6 +243,7 @@ def __init__(self, service, report_id, usage_page, usage, *, max_length): @property def report(self): + """The HID OUT report""" return self._characteristic.value From 62b50b38370d768862fe22de4675701b5ed8b43c Mon Sep 17 00:00:00 2001 From: Yihui Xiong Date: Wed, 19 Aug 2020 20:12:45 +0800 Subject: [PATCH 5/5] adjust --- adafruit_ble/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/adafruit_ble/__init__.py b/adafruit_ble/__init__.py index 471e9f2..07bd8a5 100755 --- a/adafruit_ble/__init__.py +++ b/adafruit_ble/__init__.py @@ -183,13 +183,12 @@ def start_advertising( scan_response.tx_power = self.tx_power if scan_response: scan_response_bytes = bytes(scan_response) - timeout = 0 if timeout is None else timeout self._adapter.start_advertising( advertisement_bytes, scan_response=scan_response_bytes, connectable=advertisement.connectable, interval=interval, - timeout=timeout, + timeout=0 if timeout is None else timeout, ) def stop_advertising(self):