summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGubolin <gubolin@fantasymail.de>2014-09-07 12:34:55 +0200
committerCode WvS <code-wvs@quantentunnel.de>2015-03-21 11:41:15 +0100
commitdbc463c70ad7bbd43b907ec0345bd0965698c0cf (patch)
tree69b1dbfd8777072c77dbd292b06a51af0d44a5d9
parent970bb151505e9ad7c71f518d9a4da2ab1f207acc (diff)
downloadsnap-yow-dbc463c70ad7bbd43b907ec0345bd0965698c0cf.tar.gz
snap-yow-dbc463c70ad7bbd43b907ec0345bd0965698c0cf.zip
cherry-pick compass and acceleration blocks
-rwxr-xr-xmobile.sh4
-rw-r--r--objects.js34
-rw-r--r--threads.js102
3 files changed, 138 insertions, 2 deletions
diff --git a/mobile.sh b/mobile.sh
index bfb412c..6c109a3 100755
--- a/mobile.sh
+++ b/mobile.sh
@@ -46,10 +46,10 @@ echo "Adding cordova plugins"
# add everything needed and build for $device
cordova platform add "$1" > /dev/null
cordova plugin add org.apache.cordova.geolocation \
+ org.apache.cordova.device-motion \
+ org.apache.cordova.device-orientation \
org.apache.cordova.vibration 2> /dev/null
#org.apache.cordova.plugin.softkeyboard \
- #org.apache.cordova.device-motion \
- #org.apache.cordova.device-orientation \
#de.appplant.cordova.plugin.local-notification
if [[ $1 == "android" ]]
diff --git a/objects.js b/objects.js
index 8c683cd..6282755 100644
--- a/objects.js
+++ b/objects.js
@@ -934,6 +934,26 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'sensing',
spec: 'vibrate %n seconds'
},
+ reportCompassHeading: {
+ type: 'reporter',
+ category: 'sensing',
+ spec: 'current compass heading'
+ },
+ reportAccelerationX: {
+ type: 'reporter',
+ category: 'sensing',
+ spec: 'current acceleration along the x axes'
+ },
+ reportAccelerationY: {
+ type: 'reporter',
+ category: 'sensing',
+ spec: 'current acceleration along the y axes'
+ },
+ reportAccelerationZ: {
+ type: 'reporter',
+ category: 'sensing',
+ spec: 'current acceleration along the z axes'
+ },
// Operators
reifyScript: {
@@ -2042,6 +2062,12 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
blocks.push(block('doVibrate'));
blocks.push('-');
+ blocks.push(block('reportCompassHeading'));
+ blocks.push('-');
+ blocks.push(block('reportAccelerationX'));
+ blocks.push(block('reportAccelerationY'));
+ blocks.push(block('reportAccelerationZ'));
+ blocks.push('-');
blocks.push(block('overpassQuery'));
// for debugging: ///////////////
@@ -4538,6 +4564,8 @@ StageMorph.prototype.init = function (globals) {
this.paletteCache = {}; // not to be serialized (!)
this.lastAnswer = ''; // last user input, do not persist
this.activeSounds = []; // do not persist
+ this.acceleration = null; // do not persist
+ this.compassHeading = null; // do not persist
this.trailsCanvas = null;
this.isThreadSafe = false;
@@ -5306,6 +5334,12 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push(block('reportDate'));
blocks.push('-');
blocks.push(block('doVibrate'));
+ blocks.push('-');
+ blocks.push(block('reportCompassHeading'));
+ blocks.push('-');
+ blocks.push(block('reportAccelerationX'));
+ blocks.push(block('reportAccelerationY'));
+ blocks.push(block('reportAccelerationZ'));
// for debugging: ///////////////
diff --git a/threads.js b/threads.js
index fe9e3c4..af384ef 100644
--- a/threads.js
+++ b/threads.js
@@ -2798,6 +2798,108 @@ Process.prototype.reportDate = function (datefn) {
return result;
};
+Process.prototype.getCompassHeading = function (dest) {
+ var stage = this.homeContext.receiver.parentThatIsA(StageMorph);
+
+ stage.compassHeading = null;
+ if (navigator.compass) {
+ navigator.compass.getCurrentHeading(
+ function (result) {
+ stage.compassHeading = result;
+ },
+ function () {
+ stage.compassHeading =
+ {'magneticHeading': 0, 'trueHeading': 0,
+ 'headingAccuracy': 0, 'timestamp': 0};
+ }
+ );
+ } else {
+ stage.compassHeading =
+ {'magneticHeading': 0, 'trueHeading': 0,
+ 'headingAccuracy': 0, 'timestamp': 0};
+ }
+};
+
+Process.prototype.reportCompassHeading = function () {
+ var stage = this.homeContext.receiver.parentThatIsA(StageMorph);
+
+ if (this.context.wait) {
+ if (stage.compassHeading !== null) {
+ return stage.compassHeading.magneticHeading;
+ }
+ } else {
+ this.context.wait = true;
+ this.getCompassHeading();
+ }
+ this.pushContext('doYield');
+ this.pushContext();
+};
+
+Process.prototype.getAcceleration = function (dest) {
+ var stage = this.homeContext.receiver.parentThatIsA(StageMorph);
+
+ stage.acceleration = null;
+ if (navigator.accelerometer) {
+ navigator.accelerometer.getCurrentAcceleration(
+ function (result) {
+ stage.acceleration = result;
+ },
+ function () {
+ stage.acceleration =
+ {'timestamp': 0, 'z': 0, 'y': 0, 'x': 0};
+ }
+ );
+ } else {
+ stage.acceleration =
+ {'timestamp': 0, 'z': 0, 'y': 0, 'x': 0};
+ }
+};
+
+Process.prototype.reportAccelerationX = function () {
+ var stage = this.homeContext.receiver.parentThatIsA(StageMorph);
+
+ if (this.context.wait) {
+ if (stage.acceleration !== null) {
+ return stage.acceleration.x;
+ }
+ } else {
+ this.context.wait = true;
+ this.getAcceleration();
+ }
+ this.pushContext('doYield');
+ this.pushContext();
+};
+
+Process.prototype.reportAccelerationY = function () {
+ var stage = this.homeContext.receiver.parentThatIsA(StageMorph);
+
+ if (this.context.wait) {
+ if (stage.acceleration !== null) {
+ return stage.acceleration.y;
+ }
+ } else {
+ this.context.wait = true;
+ this.getAcceleration();
+ }
+ this.pushContext('doYield');
+ this.pushContext();
+};
+
+Process.prototype.reportAccelerationZ = function () {
+ var stage = this.homeContext.receiver.parentThatIsA(StageMorph);
+
+ if (this.context.wait) {
+ if (stage.acceleration !== null) {
+ return stage.acceleration.z;
+ }
+ } else {
+ this.context.wait = true;
+ this.getAcceleration();
+ }
+ this.pushContext('doYield');
+ this.pushContext();
+};
+
Process.prototype.doVibrate = function (seconds) {
if ("vibrate" in navigator) {
window.navigator.vibrate(seconds * 1000);