btbricks 0.2.3__py3-none-any.whl → 0.2.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
btbricks/__init__.py CHANGED
@@ -7,7 +7,7 @@ use it to create custom Bluetooth peripherals like RC controllers or MIDI
7
7
  devices compatible with LEGO hubs.
8
8
  """
9
9
 
10
- __version__ = "0.2.3"
10
+ __version__ = "0.2.4"
11
11
  __author__ = "Anton Vanhoucke"
12
12
  __license__ = "MIT"
13
13
 
@@ -28,8 +28,22 @@ from .bt import (
28
28
  SETTING1,
29
29
  SETTING2,
30
30
  )
31
- from .bthub import BtHub
32
- from .ctrl_plus import SmartHub
31
+ from .bthub import (
32
+ BtHub,
33
+ OFF,
34
+ PINK,
35
+ PURPLE,
36
+ DARK_BLUE,
37
+ BLUE,
38
+ TEAL,
39
+ GREEN,
40
+ YELLOW,
41
+ ORANGE,
42
+ RED,
43
+ WHITE,
44
+ )
45
+
46
+ from .bthub import BtHub as SmartHub
33
47
 
34
48
  __all__ = [
35
49
  "BLEHandler",
btbricks/bt.py CHANGED
@@ -299,7 +299,6 @@ class BLEHandler:
299
299
 
300
300
  def __init__(self, debug=False):
301
301
  self._ble = ubluetooth.BLE()
302
- self._ble.config(rxbuf=TARGET_MTU)
303
302
  self._ble.active(True)
304
303
  try:
305
304
  self._ble.gap_disconnect(1025) # Disconnect in case of previous crash
@@ -532,10 +531,9 @@ class BLEHandler:
532
531
 
533
532
  def advertise(self, payload, interval_us=100000):
534
533
  """
535
- Advertise a BLE payload for a given time interval.
534
+ Advertise a BLE payload for a microsecond time interval.
536
535
  Create the payload with the _advertising_payload() function.
537
536
  """
538
- print("Started advertising")
539
537
  self._ble.gap_advertise(interval_us, adv_data=payload)
540
538
 
541
539
  def on_write(self, value_handle, callback):
@@ -914,7 +912,12 @@ class UARTPeripheral(BleUARTBase):
914
912
  )
915
913
 
916
914
  self.ble_handler.on_write(self._handle_rx, self._on_rx)
917
- self.ble_handler_central_disconn_callback = self._on_disconnect
915
+
916
+ def _on_disconnect(conn_handle):
917
+ # Flush buffer
918
+ self.read()
919
+ self.start_advertising()
920
+ self.ble_handler._central_disconn_callback = _on_disconnect
918
921
 
919
922
  # Characteristics and descriptors have a default maximum size of 20 bytes.
920
923
  # Anything written to them by a client will be truncated to this length.
@@ -930,15 +933,17 @@ class UARTPeripheral(BleUARTBase):
930
933
 
931
934
  # Flush
932
935
  _ = self.ble_handler._ble.gatts_read(self._handle_rx)
936
+
937
+ # Advertise
938
+ self.start_advertising()
939
+
940
+ def start_advertising(self):
933
941
  self.ble_handler.advertise(advertising_payload(name=self.name, services=[_UART_UUID]))
942
+ print("Advertising as:", self.name)
934
943
 
935
944
  def is_connected(self):
936
945
  return self.ble_handler._connected_central >= 0
937
946
 
938
- def _on_disconnect(self, conn_handle):
939
- # Flush buffer
940
- self.read()
941
-
942
947
  def write(self, data):
943
948
  """
944
949
  Write uart data to remote. This is a blocking call.
@@ -1103,16 +1108,16 @@ class RCReceiver(UARTPeripheral):
1103
1108
 
