Appcelerator Hyperloop Android - How to use certain functions of the sensor manager that use a pass along the reference structure

This is my first time joining Hyperloop, especially for Android at the moment, and although this is going pretty well, I had one problem, which I will explain below.

I managed to get the handle of the sensor manager and set up the Sensor listener event to get the values ​​from the sensor.

If someone needs this code here, it is below

var AndroidAppPkg = require('android.app.*'); var AndroidHardware = require('android.hardware.*'); var Context = require('android.content.Context'); var Sensor = AndroidHardware.Sensor; var SensorEvent = AndroidHardware.SensorEvent; var SensorEventListener = AndroidHardware.SensorEventListener; var SensorManager = AndroidHardware.SensorManager; var Activity = AndroidAppPkg.Activity; var Matrix = require('android.opengl.Matrix'); var activity = new Activity(Titanium.App.Android.getTopActivity()); var appContext = activity.getApplicationContext(); var obj = appContext.getSystemService(Context.SENSOR_SERVICE); var sensorManager = SensorManager.cast( obj ); var sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR); Ti.API.info('Set up sensor event'); var sensorEvent = new SensorEventListener({ onSensorChanged:function(event){ // sensor values retrieve here } }); 

I'm having problems using Android Sensor Manager features that include passing a parameter by reference. For example, SensorManager.remapCoordinateSystem(float[] inR, int X, int Y, float[] outR) includes an output array (rotation matrix).

I tried this approach

 var outR = new Array(16).fill(0); SensorManager.remapCoordinateSystem(inR, SensorManager.AXIS_X, SensorManager.AXIS_Z, outR); Ti.API.info(outR.join()); 

The outR array remains the same as during initialization, in this case an array of 16 0. I checked several similar functions and got the same result. I was able to work around this problem by re-creating each of the SensorManager functions that I needed and editing the function to return a variable, but I was wondering if there was any way to do this or if it was just limiting a hyperlop? It's a waste of time to redo the same functions with a slight difference, so I hope I just missed something.

Thanks!

+5
source share

All Articles