Skip to content

Commit

Permalink
Commit for v0.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
scaryghost committed Oct 3, 2017
1 parent 0a1fb75 commit cf8a421
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
7 changes: 5 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/mbientlab/MetaWear-SDK-Cpp>`_ so you will find the C++
`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
`examples <https://github.com/mbientlab/MetaWear-SDK-Python/tree/master/examples>`_ folder for full example scripts.
`examples <https://github.com/mbientlab/MetaWear-SDK-Python/tree/master/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 <https://github.com/mbientlab-projects/pymetawear>`_ **.**

Install
#######
Expand Down Expand Up @@ -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)
5 changes: 3 additions & 2 deletions examples/scan_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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): "
Expand All @@ -29,4 +29,5 @@
sleep(5.0)

device.disconnect()
sleep(1.0)
print("Disconnected")
16 changes: 12 additions & 4 deletions mbientlab/metawear/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)]
Expand All @@ -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")

Expand Down
20 changes: 13 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import os
import sys
from distutils.dir_util import copy_tree
from multiprocessing import cpu_count
from shutil import copy2
from subprocess import call, STDOUT
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):
Expand All @@ -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=[
Expand Down

0 comments on commit cf8a421

Please sign in to comment.