Last active
August 29, 2015 13:57
-
-
Save jadonk/9602198 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See this gist on jsfiddle: http://jsfiddle.net/gh/gist/jquery/1.9.1/9602198/