Skip to content

Commit

Permalink
Version 0.5.0, using CppAPI 0.5.22
Browse files Browse the repository at this point in the history
  • Loading branch information
hbldh committed Sep 15, 2016
1 parent 7a622c9 commit f67bd62
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 23 deletions.
13 changes: 13 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
v0.5.0 (2016-09-15)
===================
- Using MetaWear-CppAPI version 0.5.22
- Changed building procedure to handle ARM processors
- Updated requirements to make pygatt default, all others extras
- Bluepy backend implemented and partially working
- BL interface selection for all backends
- Magnetometer module
- Barometer module
- Ambient Light module
- Modifying notification wrappers to accommodate Epoch value in the data.
- High speed sampling for accelerometer and gyroscope

v0.4.4 (2016-04-28)
===================
- Updated MetaWear-CppAPI submodule version.
Expand Down
2 changes: 1 addition & 1 deletion pymetawear/Metawear-CppAPI
4 changes: 2 additions & 2 deletions pymetawear/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from pymetawear.utils import IS_64_BIT

# Version information.
__version__ = '0.5.0a4'
__version__ = '0.5.0'
version = __version__ # backwards compatibility name
version_info = (0, 5, 0, 'a4')
version_info = (0, 5, 0)

if os.environ.get('METAWEAR_LIB_SO_NAME') is not None:
libmetawear = cdll.LoadLibrary(os.environ["METAWEAR_LIB_SO_NAME"])
Expand Down
14 changes: 10 additions & 4 deletions pymetawear/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# from __future__ import unicode_literals
from __future__ import absolute_import

import os
import time
from ctypes import byref
import uuid
Expand All @@ -25,14 +26,15 @@

class BLECommunicationBackend(object):

def __init__(self, address, interface=None, async=True, timeout=None, debug=False):
def __init__(self, address, interface=None,
async=True, timeout=None, debug=False):
self._address = str(address)
self._interface = str(interface)
self._async = async
self._debug = debug
self._timeout = timeout

self._initialized = False
self._initialization_status = -1

self._requester = None

Expand Down Expand Up @@ -62,6 +64,10 @@ def __init__(self, address, interface=None, async=True, timeout=None, debug=Fals
# Now create a libmetawear board object and initialize it.
self.board = libmetawear.mbl_mw_metawearboard_create(
byref(self._btle_connection))

_response_time = os.environ.get('PYMETAWEAR_RESPONSE_TIME', 300)
libmetawear.mbl_mw_metawearboard_set_time_for_response(self.board, int(_response_time))

libmetawear.mbl_mw_metawearboard_initialize(
self.board, self.callbacks.get('initialization')[1])

Expand All @@ -76,7 +82,7 @@ def _build_handle_dict(self):

@property
def initialized(self):
return self._initialized
return self._initialization_status >= 0

@property
def requester(self):
Expand Down Expand Up @@ -153,7 +159,7 @@ def write_gatt_char_by_uuid(self, characteristic_uuid, data_to_send):
def _initialized_fcn(self, board, status):
if self._debug:
print("{0} initialized with status {1}.".format(self, status))
self._initialized = status == 0
self._initialization_status = status

def handle_notify_char_output(self, handle, value):
if self._debug:
Expand Down
2 changes: 1 addition & 1 deletion pymetawear/backends/bluepy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _is_connected(self):
@property
def initialized(self):
#self.requester.waitForNotifications(0.1)
return self._initialized
return self._initialization_status

@property
def requester(self):
Expand Down
13 changes: 12 additions & 1 deletion pymetawear/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from pymetawear import libmetawear, specs
from pymetawear.exceptions import *
from pymetawear import modules
from pymetawear.mbientlab.metawear.core import Status
try:
from pymetawear.backends.pygatt import PyGattBackend
except ImportError as e:
Expand Down Expand Up @@ -147,6 +148,15 @@ def __init__(self, address, backend='pygatt',
libmetawear.mbl_mw_metawearboard_is_initialized(self.board)):
self.backend.sleep(0.1)

# Check if initialization has been completed successfully.
if self.backend.initialized != Status.OK:
if self.backend._initialization_status == Status.ERROR_TIMEOUT:
raise PyMetaWearConnectionTimeout("libmetawear initialization status 16: Timeout")
else:
raise PyMetaWearException("libmetawear initialization status {0}".format(
self.backend._initialization_status))

# Read out firmware and model version.
self.firmware_version = tuple(
[int(x) for x in self.backend.read_gatt_char_by_uuid(
specs.DEV_INFO_FIRMWARE_CHAR[1]).decode().split('.')])
Expand Down Expand Up @@ -185,7 +195,8 @@ def __init__(self, address, backend='pygatt',
self.led = modules.LEDModule(self.board, debug=self._debug)

def __str__(self):
return "MetaWearClient, {0}".format(self._address)
return "MetaWearClient, {0}, Model: {1}, Firmware: {2}.{3}.{4}".format(
self._address, self.model_version, *self.firmware_version)

def __repr__(self):
return "<MetaWearClient, {0}>".format(self._address)
Expand Down
2 changes: 1 addition & 1 deletion pymetawear/modules/magnetometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def require_bmm150(f):
def wrapper(*args, **kwargs):
if getattr(args[0], 'mag_class', None) is None:
raise PyMetaWearException("There is not Magnetometer "
"module of your MetaWear board!")
"module on your MetaWear board!")
return f(*args, **kwargs)

return wrapper
Expand Down
16 changes: 3 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def build_solution():
arch = os.uname()[-1]
if arch in ('x86_64', 'amd64'):
dist_dir = 'x64'
elif arch == 'armv7l':
elif 'arm' in arch:
dist_dir = 'arm'
else:
dist_dir = 'x86'
Expand All @@ -65,17 +65,6 @@ def build_solution():
cwd=basedir, stdout=sys.stdout, stderr=sys.stderr)
p.communicate()

# Increase TIME_PER_COMMAND in MetaWear-CppAPI by pre-build
# patching of constants.h.
constants_h_file = os.path.join(
pkg_dir, 'Metawear-CppAPI', 'src', 'metawear',
'core', 'cpp', 'constant.h')
with open(constants_h_file, 'rt') as f:
t = f.read()
t = t.replace('TIME_PER_COMMAND = 150', 'TIME_PER_COMMAND = 300')
with open(constants_h_file, 'wt') as f:
f.write(t)

# Run make file for MetaWear-CppAPI
p = subprocess.Popen(
['make', 'clean'],
Expand Down Expand Up @@ -167,7 +156,8 @@ def read(f):
'build_py': PyMetaWearBuilder,
'develop': PyMetaWearDeveloper
},
packages=find_packages(exclude=['tests', 'docs', 'examples']),
packages=find_packages(exclude=['tests', 'docs', 'examples', 'examples.*']),
include_package_data=True,
# Adding MbientLab's Python code as package data since it is copied
# to folder after ``find_packages`` is run.
package_data={
Expand Down

0 comments on commit f67bd62

Please sign in to comment.