Skip to content

Instantly share code, notes, and snippets.

@scottgwald
Created May 5, 2014 23:11
Show Gist options
  • Save scottgwald/11549726 to your computer and use it in GitHub Desktop.
Save scottgwald/11549726 to your computer and use it in GitHub Desktop.
[wearscript] empa new
<html style="width:100%; height:100%; overflow:hidden">
<head>
<!-- You can include external scripts here like so... -->
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.0/zepto.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>-->
</head>
<body style="width:100%; height:100%; overflow:hidden; margin:0" bgcolor="#000">
<canvas id="canvas" width="640" height="360" style="display:block"></canvas>
<script>
console.log("Hi");
var GSR, IBI, BVP, Temp, Batt;
var sensors = [["empaGSR", "EDA/GSR"], ["empaIBI", "IBI"], ["empaBVP", "BVP"], ["empaTemperature", "Temperature"], ["empaBattery", "Battery"]];
var vals = {}, pos = {}, names = {};
var newData;
var drawInterval = 1000;
var sensorInterval = .01;
var logInterval = 10.0;
for (var i in sensors) {
vals[WS.sensor(sensors[i][0])] = 0;
pos[WS.sensor(sensors[i][0])] = i;
names[WS.sensor(sensors[i][0])] = sensors[i][1];
}
function onEmpaPaired() {
for (var i in sensors) {
WS.sensorOn(sensors[i][0], sensorInterval, onEmpa);
}
//WS.sensorOn("empaBattery", .2, function(data) {WS.say("empa battery " + Math.floor(100 * data.values[0])); console.log(JSON.stringify(data))});
setInterval(drawEmpa, drawInterval);
WS.dataLog(true, false, logInterval);
}
function onEmpa(data) {
vals[data.type] = data.values[0];
newData = true;
}
function drawEmpa() {
if (newData) {
clearCanvas();
var i = 0;
for (var key in vals) {
drawTextLine(names[key] + ": " + vals[key], pos[key]);
i++;
}
newData = false;
}
}
function clearCanvas() {
context.fillStyle = "rgb(0, 0, 0)";
context.fillRect(0, 0, 640, 360);
}
function drawTextLine(text, _number) {
var number = _number;
if ( number === undefined ) {
console.log("No number given, setting to 0");
number = 0;
}
baseline = 40 + 50 * number;
context.fillStyle = "rgb(200,200,200)";
context.font = '28pt Calibri';
context.textAlign = 'left';
context.fillText(text, 10, baseline);
}
function main() {
if (WS.scriptVersion(1)) return;
context = document.getElementById('canvas').getContext("2d");
WS.empaPair(onEmpaPaired);
}
window.onload = main;
</script>
</body>
</html>
{"name":"Empa Neww"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment