Created
February 16, 2014 07:20
-
-
Save Meiguro/9030503 to your computer and use it in GitHub Desktop.
Here's a Simply.js demo showing accelerometer support.
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
simply.text({ | |
title: 'Accel Demo', | |
body: 'Press up to stream or select to peek.', | |
}, true); | |
/** | |
* Use simply.accelConfig({ rate: 100, samples: 25 }) to configure | |
* the hertz and accel data per batch for the accelData events. | |
* See the API reference at simplyjs.io for more information. | |
*/ | |
var onAccelData = function(e) { | |
simply.body('data: ' + JSON.stringify(e.accel)); | |
}; | |
// Press up to begin accelData streaming | |
// Pressing up multiple times will register the handler more than once so be careful. | |
simply.on('singleClick', 'up', function(e) { | |
simply.on('accelData', onAccelData); | |
}); | |
// Press down until all accelData handlers are removed and you can accelPeek again | |
simply.on('singleClick', 'down', function(e) { | |
simply.off('accelData', onAccelData); | |
}); | |
// Press select to accelPeek | |
simply.on('singleClick', 'select', function(e) { | |
if (simply.accelConfig().subscribe) { | |
// accelData and accelPeek can't happen simultaneously | |
return; | |
} | |
simply.accelPeek(function(e) { | |
simply.body('peek: ' + JSON.stringify(e.accel)); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment