mirror of
https://github.com/eclipse/upm.git
synced 2025-03-14 20:47:30 +03:00
curieimu: Adds examples for both JS and Python that load MRAA Firmata subplatform
Signed-off-by: deadprogram <ron@hybridgroup.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
parent
1b8cb1361c
commit
a35e58c54c
@ -24,19 +24,24 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var mraa = require('mraa');
|
||||
console.log('MRAA Version: ' + mraa.getVersion());
|
||||
|
||||
// open connection to Firmata
|
||||
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0");
|
||||
|
||||
var curieImu = require('jsupm_curieimu');
|
||||
var myCurie = new curieImu.CurieImu();
|
||||
|
||||
var outputStr;
|
||||
var myInterval = setInterval(function()
|
||||
{
|
||||
// get accelerometer readings
|
||||
curieImu.updateAccel();
|
||||
outputStr = "accel: x " + curieImu.getAccelX()
|
||||
+ " - y " + curieImu.getAccelY()
|
||||
+ " - z " + curieImu.getAccelZ();
|
||||
myCurie.updateAccel();
|
||||
outputStr = "accel: x " + myCurie.getAccelX()
|
||||
+ " - y " + myCurie.getAccelY()
|
||||
+ " - z " + myCurie.getAccelZ();
|
||||
console.log(outputStr);
|
||||
console.log(" ");
|
||||
}, 1000);
|
||||
}, 500);
|
||||
|
||||
// Print message when exiting
|
||||
process.on('SIGINT', function()
|
||||
|
@ -22,16 +22,20 @@
|
||||
# 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 mraa
|
||||
print (mraa.getVersion())
|
||||
|
||||
# open connection to Firmata
|
||||
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0")
|
||||
|
||||
import time, sys, signal, atexit
|
||||
import pyupm_curieimu as curieimu
|
||||
sensor = curieimu.CurieImu()
|
||||
|
||||
## Exit handlers ##
|
||||
# This stops python from printing a stacktrace when you hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This lets you run code on exit,
|
||||
# including functions from myAccelrCompass
|
||||
def exitHandler():
|
||||
print "Exiting"
|
||||
sys.exit(0)
|
||||
@ -42,13 +46,11 @@ signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
|
||||
while(1):
|
||||
# Get the acceleration
|
||||
curieimu.updateAccel();
|
||||
sensor.updateAccel();
|
||||
|
||||
outputStr = "acc: gX {0} - gY {1} - gZ {2}".format(
|
||||
curieimu.getAccelX(), curieimu.getAccelY(),
|
||||
curieimu.getAccelZ())
|
||||
sensor.getAccelX(), sensor.getAccelY(),
|
||||
sensor.getAccelZ())
|
||||
print outputStr
|
||||
|
||||
print " "
|
||||
time.sleep(1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user