tizentizen-web-appsamsung-gear

Gear S3 accelerometer very slow


I'm using Gear S3 and after update its accelerometer got very slow. Before updated I registered 20-25 samples in 30s. Now, I register 10-12 samples. Someone knows why trouble?

var t0 = 0;
var cont = 0;

function onDeviceMotion(event){
    var x = event.acceleration.x.toFixed(2);
    var y = event.acceleration.y.toFixed(2);
    var z = event.acceleration.z.toFixed(2);
    var t = ((new Date().getSeconds() + 60) - t0)%60;

    var components = {
    x: x,
    y: y,
    z: z,
    t : t
    }

    counter.innerHTML = cont++;
    start.innerHTML = components.t;

    console.log(components.x + " " + components.y + " " + components.z + " " + components.t+ " " + new Date().getSeconds() );

}


window.addEventListener('devicemotion', onDeviceMotion);

Solution

  • Depending on the device you may want to use ACCELERATION or LINEAR_ ACCELERATION. You can check available sensors by calling tizen.sensorservice.getAvailableSensors(); In my case it was LINEAR_ACCELERATION (Samsung Gear Sport). Also you can modify how often you want the callbacks from the sensor (1000 is once per second).

    function startAccelerometerSensor() {
    	var accelerationSensor = tizen.sensorservice
    			.getDefaultSensor("LINEAR_ACCELERATION");
    	accelerationSensor.setChangeListener(onChangedCBAccelerometer, 1000);
    	accelerationSensor.start(onSuccessCBAccelerometer);
    }
    
    function onSuccessCBAccelerometer() {
    	console.log('Accelerometer service has started successfully.');
    }
    
    function onChangedCBAccelerometer(sensorData) {
    	console.log("######## Get ACCELEROMETER sensor data ########");
    	console.log("X : " + sensorData.x);
    	console.log("Y : " + sensorData.y);
    	console.log("Z : " + sensorData.z);
    }

    here is the documentation