Appcelerator Hyperloop Android - How to use certain Sensor Manager functions which use a pass by reference structure

313 Views Asked by At

I'm stepping into Hyperloop for the first time, specifically for Android currently, and although it's going fairly well I've had one issue which I will explain below.

I've successfully been able to get a handle to the Sensor Manager and set up a Sensor listener event to get values from the sensor.

If anyone needs that 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
    }
});

What I'm having trouble with is how to use the Android Sensor Manager functions that involve passing a parameter by reference. For example SensorManager.remapCoordinateSystem(float[] inR, int X, int Y, float[] outR) includes an out array (a 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 stays the same as when it was initialised, in this case an array of 16 0's. I've tested a few of the similar functions and have gotten the same result. I've been able to work around this issue by recreating each of the SensorManager functions I need and editing the function so it returns the variable but I was wondering if there was any way around this or if it's just a limitation of hyperloop? It's a waste of my time to be remaking the same functions with only a minor difference so I am hoping I've just missed something.

Thanks!

0

There are 0 best solutions below