Skip to content

Commit

Permalink
make SerialHandler's implementation platform-dependant
Browse files Browse the repository at this point in the history
  • Loading branch information
ImUrX committed Jul 8, 2023
1 parent bfece25 commit 2eec3e2
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 325 deletions.
12 changes: 0 additions & 12 deletions server/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* User Manual available at https://docs.gradle.org/6.3/userguide/java_library_plugin.html
*/
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.ByteArrayOutputStream

plugins {
kotlin("jvm")
Expand Down Expand Up @@ -64,7 +63,6 @@ dependencies {
implementation("org.apache.commons:commons-collections4:4.4")

implementation("com.illposed.osc:javaosc-core:0.8")
implementation("com.fazecast:jSerialComm:2.+")
implementation("org.java-websocket:Java-WebSocket:1.+")
implementation("com.melloware:jintellitype:1.+")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
Expand All @@ -79,13 +77,3 @@ dependencies {
tasks.test {
useJUnitPlatform()
}

fun String.runCommand(currentWorkingDir: File = file("./")): String {
val byteOut = ByteArrayOutputStream()
project.exec {
workingDir = currentWorkingDir
commandLine = this@runCommand.split("\\s".toRegex())
standardOutput = byteOut
}
return String(byteOut.toByteArray()).trim()
}
8 changes: 5 additions & 3 deletions server/core/src/main/java/dev/slimevr/VRServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import dev.slimevr.protocol.ProtocolAPI
import dev.slimevr.reset.ResetHandler
import dev.slimevr.serial.ProvisioningHandler
import dev.slimevr.serial.SerialHandler
import dev.slimevr.serial.SerialHandlerStub
import dev.slimevr.setup.TapSetupHandler
import dev.slimevr.status.StatusSystem
import dev.slimevr.tracking.processor.HumanPoseManager
Expand Down Expand Up @@ -41,8 +42,9 @@ typealias SteamBridgeProvider = (
) -> ISteamVRBridge?

class VRServer @JvmOverloads constructor(
driverBridgeProvider: SteamBridgeProvider = { _: VRServer, _: Tracker, _: List<Tracker> -> null },
feederBridgeProvider: (VRServer) -> ISteamVRBridge? = { _: VRServer -> null },
driverBridgeProvider: SteamBridgeProvider = { _, _, _ -> null },
feederBridgeProvider: (VRServer) -> ISteamVRBridge? = { _ -> null },
serialHandlerProvider: (VRServer) -> SerialHandler = { _ -> SerialHandlerStub() },
configPath: String,
) : Thread("VRServer") {
@JvmField
Expand Down Expand Up @@ -100,7 +102,7 @@ class VRServer @JvmOverloads constructor(
configManager = ConfigManager(configPath)
configManager.loadConfig()
deviceManager = DeviceManager(this)
serialHandler = SerialHandler()
serialHandler = serialHandlerProvider(this)
provisioningHandler = ProvisioningHandler(this)
resetHandler = ResetHandler()
tapSetupHandler = TapSetupHandler()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package dev.slimevr.protocol.rpc.serial;

import com.fazecast.jSerialComm.SerialPort;
import com.google.flatbuffers.FlatBufferBuilder;
import dev.slimevr.protocol.GenericConnection;
import dev.slimevr.protocol.ProtocolAPI;
import dev.slimevr.protocol.rpc.RPCHandler;
import dev.slimevr.serial.SerialListener;
import dev.slimevr.serial.SerialPort;
import io.eiren.util.logging.LogManager;
import solarxr_protocol.rpc.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.slimevr.serial;

import com.fazecast.jSerialComm.SerialPort;
import dev.slimevr.VRServer;
import io.eiren.util.logging.LogManager;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Timer;
Expand Down Expand Up @@ -107,7 +107,7 @@ else if (this.provisioningStatus == ProvisioningStatus.LOOKING_FOR_SERVER)


@Override
public void onSerialConnected(SerialPort port) {
public void onSerialConnected(@NotNull SerialPort port) {
if (!isRunning)
return;
this.tryProvisioning();
Expand All @@ -121,7 +121,7 @@ public void onSerialDisconnected() {
}

@Override
public void onSerialLog(String str) {
public void onSerialLog(@NotNull String str) {
if (!isRunning)
return;

Expand Down
Loading

0 comments on commit 2eec3e2

Please sign in to comment.