2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-29 13:17:43 +00:00

Pointer plugin: send delta and not abs value

This commit is contained in:
Albert Vaca Cintora 2019-07-21 00:14:05 +02:00
parent 2604bc9595
commit 7c3a297bca
2 changed files with 12 additions and 10 deletions

View File

@ -56,16 +56,12 @@ public class PresenterActivity extends AppCompatActivity implements SensorEventL
private PresenterPlugin plugin; private PresenterPlugin plugin;
private SensorManager sensorManager; private SensorManager sensorManager;
private float xPos, yPos;
static final float SENSITIVITY = 0.05f; //TODO: Make configurable? static final float SENSITIVITY = 0.05f; //TODO: Make configurable?
public void gyroscopeEvent(SensorEvent event) { public void gyroscopeEvent(SensorEvent event) {
xPos += -event.values[2] * SENSITIVITY; float xPos = -event.values[2] * SENSITIVITY;
yPos += -event.values[0] * SENSITIVITY; float yPos = -event.values[0] * SENSITIVITY;
xPos = clamp(xPos, -1.f, 1.f);
yPos = clamp(yPos, -1.f, 1.f);
plugin.sendPointer(xPos, yPos); plugin.sendPointer(xPos, yPos);
} }

View File

@ -116,10 +116,16 @@ public class PresenterPlugin extends Plugin {
device.sendPacket(np); device.sendPacket(np);
} }
public void sendPointer(float percentX, float percentY) { public void sendPointer(float xDelta, float yDelta) {
NetworkPacket np = new NetworkPacket(PACKET_TYPE_PRESENTER); NetworkPacket np = device.getAndRemoveUnsentPacket(NetworkPacket.PACKET_REPLACEID_PRESENTERPOINTER);
np.set("px", percentX); if (np == null) {
np.set("py", percentY); np = new NetworkPacket(PACKET_TYPE_PRESENTER);
} else {
xDelta += np.getInt("px");
yDelta += np.getInt("px");
}
np.set("px", xDelta);
np.set("py", yDelta);
device.sendPacket(np, NetworkPacket.PACKET_REPLACEID_PRESENTERPOINTER); device.sendPacket(np, NetworkPacket.PACKET_REPLACEID_PRESENTERPOINTER);
} }