Commit 80890ac9 authored by Matthias Möller's avatar Matthias Möller

Hinzufügen eines Sensibilitätsregelers

parent aa290a9e
No preview for this file type
......@@ -4,6 +4,8 @@ import java.awt.event.*;
import java.net.UnknownHostException;
import javax.swing.JButton;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import com.emotiv.Iedk.Edk;
import com.emotiv.Iedk.EmoState;
......@@ -13,13 +15,13 @@ import Modell.*;
import Server.WebsocketServer2;
import View.*;
public class EmotivController implements ActionListener, WindowListener{
public class EmotivController implements ActionListener, WindowListener, ChangeListener{
EmotivGUI emotivGUI;
EmotivThread emotivThread;
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);
......@@ -37,6 +39,7 @@ public class EmotivController implements ActionListener, WindowListener{
if(buttonName == "Trainiere Normal!"){
activateActionSkills();
if(this.emotivThread.getStopped()){
Edk.INSTANCE.IEE_MentalCommandSetTrainingAction(0, EmoState.IEE_MentalCommandAction_t.MC_NEUTRAL.ToInt());
Edk.INSTANCE.IEE_MentalCommandSetTrainingControl(0, Edk.IEE_MentalCommandTrainingControl_t.MC_START.getType());
......@@ -48,6 +51,7 @@ public class EmotivController implements ActionListener, WindowListener{
}
}
else if(buttonName == "Trainiere MC1!"){
activateActionSkills();
if(this.emotivThread.getStopped()){
Edk.INSTANCE.IEE_MentalCommandSetTrainingAction(0, EmoState.IEE_MentalCommandAction_t.MC_PUSH.ToInt());
Edk.INSTANCE.IEE_MentalCommandSetTrainingControl(0, Edk.IEE_MentalCommandTrainingControl_t.MC_START.getType());
......@@ -60,6 +64,7 @@ public class EmotivController implements ActionListener, WindowListener{
}
else if(buttonName == "Trainiere MC2!"){
activateActionSkills();
if(this.emotivThread.getStopped()){
Edk.INSTANCE.IEE_MentalCommandSetTrainingAction(0, EmoState.IEE_MentalCommandAction_t.MC_LIFT.ToInt());
Edk.INSTANCE.IEE_MentalCommandSetTrainingControl(0, Edk.IEE_MentalCommandTrainingControl_t.MC_START.getType());
......@@ -115,6 +120,17 @@ public class EmotivController implements ActionListener, WindowListener{
public static void main(String[] args) throws UnknownHostException{
new EmotivController();
}
private void activateActionSkills() {
int shallBeActivated = 0;
shallBeActivated += EmoState.IEE_MentalCommandAction_t.MC_PULL.ToInt();
shallBeActivated += EmoState.IEE_MentalCommandAction_t.MC_PUSH.ToInt();
NativeLongByReference activeActions = new NativeLongByReference();
Edk.INSTANCE.IEE_MentalCommandGetActiveActions(0, activeActions);
if(activeActions.getValue().intValue() != shallBeActivated) {
Edk.INSTANCE.IEE_MentalCommandSetActiveActions(0, shallBeActivated);
}
}
@Override
public void windowActivated(WindowEvent arg0) {
......@@ -159,4 +175,11 @@ public class EmotivController implements ActionListener, WindowListener{
this.emotivThread.start();
}
//ChangeListenerEvents
@Override
public void stateChanged(ChangeEvent e) {
this.emotivThread.updateMentalCommandSensibility();
}
}
......@@ -21,8 +21,6 @@ public class EmotivThread extends Thread {
public void run(){
this.emo.initialize();
try {
this.sleep(20);
System.out.println(Edk.INSTANCE.IEE_MentalCommandSetActiveActions(0, 6));
//runs all the time
while(true){
isAllowedToWork.acquire();
......@@ -74,5 +72,9 @@ public class EmotivThread extends Thread {
public void deactivateWebsocketConnection() {
this.emo.deactivateWebsocketConnection();
}
public void updateMentalCommandSensibility() {
this.emo.updateMentalCommandSensibility();
}
}
......@@ -91,4 +91,8 @@ public abstract class AbstractEmostateUpdatedComponent extends AbstractEmotiv {
public String getMaxBatteryCharge() {
return this.nextEmotivComponent.getMaxBatteryCharge();
}
public void updateMentalCommandSensibility() {
this.nextEmotivComponent.updateMentalCommandSensibility();
}
}
......@@ -57,4 +57,6 @@ public abstract class AbstractEmotiv {
public abstract String getMaxBatteryCharge();
public abstract void updateMentalCommandSensibility();
}
......@@ -227,6 +227,10 @@ public class EmotivInit extends AbstractEmotiv {
return "";
}
public void updateMentalCommandSensibility() {
this.webSocketLeader.updateMentalCommandSensibility();
};
//-----------------------------------------------------------------------------------------------------
//Behandelt generell die Auslese
......
......@@ -8,6 +8,8 @@ import Server.WebsocketServer2;
public class MentalCommandWebSocket extends AbstractWebSocketComponent{
public int actualMentalCommand;
public int iteratedTriggeredMentalCommand = 0;
public int MCPULLSensibility = 3;
public int MCPUSHSensibility = 3;
public MentalCommandWebSocket(AbstractEmotiv emo) {
......@@ -55,12 +57,23 @@ public class MentalCommandWebSocket extends AbstractWebSocketComponent{
this.iteratedTriggeredMentalCommand +=1;
}
if(this.iteratedTriggeredMentalCommand > 5){
WebsocketServer2.sendMentalCommand(this.actualMentalCommand);
switch(this.actualMentalCommand) {
case 2:
if(this.iteratedTriggeredMentalCommand >= this.MCPUSHSensibility) {
WebsocketServer2.sendMentalCommand(2);
System.out.println("MCPUSH");
}
break;
case 4:
if(this.iteratedTriggeredMentalCommand >= this.MCPULLSensibility) {
WebsocketServer2.sendMentalCommand(4);
System.out.println("MCPULL");
}
break;
}
this.nextEmotivComponent.actualizeComponents();
System.out.println(newMentalCommand);
}
......@@ -69,5 +82,10 @@ public class MentalCommandWebSocket extends AbstractWebSocketComponent{
// TODO Auto-generated method stub
}
public void updateMentalCommandSensibility() {
this.MCPUSHSensibility = this.getView().getMCPUSHSensibilitiy();
this.MCPULLSensibility = this.getView().getMCPULLSenisibility();
}
}
......@@ -5,6 +5,7 @@ import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.*;
import java.util.Hashtable;
import java.awt.BorderLayout;
import javax.swing.*;
......@@ -30,6 +31,9 @@ public class EmotivGUI extends JFrame implements ActionListener{
private JLabel maxBatteryLabel = new JLabel("");
private JLabel trainingStateLabel = new JLabel();
private JPanel buttonPanel = new JPanel();
private JPanel websocketPanel = new JPanel();
private JSlider MCPUSHSlider;
private JSlider MCPULLSlider;
public EmotivGUI(EmotivController emotivController, AbstractEmotiv modell){
this.emotivController = emotivController;
......@@ -47,6 +51,7 @@ public class EmotivGUI extends JFrame implements ActionListener{
this.contentPanel.setPreferredSize(new Dimension(500, 110));
this.add(contentPanel);
this.createTrainingContent();
this.createWebsocketConnectionPanel();
this.setSize(500, 220);
......@@ -173,13 +178,47 @@ public class EmotivGUI extends JFrame implements ActionListener{
}
private void createWebsocketConnectionPanel() {
Hashtable<Integer, JLabel> hash = new Hashtable<Integer, JLabel>();
hash.put(new Integer(1), new JLabel("high"));
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);
MC1Slider.setMajorTickSpacing(1);
MC1Slider.setMinorTickSpacing(1);
MC1Slider.setPaintTicks(true);
MC1Slider.setLabelTable(hash);
MC1Slider.setPaintLabels(true);
MC1Slider.addChangeListener(this.emotivController);
this.MCPUSHSlider = MC1Slider;
this.websocketPanel.add(this.MCPUSHSlider);
JSlider MC2Slider = new JSlider(JSlider.HORIZONTAL, 1, 5, 3);
MC2Slider.setMajorTickSpacing(1);
MC2Slider.setMinorTickSpacing(1);
MC2Slider.setPaintTicks(true);
MC2Slider.setLabelTable(hash);
MC2Slider.setPaintLabels(true);
MC2Slider.addChangeListener(this.emotivController);
this.MCPULLSlider = MC2Slider;
this.websocketPanel.add(this.MCPULLSlider);
}
private void showWebsocketConnectionPanel() {
this.contentPanel.removeAll();
this.contentPanel.updateUI();
this.contentPanel.add(this.websocketPanel);
}
public int getMCPUSHSensibilitiy(){
return this.MCPUSHSlider.getValue();
}
public int getMCPULLSenisibility() {
return this.MCPULLSlider.getValue();
}
//---------------------------------------------------------------------------------------------------------------
//Update-Funktion
......@@ -226,6 +265,7 @@ public class EmotivGUI extends JFrame implements ActionListener{
this.buttonPanel.setVisible(bool);
}
//--------------------------------------------------------------------------------------------------
//ActionEvents
......@@ -272,7 +312,7 @@ public class EmotivGUI extends JFrame implements ActionListener{
}
else if(buttonName == "Verbindung") {
this.createWebsocketConnectionPanel();
this.showWebsocketConnectionPanel();
}
else if(buttonName=="<html><span color='green'>Accept Training</span></html>") {
......
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