Browse Source

curieimu: Add WIP for Python example

Signed-off-by: deadprogram <ron@hybridgroup.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
deadprogram 9 years ago
parent
commit
d8fc664178
1 changed files with 54 additions and 0 deletions
  1. 54
    0
      examples/python/curieimu.py

+ 54
- 0
examples/python/curieimu.py View File

@@ -0,0 +1,54 @@
1
+#!/usr/bin/python
2
+
3
+# Author: Ron Evans (@deadprogram)
4
+# Copyright (c) 2016 Intel Corporation.
5
+#
6
+# Permission is hereby granted, free of charge, to any person obtaining
7
+# a copy of this software and associated documentation files (the
8
+# "Software"), to deal in the Software without restriction, including
9
+# without limitation the rights to use, copy, modify, merge, publish,
10
+# distribute, sublicense, and/or sell copies of the Software, and to
11
+# permit persons to whom the Software is furnished to do so, subject to
12
+# the following conditions:
13
+#
14
+# The above copyright notice and this permission notice shall be
15
+# included in all copies or substantial portions of the Software.
16
+#
17
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
24
+
25
+import time, sys, signal, atexit
26
+import pyupm_curieimu as curieimu
27
+
28
+## Exit handlers ##
29
+# This stops python from printing a stacktrace when you hit control-C
30
+def SIGINTHandler(signum, frame):
31
+	raise SystemExit
32
+
33
+# This lets you run code on exit,
34
+# including functions from myAccelrCompass
35
+def exitHandler():
36
+	print "Exiting"
37
+	sys.exit(0)
38
+
39
+# Register exit handlers
40
+atexit.register(exitHandler)
41
+signal.signal(signal.SIGINT, SIGINTHandler)
42
+
43
+
44
+while(1):
45
+	# Get the acceleration
46
+	curieimu.updateAccel();
47
+
48
+	outputStr = "acc: gX {0} - gY {1} - gZ {2}".format(
49
+	curieimu.getAccelX(), curieimu.getAccelY(),
50
+	curieimu.getAccelZ())
51
+	print outputStr
52
+
53
+	print " "
54
+	time.sleep(1)