Skip to content
This repository was archived by the owner on Jul 20, 2025. It is now read-only.

Commit cf8a421

Browse files
committed
Commit for v0.1.9
1 parent 0a1fb75 commit cf8a421

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

README.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ MetaWear Python SDK
22
###################
33
Python SDK for creating MetaWear apps on the Linux platform. This is a thin wrapper around the `MetaWear C++ API <https://github.com/mbientlab/MetaWear-SDK-Cpp>`_ so you will find the C++
44
`documentation <https://mbientlab.com/cppdocs/latest/>`_ and `API reference <https://mbientlab.com/docs/metawear/cpp/latest/globals.html>`_ useful. Also, check out the scripts in the
5-
`examples <https://github.com/mbientlab/MetaWear-SDK-Python/tree/master/examples>`_ folder for full example scripts.
5+
`examples <https://github.com/mbientlab/MetaWear-SDK-Python/tree/master/examples>`_ folder for full sample code.
6+
7+
**This is not the pymetawear package. That is a community developed Python SDK which you can find over**
8+
`here <https://github.com/mbientlab-projects/pymetawear>`_ **.**
69

710
Install
811
#######
@@ -45,6 +48,6 @@ Upon a successful connection, you can begin calling any of the functions from th
4548
.. code-block:: python
4649
4750
pattern= LedPattern(repeat_count= Const.LED_REPEAT_INDEFINITELY)
48-
libmetawear.mbl_mw_led_load_preset_pattern(byref(pattern), LedPreset.SOLID)
51+
libmetawear.mbl_mw_led_load_preset_pattern(byref(pattern), LedPreset.BLINK)
4952
libmetawear.mbl_mw_led_write_pattern(device.board, byref(pattern), LedColor.GREEN)
5053
libmetawear.mbl_mw_led_play(device.board)

examples/scan_connect.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
devices = service.discover(2)
1414

1515
i = 0
16-
for address, name in devices.items():
17-
print("[%d] %s" % (i, address))
16+
for address, attr in devices.items():
17+
print("[%d] %s (%s)" % (i, address, attr['name']))
1818
i+= 1
1919

2020
msg = "Select your device (-1 to rescan): "
@@ -29,4 +29,5 @@
2929
sleep(5.0)
3030

3131
device.disconnect()
32+
sleep(1.0)
3233
print("Disconnected")

mbientlab/metawear/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def on_notification(self, handle, data):
8787

8888
class MetaWear(object):
8989
_METABOOT_SERVICE = uuid.UUID("00001530-1212-efde-1523-785feabcd123")
90+
_METABOOT_CONTROL_POINT = GattChar(service_uuid_high = 0x000015301212efde, service_uuid_low = 0x1523785feabcd123,
91+
uuid_high = 0x000015311212efde, uuid_low = 0x1523785feabcd123)
9092

9193
def __init__(self, address, **kwargs):
9294
"""
@@ -115,16 +117,20 @@ def __init__(self, address, **kwargs):
115117

116118
self.board = libmetawear.mbl_mw_metawearboard_create(byref(self._btle_connection))
117119

120+
if 'deserialize' not in kwargs or kwargs['deserialize']:
121+
self.deserialize()
122+
118123
try:
119124
os.makedirs(self.cache)
120-
if 'deserialize' not in kwargs or kwargs['deserialize']:
121-
self.deserialize()
122125
except OSError as exception:
123126
if exception.errno != errno.EEXIST:
124127
raise
125128

126129
@property
127130
def in_metaboot_mode(self):
131+
"""
132+
True if the board is in MetaBoot mode. The only permitted operation for MetaBoot boards is to update the firmware
133+
"""
128134
return str(MetaWear._METABOOT_SERVICE) in self.services
129135

130136
def disconnect(self):
@@ -179,7 +185,10 @@ def _write_gatt_char(self, caller, write_type, ptr_gattchar, value, length):
179185
buffer.append(value[i])
180186

181187
handle = self.characteristics[_gattchar_to_string(ptr_gattchar.contents)]
182-
self.gatt.write_by_handle_async(handle, bytes(bytearray(buffer)), self.response)
188+
if self.in_metaboot_mode and ptr_gattchar.contents == MetaWear._METABOOT_CONTROL_POINT:
189+
self.gatt.write_by_handle_async(handle, bytes(bytearray(buffer)), self.response)
190+
else:
191+
self.gatt.write_cmd_by_handle(handle, bytes(bytearray(buffer)))
183192

184193
def _enable_notifications(self, caller, ptr_gattchar, handler, ready):
185194
handle = self.characteristics[_gattchar_to_string(ptr_gattchar.contents)]
@@ -190,7 +199,6 @@ def _enable_notifications(self, caller, ptr_gattchar, handler, ready):
190199
def _on_disconnect(self, caller, handler):
191200
pass
192201

193-
194202
def _download_firmware(self, version=None):
195203
firmware_root = os.path.join(self.cache, "firmware")
196204

setup.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import os
2-
import sys
31
from distutils.dir_util import copy_tree
42
from multiprocessing import cpu_count
53
from shutil import copy2
64
from subprocess import call, STDOUT
75
from setuptools import setup
86
from setuptools.command.build_py import build_py
97

10-
machine = "x64" if sys.maxsize > 2**32 else "x86"
8+
import os
9+
import platform
10+
import sys
11+
12+
machine = "arm" if "arm" in platform.machine() else ("x64" if sys.maxsize > 2**32 else "x86")
1113

1214
class MetaWearBuild(build_py):
1315
def run(self):
@@ -30,21 +32,25 @@ def run(self):
3032
setup(
3133
name='metawear',
3234
packages=['mbientlab', 'mbientlab.metawear'],
33-
version='0.1.1',
34-
description='Python bindings for the MetaWear C++ SDK',
35+
version='0.1.9',
36+
description='Python bindings for the MetaWear C++ SDK by MbientLab',
37+
long_description=open(os.path.join(os.path.dirname(__file__), "README.rst")).read(),
3538
package_data={'mbientlab.metawear': ['libmetawear.so*']},
3639
include_package_data=True,
3740
url='https://github.com/mbientlab/MetaWear-SDK-Python',
3841
author='MbientLab',
3942
author_email="[email protected]",
4043
install_requires=[
41-
'gattlib==0.20160216',
44+
'gattlib==0.20171002',
4245
'requests'
4346
],
4447
cmdclass={
4548
'build_py': MetaWearBuild,
4649
},
47-
dependency_links=['git+https://github.com/mbientlab/pygattlib.git@master#egg=gattlib-0.20160216'],
50+
dependency_links=[
51+
'git+https://github.com/mbientlab/pygattlib.git/@master#egg=gattlib-0.20171002',
52+
'git+https://github.com/mbientlab/pygattlib.git@master#egg=gattlib-0.20171002'
53+
],
4854
keywords = ['sensors', 'mbientlab', 'metawear', 'bluetooth le', 'native'],
4955
python_requires='>=2.7',
5056
classifiers=[

0 commit comments

Comments
 (0)