From b4f5481fbe8ff65796d25a9053ee10ac22749776 Mon Sep 17 00:00:00 2001 From: Andrey Pohilko Date: Sat, 23 Mar 2019 13:49:50 +0300 Subject: [PATCH] Cosmetics --- README.md | 2 +- examples/automata/__init__.py | 11 +---------- pylgbst/__init__.py | 2 ++ pylgbst/constants.py | 2 ++ pylgbst/movehub.py | 4 ++++ 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 640ddff..c7b13de 100644 --- a/README.md +++ b/README.md @@ -337,8 +337,8 @@ Then push green button on MoveHub, so permanent BLE connection will be establish ## Links +- https://github.com/LEGO/lego-ble-wireless-protocol-docs - true docs for LEGO BLE protocol - https://github.com/JorgePe/BOOSTreveng - initial source of protocol knowledge -- https://github.com/LEGO/lego-ble-wireless-protocol-docs - true docs of BLE protocol - https://github.com/spezifisch/sphero-python/blob/master/BB8joyDrive.py - example with another approach to bluetooth libs Some things around visual programming: diff --git a/examples/automata/__init__.py b/examples/automata/__init__.py index 409152a..89c890c 100644 --- a/examples/automata/__init__.py +++ b/examples/automata/__init__.py @@ -1,7 +1,7 @@ import time from collections import Counter -from pylgbst.constants import COLORS, COLOR_NONE, COLOR_BLACK, COLOR_CYAN, COLOR_BLUE +from pylgbst.constants import COLOR_NONE, COLOR_BLACK, COLOR_CYAN, COLOR_BLUE from pylgbst.movehub import MoveHub from pylgbst.peripherals import ColorDistanceSensor @@ -47,12 +47,3 @@ class Automata(object): def backward(self): self.__hub.motor_AB.angled(830, -0.25) time.sleep(0.5) - - -automata = Automata() - -for x in range(16): - automata.feed_tape() - print (x, COLORS[automata.get_color()]) - -# time.sleep(1000) diff --git a/pylgbst/__init__.py b/pylgbst/__init__.py index d3cff1b..ae6594f 100644 --- a/pylgbst/__init__.py +++ b/pylgbst/__init__.py @@ -7,6 +7,7 @@ log = logging.getLogger('pylgbst') def get_connection_bluegiga(controller=None, hub_mac=None): + del controller # to prevent code analysis warning from pylgbst.comms.cpygatt import BlueGigaConnection return BlueGigaConnection().connect(hub_mac) @@ -29,6 +30,7 @@ def get_connection_gattlib(controller='hci0', hub_mac=None): return GattLibConnection(controller).connect(hub_mac) + def get_connection_bluepy(controller='hci0', hub_mac=None): from pylgbst.comms.cbluepy import BluepyConnection diff --git a/pylgbst/constants.py b/pylgbst/constants.py index 44c0432..fb10f90 100644 --- a/pylgbst/constants.py +++ b/pylgbst/constants.py @@ -38,6 +38,8 @@ MSG_DEVICE_SHUTDOWN = 0x02 # sent when hub shuts down by button hold MSG_PING_RESPONSE = 0x03 MSG_PORT_INFO = 0x04 MSG_PORT_CMD_ERROR = 0x05 + + MSG_SET_PORT_VAL = 0x81 MSG_PORT_STATUS = 0x82 MSG_SENSOR_SUBSCRIBE = 0x41 diff --git a/pylgbst/movehub.py b/pylgbst/movehub.py index 49f83f2..9076392 100644 --- a/pylgbst/movehub.py +++ b/pylgbst/movehub.py @@ -244,3 +244,7 @@ class MoveHub(object): time.sleep(0.05) return self.info[info_type] + + def __del__(self): + if self.connection and self.connection.is_alive(): + self.connection.disconnect()