Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.sw?
__pycache__
MANIFEST
dist
etc/config.yml
build
*.pyc
*.pyo
6 changes: 6 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# file GENERATED by distutils, do NOT edit
include setup.py
include README.md
include MANIFEST.in
recursive-include pyb00st *.py

78 changes: 78 additions & 0 deletions RPM/python3-pyb00st.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#
# 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
%define skip_python2 1

Name: python3-%{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
%if 0%{?fedora}
BuildRequires: python3-devel
%define debug_package %{nil}
%endif

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
[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
python3 setup.py build

%install
python3 setup.py install --prefix=%{_prefix} --root=%{buildroot}

%files
%defattr(-,root,root)
%doc README.md
%{python3_sitelib}/*

%changelog
3 changes: 3 additions & 0 deletions etc/config.yml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MY_MOVEHUB_ADD: 00:16:53:XX:XX:XX
MY_BTCTRLR_HCI: hci0
# LogLevel: DEBUG
21 changes: 21 additions & 0 deletions examples/config.py
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 5 additions & 3 deletions examples/demo_button_read.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -23,5 +23,7 @@
print('RELEASED')
else:
print('')
except KeyboardInterrupt:
print("\nCTRL-C pressed! Exiting ...")
finally:
mymovehub.stop()
10 changes: 6 additions & 4 deletions examples/demo_colordist.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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()
10 changes: 6 additions & 4 deletions examples/demo_encoder_and_color.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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()
8 changes: 5 additions & 3 deletions examples/demo_encoder_read.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -18,5 +18,7 @@
while True:
sleep(0.2)
print(mymovehub.last_angle_C)
except KeyboardInterrupt:
print("\nCTRL-C pressed! Exiting ...")
finally:
mymovehub.stop()
108 changes: 59 additions & 49 deletions examples/demo_motor.py
Original file line number Diff line number Diff line change
@@ -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


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()

# 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)

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)

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)

sleep(0.5)

# 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()

from time import sleep

MY_MOVEHUB_ADD = '00:16:53:A4:CD:7E'
MY_BTCTRLR_HCI = 'hci0'

mymovehub = MoveHub(MY_MOVEHUB_ADD, 'BlueZ', MY_BTCTRLR_HCI)

try:
mymovehub.start()

# 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)

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)

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)

sleep(0.5)

# 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()
13 changes: 6 additions & 7 deletions examples/demo_tilt_read.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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()

6 changes: 3 additions & 3 deletions examples/test_connection.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
Loading