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

Commit 0a1fb75

Browse files
committed
commit for v0.1.1
1 parent e90ae0a commit 0a1fb75

File tree

12 files changed

+576
-10
lines changed

12 files changed

+576
-10
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/build/
2+
/dist/
23
/metawear.egg-info/
34
mbientlab/metawear/*.so*
45
mbientlab/metawear/cbindings.py
56
*.pyc
7+
.metawear

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "MetaWear-SDK-Cpp"]
22
path = MetaWear-SDK-Cpp
3-
url = git@github.com:mbientlab/MetaWear-SDK-Cpp.git
3+
url = https://github.com/mbientlab/MetaWear-SDK-Cpp.git

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright 2014-2017 MbientLab Inc. All rights reserved.
2+
3+
IMPORTANT: Your use of this Software is limited to those specific rights granted under the terms of a software
4+
license agreement between the user who downloaded the software, his/her employer (which must be your
5+
employer) and MbientLab Inc, (the "License"). You may not use this Software unless you agree to abide by the
6+
terms of the License which can be found at www.mbientlab.com/terms. The License limits your use, and you
7+
acknowledge, that the Software may be modified, copied, and distributed when used in conjunction with an
8+
MbientLab Inc, product. Other than for the foregoing purpose, you may not use, reproduce, copy, prepare
9+
derivative works of, modify, distribute, perform, display or sell this Software and/or its documentation for any
10+
purpose.
11+
12+
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY
13+
OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
14+
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MBIENTLAB OR ITS LICENSORS BE LIABLE OR
15+
OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE
16+
THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT,
17+
PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY,
18+
SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
19+
20+
Should you have any questions regarding your right to use this Software, contact MbientLab via email:
21+

MANIFEST.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
include LICENSE.txt
2+
include README.rst
3+
4+
recursive-include MetaWear-SDK-Cpp *
5+
prune MetaWear-SDK-Cpp/.git
6+
prune MetaWear-SDK-Cpp/build
7+
prune MetaWear-SDK-Cpp/dist
8+
9+
recursive-include mbientlab *.py
10+
recursive-include examples *.py
11+
12+
recursive-exclude * __pycache__
13+
recursive-exclude * *.py[co]

README.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
MetaWear Python SDK
2+
###################
3+
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++
4+
`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.
6+
7+
Install
8+
#######
9+
Use pip to install the metawear package. It depends on `pygattlib <https://bitbucket.org/OscarAcena/pygattlib>`_ so ensure your Linux environment first has the necessary
10+
`dependencies <https://bitbucket.org/OscarAcena/pygattlib/src/a858e8626a93cb9b4ad56f3fb980a6517a0702c6/DEPENDS?at=default&fileviewer=file-view-default>`_ installed.
11+
12+
.. code-block:: bash
13+
14+
pip install metawear --process-dependency-links
15+
16+
Usage
17+
#####
18+
Import the MetaWear class and libmetawear variable from the metawear module and everything from the cbindings module.
19+
20+
.. code-block:: python
21+
22+
from mbientlab.metawear import MetaWear, libmetawear
23+
from mbientlab.metawear.cbindings import *
24+
25+
If you do not know the MAC address of your device, use ``pygattlib`` to scan for nearby devices.
26+
27+
.. code-block:: python
28+
29+
from gattlib import DiscoveryService
30+
service = DiscoveryService("hci0")
31+
devices = service.discover(2)
32+
33+
# grab the first scanned device
34+
address = devices.items()[0][0]
35+
36+
Once you have the device's MAC address, create a MetaWear object with the MAC address and connect to the device.
37+
38+
.. code-block:: python
39+
40+
device = MetaWear(address)
41+
status = device.connect()
42+
43+
Upon a successful connection, you can begin calling any of the functions from the C++ SDK, for example, blinking the LED green.
44+
45+
.. code-block:: python
46+
47+
pattern= LedPattern(repeat_count= Const.LED_REPEAT_INDEFINITELY)
48+
libmetawear.mbl_mw_led_load_preset_pattern(byref(pattern), LedPreset.SOLID)
49+
libmetawear.mbl_mw_led_write_pattern(device.board, byref(pattern), LedColor.GREEN)
50+
libmetawear.mbl_mw_led_play(device.board)

examples/led.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from mbientlab.metawear import MetaWear, libmetawear
2+
from mbientlab.metawear.cbindings import *
3+
from time import sleep
4+
from threading import Event
5+
6+
import sys
7+
8+
device = MetaWear(sys.argv[1])
9+
device.connect()
10+
print("Connected")
11+
12+
pattern= LedPattern(repeat_count= Const.LED_REPEAT_INDEFINITELY)
13+
libmetawear.mbl_mw_led_load_preset_pattern(byref(pattern), LedPreset.SOLID)
14+
libmetawear.mbl_mw_led_write_pattern(device.board, byref(pattern), LedColor.GREEN)
15+
libmetawear.mbl_mw_led_play(device.board)
16+
17+
sleep(5.0)
18+
19+
libmetawear.mbl_mw_led_stop_and_clear(device.board)
20+
sleep(1.0)
21+
22+
device.disconnect()
23+
sleep(1.0)

examples/multi_device.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from mbientlab.metawear import MetaWear, libmetawear, parse_value
2+
from mbientlab.metawear.cbindings import *
3+
from time import sleep
4+
from threading import Event
5+
6+
import platform
7+
import sys
8+
9+
class State:
10+
def __init__(self, device):
11+
self.device = device
12+
self.samples = 0
13+
self.callback = FnVoid_DataP(self.data_handler)
14+
15+
def data_handler(self, data):
16+
print("%s -> %s" % (self.device.address, parse_value(data)))
17+
self.samples+= 1
18+
19+
states = []
20+
for i in xrange(len(sys.argv) - 1):
21+
d = MetaWear(sys.argv[i + 1])
22+
d.connect()
23+
print("Connected to " + d.address)
24+
states.append(State(d))
25+
26+
for s in states:
27+
print("configuring device")
28+
libmetawear.mbl_mw_settings_set_connection_parameters(s.device.board, 7.5, 7.5, 0, 6000);
29+
libmetawear.mbl_mw_acc_set_odr(s.device.board, 25.0);
30+
libmetawear.mbl_mw_acc_set_range(s.device.board, 16.0);
31+
libmetawear.mbl_mw_acc_write_acceleration_config(s.device.board);
32+
33+
signal = libmetawear.mbl_mw_acc_get_acceleration_data_signal(s.device.board)
34+
libmetawear.mbl_mw_datasignal_subscribe(signal, s.callback)
35+
36+
libmetawear.mbl_mw_acc_enable_acceleration_sampling(s.device.board);
37+
libmetawear.mbl_mw_acc_start(s.device.board);
38+
39+
sleep(30.0)
40+
41+
for s in states:
42+
libmetawear.mbl_mw_acc_stop(s.device.board)
43+
libmetawear.mbl_mw_acc_disable_acceleration_sampling(s.device.board)
44+
45+
signal = libmetawear.mbl_mw_acc_get_acceleration_data_signal(s.device.board)
46+
libmetawear.mbl_mw_datasignal_unsubscribe(signal)
47+
libmetawear.mbl_mw_debug_disconnect(s.device.board)
48+
49+
sleep(1.0)
50+
51+
print("Total Samples Received")
52+
for s in states:
53+
print("%s -> %d" % (s.device.address, s.samples))

examples/scan_connect.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from mbientlab.metawear import MetaWear
2+
from mbientlab.metawear.cbindings import *
3+
from gattlib import DiscoveryService
4+
from time import sleep
5+
6+
import platform
7+
8+
selection = -1
9+
devices = None
10+
11+
while selection == -1:
12+
service = DiscoveryService("hci0")
13+
devices = service.discover(2)
14+
15+
i = 0
16+
for address, name in devices.items():
17+
print("[%d] %s" % (i, address))
18+
i+= 1
19+
20+
msg = "Select your device (-1 to rescan): "
21+
selection = int(raw_input(msg) if platform.python_version_tuple()[0] == '2' else input(msg))
22+
23+
address = list(devices)[selection]
24+
print("Connecting to %s..." % (address))
25+
device = MetaWear(address)
26+
device.connect()
27+
28+
print("Connected")
29+
sleep(5.0)
30+
31+
device.disconnect()
32+
print("Disconnected")

mbientlab/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)