Commit a47a3a10 authored by Matthias Möller's avatar Matthias Möller

Server isn't sending anymore, when client hasn't activated BCI-mode

parent a47a8725
No preview for this file type
......@@ -21,7 +21,7 @@ public class EmotivController implements ActionListener, WindowListener, ChangeL
WebsocketServer2 emotivServer;
public EmotivController() throws UnknownHostException{
EmotivInit emo = new EmotivInit(1);
EmotivInit emo = new EmotivInit(2);
AbstractEmostateUpdatedComponent guiModel = new MentalCommandComponent(emo);
guiModel = new HardwareComponent(guiModel);
guiModel = new BatteryComponent(guiModel);
......
......@@ -47,7 +47,6 @@ public class MentalCommandWebSocket extends AbstractWebSocketComponent{
public void actualizeComponents() {
int newMentalCommand = EmoState.INSTANCE.IS_MentalCommandGetCurrentAction(getEmoState());
float newMentalCommandStrength = EmoState.INSTANCE.IS_MentalCommandGetCurrentActionPower(getEmoState());
System.out.println(newMentalCommand + " " + newMentalCommandStrength);
if(newMentalCommand != this.actualMentalCommand){
this.actualMentalCommand = newMentalCommand;
......@@ -85,8 +84,8 @@ public class MentalCommandWebSocket extends AbstractWebSocketComponent{
}
public void updateMentalCommandSensibility() {
this.MCPUSHSensibility = (float) (this.getView().getMCPUSHSensibilitiy() * 0.05 + 0.3);
this.MCPULLSensibility = (float) (this.getView().getMCPULLSenisibility() * 0.05 + 0.3);
this.MCPUSHSensibility = (float) (this.getView().getMCPUSHSensibilitiy() * 0.05 + 0.1);
this.MCPULLSensibility = (float) (this.getView().getMCPULLSenisibility() * 0.05 + 0.1);
System.out.print("MCPUSH " + this.MCPUSHSensibility);
System.out.println("MCPULL " + this.MCPULLSensibility);
}
......
......@@ -15,6 +15,8 @@ import org.java_websocket.server.WebSocketServer;
public class WebsocketServer2 extends WebSocketServer{
private static Boolean shallSend = false;
public static WebsocketServer2 Singleton = null;
public static void initialize(int addr) throws UnknownHostException {
......@@ -38,12 +40,12 @@ public class WebsocketServer2 extends WebSocketServer{
@Override
public void onClose( WebSocket conn, int code, String reason, boolean remote ) {
System.out.println( conn + " has left the room!" );
shallSend = false;
}
@Override
public void onMessage( WebSocket conn, String message ) {
System.out.println( conn + ": " + message );
shallSend = Boolean.valueOf(message);
}
@Override
......@@ -66,13 +68,15 @@ public class WebsocketServer2 extends WebSocketServer{
public static void sendMentalCommand(int mentalCommand) {
System.out.println(mentalCommand);
Collection<WebSocket> sockets = Singleton.connections();
for(WebSocket socket : sockets) {
String message = "{";
message = message+ " \"mentalCommand\" : " + Integer.toString(mentalCommand);
message = message + "}";
socket.send(message);
if(shallSend){
System.out.println(mentalCommand);
Collection<WebSocket> sockets = Singleton.connections();
for(WebSocket socket : sockets) {
String message = "{";
message = message+ " \"mentalCommand\" : " + Integer.toString(mentalCommand);
message = message + "}";
socket.send(message);
}
}
}
......
......@@ -201,7 +201,7 @@ public class EmotivGUI extends JFrame implements ActionListener{
hash.put(new Integer(3), new JLabel("average"));
hash.put(new Integer(6), new JLabel("low"));
JSlider MC1Slider = new JSlider(JSlider.HORIZONTAL, 1, 5, 3);
JSlider MC1Slider = new JSlider(JSlider.HORIZONTAL, 1, 10, 5);
MC1Slider.setMajorTickSpacing(1);
MC1Slider.setMinorTickSpacing(1);
MC1Slider.setPaintTicks(true);
......@@ -211,7 +211,7 @@ public class EmotivGUI extends JFrame implements ActionListener{
this.MCPUSHSlider = MC1Slider;
this.websocketPanel.add(this.MCPUSHSlider);
JSlider MC2Slider = new JSlider(JSlider.HORIZONTAL, 1, 5, 3);
JSlider MC2Slider = new JSlider(JSlider.HORIZONTAL, 1, 10, 5);
MC2Slider.setMajorTickSpacing(1);
MC2Slider.setMinorTickSpacing(1);
MC2Slider.setPaintTicks(true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment