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

Commit 0c16a98

Browse files
committed
api v0.5.0 commit
1 parent 805bec6 commit 0c16a98

File tree

6 files changed

+75
-44
lines changed

6 files changed

+75
-44
lines changed

MANIFEST.in

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
include LICENSE.txt
22
include README.rst
33

4-
recursive-include MetaWear-SDK-Cpp *
5-
prune MetaWear-SDK-Cpp/.git
4+
graft MetaWear-SDK-Cpp
5+
prune MetaWear-SDK-Cpp/bindings/javascript
6+
prune MetaWear-SDK-Cpp/bindings/swift
7+
prune MetaWear-SDK-Cpp/cppdocs
68
prune MetaWear-SDK-Cpp/build
79
prune MetaWear-SDK-Cpp/dist
10+
prune MetaWear-SDK-Cpp/Debug
11+
prune MetaWear-SDK-Cpp/Release
12+
prune MetaWear-SDK-Cpp/x64
813

9-
recursive-include mbientlab *.py
10-
recursive-include examples *.py
14+
graft mbientlab
15+
recursive-exclude mbientlab/metawear cbindings.py
1116

12-
recursive-exclude * __pycache__
13-
recursive-exclude * *.py[co]
17+
global-exclude *.git
18+
global-exclude *.gitmodules
19+
global-exclude *.gitignore
20+
global-exclude __pycache__
21+
global-exclude *.py[co]
22+
global-exclude *.d
23+
global-exclude *.o
24+
global-exclude *.so*
25+
global-exclude *.dll
26+
global-exclude *.a

README.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,23 @@ If you do not know the MAC address of your device, use ``PyWarble`` to scan for
2929
.. code-block:: python
3030
3131
from mbientlab.warble import *
32+
from mbientlab.metawear import *
3233
from threading import Event
3334
3435
e = Event()
3536
address = None
3637
def device_discover_task(result):
3738
global address
38-
# grab the first discoered device
39-
address = result.mac
40-
e.set()
39+
if (result.has_service_uuid(MetaWear.GATT_SERVICE)):
40+
# grab the first discovered metawear device
41+
address = result.mac
42+
e.set()
4143
42-
BleScanner.set_handler(scan_result_printer)
44+
BleScanner.set_handler(device_discover_task)
4345
BleScanner.start()
4446
e.wait()
47+
48+
BleScanner.stop()
4549
4650
Once you have the device's MAC address, create a MetaWear object with the MAC address and connect to the device.
4751

mbientlab/metawear/__init__.py

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,35 @@
1616

1717
from .metawear import MetaWear
1818

19+
_value_parsers = {
20+
DataTypeId.UINT32: lambda p: cast(p.contents.value, POINTER(c_uint)).contents.value,
21+
DataTypeId.INT32: lambda p: cast(p.contents.value, POINTER(c_int)).contents.value,
22+
DataTypeId.FLOAT: lambda p: cast(p.contents.value, POINTER(c_float)).contents.value,
23+
DataTypeId.CARTESIAN_FLOAT: lambda p: cast(p.contents.value, POINTER(CartesianFloat)).contents,
24+
DataTypeId.BATTERY_STATE: lambda p: cast(p.contents.value, POINTER(BatteryState)).contents,
25+
DataTypeId.TCS34725_ADC: lambda p: cast(p.contents.value, POINTER(Tcs34725ColorAdc)).contents,
26+
DataTypeId.EULER_ANGLE: lambda p: cast(p.contents.value, POINTER(EulerAngles)).contents,
27+
DataTypeId.QUATERNION: lambda p: cast(p.contents.value, POINTER(Quaternion)).contents,
28+
DataTypeId.CORRECTED_CARTESIAN_FLOAT: lambda p: cast(p.contents.value, POINTER(CorrectedCartesianFloat)).contents,
29+
DataTypeId.OVERFLOW_STATE: lambda p: cast(p.contents.value, POINTER(OverflowState)).contents,
30+
DataTypeId.LOGGING_TIME: lambda p: cast(p.contents.value, POINTER(LoggingTime)).contents,
31+
DataTypeId.BTLE_ADDRESS: lambda p: cast(p.contents.value, POINTER(BtleAddress)).contents,
32+
DataTypeId.BOSCH_ANY_MOTION: lambda p: cast(p.contents.value, POINTER(BoschAnyMotion)).contents,
33+
DataTypeId.CALIBRATION_STATE: lambda p: cast(p.contents.value, POINTER(CalibrationState)).contents
34+
}
1935
def parse_value(p_data):
2036
"""
2137
Helper function to extract the value from a Data object. If you are storing the values to be used at a later time,
2238
call copy.deepcopy preserve the value. You do not need to do this if the underlying type is a native type or a byte array
2339
@params:
2440
p_data - Required : Pointer to a Data object
2541
"""
26-
if (p_data.contents.type_id == DataTypeId.UINT32):
27-
return cast(p_data.contents.value, POINTER(c_uint)).contents.value
28-
elif (p_data.contents.type_id == DataTypeId.INT32 or p_data.contents.type_id == DataTypeId.SENSOR_ORIENTATION):
29-
return cast(p_data.contents.value, POINTER(c_int)).contents.value
30-
elif (p_data.contents.type_id == DataTypeId.FLOAT):
31-
return cast(p_data.contents.value, POINTER(c_float)).contents.value
32-
elif (p_data.contents.type_id == DataTypeId.CARTESIAN_FLOAT):
33-
return cast(p_data.contents.value, POINTER(CartesianFloat)).contents
34-
elif (p_data.contents.type_id == DataTypeId.BATTERY_STATE):
35-
return cast(p_data.contents.value, POINTER(BatteryState)).contents
42+
if (p_data.contents.type_id in _value_parsers):
43+
return _value_parsers[p_data.contents.type_id](p_data)
44+
elif (p_data.contents.type_id == DataTypeId.SENSOR_ORIENTATION):
45+
return _value_parsers[DataTypeId.INT32](p_data)
3646
elif (p_data.contents.type_id == DataTypeId.BYTE_ARRAY):
37-
p_data_ptr= cast(p_data.contents.value, POINTER(c_ubyte * p_data.contents.length))
38-
39-
byte_array= []
40-
for i in range(0, p_data.contents.length):
41-
byte_array.append(p_data_ptr.contents[i])
42-
return byte_array
43-
elif (p_data.contents.type_id == DataTypeId.TCS34725_ADC):
44-
return cast(p_data.contents.value, POINTER(Tcs34725ColorAdc)).contents
45-
elif (p_data.contents.type_id == DataTypeId.EULER_ANGLE):
46-
return cast(p_data.contents.value, POINTER(EulerAngles)).contents
47-
elif (p_data.contents.type_id == DataTypeId.QUATERNION):
48-
return cast(p_data.contents.value, POINTER(Quaternion)).contents
49-
elif (p_data.contents.type_id == DataTypeId.CORRECTED_CARTESIAN_FLOAT):
50-
return cast(p_data.contents.value, POINTER(CorrectedCartesianFloat)).contents
51-
elif (p_data.contents.type_id == DataTypeId.OVERFLOW_STATE):
52-
return cast(p_data.contents.value, POINTER(OverflowState)).contents
47+
array_ptr= cast(p_data.contents.value, POINTER(c_ubyte * p_data.contents.length))
48+
return [array_ptr.contents[i] for i in range(0, p_data.contents.length)]
5349
else:
5450
raise RuntimeError('Unrecognized data type id: ' + str(p_data.contents.type_id))

mbientlab/metawear/metawear.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def _download_file(url, dest):
4848
return content
4949

