Skip to content

Commit

Permalink
Merge pull request #114 from SlimeVR/test
Browse files Browse the repository at this point in the history
Network refactoring
  • Loading branch information
Eirenliel committed Jan 27, 2022
2 parents fe4dde6 + 930b5c7 commit 4f14f01
Show file tree
Hide file tree
Showing 32 changed files with 1,300 additions and 517 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ run gradle command `shadowJar` to build a runnable server JAR
* You must provide a copy of the original license (see LICENSE file)
* You don't have to release your own software under MIT License or even open source at all, but you have to state that it's based on SlimeVR
* This applies even if you distribute software without the source code

## Contributions

By contributing to this project you are placing all your code under MIT or less restricting licenses, and you certify that the code you have used is compatible with those licenses or is authored by you. If you're doing so on your work time, you certify that your employer is okay with this.
2 changes: 1 addition & 1 deletion slime-java-commons
Submodule slime-java-commons updated 1 files
+6 −1 README.md
2 changes: 1 addition & 1 deletion src/main/java/dev/slimevr/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class Main {

public static String VERSION = "0.1.3";
public static String VERSION = "0.1.4";

public static VRServer vrServer;

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/dev/slimevr/NetworkProtocol.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.slimevr;

public enum NetworkProtocol {

OWO_LEGACY,
SLIMEVR_RAW,
SLIMEVR_FLATBUFFER,
SLIMEVR_WEBSOCKET;
}
2 changes: 1 addition & 1 deletion src/main/java/dev/slimevr/VRServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import dev.slimevr.vr.trackers.ShareableTracker;
import dev.slimevr.vr.trackers.Tracker;
import dev.slimevr.vr.trackers.TrackerConfig;
import dev.slimevr.vr.trackers.TrackersUDPServer;
import dev.slimevr.vr.trackers.udp.TrackersUDPServer;
import io.eiren.util.OperatingSystem;
import io.eiren.util.ann.ThreadSafe;
import io.eiren.util.ann.ThreadSecure;
Expand Down
73 changes: 51 additions & 22 deletions src/main/java/dev/slimevr/gui/TrackersList.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class TrackersList extends EJBoxNoStretch {
private final VRServer server;
private final VRServerGUI gui;
private long lastUpdate = 0;
private boolean debug = false;

public TrackersList(VRServer server, VRServerGUI gui) {
super(BoxLayout.PAGE_AXIS, false, true);
Expand All @@ -59,6 +60,12 @@ public TrackersList(VRServer server, VRServerGUI gui) {
server.addNewTrackerConsumer(this::newTrackerAdded);
}

@AWTThread
public void setDebug(boolean debug) {
this.debug = debug;
build();
}

@AWTThread
private void build() {
removeAll();
Expand Down Expand Up @@ -142,10 +149,12 @@ private class TrackerPanel extends EJBagNoStretch {
JLabel magAccuracy;
JLabel adj;
JLabel adjYaw;
JLabel adjGyro;
JLabel correction;
JLabel signalStrength;
JLabel rotQuat;
JLabel rotAdj;
JLabel temperature;

@AWTThread
public TrackerPanel(Tracker t) {
Expand Down Expand Up @@ -245,18 +254,17 @@ public void actionPerformed(ActionEvent e) {
row++;
add(new JLabel("Raw:"), c(0, row, 2, GridBagConstraints.FIRST_LINE_START));
add(raw = new JLabel("0 0 0"), s(c(1, row, 2, GridBagConstraints.FIRST_LINE_START), 3, 1));
/*
if(realTracker instanceof IMUTracker) {

if(debug && realTracker instanceof IMUTracker) {
add(new JLabel("Quat:"), c(2, row, 2, GridBagConstraints.FIRST_LINE_START));
add(rotQuat = new JLabel("0"), c(3, row, 2, GridBagConstraints.FIRST_LINE_START));
}
//*/
row++;
/*
if(realTracker instanceof IMUTracker) {

if(debug && realTracker instanceof IMUTracker) {
add(new JLabel("Raw mag:"), c(0, row, 2, GridBagConstraints.FIRST_LINE_START));
add(rawMag = new JLabel("0 0 0"), s(c(1, row, 2, GridBagConstraints.FIRST_LINE_START), 3, 1));
add(new JLabel("Hash:"), c(2, row, 2, GridBagConstraints.FIRST_LINE_START));
add(new JLabel("Gyro fix:"), c(2, row, 2, GridBagConstraints.FIRST_LINE_START));
add(new JLabel(String.format("0x%8x", realTracker.hashCode())), s(c(3, row, 2, GridBagConstraints.FIRST_LINE_START), 3, 1));
row++;
add(new JLabel("Cal:"), c(0, row, 2, GridBagConstraints.FIRST_LINE_START));
Expand All @@ -270,16 +278,18 @@ public void actionPerformed(ActionEvent e) {
add(rotAdj = new JLabel("0"), c(3, row, 2, GridBagConstraints.FIRST_LINE_START));
row++;
}
//*/

/*
if(t instanceof ReferenceAdjustedTracker) {
add(new JLabel("Adj:"), c(0, row, 2, GridBagConstraints.FIRST_LINE_START));
if(debug && t instanceof ReferenceAdjustedTracker) {
add(new JLabel("Att fix:"), c(0, row, 2, GridBagConstraints.FIRST_LINE_START));
add(adj = new JLabel("0 0 0 0"), c(1, row, 2, GridBagConstraints.FIRST_LINE_START));
add(new JLabel("AdjY:"), c(2, row, 2, GridBagConstraints.FIRST_LINE_START));
add(new JLabel("Yaw Fix:"), c(2, row, 2, GridBagConstraints.FIRST_LINE_START));
add(adjYaw = new JLabel("0 0 0 0"), c(3, row, 2, GridBagConstraints.FIRST_LINE_START));
row++;
add(new JLabel("Gyro Fix:"), c(0, row, 2, GridBagConstraints.FIRST_LINE_START));
add(adjGyro = new JLabel("0 0 0 0"), c(1, row, 2, GridBagConstraints.FIRST_LINE_START));
add(new JLabel("Temp:"), c(2, row, 2, GridBagConstraints.FIRST_LINE_START));
add(temperature = new JLabel("?"), c(3, row, 2, GridBagConstraints.FIRST_LINE_START));
}
//*/

setBorder(BorderFactory.createLineBorder(new Color(0x663399), 2, false));
TrackersList.this.add(this);
Expand Down Expand Up @@ -314,21 +324,30 @@ public void update() {
if(realTracker instanceof TrackerWithBattery)
bat.setText(String.format("%d%% (%sV)", Math.round(((TrackerWithBattery) realTracker).getBatteryLevel()), StringUtils.prettyNumber(((TrackerWithBattery) realTracker).getBatteryVoltage(), 2)));
if(t instanceof ReferenceAdjustedTracker) {
((ReferenceAdjustedTracker<Tracker>) t).attachmentFix.toAngles(angles);
if(adj != null)
ReferenceAdjustedTracker<Tracker> rat = (ReferenceAdjustedTracker<Tracker>) t;
if(adj != null) {
rat.attachmentFix.toAngles(angles);
adj.setText(StringUtils.prettyNumber(angles[0] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[1] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[2] * FastMath.RAD_TO_DEG, 0));
((ReferenceAdjustedTracker<Tracker>) t).yawFix.toAngles(angles);
if(adjYaw != null)
}
if(adjYaw != null) {
rat.yawFix.toAngles(angles);
adjYaw.setText(StringUtils.prettyNumber(angles[0] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[1] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[2] * FastMath.RAD_TO_DEG, 0));
}
if(adjGyro != null) {
rat.gyroFix.toAngles(angles);
adjGyro.setText(StringUtils.prettyNumber(angles[0] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[1] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[2] * FastMath.RAD_TO_DEG, 0));
}
}
if(realTracker instanceof IMUTracker) {
if(ping != null)
ping.setText(String.valueOf(((IMUTracker) realTracker).ping));
if (signalStrength != null) {
if(signalStrength != null) {
int signal = ((IMUTracker) realTracker).signalStrength;
if (signal == -1) {
signalStrength.setText("N/A");
Expand All @@ -347,21 +366,23 @@ public void update() {
+ " " + StringUtils.prettyNumber(angles[2] * FastMath.RAD_TO_DEG, 0));
if(realTracker instanceof IMUTracker) {
IMUTracker imu = (IMUTracker) realTracker;
imu.rotMagQuaternion.toAngles(angles);
if(rawMag != null)
if(rawMag != null) {
imu.rotMagQuaternion.toAngles(angles);
rawMag.setText(StringUtils.prettyNumber(angles[0] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[1] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[2] * FastMath.RAD_TO_DEG, 0));
}
if(calibration != null)
calibration.setText(imu.calibrationStatus + " / " + imu.magCalibrationStatus);
if(magAccuracy != null)
magAccuracy.setText(StringUtils.prettyNumber(imu.magnetometerAccuracy * FastMath.RAD_TO_DEG, 1) + "°");
imu.getCorrection(q);
q.toAngles(angles);
if(correction != null)
if(correction != null) {
imu.getCorrection(q);
q.toAngles(angles);
correction.setText(StringUtils.prettyNumber(angles[0] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[1] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[2] * FastMath.RAD_TO_DEG, 0));
}
if(rotQuat != null) {
imu.rotQuaternion.toAngles(angles);
rotQuat.setText(StringUtils.prettyNumber(angles[0] * FastMath.RAD_TO_DEG, 0)
Expand All @@ -374,6 +395,14 @@ public void update() {
+ " " + StringUtils.prettyNumber(angles[1] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[2] * FastMath.RAD_TO_DEG, 0));
}
if(temperature != null) {
if(imu.temperature == 0.0f) {
// Can't be exact 0, so no info received
temperature.setText("?");
} else {
temperature.setText(StringUtils.prettyNumber(imu.temperature, 1) + "∘C");
}
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/dev/slimevr/gui/VRServerGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ public void mouseClicked(MouseEvent e) {

add(new EJBoxNoStretch(PAGE_AXIS, false, true) {{
setAlignmentY(TOP_ALIGNMENT);

JCheckBox debugCb;
add(debugCb = new JCheckBox("Show debug information"));
debugCb.setSelected(false);
debugCb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
trackersList.setDebug(debugCb.isSelected());
}
});

JLabel l;
add(l = new JLabel("Body proportions"));
l.setFont(l.getFont().deriveFont(Font.BOLD));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/slimevr/vr/trackers/IMUTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;

import dev.slimevr.vr.trackers.udp.TrackersUDPServer;
import io.eiren.util.BufferedTimer;

public class IMUTracker implements Tracker, TrackerWithTPS, TrackerWithBattery {
Expand Down Expand Up @@ -36,9 +37,8 @@ public class IMUTracker implements Tracker, TrackerWithTPS, TrackerWithBattery {
protected BufferedTimer timer = new BufferedTimer(1f);
public int ping = -1;
public int signalStrength = -1;
public float temperature = 0;

public StringBuilder serialBuffer = new StringBuilder();
long lastSerialUpdate = 0;
public TrackerPosition bodyPosition = null;

public IMUTracker(int trackerId, String name, String descriptiveName, TrackersUDPServer server) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/dev/slimevr/vr/trackers/MPUTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.nio.ByteBuffer;

import dev.slimevr.vr.trackers.udp.TrackersUDPServer;

public class MPUTracker extends IMUTracker {

public ConfigurationData newCalibrationData;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package dev.slimevr.vr.trackers;

public class BnoTap {
public class SensorTap {

public final boolean doubleTap;

public BnoTap(int tapBits) {
public SensorTap(int tapBits) {
doubleTap = (tapBits & 0x40) > 0;
}

Expand Down
Loading

0 comments on commit 4f14f01

Please sign in to comment.