Skip to content

Commit

Permalink
fix packed mode mms
Browse files Browse the repository at this point in the history
  • Loading branch information
lkasso committed Jun 22, 2021
1 parent 31e1719 commit 7878b1b
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
2 changes: 1 addition & 1 deletion MetaWear-SDK-Cpp
46 changes: 46 additions & 0 deletions examples/stream_acc_packed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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.')
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))
}))

console.log('Start accelerometer.')
MetaWear.mbl_mw_acc_enable_acceleration_sampling(device.board)
MetaWear.mbl_mw_acc_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_packed.js ea:78:c3:d3:f0:8a
mainAsync(process.argv[2])

54 changes: 54 additions & 0 deletions examples/stream_gyro_packed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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)
})
})

// For MMS
let acc = MetaWear.mbl_mw_gyro_bmi270_get_packed_rotation_data_signal(device.board)
// Uncomment for MMRL, MMR, MMC
//let acc = MetaWear.mbl_mw_gyro_bmi160_get_packed_rotation_data_signal(device.board)

console.log('Set up stream.')
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 + ' gyro: ' + 'x: ' + entry[0].toFixed(3) + ' y: ' + entry[1].toFixed(3) + ' z: ' + entry[2].toFixed(3))
}))

console.log('Start gyroscope.')
// For MMS
MetaWear.mbl_mw_gyro_bmi270_enable_rotation_sampling(device.board)
MetaWear.mbl_mw_gyro_bmi270_start(device.board)
// Uncomment for MMRL, MMR, MMC
//MetaWear.mbl_mw_gyro_bmi160_enable_rotation_sampling(device.board)
//MetaWear.mbl_mw_gyro_bmi160_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_gyro_packed.js ea:78:c3:d3:f0:8a
mainAsync(process.argv[2])

0 comments on commit 7878b1b

Please sign in to comment.