added getBattery() + setFeedback()

This commit is contained in:
helori_ollivier
2026-01-05 21:53:27 +01:00
parent e22c4a2555
commit e2bde1fecb
4 changed files with 95 additions and 15 deletions

View File

@@ -0,0 +1,58 @@
package bzh.risotto.dualsensgui;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class DualsensController {
private static DualsensController dualsensController;
private DualsensController() {
}
public int getBattery() {
String res = run("battery");
String value = res.split(" ")[0];
return Integer.parseInt(value);
}
public void setFeedback(Trigger trigger, int position, int strength) {
run("trigger " + trigger + " feedback " + position + " " + strength);
}
private String run(String command) {
StringBuilder res = new StringBuilder();
command = "dualsensectl " + command;
String[] commandParts = command.split(" ");
try {
ProcessBuilder processBuilder = new ProcessBuilder(commandParts);
processBuilder.redirectErrorStream(true);
Process process = processBuilder.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
res.append(line);
}
process.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
return res.toString();
}
public static DualsensController getController() {
if (dualsensController == null) {
dualsensController = new DualsensController();
}
return dualsensController;
}
}

View File

@@ -1,13 +1,23 @@
package main.java.bzh.risotto.dualsensgui;
package bzh.risotto.dualsensgui;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.io.BufferedReader;
import java.io.InputStreamReader;
@SpringBootApplication
public class DualsensguiApplication {
public static void main(String[] args) {
SpringApplication.run(DualsensguiApplication.class, args);
DualsensController controller = DualsensController.getController();
int battery = controller.getBattery();
System.out.println(battery);
controller.setFeedback(Trigger.LEFT, 1, 1);
//SpringApplication.run(DualsensguiApplication.class, args);
}
}

View File

@@ -0,0 +1,25 @@
package bzh.risotto.dualsensgui;
public enum Trigger {
LEFT {
@Override
public String toString(){
return "left";
}
},
RIGHT {
@Override
public String toString(){
return "right";
}
},
BOTH {
@Override
public String toString(){
return "both";
}
}
}

View File

@@ -1,13 +0,0 @@
package test.java.bzh.risotto.dualsensgui;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class DualsensguiApplicationTests {
@Test
void contextLoads() {
}
}