I am using Google Nexus 4 and trying to write an app that controls mouse cursor on PC. More spesifically, when i move the phone to the right, mouse cursor should move to the right as well.
I am working on just x-axis right now and following the instructions of the document in this answer.
But i couldn't get the result that i wanted. When i move the phone to the right, the cursor is moved to the right and it moved back to the left. Here is part of my code:
@Override
public void onSensorChanged(SensorEvent event)
{
// sampling acceleration
do
{
acceleration_x[1] = acceleration_x[1] + (int) event.values[0];
count_x++;
} while ( count_x < 64);
acceleration_x[1] = acceleration_x[1] >> 6;
count_x = 0;
//Mechanical Filtering
if( (acceleration_x[1] <= 3) && (acceleration_x[1] >= -3) )
acceleration_x[1] = 0;
// first integration
velocity_x[1] = velocity_x[0] + acceleration_x[0] +
((acceleration_x[1] - acceleration_x[0]) >> 1);
// second integration
position_x[1] = position_x[0] + velocity_x[0] +
((velocity_x[1] - velocity_x[0]) >> 1);
acceleration_x[0] = acceleration_x[1];
velocity_x[0] = velocity_x[1];
sendData.sendPacket(position_x[1], 0); // sending data(x,y) to PC
movement_end_check(event);
position_x[0] = position_x[1];
}
Integration formula and movement_end_check method were taken from the document.
So,can you help me with this issue ?