openi2c
Version:
This library is a set of cross platform drivers for common I2C devices.
42 lines (41 loc) • 2.4 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = require(".");
function main() {
return __awaiter(this, void 0, void 0, function* () {
const bno = new _1.BNO08X();
yield bno.init();
yield bno.enableFeature(_1.BNO_REPORT_ACCELEROMETER);
yield bno.enableFeature(_1.BNO_REPORT_GYROSCOPE);
yield bno.enableFeature(_1.BNO_REPORT_MAGNETOMETER);
yield bno.enableFeature(_1.BNO_REPORT_ROTATION_VECTOR);
yield bno.enableFeature(_1.BNO_REPORT_GAME_ROTATION_VECTOR);
// await bno.beginCalibration();
// setInterval(async ()=>{
// const acc = await bno.calibrationStatus();
// console.log(acc);
// }, 500)
setInterval(() => __awaiter(this, void 0, void 0, function* () {
const xyz = yield bno.euler();
console.log(`XYZ`, xyz);
// const [accelX, accelY, accelZ] = await bno.acceleration();
// console.log(`Accel: X: ${accelX.toFixed(6)} Y: ${accelY.toFixed(6)} Z: ${accelZ.toFixed(6)} m/s^2`);
// const [gyroX, gyroY, gyroZ] = await bno.gyro();
// console.log(`Gyro: X: ${gyroX.toFixed(6)} Y: ${gyroY.toFixed(6)} Z: ${gyroZ.toFixed(6)} rads/s`);
// const [magX, magY, magZ] = await bno.magnetic();
// console.log(`Mag: X: ${magX.toFixed(6)} Y: ${magY.toFixed(6)} Z: ${magZ.toFixed(6)} m/s^2`);
// const [quatI, quatJ, quatK, quatReal] = await bno.quaternion();
// console.log(`Quat: I: ${quatI.toFixed(6)} J: ${quatJ.toFixed(6)} K: ${quatK.toFixed(6)} Real: ${quatReal.toFixed(6)}`);
}), 1000);
});
}
main();