Skip to content

Commit

Permalink
Added fuser example script
Browse files Browse the repository at this point in the history
  • Loading branch information
scaryghost committed Nov 11, 2018
1 parent bcdb325 commit d126c0c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
52 changes: 52 additions & 0 deletions examples/fuser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
var MetaWear = require('../index.js')//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) => {
device.connectAndSetUp(error => {
if(error == null) resolve(null)
else reject(error)
})
})

let acc = MetaWear.mbl_mw_acc_get_acceleration_data_signal(device.board)
let gyro = MetaWear.mbl_mw_gyro_bmi160_get_rotation_data_signal(device.board)

let fuser = await new Promise((resolve, reject) => {
//ArrayType(ref.refType(AnonymousDataSignal));
console.log("creating fuser? ")
console.log(acc)
console.log(gyro)
MetaWear.mbl_mw_dataprocessor_fuser_create(acc, new MetaWear.ArrayDataSignalP([gyro]), 1, ref.NULL, MetaWear.FnVoid_VoidP_DataProcessorP.toPointer((ctx, pointer) => {
if (!pointer) {
reject("Failed to create fuser")
} else {
resolve(pointer);
}
}))
console.log("fuser created?")
})

MetaWear.mbl_mw_datasignal_subscribe(fuser, ref.NULL, MetaWear.FnVoid_VoidP_DataP.toPointer((ctx, pointer) => {
var data = pointer.deref();
var values = data.parseValue({'nElem': 2});

let acc = values[0]
let gyro = values[1]

console.log(`acc: (${acc.x},${acc.y},${acc.z}), gyro; (${gyro.x},${gyro.y},${gyro.z})`)
}))

MetaWear.mbl_mw_gyro_bmi160_enable_rotation_sampling(device.board)
MetaWear.mbl_mw_acc_enable_acceleration_sampling(device.board)

MetaWear.mbl_mw_gyro_bmi160_start(device.board)
MetaWear.mbl_mw_acc_start(device.board)

process.openStdin().addListener("data", data => {
MetaWear.mbl_mw_debug_reset(device.board)
})
}

mainAsync(process.argv[2])
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metawear",
"version": "0.2.0",
"version": "0.3.0",
"author": "Stephen Schiffli <[email protected]>",
"license": "SEE LICENSE IN LICENSE",
"description": "Official JavaScript SDK for MetaWear",
Expand Down

0 comments on commit d126c0c

Please sign in to comment.