diff --git a/README.md b/README.md index c404a8c..4a03cef 100644 --- a/README.md +++ b/README.md @@ -167,7 +167,7 @@ getTemperature #### Example 5: record motion data on chip To record, and playback a specific motion feature: ``` -eraseStorage //erase the on-chip recorder (optional) +eraseStorage 0 //erase the on-chip recorder (optional), 0: quick erase, 1: mass erase sessionRecordQuaternion //by default, the streaming frequency is 50 Hz. sessionPlayback //use the same session ID as returned by the record command ``` diff --git a/docs/img/record_data.png b/docs/img/record_data.png index 1bac5e0..b16b414 100644 Binary files a/docs/img/record_data.png and b/docs/img/record_data.png differ diff --git a/examples/streamRecord.py b/examples/streamRecord.py new file mode 100644 index 0000000..1bc473c --- /dev/null +++ b/examples/streamRecord.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python +################################################################################### +# +# Copyright (c) 2010-2016 Motsai +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +################################################################################### + +import getopt +import signal +import sys +import time + +from neblina import * +from neblinaAPI import NeblinaAPI + +################################################################################### + + +class GracefulKiller: + isKilled = False + + def __init__(self): + signal.signal(signal.SIGINT, self.exit) + signal.signal(signal.SIGTERM, self.exit) + + def exit(self, signum, frame): + print("Signal received: {0}.".format(signum)) + self.isKilled = True + +################################################################################### + + +def main(address): + signalKiller = GracefulKiller() + + print("Initialize NeblinaAPI") + api = NeblinaAPI(Interface.UART) + print("Setting up the connection...") # initial delay needed for the device to synchronize its processors + time.sleep(1) + print('.') + time.sleep(1) + print('.') + time.sleep(1) + print('.') + api.open(address) + api.streamDisableAll() # disable all streaming options after storing the initial state + api.setDataPortState(Interface.BLE, False) # Close BLE streaming to prevent slowed streaming + api.setDataPortState(Interface.UART, True) # Open UART streaming + + print("Starting the Quaternion Streaming...") + api.streamQuaternion(True) + print("Starting the IMU Data Streaming...") + api.streamIMU(True) + print("Starting the Recording...") + api.sessionRecord(True) + print("Exiting...") + +################################################################################### + + +def printArguments(): + print("Neblina quaternion stream v1.0.0") + print("Copyright Motsai 2010-2016") + print("") + print("Neblina commands:") + print(" -h --help : Display available commands.") + print(" -a --address: Device address to use (COM port)") + +################################################################################### + +if __name__ == '__main__': + try: + opts, args = getopt.getopt(sys.argv[1:], "ha:") + except getopt.GetoptError: + printArguments() + sys.exit() + + for opt, arg in opts: + if opt in ("-h", "--help"): + printArguments() + sys.exit() + elif opt in ("-a", "--address"): + main(arg) + sys.exit() + + print("No device address specified. Exiting.") + + diff --git a/examples/streammenu.py b/examples/streammenu.py index 46cb28c..0103ffd 100644 --- a/examples/streammenu.py +++ b/examples/streammenu.py @@ -234,6 +234,17 @@ def do_streamEulerAngle(self, args): print(self.api.getEulerAngle()) self.api.streamEulerAngle(False) + def do_streamMotionState(self, args): + """ + Stream MotionState until stopped with Ctrl+C + + Usage: >>streamMotionState + """ + self.api.streamMotionState(True) + while not self.signalKiller.isKilled: + print(self.api.getMotionState()) + self.api.streamMotionState(False) + def do_streamIMU(self, args): """ Stream 6-axis IMU (Inertial Measurement Unit) until stopped with Ctrl+C @@ -550,6 +561,15 @@ def do_sessionPlayback(self, args): self.api.sessionPlayback(mySessionID, dump) print("sessionPlayback completed") + def do_streamRSSI(self, args): + """ + Stream BLE's RSSI until stopped with Ctrl+C + + Usage: >>streamRSSI + """ + while not self.signalKiller.isKilled: + print(self.api.getRSSI()) + def do_getFirmwareVersions(self, args): """ Retrieve firmware versions diff --git a/neblina.py b/neblina.py index b3a1eaf..2dcb791 100644 --- a/neblina.py +++ b/neblina.py @@ -122,6 +122,7 @@ class Debug: UnitTestMotionData = 0x04 FWVersions = 0x05 InterfaceState = 0x09 + RSSI = 0x07 class Power: """ @@ -211,6 +212,7 @@ class BLE: (SubSystem.Debug, Commands.Debug.StartUnitTestMotion): 'Enable/Disable Unit Test Motion', (SubSystem.Debug, Commands.Debug.UnitTestMotionData): 'Unit Test Data', (SubSystem.Debug, Commands.Debug.FWVersions): 'Firmware Versions', + (SubSystem.Debug, Commands.Debug.RSSI): 'Firmware Versions', (SubSystem.Motion, Commands.Motion.Downsample): 'Downsample', (SubSystem.Motion, Commands.Motion.MotionState): 'MotionState', (SubSystem.Motion, Commands.Motion.IMU): 'IMU Data', @@ -273,12 +275,13 @@ class Data: Temperature = "