1104
1109
  """
1105
1110
  try:
1106
- controller_state = struct.unpack("bbbbBBhhB", self.read_buffer)
1111
+ state = struct.unpack("bbbbBBhhB", self.read_buffer)
1107
1112
  except:
1108
- controller_state = [0] * 9
1113
+ state = [0] * 9
1109
1114
  if indices:
1110
1115
  if len(indices) == 1:
1111
- return controller_state[indices[0]]
1116
+ return state[indices[0]]
1112
1117
  else:
1113
- return [controller_state[i] for i in indices]
1118
+ return [state[i] for i in indices]
1114
1119
  else:
1115
- return controller_state
1120
+ return state
1116
1121
 
1117
1122
 
1118
1123
  class RCTransmitter(UARTCentral):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: btbricks
3
- Version: 0.2.3
3
+ Version: 0.2.5
4
4
  Summary: A MicroPython Bluetooth library for remote controlling LEGO hubs via BLE
5
5
  Home-page: https://github.com/antonvh/btbricks
6
6
  Author: Anton Vanhoucke
@@ -1,14 +1,14 @@
1
- btbricks/__init__.py,sha256=eUuqwGNWUQIA61IJp_p-b79RyEl2bvR_0mQmeQ_beeI,1051
2
- btbricks/bt.py,sha256=JLtXm3RsfpLTbWzGYhrEC1_AMlTpyXHaEoBR1Q5lC7A,44575
1
+ btbricks/__init__.py,sha256=fYiEL6h9s2vBgqGCY-CFqjONW4kU6dNbY4O4sCl64J8,1187
2
+ btbricks/bt.py,sha256=wsXJzY180ug3_SZWKF6zLB5Tsq5a63myYpGazIeAuiY,44633
3
3
  btbricks/bthub.py,sha256=TVvpVo5E9nIzwmASMTAjjLs0lbY4Su4CYFlBU4KZ3dY,7967
4
4
  btbricks/ctrl_plus.py,sha256=CAnkG_SZ9Zysv4ZUDJ7UE0HTLMGeZYD0JxPEIIf-o6Y,177
5
- btbricks-0.2.3.dist-info/licenses/LICENSE,sha256=yVFkYtNY8Mlp5U_xedI4-O8Hxjg_vu-taxJlv8y-xVk,1078
5
+ btbricks-0.2.5.dist-info/licenses/LICENSE,sha256=yVFkYtNY8Mlp5U_xedI4-O8Hxjg_vu-taxJlv8y-xVk,1078
6
6
  tests/__init__.py,sha256=CtJ2NCOCvkNNpVgAw3XHsKd_S-C36d7Yuq4QfTPmwgg,34
7
7
  tests/test_bthub.py,sha256=9yyBhsydjwN7_yXKzsKTEAxcjW_PqOzwZFcQ2dDv_f0,3298
8
8
  tests/test_constants.py,sha256=L0rIn8VsPIPc80qITblsPu9mQltL85pAFLQl2KQUpGY,2023
9
9
  tests/test_imports.py,sha256=kHrRnueFPnQxU807Bo9Ddr3x4hsryMroUoWC816N-Nc,2147
10
10
  tests/test_precommit_checks.py,sha256=mXDtYdLFDgBdOrMBGZyaGz5Z4QtzSfwFpP7axU_H-WE,7075
11
- btbricks-0.2.3.dist-info/METADATA,sha256=oZGjCxcMEkjr96h-xxk956TLDmdlhEjX4DwwXiRz48o,8160
12
- btbricks-0.2.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
- btbricks-0.2.3.dist-info/top_level.txt,sha256=nznVmPKoDx79OB6rEM180swD9X5G22V35afi5zon1d8,15
14
- btbricks-0.2.3.dist-info/RECORD,,
11
+ btbricks-0.2.5.dist-info/METADATA,sha256=VgJThtODg5eYr6S0IgN92LBX93lRBCiCBfyKduDY8es,8160
12
+ btbricks-0.2.5.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
13
+ btbricks-0.2.5.dist-info/top_level.txt,sha256=nznVmPKoDx79OB6rEM180swD9X5G22V35afi5zon1d8,15
14
+ btbricks-0.2.5.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5