-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
63 additions
and
3 deletions.
There are no files selected for viewing
Submodule MetaWear-SDK-Cpp
updated
9 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// LOCAL | ||
var MetaWear = require('../index') | ||
// METAWEAR | ||
//require('metawear'); | ||
|
||
var ref = require('ref') | ||
|
||
async function mainAsync(mac) { | ||
var device = await new Promise((resolve, reject) => MetaWear.discoverByAddress(mac.toLowerCase(), d => resolve(d))) | ||
await new Promise((resolve, reject) => { | ||
console.log('Connecting...') | ||
device.connectAndSetUp(error => { | ||
console.log('Connected.') | ||
if(error == null) resolve(null) | ||
else reject(error) | ||
}) | ||
}) | ||
|
||
let acc = MetaWear.mbl_mw_acc_get_packed_acceleration_data_signal(device.board) | ||
console.log('Set up stream acc .') | ||
MetaWear.mbl_mw_datasignal_subscribe(acc, ref.NULL, MetaWear.FnVoid_VoidP_DataP.toPointer((ctx, pointer) => { | ||
var data = pointer.deref(); | ||
let value = data.parseValue() | ||
let entry = [value.x, value.y, value.z] | ||
console.log('epoch: ' + data.epoch + ' acc: ' + 'x: ' + entry[0].toFixed(3) + ' y: ' + entry[1].toFixed(3) + ' z: ' + entry[2].toFixed(3)) | ||
})) | ||
|
||
let gyro = MetaWear.mbl_mw_gyro_bmi270_get_packed_rotation_data_signal(device.board) | ||
|
||
console.log('Set up stream gyro.') | ||
MetaWear.mbl_mw_datasignal_subscribe(gyro, ref.NULL, MetaWear.FnVoid_VoidP_DataP.toPointer((ctx, pointer) => { | ||
var data = pointer.deref(); | ||
let value = data.parseValue() | ||
let entry = [value.x, value.y, value.z] | ||
console.log('epoch: ' + data.epoch + ' gyro: ' + 'x: ' + entry[0].toFixed(3) + ' y: ' + entry[1].toFixed(3) + ' z: ' + entry[2].toFixed(3)) | ||
})) | ||
|
||
console.log('Start accelerometer.') | ||
MetaWear.mbl_mw_acc_enable_acceleration_sampling(device.board) | ||
MetaWear.mbl_mw_acc_start(device.board) | ||
|
||
console.log('Start gyroscope.') | ||
MetaWear.mbl_mw_gyro_bmi270_enable_rotation_sampling(device.board) | ||
MetaWear.mbl_mw_gyro_bmi270_start(device.board) | ||
|
||
// Terminal on terminal input | ||
process.openStdin().addListener("data", data => { | ||
console.log('Reset.') | ||
MetaWear.mbl_mw_debug_reset(device.board) | ||
setTimeout(function () { | ||
// Exit terminal | ||
process.exit(1); | ||
}, 2000); | ||
}) | ||
} | ||
|
||
// Run this example by putting the MAC address on the command line | ||
// sudo node stream_acc_gyro_packed.js ea:78:c3:d3:f0:8a | ||
mainAsync(process.argv[2]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters