How to display value of cordovaDeviceMotion?


#1

Hey there,

How can I display value of the DeviceMotion and pass it over to another view into an input field?
(main view on the right where to value should be placed (alpha), because there is some math going on.)

preferably the svg img should rotate with it. ( so you know you’re in the green zone )


#3

So I’ve managed to get this to work.
I had to do Math.round(((acceleration.x) / 9.81) * 90) to get the degrees from the acceleration.x …

My next question is:
How can I pass the value I get, to another view into the right input field?

Like I wanna tilt my phone get a value of lets say 45 (degree) and then press the “transfer angle” button, then it should go back and put the 45 into the Angle alpha field.

This is my controller.

.controller('DiagWinkelACtrl', function() {

platform = 0;

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {

  	if(device.platform){
   	   var suchErgebnis = device.platform.search("Android");
	   if (suchErgebnis != -1) {
	   		platform = 1;

	   }
   	}

	function onSuccess(acceleration) {
	    var element = document.getElementById('accX');

		iDeg  = Math.round(((acceleration.x) / 9.81) * 90)
	    if(iDeg > 0) {
			myDeg = 90 - iDeg;
		} else {
			myDeg = 90 + iDeg;
		}

	    element.innerHTML  = myDeg + '°';
	    $('img#daDreh').css('transform', 'rotate('+iDeg+'deg)');
	};

	function onError() {
	    alert('onError!');
	};

	var options = { frequency: 100 };  // Update every 3 seconds

	var watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
}


})