Skip to content

Commit

Permalink
Version 0.10.0
Browse files Browse the repository at this point in the history
Added logging support for acc, gyro, mag and sensor fusion modules.
Locked metawear package to 0.3.1.
Added documentation and examples.
  • Loading branch information
hbldh committed Jun 18, 2018
2 parents 1cc12ac + 83329a2 commit f0811ff
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 107 deletions.
9 changes: 8 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
History
=======

v0.10.0 (2018-06-18)
--------------------
- Added support for data logging, thanks to ``dmatthes1982`` (#32, #46, #48, #49)
- Locked ``metawear`` version to ``0.3.1``
- Documentation for data logging
- Fixes for code examples and documentation examples.

v0.9.1 (2018-04-02)
-------------------
- Fix for documentation and README
Expand All @@ -19,7 +26,7 @@ v0.8.0 (2017-07-04)
v0.7.1 (2017-02-04)
-------------------
- Using MetaWear-CppAPI version 0.7.10
- Sensor fusion module contributed from user m-georgi (#26).
- Sensor fusion module contributed from user ``m-georgi`` (#26).
- Fix to magnetometer power preset setting due to
change in MetaWear-CppAPI (#25).

Expand Down
3 changes: 2 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name = "pypi"
[packages]

gattlib = {git = "https://github.com/mbientlab/pygattlib"}
metawear = "*"
metawear = "==0.3.1"
tqdm = "*"


Expand All @@ -18,3 +18,4 @@ pytest = "*"
sphinx = "*"
sphinx-rtd-theme = "*"
pylint = "*"
"flake8" = "*"
2 changes: 0 additions & 2 deletions docs/source/exceptions.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
Exceptions
==========

These are the PyMetaWear specific exceptions.

.. automodule:: pymetawear.exceptions
:members:
30 changes: 21 additions & 9 deletions docs/source/modules/accelerometer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ attribute of the client.
Data streaming example
----------------------

If you need a real time stream of sensor data, use the :py:method:`notifications` method on the :py:mod:`accelerometer` module:
If you need a real time stream of sensor data, use the :py:func:`notifications` method on the :py:mod:`accelerometer` module:

.. code-block:: python
Expand All @@ -35,11 +35,14 @@ Logging example
---------------

If you want to log data to the MetaWear board and retrieve it after some time, then use the
:py:method:`start_logging`, :py:method:`stop_logging` and :py:method:`download_log` methods:
:py:func:`start_logging`, :py:func:`stop_logging` and :py:func:`download_log` methods:

.. code-block:: python
import os
import json
import time
from pymetawear.client import MetaWearClient
from pymetawear.exceptions import PyMetaWearException, PyMetaWearDownloadTimeout
Expand All @@ -49,35 +52,44 @@ If you want to log data to the MetaWear board and retrieve it after some time, t
c.accelerometer.set_settings(data_rate=200.0, data_range=8)
# Log data for 10 seconds.
client.accelerometer.start_logging()
c.accelerometer.start_logging()
print("Logging accelerometer data...")
time.sleep(10.0)
client.accelerometer.stop_logging()
c.accelerometer.stop_logging()
print("Finished logging.")
# Download the stored data from the MetaWear board.
print("Downloading data...")
download_done = False
n = 0
data = None
while download_done and n < 3:
while (not download_done) and n < 3:
try:
data = client.accelerometer.download_log()
data = c.accelerometer.download_log()
download_done = True
except PyMetaWearDownloadTimeout:
print("Download of log interrupted. Trying to reconnect...")
client.disconnect()
client.connect()
c.disconnect()
c.connect()
n += 1
if data is None:
raise PyMetaWearException("Download of logging data failed.")
print("Disconnecting...")
client.disconnect()
c.disconnect()
# Save the logged data.
class MetaWearDataEncoder(json.JSONEncoder):
"""JSON Encoder for converting ``mbientlab`` module's CartesianFloat
class to data tuple ``(x,y,z)``."""
def default(self, o):
if isinstance(o, CartesianFloat):
return o.x, o.y, o.z
else:
return super(MetaWearDataEncoder, self).default(o)
data_file = os.path.join(os.getcwd(), "logged_data.json")
print("Saving the data to file: {0}".format(data_file))
with open("logged_data.json", "wt") as f:
Expand Down
4 changes: 2 additions & 2 deletions docs/source/modules/ambientlight.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. _modules_accelerometer:
.. _modules_ambientlight:

Ambient light module
====================
Expand All @@ -13,7 +13,7 @@ attribute of the client.
Data streaming example
----------------------

If you need a real time stream of sensor data, use the :py:method:`notifications` method on the :py:mod:`ambient_light` module:
If you need a real time stream of sensor data, use the :py:func:`notifications` method on the :py:mod:`ambient_light` module:

.. code-block:: python
Expand Down
32 changes: 22 additions & 10 deletions docs/source/modules/gyroscope.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The only MetaWear gyroscope available is the BMI160 sensor.
Data streaming example
----------------------

If you need a real time stream of sensor data, use the :py:method:`notifications` method on the :py:mod:`gyroscope` module:
If you need a real time stream of sensor data, use the :py:func:`notifications` method on the :py:mod:`gyroscope` module:

.. code-block:: python
Expand All @@ -36,12 +36,15 @@ If you need a real time stream of sensor data, use the :py:method:`notifications
Logging Example
---------------

If you want to log data to the MetaWear board and retrieve it after some time, then use the
:py:method:`start_logging`, :py:method:`stop_logging` and :py:method:`download_log` methods:
If you want to log data to the MetaWear board and retrieve it after some time, then use the
:py:func:`start_logging`, :py:func:`stop_logging` and :py:func:`download_log` methods:

.. code-block:: python
import os
import json
import time
from pymetawear.client import MetaWearClient
from pymetawear.exceptions import PyMetaWearException, PyMetaWearDownloadTimeout
Expand All @@ -51,35 +54,44 @@ If you want to log data to the MetaWear board and retrieve it after some time, t
c.gyroscope.set_settings(data_rate=200.0, data_range=1000.0)
# Log data for 10 seconds.
client.gyroscope.start_logging()
c.gyroscope.start_logging()
print("Logging gyroscope data...")
time.sleep(10.0)
client.gyroscope.stop_logging()
c.gyroscope.stop_logging()
print("Finished logging.")
# Download the stored data from the MetaWear board.
print("Downloading data...")
download_done = False
n = 0
data = None
while download_done and n < 3:
while (not download_done) and n < 3:
try:
data = client.gyroscope.download_log()
data = c.gyroscope.download_log()
download_done = True
except PyMetaWearDownloadTimeout:
print("Download of log interrupted. Trying to reconnect...")
client.disconnect()
client.connect()
c.disconnect()
c.connect()
n += 1
if data is None:
raise PyMetaWearException("Download of logging data failed.")
print("Disconnecting...")
client.disconnect()
c.disconnect()
# Save the logged data.
class MetaWearDataEncoder(json.JSONEncoder):
"""JSON Encoder for converting ``mbientlab`` module's CartesianFloat
class to data tuple ``(x,y,z)``."""
def default(self, o):
if isinstance(o, CartesianFloat):
return o.x, o.y, o.z
else:
return super(MetaWearDataEncoder, self).default(o)
data_file = os.path.join(os.getcwd(), "logged_data.json")
print("Saving the data to file: {0}".format(data_file))
with open("logged_data.json", "wt") as f:
Expand Down
35 changes: 24 additions & 11 deletions docs/source/modules/magnetometer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ It is initialized at the creation of the :py:class:`~MetaWearClient`
client and can then be accessed in the ``magnetometer``
attribute of the client.

Example streaming data
Data streaming example
----------------------

If you need a real time stream of sensor data, use the :py:method:`notifications` method on the :py:mod:`magnetometer` module:
If you need a real time stream of sensor data, use the
:py:func:`notifications` method on the :py:mod:`magnetometer` module:

.. code-block:: python
Expand All @@ -36,12 +37,15 @@ If you need a real time stream of sensor data, use the :py:method:`notifications
Logging Example
---------------

If you want to log data to the MetaWear board and retrieve it after some time, then use the
:py:method:`start_logging`, :py:method:`stop_logging` and :py:method:`download_log` methods:
If you want to log data to the MetaWear board and retrieve it after some time, then use the
:py:func:`start_logging`, :py:func:`stop_logging` and :py:func:`download_log` methods:

.. code-block:: python
import os
import json
import time
from pymetawear.client import MetaWearClient
from pymetawear.exceptions import PyMetaWearException, PyMetaWearDownloadTimeout
Expand All @@ -51,35 +55,44 @@ If you want to log data to the MetaWear board and retrieve it after some time, t
c.magnetometer.set_settings(power_preset='low_power')
# Log data for 10 seconds.
client.magnetometer.start_logging()
c.magnetometer.start_logging()
print("Logging magnetometer data...")
time.sleep(10.0)
client.magnetometer.stop_logging()
c.magnetometer.stop_logging()
print("Finished logging.")
# Download the stored data from the MetaWear board.
print("Downloading data...")
download_done = False
n = 0
data = None
while download_done and n < 3:
while (not download_done) and n < 3:
try:
data = client.magnetometer.download_log()
data = c.magnetometer.download_log()
download_done = True
except PyMetaWearDownloadTimeout:
print("Download of log interrupted. Trying to reconnect...")
client.disconnect()
client.connect()
c.disconnect()
c.connect()
n += 1
if data is None:
raise PyMetaWearException("Download of logging data failed.")
print("Disconnecting...")
client.disconnect()
c.disconnect()
# Save the logged data.
class MetaWearDataEncoder(json.JSONEncoder):
"""JSON Encoder for converting ``mbientlab`` module's CartesianFloat
class to data tuple ``(x,y,z)``."""
def default(self, o):
if isinstance(o, CartesianFloat):
return o.x, o.y, o.z
else:
return super(MetaWearDataEncoder, self).default(o)
data_file = os.path.join(os.getcwd(), "logged_data.json")
print("Saving the data to file: {0}".format(data_file))
with open("logged_data.json", "wt") as f:
Expand Down
2 changes: 1 addition & 1 deletion examples/accelerometer_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
download_done = False
n = 0
data = None
while download_done and n < 3:
while (not download_done) and n < 3:
try:
data = client.accelerometer.download_log()
download_done = True
Expand Down
4 changes: 0 additions & 4 deletions examples/magnetometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@

time.sleep(1.0)

#print("Check accelerometer settings...")
#settings = c.accelerometer.get_current_settings()
#print(settings)

print("Subscribing to magnetometer signal notifications...")
c.magnetometer.notifications(lambda data: print(data))

Expand Down
1 change: 1 addition & 0 deletions pymetawear/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Main module for PyMetaWear
.. moduleauthor:: hbldh <henrik.blidh@nedomkull.com>
Expand Down
3 changes: 1 addition & 2 deletions pymetawear/discover.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
discover
--------
Performing BLE scans
:copyright: 2016-11-29 by hbldh <henrik.blidh@nedomkull.com>
Expand Down
3 changes: 1 addition & 2 deletions pymetawear/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
exceptions
----------
Specific exceptions for PyMetaWear
Created by hbldh <henrik.blidh@nedomkull.com> on 2016-03-30
Expand Down
2 changes: 0 additions & 2 deletions pymetawear/modules/accelerometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@

import re
import logging
import time
from ctypes import c_float

from pymetawear import libmetawear
from pymetawear.exceptions import PyMetaWearException
from mbientlab.metawear.cbindings import AccBma255Odr, AccBmi160Odr, \
AccBmi160StepCounterMode, AccBoschOrientationMode, AccBoschRange, \
AccMma8452qOdr, AccMma8452qRange, Const
Expand Down

0 comments on commit f0811ff

Please sign in to comment.