Add User Action packet. Allows for reset buttons on trackers and not just tap detection to reset. (#457)

This commit is contained in:
Carl Andersson
2023-01-06 18:55:21 +01:00
committed by GitHub
parent 4d7c931b69
commit 93f7a7482b
3 changed files with 68 additions and 0 deletions

View File

@@ -564,6 +564,40 @@ public class TrackersUDPServer extends Thread {
break;
tracker.temperature = temp.temperature;
break;
case UDPProtocolParser.PACKET_USER_ACTION:
if (connection == null)
break;
UDPPacket21UserAction action = (UDPPacket21UserAction) packet;
switch (action.type) {
case UDPPacket21UserAction.RESET:
case UDPPacket21UserAction.RESET_YAW:
case UDPPacket21UserAction.RESET_MOUNTING:
String name = "";
switch (action.type) {
case UDPPacket21UserAction.RESET:
name = "Full";
Main.getVrServer().resetTrackers();
break;
case UDPPacket21UserAction.RESET_YAW:
name = "Yaw";
Main.getVrServer().resetTrackersYaw();
break;
case UDPPacket21UserAction.RESET_MOUNTING:
name = "Mounting";
Main.getVrServer().resetTrackersMounting();
break;
}
LogManager
.info(
"[TrackerServer] User action from "
+ connection.descriptiveName
+ " received. "
+ name
+ " reset performed."
);
break;
}
break;
default:
LogManager.warning("[TrackerServer] Skipped packet " + packet);
break;

View File

@@ -0,0 +1,32 @@
package dev.slimevr.vr.trackers.udp;
import java.io.IOException;
import java.nio.ByteBuffer;
public class UDPPacket21UserAction extends UDPPacket {
public static final int RESET = 2;
public static final int RESET_YAW = 3;
public static final int RESET_MOUNTING = 4;
public int type;
public UDPPacket21UserAction() {
}
@Override
public int getPacketId() {
return 21;
}
@Override
public void readData(ByteBuffer buf) throws IOException {
type = buf.get() & 0xFF;
}
@Override
public void writeData(ByteBuffer buf) throws IOException {
// Never sent back in current protocol
}
}

View File

@@ -30,6 +30,7 @@ public class UDPProtocolParser {
public static final int PACKET_MAGNETOMETER_ACCURACY = 18;
public static final int PACKET_SIGNAL_STRENGTH = 19;
public static final int PACKET_TEMPERATURE = 20;
public static final int PACKET_USER_ACTION = 21;
public static final int PACKET_PROTOCOL_CHANGE = 200;
@@ -112,6 +113,7 @@ public class UDPProtocolParser {
case PACKET_MAGNETOMETER_ACCURACY -> new UDPPacket18MagnetometerAccuracy();
case PACKET_SIGNAL_STRENGTH -> new UDPPacket19SignalStrength();
case PACKET_TEMPERATURE -> new UDPPacket20Temperature();
case PACKET_USER_ACTION -> new UDPPacket21UserAction();
case PACKET_PROTOCOL_CHANGE -> new UDPPacket200ProtocolChange();
default -> null;
};