Skip to content

Instantly share code, notes, and snippets.

@jadonk
Last active August 29, 2015 13:57
Show Gist options
  • Save jadonk/9602198 to your computer and use it in GitHub Desktop.
Save jadonk/9602198 to your computer and use it in GitHub Desktop.
<h1>BoneScript Flot Demo</h1>
<div id="myplot" style="width:500px;height:300px;"></div>
<p><a href="https://gist.github.com/jadonk/9602198">fork me on github</a></p>
setTargetAddress('beaglebone.local', {
initialized: run
});
setTargetAddress('192.168.7.2', {
initialized: run
});
function run() {
var b = require('bonescript');
var POT = 'P9_36';
var container = $("#myplot");
var totalPoints = container.outerWidth() / 2 || 250;
var data = [];
var plotOptions = {
series: {
shadowSize: 0
},
yaxis: {
min: 0,
max: 1
},
xaxis: {
min: 0,
max: totalPoints,
show: false
}
};
var plot = $.plot(container, getData(), plotOptions);
drawGraph();
function drawGraph() {
plot.setData(getData());
plot.draw();
b.analogRead(POT, onAnalogRead);
}
// Handle data back from potentiometer
function onAnalogRead(x) {
if (!x.err && typeof x.value == 'number') {
pushData(x.value);
}
setTimeout(drawGraph, 20);
}
function pushData(y) {
if (data.length && (data.length + 1) > totalPoints) {
data = data.slice(1);
}
if (data.length < totalPoints) {
data.push(y);
}
}
function getData() {
var res = [];
for (var i = 0; i < data.length; ++i) {
res.push([i, data[i]]);
}
var series = [{
data: res,
lines: {
fill: true
}
}];
return series;
}
}
name: BoneScript Flot Demo
description: Put a BeagleBone on your network with a potentiometer (between 0 and 1.8V) on P9_36 to see a simple jQuery Flot graph.
authors:
- Jason Kridner
resources:
- http://www.flotcharts.org/flot/jquery.flot.js
- http://beagleboard.org/static/bonescript.js
@jadonk
Copy link
Author

jadonk commented Mar 17, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment