From 94edf5e56f497c25065df5dba0f4a0a996da08cc Mon Sep 17 00:00:00 2001 From: Frank Schreiner Date: Mon, 25 Dec 2017 12:01:05 +0100 Subject: [PATCH 01/15] initial version for packaging (setup.py, openSUSE rpm spec) --- .gitignore | 6 +++ MANIFEST.in | 6 +++ RPM/openSUSE/python-pyb00st.spec | 75 ++++++++++++++++++++++++++++++++ setup.py | 14 ++++++ 4 files changed, 101 insertions(+) create mode 100644 .gitignore create mode 100644 MANIFEST.in create mode 100644 RPM/openSUSE/python-pyb00st.spec create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..046b0e0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.sw? +__pycache__ +MANIFEST +dist +etc/config.yml +build diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..e1f5fd8 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,6 @@ +# file GENERATED by distutils, do NOT edit +include setup.py +include README.md +include MANIFEST.in +recursive-include pyb00st *.py + diff --git a/RPM/openSUSE/python-pyb00st.spec b/RPM/openSUSE/python-pyb00st.spec new file mode 100644 index 0000000..d02ecd1 --- /dev/null +++ b/RPM/openSUSE/python-pyb00st.spec @@ -0,0 +1,75 @@ +# +# spec file for package python-pyb00st +# +# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via http://bugs.opensuse.org/ +# + +%define pypi_name pyb00st +%{?!python_module:%define python_module() python-%{**} python3-%{**}} + +Name: python-%{pypi_name} +Version: 0.0.0 +Release: 0 +Summary: Python for LEGO BOOST +License: MIT +Group: Development/Languages/Python +Url: https://github.com/JorgePe/pyb00st +Source: %{pypi_name}-%{version}.tar.gz +BuildRequires: python-rpm-macros +BuildRequires: fdupes +BuildRequires: python3 +BuildRoot: %{_tmppath}/%{name}-%{version}-build +Requires: python3 + +%python_subpackages + +%description +The LEGO BOOST Move Hub is a BLE (Bluetooth Low Energy) device like the LEGO WeDo 2.0 Smart Hub + and the Vengit SBrick which I already managed to control with the LEGO MINDSTORMS EV3 thanks to + [pygattlib](https://bitbucket.org/OscarAcena/pygattlib), a python library for BLE. + +I've been [reverse engineering the LEGO BOOST](https://github.com/JorgePe/BOOSTreveng) Move Hub + and since I'm now officially crazy I decided to try to write a python package. + +I started this project with pygattlib. It's a library that makes direct use of BlueZ and has been + included in pybluez. But since python3 version of pygattlib has problems with notifications I + started to use a different library, [pygatt](https://github.com/peplin/pygatt/tree/master/pygatt), + that doesn't make direct use of Bluez - instead, it makes use of a *backend*. On linux systems + this backend can be BlueZ (through system calls to BlueZ commands like hcitool and gattool) but on + other systems (and probably also on linux aswell) it uses a different backend, based on BlueGiga's + API - so a BG adapter, like BLED112, is needed. + +Why did I call it pyb00st? Well, boost is a C++ library and there are already lots of python libraries + related to it and I don't want to add the LEGO word because I don't want troubles. + +By the way... + + +%prep +%setup -q -n %{pypi_name}-%{version} + +%build +%python_build + +%install +%python_install +%python_expand %fdupes %{buildroot}%{$python_sitelib}/pyb00st + +%files %{python_files} +%defattr(-,root,root) +%doc README.md +%{python_sitelib}/* + +%changelog + diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..1b893f0 --- /dev/null +++ b/setup.py @@ -0,0 +1,14 @@ +from distutils.core import setup + +setup( + name='pyb00st', + version='0.1.0', + packages=['pyb00st',], + license='MIT License', + long_description=open('README.md').read(), + url="git@github.com:M0ses/pyb00st", + author='Jorge Pereira ', + author_email='...', + maintainer="Frank Schreiner", + maintainer_email="fschreiner@suse.de" +) From f29c9b6c60060a990f0b71a43e54aecc5d97268b Mon Sep 17 00:00:00 2001 From: Frank Schreiner Date: Wed, 27 Dec 2017 15:20:44 +0100 Subject: [PATCH 02/15] added pyc/pyo files to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 046b0e0..67e2665 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ MANIFEST dist etc/config.yml build +*.pyc +*.pyo From dfb7529dfffe8f484f74820bb0b1a5194f55ae0d Mon Sep 17 00:00:00 2001 From: Frank Schreiner Date: Wed, 27 Dec 2017 15:34:38 +0100 Subject: [PATCH 03/15] initial version B00stLogger and B00stConfig --- etc/config.yml.template | 3 ++ examples/config.py | 21 +++++++++++ pyb00st/__init__.py | 79 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 etc/config.yml.template create mode 100755 examples/config.py diff --git a/etc/config.yml.template b/etc/config.yml.template new file mode 100644 index 0000000..926c243 --- /dev/null +++ b/etc/config.yml.template @@ -0,0 +1,3 @@ +MY_MOVEHUB_ADD: 00:16:53:XX:XX:XX +MY_BTCTRLR_HCI: hci0 +# LogLevel: DEBUG diff --git a/examples/config.py b/examples/config.py new file mode 100755 index 0000000..20e2764 --- /dev/null +++ b/examples/config.py @@ -0,0 +1,21 @@ +#!/usr/bin/python3 +''' +This is an example script to demonstrate the usage of +B00stLogger and B00stConfig +''' + +from pyb00st import B00stLogger +from pyb00st import B00stConfig + + +def get_config(): + '''This function only exists to avoid 'invalid-name' errors from pylint''' + cfg = B00stConfig() + log = B00stLogger().logger + + log.error("MY_MOVEHUB_ADD: %s", cfg.MY_MOVEHUB_ADD) + log.error("MY_BTCTRLR_HCI: %s", cfg.MY_BTCTRLR_HCI) + + +if __name__ == "__main__": + get_config() diff --git a/pyb00st/__init__.py b/pyb00st/__init__.py index e69de29..f3bcdd2 100644 --- a/pyb00st/__init__.py +++ b/pyb00st/__init__.py @@ -0,0 +1,79 @@ +import sys +import os +import logging +from pathlib import Path +from yaml import load + +try: + from yaml import CLoader as Loader +except ImportError: + from yaml import Loader + + +class ConfigError(Exception): + """Exception raised on errors in configuration""" + pass + +class B00stLogger: + class __B00stLogger: + def __init__(self): + self.logger = logging.getLogger('pyb00st') + self.logger.setLevel(os.getenv('PYB00ST_LOGLEVEL', 'ERROR')) + formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') + ch = logging.StreamHandler() + ch.setFormatter(formatter) + self.logger.addHandler(ch) + def __str__(self): + return repr(self) + self.val + instance = None + def __init__(self): + if not B00stLogger.instance: + B00stLogger.instance = B00stLogger.__B00stLogger() + + def __getattr__(self, name): + return getattr(self.instance, name) + +class B00stConfig: + class __B00stConfig: + def __init__(self): + logger = B00stLogger().logger + self.MY_MOVEHUB_ADD = '' + self.MY_BTCTRLR_HCI = '' + home = str(Path.home()) + dir_path = os.path.dirname(os.path.realpath(__file__)) + + configs = [ + home + '.config/pyb00st/config.yml', + '/etc/pyb00st/config.yml', + dir_path + '/../etc/config.yml' + ] + config = 0 + for cfg_file in configs: + logger.debug("Checking for file '%s'", cfg_file) + if os.path.isfile(cfg_file): + config = cfg_file + break + + if config: + stream = open(config) + cfg = load(stream, Loader=Loader) + for key in ('MY_MOVEHUB_ADD', 'MY_BTCTRLR_HCI'): + if not cfg[key]: + raise ConfigError("Mandatory parameter '"+key+"'"+ + " not found in configuration") + else: + logger.debug("Setting '%s' to '%s'" % (key, cfg[key])) + setattr(self, key, cfg[key]) + if cfg['LogLevel'] and not os.environ.get('PYB00ST_LOGLEVEL'): + logger.setLevel(cfg['LogLevel']) + else: + raise ConfigError("No configuration file found") + def __str__(self): + return repr(self) + self.val + instance = None + def __init__(self): + if not B00stConfig.instance: + B00stConfig.instance = B00stConfig.__B00stConfig() + + def __getattr__(self, name): + return getattr(self.instance, name) From 90ffaac9853ab627fba3ef98e65f51330fa3c66b Mon Sep 17 00:00:00 2001 From: Frank Schreiner Date: Wed, 27 Dec 2017 16:28:16 +0100 Subject: [PATCH 04/15] examples/demo_motor.py with B00stConfig --- examples/demo_motor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/demo_motor.py b/examples/demo_motor.py index 77f3303..b73a217 100755 --- a/examples/demo_motor.py +++ b/examples/demo_motor.py @@ -1,14 +1,14 @@ #!/usr/bin/env python3 +from pyb00st import B00stConfig from pyb00st.movehub import MoveHub from pyb00st.constants import * from time import sleep -MY_MOVEHUB_ADD = '00:16:53:A4:CD:7E' -MY_BTCTRLR_HCI = 'hci0' +CFG = B00stConfig() -mymovehub = MoveHub(MY_MOVEHUB_ADD, 'BlueZ', MY_BTCTRLR_HCI) +mymovehub = MoveHub(CFG.MY_MOVEHUB_ADD, 'BlueZ', CFG.MY_BTCTRLR_HCI) try: mymovehub.start() From 1c8c71a6fad300b677441b6f6e3888ea382fec6a Mon Sep 17 00:00:00 2001 From: Frank Schreiner Date: Wed, 27 Dec 2017 16:37:26 +0100 Subject: [PATCH 05/15] make examples/demo_motor.py pylint/flake8 ready --- examples/demo_motor.py | 86 +++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 38 deletions(-) diff --git a/examples/demo_motor.py b/examples/demo_motor.py index b73a217..a7218e0 100755 --- a/examples/demo_motor.py +++ b/examples/demo_motor.py @@ -1,54 +1,64 @@ #!/usr/bin/env python3 +'''Example script to show how to control motors''' + +from time import sleep from pyb00st import B00stConfig from pyb00st.movehub import MoveHub -from pyb00st.constants import * +from pyb00st.constants import MOTOR_A, MOTOR_AB -from time import sleep -CFG = B00stConfig() +def run(): + ''' + This function is required for pylint, without cfg and mymovehub are + treated as constants + ''' + cfg = B00stConfig() + mymovehub = MoveHub(cfg.MY_MOVEHUB_ADD, 'BlueZ', cfg.MY_BTCTRLR_HCI) + + try: + mymovehub.start() -mymovehub = MoveHub(CFG.MY_MOVEHUB_ADD, 'BlueZ', CFG.MY_BTCTRLR_HCI) + # turn motor A ON for 1000 ms at 100% duty cycle in both directions + mymovehub.run_motor_for_time(MOTOR_A, 1000, 100) + sleep(1) + mymovehub.run_motor_for_time(MOTOR_A, 1000, -100) + sleep(1) -try: - mymovehub.start() + sleep(0.5) - # turn motor A ON for 1000 ms at 100% duty cycle in both directions - mymovehub.run_motor_for_time(MOTOR_A, 1000, 100) - sleep(1) - mymovehub.run_motor_for_time(MOTOR_A, 1000, -100) - sleep(1) + # rotate motor 90 degrees at 100% duty cycle in both directions + mymovehub.run_motor_for_angle(MOTOR_A, 90, 100) + sleep(0.5) + mymovehub.run_motor_for_angle(MOTOR_A, 90, -100) - sleep(0.5) + sleep(0.5) - # rotate motor 90 degrees at 100% duty cycle in both directions - mymovehub.run_motor_for_angle(MOTOR_A, 90, 100) - sleep(0.5) - mymovehub.run_motor_for_angle(MOTOR_A, 90, -100) + # turn pair AB ON for 1000 ms at 100% duty cycle in both direction + mymovehub.run_motors_for_time(MOTOR_AB, 1000, 100, 100) + sleep(1) + mymovehub.run_motors_for_time(MOTOR_AB, 1000, 100, -100) + sleep(1) + mymovehub.run_motors_for_time(MOTOR_AB, 1000, -100, -100) + sleep(1) + mymovehub.run_motors_for_time(MOTOR_AB, 1000, -100, 100) + sleep(1) - sleep(0.5) + sleep(0.5) - # turn pair AB ON for 1000 ms at 100% duty cycle in both direction - mymovehub.run_motors_for_time(MOTOR_AB, 1000, 100, 100) - sleep(1) - mymovehub.run_motors_for_time(MOTOR_AB, 1000, 100, -100) - sleep(1) - mymovehub.run_motors_for_time(MOTOR_AB, 1000, -100, -100) - sleep(1) - mymovehub.run_motors_for_time(MOTOR_AB, 1000, -100, 100) - sleep(1) + # rotate pair AB 90 degrees at 100% duty cycle in both direction + mymovehub.run_motors_for_angle(MOTOR_AB, 90, 100, 100) + sleep(0.5) + mymovehub.run_motors_for_angle(MOTOR_AB, 90, 100, -100) + sleep(0.5) + mymovehub.run_motors_for_angle(MOTOR_AB, 90, -100, -100) + sleep(0.5) + mymovehub.run_motors_for_angle(MOTOR_AB, 90, -100, 100) + sleep(0.5) - sleep(0.5) + finally: + mymovehub.stop() - # rotate pair AB 90 degrees at 100% duty cycle in both direction - mymovehub.run_motors_for_angle(MOTOR_AB, 90, 100, 100) - sleep(0.5) - mymovehub.run_motors_for_angle(MOTOR_AB, 90, 100, -100) - sleep(0.5) - mymovehub.run_motors_for_angle(MOTOR_AB, 90, -100, -100) - sleep(0.5) - mymovehub.run_motors_for_angle(MOTOR_AB, 90, -100, 100) - sleep(0.5) -finally: - mymovehub.stop() +if __name__ == '__main__': + run() From f93114214d093bcb0a13a16aa32ade8f361ce5df Mon Sep 17 00:00:00 2001 From: Frank Schreiner Date: Wed, 27 Dec 2017 16:51:01 +0100 Subject: [PATCH 06/15] examples/test_connection.py with B00stConfig --- examples/test_connection.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/test_connection.py b/examples/test_connection.py index 417f36e..9ff6aca 100755 --- a/examples/test_connection.py +++ b/examples/test_connection.py @@ -1,14 +1,14 @@ #!/usr/bin/env python3 +from pyb00st import B00stConfig from pyb00st.movehub import MoveHub from pyb00st.constants import * from time import sleep -MY_MOVEHUB_ADD = '00:16:53:A4:CD:7E' -MY_BTCTRLR_HCI = 'hci0' +CFG = B00stConfig() -mymovehub = MoveHub(MY_MOVEHUB_ADD, 'BlueZ', MY_BTCTRLR_HCI) +mymovehub = MoveHub(CFG.MY_MOVEHUB_ADD, 'BlueZ', CFG.MY_BTCTRLR_HCI) try: mymovehub.start() From cca06efd1a5da3afa682d54e6b8cd8e53237efbf Mon Sep 17 00:00:00 2001 From: Frank Schreiner Date: Wed, 27 Dec 2017 17:00:30 +0100 Subject: [PATCH 07/15] make setup.py pylint/flake8 ready --- setup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1b893f0..470116d 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,11 @@ +'''setup.py - build and install libraries''' + from distutils.core import setup setup( name='pyb00st', version='0.1.0', - packages=['pyb00st',], + packages=['pyb00st'], license='MIT License', long_description=open('README.md').read(), url="git@github.com:M0ses/pyb00st", From 7b18beb63662c270a90f9ad0e35d5b59c8752423 Mon Sep 17 00:00:00 2001 From: Frank Schreiner Date: Wed, 27 Dec 2017 17:45:22 +0100 Subject: [PATCH 08/15] remove %python_subpackages from spec as not working in fedora --- ...thon-pyb00st.spec => python3-pyb00st.spec} | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) rename RPM/{openSUSE/python-pyb00st.spec => python3-pyb00st.spec} (90%) diff --git a/RPM/openSUSE/python-pyb00st.spec b/RPM/python3-pyb00st.spec similarity index 90% rename from RPM/openSUSE/python-pyb00st.spec rename to RPM/python3-pyb00st.spec index d02ecd1..3ed7fe7 100644 --- a/RPM/openSUSE/python-pyb00st.spec +++ b/RPM/python3-pyb00st.spec @@ -16,9 +16,9 @@ # %define pypi_name pyb00st -%{?!python_module:%define python_module() python-%{**} python3-%{**}} +%define skip_python2 1 -Name: python-%{pypi_name} +Name: python3-%{pypi_name} Version: 0.0.0 Release: 0 Summary: Python for LEGO BOOST @@ -29,11 +29,14 @@ Source: %{pypi_name}-%{version}.tar.gz BuildRequires: python-rpm-macros BuildRequires: fdupes BuildRequires: python3 +%if 0%{?fedora} +BuildRequires: python3-devel +%define debug_package %{nil} +%endif + BuildRoot: %{_tmppath}/%{name}-%{version}-build Requires: python3 -%python_subpackages - %description The LEGO BOOST Move Hub is a BLE (Bluetooth Low Energy) device like the LEGO WeDo 2.0 Smart Hub and the Vengit SBrick which I already managed to control with the LEGO MINDSTORMS EV3 thanks to @@ -60,16 +63,14 @@ By the way... %setup -q -n %{pypi_name}-%{version} %build -%python_build +python3 setup.py build %install -%python_install -%python_expand %fdupes %{buildroot}%{$python_sitelib}/pyb00st +python3 setup.py install --prefix=%{_prefix} --root=%{buildroot} -%files %{python_files} +%files %defattr(-,root,root) %doc README.md -%{python_sitelib}/* +%{python3_sitelib}/* %changelog - From 8f5978478c53e254b4992f82f3246b3d93dcc9f5 Mon Sep 17 00:00:00 2001 From: Frank Schreiner Date: Wed, 27 Dec 2017 23:02:13 +0100 Subject: [PATCH 09/15] examples/demo_button_read.py using B00stConfig --- examples/demo_button_read.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/demo_button_read.py b/examples/demo_button_read.py index 273825a..896bb83 100755 --- a/examples/demo_button_read.py +++ b/examples/demo_button_read.py @@ -1,14 +1,14 @@ #!/usr/bin/env python3 +from pyb00st import B00stConfig from pyb00st.movehub import MoveHub from pyb00st.constants import * from time import sleep -MY_MOVEHUB_ADD = '00:16:53:A4:CD:7E' -MY_BTCTRLR_HCI = 'hci0' +CFG = B00stConfig() -mymovehub = MoveHub(MY_MOVEHUB_ADD, 'BlueZ', MY_BTCTRLR_HCI) +mymovehub = MoveHub(CFG.MY_MOVEHUB_ADD, 'BlueZ', CFG.MY_BTCTRLR_HCI) try: mymovehub.start() @@ -23,5 +23,7 @@ print('RELEASED') else: print('') +except KeyboardInterrupt: + print("\nCTRL-C pressed! Exiting ...") finally: mymovehub.stop() From f9a797bb08c014fbb5a0dc5a98f03b2b78515a7a Mon Sep 17 00:00:00 2001 From: Frank Schreiner Date: Wed, 27 Dec 2017 23:30:15 +0100 Subject: [PATCH 10/15] examples/demo_colordist.py using B00stConfig --- examples/demo_colordist.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/demo_colordist.py b/examples/demo_colordist.py index d17aac5..c565d3a 100755 --- a/examples/demo_colordist.py +++ b/examples/demo_colordist.py @@ -1,14 +1,14 @@ #!/usr/bin/env python3 +from pyb00st import B00stConfig from pyb00st.movehub import MoveHub -from pyb00st.constants import * +from pyb00st.constants import PORT_C from time import sleep -MY_MOVEHUB_ADD = '00:16:53:A4:CD:7E' -MY_BTCTRLR_HCI = 'hci0' +CFG = B00stConfig() -mymovehub = MoveHub(MY_MOVEHUB_ADD, 'BlueZ', MY_BTCTRLR_HCI) +mymovehub = MoveHub(CFG.MY_MOVEHUB_ADD, 'BlueZ', CFG.MY_BTCTRLR_HCI) try: mymovehub.start() @@ -19,5 +19,7 @@ sleep(0.2) print('Color: {} Distance: {}'.format(mymovehub.last_color_C, mymovehub.last_distance_C)) +except KeyboardInterrupt: + print("\nCTRL-C pressed! Exiting ...") finally: mymovehub.stop() From a4710aec0041560483cba4df61525935c3c77d7d Mon Sep 17 00:00:00 2001 From: Frank Schreiner Date: Thu, 28 Dec 2017 00:25:10 +0100 Subject: [PATCH 11/15] examples/demo_encoder_and_color.py using B00stConfig --- examples/demo_encoder_and_color.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/demo_encoder_and_color.py b/examples/demo_encoder_and_color.py index 77d832c..c587158 100755 --- a/examples/demo_encoder_and_color.py +++ b/examples/demo_encoder_and_color.py @@ -1,14 +1,14 @@ #!/usr/bin/env python3 +from pyb00st import B00stConfig from pyb00st.movehub import MoveHub -from pyb00st.constants import * +from pyb00st.constants import PORT_D, PORT_C from time import sleep -MY_MOVEHUB_ADD = '00:16:53:A4:CD:7E' -MY_BTCTRLR_HCI = 'hci0' +CFG = B00stConfig() -mymovehub = MoveHub(MY_MOVEHUB_ADD, 'BlueZ', MY_BTCTRLR_HCI) +mymovehub = MoveHub(CFG.MY_MOVEHUB_ADD, 'BlueZ', CFG.MY_BTCTRLR_HCI) try: mymovehub.start() @@ -19,5 +19,7 @@ while True: sleep(0.2) print('Motor D: {} Color: {}'.format(mymovehub.last_angle_D, mymovehub.last_color_C)) +except KeyboardInterrupt: + print("\nCTRL-C pressed! Exiting ...") finally: mymovehub.stop() From 703675845b064e65cfa1184d44ab8ffab8075aa4 Mon Sep 17 00:00:00 2001 From: Frank Schreiner Date: Thu, 28 Dec 2017 00:31:25 +0100 Subject: [PATCH 12/15] examples/demo_encoder_read.py using B00stConfig --- examples/demo_encoder_read.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/demo_encoder_read.py b/examples/demo_encoder_read.py index f3b9db9..e9a5bec 100755 --- a/examples/demo_encoder_read.py +++ b/examples/demo_encoder_read.py @@ -1,14 +1,14 @@ #!/usr/bin/env python3 +from pyb00st import B00stConfig from pyb00st.movehub import MoveHub from pyb00st.constants import * from time import sleep -MY_MOVEHUB_ADD = '00:16:53:A4:CD:7E' -MY_BTCTRLR_HCI = 'hci0' +CFG = B00stConfig() -mymovehub = MoveHub(MY_MOVEHUB_ADD, 'BlueZ', MY_BTCTRLR_HCI) +mymovehub = MoveHub(CFG.MY_MOVEHUB_ADD, 'BlueZ', CFG.MY_BTCTRLR_HCI) try: mymovehub.start() @@ -18,5 +18,7 @@ while True: sleep(0.2) print(mymovehub.last_angle_C) +except KeyboardInterrupt: + print("\nCTRL-C pressed! Exiting ...") finally: mymovehub.stop() From 11f8dd26ab92886ae5683c9062205458596941db Mon Sep 17 00:00:00 2001 From: Frank Schreiner Date: Thu, 28 Dec 2017 00:44:48 +0100 Subject: [PATCH 13/15] examples/demo_tilt_read.py using B00stConfig --- examples/demo_tilt_read.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/examples/demo_tilt_read.py b/examples/demo_tilt_read.py index bceb447..c3bb053 100755 --- a/examples/demo_tilt_read.py +++ b/examples/demo_tilt_read.py @@ -1,16 +1,14 @@ #!/usr/bin/env python3 +from pyb00st import B00stConfig from pyb00st.movehub import MoveHub -from pyb00st.constants import * +from pyb00st.constants import MODE_HUBTILT_BASIC, TILT_BASIC_VALUES, TILT_BASIC_TEXT from time import sleep -MY_MOVEHUB_ADD = '00:16:53:A4:CD:7E' -MY_BTCTRLR_HCI = 'hci0' +CFG = B00stConfig() -#mymovehub = MoveHub(MY_MOVEHUB_ADD, 'BlueZ', MY_BTCTRLR_HCI) -#mymovehub = MoveHub(MY_MOVEHUB_ADD, 'BlueGiga', '') -mymovehub = MoveHub(MY_MOVEHUB_ADD, 'Auto', MY_BTCTRLR_HCI) +mymovehub = MoveHub(CFG.MY_MOVEHUB_ADD, 'Auto', CFG.MY_BTCTRLR_HCI) try: mymovehub.start() @@ -22,6 +20,7 @@ sleep(0.2) if mymovehub.last_hubtilt in TILT_BASIC_VALUES: print(TILT_BASIC_TEXT[mymovehub.last_hubtilt]) +except KeyboardInterrupt: + print("\nCTRL-C pressed! Exiting ...") finally: mymovehub.stop() - From eade0a21db2e17c203cc17cf752bd8cf4f7423e1 Mon Sep 17 00:00:00 2001 From: Frank Schreiner Date: Sun, 10 Feb 2019 16:13:24 +0100 Subject: [PATCH 14/15] added missing Requires for python3-pygatt in spec --- RPM/python3-pyb00st.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RPM/python3-pyb00st.spec b/RPM/python3-pyb00st.spec index 3ed7fe7..9837a2b 100644 --- a/RPM/python3-pyb00st.spec +++ b/RPM/python3-pyb00st.spec @@ -36,7 +36,7 @@ BuildRequires: python3-devel BuildRoot: %{_tmppath}/%{name}-%{version}-build Requires: python3 - +Requires: python3-pygatt %description The LEGO BOOST Move Hub is a BLE (Bluetooth Low Energy) device like the LEGO WeDo 2.0 Smart Hub and the Vengit SBrick which I already managed to control with the LEGO MINDSTORMS EV3 thanks to From 3d5060fe2edee2025d32e8f860649229c25da775 Mon Sep 17 00:00:00 2001 From: Frank Schreiner Date: Sun, 10 Feb 2019 16:14:21 +0100 Subject: [PATCH 15/15] added missing Requires for python3-PyYAML in spec --- RPM/python3-pyb00st.spec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RPM/python3-pyb00st.spec b/RPM/python3-pyb00st.spec index 9837a2b..88c701c 100644 --- a/RPM/python3-pyb00st.spec +++ b/RPM/python3-pyb00st.spec @@ -37,6 +37,8 @@ BuildRequires: python3-devel BuildRoot: %{_tmppath}/%{name}-%{version}-build Requires: python3 Requires: python3-pygatt +Requires: python3-PyYAML + %description The LEGO BOOST Move Hub is a BLE (Bluetooth Low Energy) device like the LEGO WeDo 2.0 Smart Hub and the Vengit SBrick which I already managed to control with the LEGO MINDSTORMS EV3 thanks to