mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-12-02 06:42:36 -08:00
feat: feedback sound when reset triggered (#576)
Co-authored-by: @EvaSachkova
This commit is contained in:
1 parent
5f8eaf432b
commit
242cfd5fe5
22 files changed
+262
-13
No files matched your search
@@ -6,6 +6,7 @@ import dev.slimevr.config.KeybindingsConfig;
|
||||
import io.eiren.util.OperatingSystem;
|
||||
import io.eiren.util.ann.AWTThread;
|
||||
import io.eiren.util.logging.LogManager;
|
||||
import solarxr_protocol.rpc.ResetType;
|
||||
|
||||
|
||||
public class Keybinding implements HotkeyListener {
|
||||
@@ -60,12 +61,15 @@ public class Keybinding implements HotkeyListener {
|
||||
public void onHotKey(int identifier) {
|
||||
switch (identifier) {
|
||||
case FULL_RESET -> {
|
||||
server.getResetHandler().sendStarted(ResetType.Full);
|
||||
server.scheduleResetTrackersFull(resetSourceName, this.config.getFullResetDelay());
|
||||
}
|
||||
case YAW_RESET -> {
|
||||
server.getResetHandler().sendStarted(ResetType.Yaw);
|
||||
server.scheduleResetTrackersYaw(resetSourceName, this.config.getYawResetDelay());
|
||||
}
|
||||
case MOUNTING_RESET -> {
|
||||
server.getResetHandler().sendStarted(ResetType.Mounting);
|
||||
server
|
||||
.scheduleResetTrackersMounting(
|
||||
resetSourceName,
|
||||
|
||||
@@ -13,6 +13,7 @@ import dev.slimevr.platform.linux.UnixSocketBridge;
|
||||
import dev.slimevr.platform.windows.WindowsNamedPipeBridge;
|
||||
import dev.slimevr.poserecorder.BVHRecorder;
|
||||
import dev.slimevr.protocol.ProtocolAPI;
|
||||
import dev.slimevr.reset.ResetHandler;
|
||||
import dev.slimevr.serial.ProvisioningHandler;
|
||||
import dev.slimevr.serial.SerialHandler;
|
||||
import dev.slimevr.tracking.DeviceManager;
|
||||
@@ -64,6 +65,7 @@ public class VRServer extends Thread {
|
||||
private final Timer timer = new Timer();
|
||||
private final NanoTimer fpsTimer = new NanoTimer();
|
||||
private final ProvisioningHandler provisioningHandler;
|
||||
private final ResetHandler resetHandler;
|
||||
|
||||
/**
|
||||
* This function is used by VRWorkout, do not remove!
|
||||
@@ -84,6 +86,8 @@ public class VRServer extends Thread {
|
||||
|
||||
provisioningHandler = new ProvisioningHandler(this);
|
||||
|
||||
resetHandler = new ResetHandler();
|
||||
|
||||
autoBoneHandler = new AutoBoneHandler(this);
|
||||
protocolAPI = new ProtocolAPI(this);
|
||||
|
||||
@@ -429,6 +433,10 @@ public class VRServer extends Thread {
|
||||
return this.serialHandler;
|
||||
}
|
||||
|
||||
public ResetHandler getResetHandler() {
|
||||
return this.resetHandler;
|
||||
}
|
||||
|
||||
public AutoBoneHandler getAutoBoneHandler() {
|
||||
return this.autoBoneHandler;
|
||||
}
|
||||
|
||||
@@ -102,4 +102,5 @@ public class TapDetectionConfig {
|
||||
public void setNumberTrackersOverThreshold(int numberTrackersOverThreshold) {
|
||||
this.numberTrackersOverThreshold = numberTrackersOverThreshold;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import dev.slimevr.poserecorder.PoseFrames;
|
||||
import dev.slimevr.protocol.GenericConnection;
|
||||
import dev.slimevr.protocol.ProtocolAPI;
|
||||
import dev.slimevr.protocol.ProtocolHandler;
|
||||
import dev.slimevr.protocol.rpc.reset.RPCResetHandler;
|
||||
import dev.slimevr.protocol.rpc.serial.RPCProvisioningHandler;
|
||||
import dev.slimevr.protocol.rpc.serial.RPCSerialHandler;
|
||||
import dev.slimevr.protocol.rpc.settings.RPCSettingsHandler;
|
||||
@@ -42,6 +43,7 @@ public class RPCHandler extends ProtocolHandler<RpcMessageHeader>
|
||||
super();
|
||||
this.api = api;
|
||||
|
||||
new RPCResetHandler(this, api);
|
||||
new RPCSerialHandler(this, api);
|
||||
new RPCProvisioningHandler(this, api);
|
||||
new RPCSettingsHandler(this, api);
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package dev.slimevr.protocol.rpc.reset;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
|
||||
import dev.slimevr.protocol.GenericConnection;
|
||||
|
||||
import dev.slimevr.protocol.ProtocolAPI;
|
||||
import dev.slimevr.protocol.rpc.RPCHandler;
|
||||
import dev.slimevr.reset.ResetListener;
|
||||
import solarxr_protocol.rpc.ResetResponse;
|
||||
import solarxr_protocol.rpc.ResetStatus;
|
||||
import solarxr_protocol.rpc.RpcMessage;
|
||||
|
||||
|
||||
public record RPCResetHandler(RPCHandler rpcHandler, ProtocolAPI api) implements ResetListener {
|
||||
public RPCResetHandler(RPCHandler rpcHandler, ProtocolAPI api) {
|
||||
this.rpcHandler = rpcHandler;
|
||||
this.api = api;
|
||||
|
||||
this.api.server.getResetHandler().addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStarted(int resetType) {
|
||||
|
||||
FlatBufferBuilder fbb = new FlatBufferBuilder(32);
|
||||
ResetResponse.startResetResponse(fbb);
|
||||
ResetResponse.addResetType(fbb, resetType);
|
||||
ResetResponse.addStatus(fbb, ResetStatus.STARTED);
|
||||
int update = ResetResponse.endResetResponse(fbb);
|
||||
int outbound = rpcHandler.createRPCMessage(fbb, RpcMessage.ResetResponse, update);
|
||||
fbb.finish(outbound);
|
||||
|
||||
this.forAllListeners((conn) -> {
|
||||
conn.send(fbb.dataBuffer());
|
||||
});
|
||||
}
|
||||
|
||||
public void forAllListeners(Consumer<? super GenericConnection> action) {
|
||||
this.api
|
||||
.getAPIServers()
|
||||
.forEach(
|
||||
(server) -> server
|
||||
.getAPIConnections()
|
||||
.forEach(action)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,8 +141,7 @@ public class RPCSettingsBuilder {
|
||||
tapDetectionConfig.getYawResetTaps(),
|
||||
tapDetectionConfig.getMountingResetDelay(),
|
||||
tapDetectionConfig.getMountingResetEnabled(),
|
||||
tapDetectionConfig.getMountingResetTaps(),
|
||||
false
|
||||
tapDetectionConfig.getMountingResetTaps()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package dev.slimevr.reset;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
|
||||
public class ResetHandler {
|
||||
|
||||
private final List<ResetListener> listeners = new CopyOnWriteArrayList<>();
|
||||
|
||||
public ResetHandler() {
|
||||
|
||||
}
|
||||
|
||||
public void sendStarted(int resetType) {
|
||||
this.listeners.forEach((listener) -> listener.onStarted(resetType));
|
||||
}
|
||||
|
||||
public void addListener(ResetListener listener) {
|
||||
this.listeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeListener(ResetListener l) {
|
||||
listeners.removeIf(listener -> l == listener);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package dev.slimevr.reset;
|
||||
|
||||
public interface ResetListener {
|
||||
|
||||
void onStarted(int resetType);
|
||||
}
|
||||
@@ -173,7 +173,8 @@ public class HumanSkeleton {
|
||||
tapDetectionManager = new TapDetectionManager(
|
||||
this,
|
||||
humanPoseManager,
|
||||
server.getConfigManager().getVrConfig().getTapDetection()
|
||||
server.getConfigManager().getVrConfig().getTapDetection(),
|
||||
server.getResetHandler()
|
||||
);
|
||||
legTweaks.setConfig(server.getConfigManager().getVrConfig().getLegTweaks());
|
||||
}
|
||||
|
||||
+33
-1
@@ -2,8 +2,10 @@ package dev.slimevr.tracking.processor.skeleton;
|
||||
|
||||
|
||||
import dev.slimevr.config.TapDetectionConfig;
|
||||
import dev.slimevr.reset.ResetHandler;
|
||||
import dev.slimevr.tracking.processor.HumanPoseManager;
|
||||
import dev.slimevr.tracking.trackers.Tracker;
|
||||
import solarxr_protocol.rpc.ResetType;
|
||||
|
||||
|
||||
// handles tap detection for the skeleton
|
||||
@@ -31,6 +33,13 @@ public class TapDetectionManager {
|
||||
private float yawResetDelayNs = 1.00f * NS_CONVERTER;
|
||||
private float mountingResetDelayNs = 1.00f * NS_CONVERTER;
|
||||
|
||||
// feedback
|
||||
private boolean yawResetAllowPlaySound = true;
|
||||
private boolean fullResetAllowPlaySound = true;
|
||||
private boolean mountingResetAllowPlaySound = true;
|
||||
|
||||
private ResetHandler resetHandler;
|
||||
|
||||
public TapDetectionManager(HumanSkeleton skeleton) {
|
||||
this.skeleton = skeleton;
|
||||
}
|
||||
@@ -38,11 +47,13 @@ public class TapDetectionManager {
|
||||
public TapDetectionManager(
|
||||
HumanSkeleton skeleton,
|
||||
HumanPoseManager humanPoseManager,
|
||||
TapDetectionConfig config
|
||||
TapDetectionConfig config,
|
||||
ResetHandler resetHandler
|
||||
) {
|
||||
this.skeleton = skeleton;
|
||||
this.humanPoseManager = humanPoseManager;
|
||||
this.config = config;
|
||||
this.resetHandler = resetHandler;
|
||||
|
||||
yawResetDetector = new TapDetection(skeleton, getTrackerToWatchYawReset());
|
||||
fullResetDetector = new TapDetection(skeleton, getTrackerToWatchFullReset());
|
||||
@@ -98,6 +109,11 @@ public class TapDetectionManager {
|
||||
private void checkYawReset() {
|
||||
boolean tapped = (yawResetTaps <= yawResetDetector.getTaps());
|
||||
|
||||
if (tapped && yawResetAllowPlaySound) {
|
||||
this.resetHandler.sendStarted(ResetType.Yaw);
|
||||
yawResetAllowPlaySound = false;
|
||||
}
|
||||
|
||||
if (
|
||||
tapped && System.nanoTime() - yawResetDetector.getDetectionTime() > yawResetDelayNs
|
||||
) {
|
||||
@@ -105,13 +121,20 @@ public class TapDetectionManager {
|
||||
humanPoseManager.resetTrackersYaw(resetSourceName);
|
||||
else
|
||||
skeleton.resetTrackersYaw(resetSourceName);
|
||||
|
||||
yawResetDetector.resetDetector();
|
||||
yawResetAllowPlaySound = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void checkFullReset() {
|
||||
boolean tapped = (fullResetTaps <= fullResetDetector.getTaps());
|
||||
|
||||
if (tapped && fullResetAllowPlaySound) {
|
||||
this.resetHandler.sendStarted(ResetType.Full);
|
||||
fullResetAllowPlaySound = false;
|
||||
}
|
||||
|
||||
if (
|
||||
tapped && System.nanoTime() - fullResetDetector.getDetectionTime() > fullResetDelayNs
|
||||
) {
|
||||
@@ -119,13 +142,20 @@ public class TapDetectionManager {
|
||||
humanPoseManager.resetTrackersFull(resetSourceName);
|
||||
else
|
||||
skeleton.resetTrackersFull(resetSourceName);
|
||||
|
||||
fullResetDetector.resetDetector();
|
||||
yawResetAllowPlaySound = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void checkMountingReset() {
|
||||
boolean tapped = (mountingResetTaps <= mountingResetDetector.getTaps());
|
||||
|
||||
if (tapped && mountingResetAllowPlaySound) {
|
||||
this.resetHandler.sendStarted(ResetType.Mounting);
|
||||
mountingResetAllowPlaySound = false;
|
||||
}
|
||||
|
||||
if (
|
||||
tapped
|
||||
&& System.nanoTime() - mountingResetDetector.getDetectionTime()
|
||||
@@ -133,9 +163,11 @@ public class TapDetectionManager {
|
||||
) {
|
||||
skeleton.resetTrackersMounting(resetSourceName);
|
||||
mountingResetDetector.resetDetector();
|
||||
mountingResetAllowPlaySound = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// returns either the chest tracker, hip tracker, or waist tracker depending
|
||||
// on which one is available
|
||||
// if none are available, returns null
|
||||
|
||||
@@ -11,6 +11,8 @@ import dev.slimevr.tracking.trackers.TrackerStatus;
|
||||
import io.eiren.util.Util;
|
||||
import io.eiren.util.collections.FastList;
|
||||
import io.eiren.util.logging.LogManager;
|
||||
import solarxr_protocol.rpc.ResetType;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -578,14 +580,20 @@ public class TrackersUDPServer extends Thread {
|
||||
switch (action.type) {
|
||||
case UDPPacket21UserAction.RESET_FULL:
|
||||
name = "Full";
|
||||
Main.getVrServer().getResetHandler().sendStarted(ResetType.Full);
|
||||
Main.getVrServer().resetTrackersFull(resetSourceName);
|
||||
break;
|
||||
case UDPPacket21UserAction.RESET_YAW:
|
||||
name = "Yaw";
|
||||
Main.getVrServer().getResetHandler().sendStarted(ResetType.Yaw);
|
||||
Main.getVrServer().resetTrackersYaw(resetSourceName);
|
||||
break;
|
||||
case UDPPacket21UserAction.RESET_MOUNTING:
|
||||
name = "Mounting";
|
||||
Main
|
||||
.getVrServer()
|
||||
.getResetHandler()
|
||||
.sendStarted(ResetType.Mounting);
|
||||
Main.getVrServer().resetTrackersMounting(resetSourceName);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user