added getBattery() + setFeedback()
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,23 @@
|
|||||||
package main.java.bzh.risotto.dualsensgui;
|
package bzh.risotto.dualsensgui;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class DualsensguiApplication {
|
public class DualsensguiApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
25
src/main/java/bzh/risotto/dualsensgui/Trigger.java
Normal file
25
src/main/java/bzh/risotto/dualsensgui/Trigger.java
Normal 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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user