From cf8a421c8982aedd23283343cf696f7183a2d540 Mon Sep 17 00:00:00 2001 From: Eric Tsai Date: Mon, 2 Oct 2017 18:38:19 -0700 Subject: [PATCH] Commit for v0.1.9 --- README.rst | 7 +++++-- examples/scan_connect.py | 5 +++-- mbientlab/metawear/__init__.py | 16 ++++++++++++---- setup.py | 20 +++++++++++++------- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/README.rst b/README.rst index b43d4ba..16dde00 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,10 @@ MetaWear Python SDK ################### Python SDK for creating MetaWear apps on the Linux platform. This is a thin wrapper around the `MetaWear C++ API `_ so you will find the C++ `documentation `_ and `API reference `_ useful. Also, check out the scripts in the -`examples `_ folder for full example scripts. +`examples `_ folder for full sample code. + +**This is not the pymetawear package. That is a community developed Python SDK which you can find over** +`here `_ **.** Install ####### @@ -45,6 +48,6 @@ Upon a successful connection, you can begin calling any of the functions from th .. code-block:: python pattern= LedPattern(repeat_count= Const.LED_REPEAT_INDEFINITELY) - libmetawear.mbl_mw_led_load_preset_pattern(byref(pattern), LedPreset.SOLID) + libmetawear.mbl_mw_led_load_preset_pattern(byref(pattern), LedPreset.BLINK) libmetawear.mbl_mw_led_write_pattern(device.board, byref(pattern), LedColor.GREEN) libmetawear.mbl_mw_led_play(device.board) diff --git a/examples/scan_connect.py b/examples/scan_connect.py index 4b1f29c..62afbdc 100644 --- a/examples/scan_connect.py +++ b/examples/scan_connect.py @@ -13,8 +13,8 @@ devices = service.discover(2) i = 0 - for address, name in devices.items(): - print("[%d] %s" % (i, address)) + for address, attr in devices.items(): + print("[%d] %s (%s)" % (i, address, attr['name'])) i+= 1 msg = "Select your device (-1 to rescan): " @@ -29,4 +29,5 @@ sleep(5.0) device.disconnect() +sleep(1.0) print("Disconnected") diff --git a/mbientlab/metawear/__init__.py b/mbientlab/metawear/__init__.py index b4c29d5..b0168e9 100644 --- a/mbientlab/metawear/__init__.py +++ b/mbientlab/metawear/__init__.py @@ -87,6 +87,8 @@ def on_notification(self, handle, data): class MetaWear(object): _METABOOT_SERVICE = uuid.UUID("00001530-1212-efde-1523-785feabcd123") + _METABOOT_CONTROL_POINT = GattChar(service_uuid_high = 0x000015301212efde, service_uuid_low = 0x1523785feabcd123, + uuid_high = 0x000015311212efde, uuid_low = 0x1523785feabcd123) def __init__(self, address, **kwargs): """ @@ -115,16 +117,20 @@ def __init__(self, address, **kwargs): self.board = libmetawear.mbl_mw_metawearboard_create(byref(self._btle_connection)) + if 'deserialize' not in kwargs or kwargs['deserialize']: + self.deserialize() + try: os.makedirs(self.cache) - if 'deserialize' not in kwargs or kwargs['deserialize']: - self.deserialize() except OSError as exception: if exception.errno != errno.EEXIST: raise @property def in_metaboot_mode(self): + """ + True if the board is in MetaBoot mode. The only permitted operation for MetaBoot boards is to update the firmware + """ return str(MetaWear._METABOOT_SERVICE) in self.services def disconnect(self): @@ -179,7 +185,10 @@ def _write_gatt_char(self, caller, write_type, ptr_gattchar, value, length): buffer.append(value[i]) handle = self.characteristics[_gattchar_to_string(ptr_gattchar.contents)] - self.gatt.write_by_handle_async(handle, bytes(bytearray(buffer)), self.response) + if self.in_metaboot_mode and ptr_gattchar.contents == MetaWear._METABOOT_CONTROL_POINT: + self.gatt.write_by_handle_async(handle, bytes(bytearray(buffer)), self.response) + else: + self.gatt.write_cmd_by_handle(handle, bytes(bytearray(buffer))) def _enable_notifications(self, caller, ptr_gattchar, handler, ready): handle = self.characteristics[_gattchar_to_string(ptr_gattchar.contents)] @@ -190,7 +199,6 @@ def _enable_notifications(self, caller, ptr_gattchar, handler, ready): def _on_disconnect(self, caller, handler): pass - def _download_firmware(self, version=None): firmware_root = os.path.join(self.cache, "firmware") diff --git a/setup.py b/setup.py index 472ea4d..d95a096 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,3 @@ -import os -import sys from distutils.dir_util import copy_tree from multiprocessing import cpu_count from shutil import copy2 @@ -7,7 +5,11 @@ from setuptools import setup from setuptools.command.build_py import build_py -machine = "x64" if sys.maxsize > 2**32 else "x86" +import os +import platform +import sys + +machine = "arm" if "arm" in platform.machine() else ("x64" if sys.maxsize > 2**32 else "x86") class MetaWearBuild(build_py): def run(self): @@ -30,21 +32,25 @@ def run(self): setup( name='metawear', packages=['mbientlab', 'mbientlab.metawear'], - version='0.1.1', - description='Python bindings for the MetaWear C++ SDK', + version='0.1.9', + description='Python bindings for the MetaWear C++ SDK by MbientLab', + long_description=open(os.path.join(os.path.dirname(__file__), "README.rst")).read(), package_data={'mbientlab.metawear': ['libmetawear.so*']}, include_package_data=True, url='https://github.com/mbientlab/MetaWear-SDK-Python', author='MbientLab', author_email="hello@mbientlab.com", install_requires=[ - 'gattlib==0.20160216', + 'gattlib==0.20171002', 'requests' ], cmdclass={ 'build_py': MetaWearBuild, }, - dependency_links=['git+https://github.com/mbientlab/pygattlib.git@master#egg=gattlib-0.20160216'], + dependency_links=[ + 'git+https://github.com/mbientlab/pygattlib.git/@master#egg=gattlib-0.20171002', + 'git+https://github.com/mbientlab/pygattlib.git@master#egg=gattlib-0.20171002' + ], keywords = ['sensors', 'mbientlab', 'metawear', 'bluetooth le', 'native'], python_requires='>=2.7', classifiers=[