const SerialPort = require('serialport');
const Readline = require('@serialport/parser-readline');
const port = new SerialPort('/dev/ttyUSB0', { baudRate: 115200 }); // Replace with your port
const parser = port.pipe(new Readline({ delimiter: '\n' }));
let gyroOffsets = [0, 0, 0];
let magOffsets = [0, 0, 0];
let gyroData = [];
let magData = [];
// Number of calibration samples
const NUM_SAMPLES = 1000;
function parseData(data) {
const [type, x, y, z] = data.split(',').map(Number);
if (type === 0) { // Gyroscope data
gyroData.push([x, y, z]);
} else if (type === 1) { // Magnetometer data
magData.push([x, y, z]);
}
}