5050
class MetaWear(object):
51-
_METABOOT_SERVICE = "00001530-1212-efde-1523-785feabcd123"
51+
GATT_SERVICE = "326a9000-85cb-9195-d9dd-464cfbbae75a"
5252
_DEV_INFO = {
5353
"00002a27-0000-1000-8000-00805f9b34fb": "hardware",
5454
"00002a29-0000-1000-8000-00805f9b34fb": "manufacturer",
@@ -117,7 +117,7 @@ def in_metaboot_mode(self):
117117
"""
118118
True if the board is in MetaBoot mode. The only permitted operation for MetaBoot boards is to update the firmware
119119
"""
120-
return self.warble.service_exists(MetaWear._METABOOT_SERVICE)
120+
return self.warble.service_exists("00001530-1212-efde-1523-785feabcd123")
121121

122122
def disconnect(self):
123123
"""

setup.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from distutils.command.clean import clean
12
from multiprocessing import cpu_count
23
from shutil import copy2, move
34
from subprocess import call, STDOUT
@@ -9,6 +10,23 @@
910
import sys
1011

1112
machine = "arm" if "arm" in platform.machine() else ("x64" if sys.maxsize > 2**32 else "x86")
13+
root = os.path.dirname(os.path.abspath(__file__))
14+
dest = os.path.join("mbientlab", "metawear")
15+
16+
class MetaWearClean(clean):
17+
def run(self):
18+
bindings = os.path.join(dest, "cbindings.py")
19+
if os.path.isfile(bindings):
20+
os.remove(bindings)
21+
22+
if (platform.system() == 'Windows'):
23+
dll = os.path.join(dest, "MetaWear.Win32.dll")
24+
if os.path.isfile(dll):
25+
os.remove(dll)
26+
elif (platform.system() == 'Linux'):
27+
for f in os.listdir(dest):
28+
if (f.startswith("libmetawear.so")):
29+
os.remove(os.path.join(dest, f))
1230

1331
class MetaWearBuild(build_py):
1432
@staticmethod
@@ -17,9 +35,7 @@ def _move(src, dest, basename):
1735
if (f.startswith(basename)):
1836
move(os.path.join(src, f), dest)
1937

20-
def run(self):
21-
root = os.path.dirname(os.path.abspath(__file__))
22-
dest = os.path.join("mbientlab", "metawear")
38+
def run(self):
2339
cpp_sdk = os.path.join(root, 'MetaWear-SDK-Cpp')
2440
dist_dir = os.path.join(cpp_sdk, 'dist', 'release', 'lib', machine)
2541

@@ -49,7 +65,7 @@ def run(self):
4965
setup(
5066
name='metawear',
5167
packages=['mbientlab', 'mbientlab.metawear'],
52-
version='0.4.0',
68+
version='0.5.0',
5369
description='Python bindings for the MetaWear C++ SDK by MbientLab',
5470
long_description=open(os.path.join(os.path.dirname(__file__), "README.rst")).read(),
5571
package_data={'mbientlab.metawear': so_pkg_data},
@@ -58,18 +74,20 @@ def run(self):
5874
author='MbientLab',
5975
author_email="[email protected]",
6076
install_requires=[
61-
'warble >= 1.0, < 2.0',
77+
'warble >= 1.1, < 2.0',
6278
'requests'
6379
],
6480
cmdclass={
6581
'build_py': MetaWearBuild,
82+
'clean': MetaWearClean
6683
},
6784
keywords = ['sensors', 'mbientlab', 'metawear', 'bluetooth le', 'native'],
6885
python_requires='>=2.7',
6986
classifiers=[
7087
'Development Status :: 4 - Beta',
7188
'Intended Audience :: Developers',
7289
'Operating System :: POSIX :: Linux',
90+
'Operating System :: Microsoft :: Windows :: Windows 10',
7391
'Programming Language :: Python :: 2.7',
7492
'Programming Language :: Python :: 3',
7593
]

0 commit comments

Comments
 (0)