xxxxxxxxxx
86
// Visualization of data from EVM board:
// https://github.com/mitmedialab/TI_EVM_logger
var host = 'localhost:8080';
var socket;
var SensorValues = [];
var cpt = 200;
function setup()
{
createCanvas(displayWidth, displayHeight);
let fs = fullscreen();
fullscreen(!fs);
// Create a new plot and set its position on the screen
points = [];
seed = cpt * random();
// random init:
for (i = 0; i < cpt; i++)
{
points[i] = new GPoint(i, 0);
}
plot = new GPlot(this);
plot.setOuterDim(displayWidth/2, displayHeight/2);
plot.setLineColor(color(255, 0, 0));
// Set the plot title and the axis labels
plot.getXAxis().setDrawTickLabels(false);
plot.setHorizontalAxesTicks(1);
plot.getYAxis().setDrawTickLabels(false);
plot.setFixedYLim(true);
// data RX
socket = new WebSocket('ws://' + host);
socket.onmessage = readMessage;
}
function draw()
{
// Add the points
plot.setPoints(points);
plot.defaultDraw();
// shift:
points.shift();
// use differential approach, and normalize:
var accel = (100+SensorValues[1] - SensorValues[0])/200.0;
points.push( new GPoint(cpt++, accel) );
}
function readMessage(event) {
// make an array of floats (from the received string):
var float_strings = split(event.data, ',');
for (var i=0; i < float_strings.length; i++) {
SensorValues[i] = parseFloat(float_strings[i]);
}
// println(SensorValues); // use the data...
}
function mousePressed() {
if (mouseX > 0 && mouseX < windowWidth &&
mouseY > 0 && mouseY < windowHeight) {
let fs = fullscreen();
fullscreen(!fs);
}
}
function windowResized() {
resizeCanvas(displayWidth, displayHeight*0.99);
background(255);
plot.setPos(0.005*displayWidth, 0.25*displayHeight);
}
// Grafica doc: https://github.com/jagracar/grafica.js
// examples: https://jagracar.com/grafica.php