Martin Kunz 4 years ago
parent
commit
771f6c94cf

+ 0 - 2
src/main/java/uraxis/Activator.java

@@ -24,9 +24,7 @@ public class Activator implements BundleActivator {
 		System.out.println("Activator says Hello World!");
 		MyDaemonDaemonService daemonService = new MyDaemonDaemonService();
 		MyDaemonInstallationNodeService installationNodeService = new MyDaemonInstallationNodeService(daemonService);
-
 		context.registerService(InstallationNodeService.class, installationNodeService, null);
-		// context.registerService(ProgramNodeService.class, new MyDaemonProgramNodeService(), null);
 		context.registerService(DaemonService.class, daemonService, null);
 		context.registerService(SwingToolbarService.class, new MyToolbarService(), null);
 		context.registerService(SwingProgramNodeService.class, new AbsFestoNodeService(), null);

+ 15 - 0
src/main/java/uraxis/MyDaemonInstallationNodeContribution.java

@@ -43,6 +43,9 @@ public class MyDaemonInstallationNodeContribution implements InstallationNodeCon
 	@Input(id = "btnRef")
 	private InputButton refButtonRef;
 
+    @Input(id = "btnReady")
+    private InputButton refButtonrReady;
+
 	@Input(id = "textIP")
 	private InputTextField refTextIP;
 
@@ -70,6 +73,17 @@ public class MyDaemonInstallationNodeContribution implements InstallationNodeCon
 		}
 	}
 
+    @Input(id = "btnReady")
+    public void onBtnReady(InputEvent event) {
+        if (event.getEventType() == InputEvent.EventType.ON_RELEASED) {
+            try {
+                getDaemonInterface().client.execute("ready", new String[]{});
+            } catch (XmlRpcException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
 	@Input(id = "btnEnableDaemon")
 	public void onStartClick(InputEvent event) {
 		if (event.getEventType() == InputEvent.EventType.ON_CHANGE) {
@@ -90,6 +104,7 @@ public class MyDaemonInstallationNodeContribution implements InstallationNodeCon
 	public void openView() {
 		enableDaemonButton.setText("Start Daemon");
 		disableDaemonButton.setText("Stop daemon");
+		refButtonrReady.setText("Ready");
 		refTextIP.setText(getIP());
 		refTextPort.setText(getPort());
 

+ 25 - 6
src/main/java/uraxis/MyDaemonInterface.java

@@ -43,20 +43,39 @@ public class MyDaemonInterface {
 		return "";
 	}
 
-	public boolean rel(int val) {
+	public int getpos() {
 		try {
-			client.execute("rel", new Object[]{String.valueOf(val)});
-			return true;
+			Object res= client.execute("getpos", new Object[]{});
+			return (int) res;
+		} catch (XmlRpcException e) {
+			e.printStackTrace();
+			return -1;
+		}
+	}
+	public String getstatus() {
+		try {
+			String res= (String) client.execute("status", new Object[]{});
+			return res;
+		} catch (XmlRpcException e) {
+			e.printStackTrace();
+			return "";
+		}
+	}
+
+	public boolean rel(int pos, int speed) {
+		try {
+			boolean success= (boolean) client.execute("rel", new Object[]{String.valueOf(pos), String.valueOf(speed)});
+			return success;
 		} catch (XmlRpcException e) {
 			e.printStackTrace();
 			return false;
 		}
 	}
 
-	public boolean abs(int val) {
+	public boolean abs(int pos, int speed) {
 		try {
-			client.execute("abs", new Object[]{String.valueOf(val)});
-			return true;
+			boolean success= (boolean) client.execute("abs", new Object[]{String.valueOf(pos), String.valueOf(speed)});
+			return success;
 		} catch (XmlRpcException e) {
 			e.printStackTrace();
 			return false;

+ 48 - 11
src/main/java/uraxis/programnodes/FestoNodeContribution.java

@@ -11,8 +11,14 @@ import com.ur.urcap.api.domain.userinteraction.keyboard.KeyboardInputFactory;
 import com.ur.urcap.api.domain.userinteraction.keyboard.KeyboardNumberInput;
 import uraxis.MyDaemonInstallationNodeContribution;
 
+import java.awt.*;
+import java.util.Timer;
+import java.util.TimerTask;
+
 public class FestoNodeContribution implements ProgramNodeContribution {
-    private final String VALUE="VALUE";
+    private final String POSITION="POSITION";
+    private final String SPEED="SPEED";
+
     private final ProgramAPI programAPI;
     private final UndoRedoManager undoRedoManager;
     private final KeyboardInputFactory keyboardFactory;
@@ -21,6 +27,7 @@ public class FestoNodeContribution implements ProgramNodeContribution {
     private final DataModel model;
     private final NodeType nodeType;
 
+
     public FestoNodeContribution(ProgramAPIProvider apiProvider, FestoNodeView view, DataModel model, NodeType nt) {
         this.programAPI = apiProvider.getProgramAPI();
         this.undoRedoManager = apiProvider.getProgramAPI().getUndoRedoManager();
@@ -33,12 +40,15 @@ public class FestoNodeContribution implements ProgramNodeContribution {
 
     @Override
     public void openView() {
-        view.setValue(model.get(VALUE, 0));
+        view.setPosition(model.get(POSITION, 0));
+        view.setSpeed(model.get(SPEED, 20));
     }
 
     @Override
     public void closeView() {
-        model.set(VALUE, view.getValue());
+        model.set(POSITION, view.getPosition());
+        model.set(SPEED, view.getSpeed());
+
     }
 
     @Override
@@ -46,36 +56,63 @@ public class FestoNodeContribution implements ProgramNodeContribution {
         return "Festo "+ nodeType.name();
     }
 
+    public int getPosition() {
+        return model.get(POSITION,0);
+    }
+
+    public int getSpeed() {
+        return model.get(SPEED,20);
+    }
+
 
     @Override
     public void generateScript(ScriptWriter writer) {
         if(nodeType==NodeType.ABS) {
-            writer.appendLine(getInstallation().getXMLRPCVariable() + ".abs(\"" + view.getValue() + "\")");
-            writer.appendLine("write_output_integer_register(3,"+view.getValue()+")");
+            writer.appendLine(getInstallation().getXMLRPCVariable() + ".abs(\"" + getPosition() + ", "+ getSpeed() +")\")");
+            writer.appendLine("write_output_integer_register(3,"+ getPosition()+")");
         }
         else {
-            writer.appendLine(getInstallation().getXMLRPCVariable() + ".rel(\"" + view.getValue() + "\")");
-            writer.appendLine("write_output_integer_register(3," + view.getValue() + ")");
+            writer.appendLine(getInstallation().getXMLRPCVariable() + ".rel(\"" + getPosition() + ", " + getSpeed() +")\")");
+            writer.appendLine("write_output_integer_register(3," + getPosition() + ")");
         }
         writer.writeChildren();
 
     }
 
-    public KeyboardNumberInput getKeyboardForTextField() {
+    public KeyboardNumberInput getKeyboardForPositionField() {
         KeyboardNumberInput<Integer> keyboardInput = keyboardFactory.createIntegerKeypadInput();
-        keyboardInput.setInitialValue(0);
+        keyboardInput.setInitialValue(model.get(POSITION, 0));
         return keyboardInput;
     }
 
-    public KeyboardInputCallback<Integer> getCallbackForTextField() {
+    public KeyboardInputCallback<Integer> getCallbackForPositionField() {
         return new KeyboardInputCallback<Integer>() {
             @Override
             public void onOk(Integer value) {
-                view.setValue(value);
+                model.set(POSITION, value);
+                view.setPosition(value);
             }
         };
     }
 
+
+    public KeyboardNumberInput getKeyboardForSpeedField() {
+        KeyboardNumberInput<Integer> keyboardInput = keyboardFactory.createIntegerKeypadInput();
+        keyboardInput.setInitialValue(model.get(SPEED, 0));
+        return keyboardInput;
+    }
+
+    public KeyboardInputCallback<Integer> getCallbackForSpeedField() {
+        return new KeyboardInputCallback<Integer>() {
+            @Override
+            public void onOk(Integer value) {
+                model.set(SPEED, value);
+                view.setSpeed(value);
+            }
+        };
+    }
+
+
     private MyDaemonInstallationNodeContribution getInstallation() {
         return programAPI.getInstallationNode(MyDaemonInstallationNodeContribution.class);
     }

+ 47 - 16
src/main/java/uraxis/programnodes/FestoNodeView.java

@@ -17,7 +17,7 @@ import java.awt.event.MouseEvent;
 public class FestoNodeView implements SwingProgramNodeView<FestoNodeContribution>{
 
     private final Style style;
-    private JTextField jTextField;
+    private JTextField jtfPosition, jtfSpeed;
 
     public FestoNodeView(Style style) {
         this.style = style;
@@ -27,33 +27,55 @@ public class FestoNodeView implements SwingProgramNodeView<FestoNodeContribution
     public void buildUI(JPanel jPanel, final ContributionProvider<FestoNodeContribution> provider) {
         jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
         jPanel.add(createVerticalSpacing(style.getVerticalSpacing()));
-        jPanel.add(createInput(provider));
+        jPanel.add(createInputPosition(provider));
+        jPanel.add(createInputSpeed(provider));
         jPanel.add(createVerticalSpacing(style.getExtraLargeVerticalSpacing()));
     }
 
-    private Box createInput(final ContributionProvider<FestoNodeContribution> provider) {
+    private Box createInputPosition(final ContributionProvider<FestoNodeContribution> provider) {
         Box inputBox = Box.createHorizontalBox();
         inputBox.setAlignmentX(Component.LEFT_ALIGNMENT);
         inputBox.add(new JLabel("Move by:"));
         inputBox.add(createHorizontalSpacing());
 
-        jTextField = new JTextField();
-        jTextField.setFocusable(false);
-        jTextField.setPreferredSize(style.getInputfieldSize());
-        jTextField.setMaximumSize(jTextField.getPreferredSize());
-        jTextField.addMouseListener(new MouseAdapter() {
+        jtfPosition = new JTextField();
+        jtfPosition.setFocusable(false);
+        jtfPosition.setPreferredSize(style.getInputfieldSize());
+        jtfPosition.setMaximumSize(jtfPosition.getPreferredSize());
+        jtfPosition.addMouseListener(new MouseAdapter() {
             @Override
             public void mousePressed(MouseEvent e) {
-                KeyboardNumberInput keyboardInput = provider.get().getKeyboardForTextField();
-                keyboardInput.show(jTextField, provider.get().getCallbackForTextField());
+                KeyboardNumberInput keyboardInput = provider.get().getKeyboardForPositionField();
+                keyboardInput.show(jtfPosition, provider.get().getCallbackForPositionField());
             }
         });
+        inputBox.add(jtfPosition);
 
-        inputBox.add(jTextField);
         return inputBox;
     }
 
-    private Component createVerticalSpacing(int height) {
+    private Box createInputSpeed(final ContributionProvider<FestoNodeContribution> provider) {
+        Box inputBox = Box.createHorizontalBox();
+        inputBox.setAlignmentX(Component.LEFT_ALIGNMENT);
+        inputBox.add(new JLabel("Speed %:"));
+        inputBox.add(createHorizontalSpacing());
+
+        jtfSpeed = new JTextField();
+        jtfSpeed.setFocusable(false);
+        jtfSpeed.setPreferredSize(style.getInputfieldSize());
+        jtfSpeed.setMaximumSize(jtfSpeed.getPreferredSize());
+        jtfSpeed.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mousePressed(MouseEvent e) {
+                KeyboardNumberInput keyboardInput = provider.get().getKeyboardForSpeedField();
+                keyboardInput.show(jtfSpeed, provider.get().getCallbackForSpeedField());
+            }
+        });
+        inputBox.add(jtfSpeed);
+        return inputBox;
+    }
+
+        private Component createVerticalSpacing(int height) {
         return Box.createRigidArea(new Dimension(0, height));
     }
 
@@ -61,11 +83,20 @@ public class FestoNodeView implements SwingProgramNodeView<FestoNodeContribution
         return Box.createRigidArea(new Dimension(style.getHorizontalSpacing(), 0));
     }
 
-    public void setValue(Integer value) {
-        jTextField.setText(value.toString());
+    public void setPosition(Integer value) {
+        jtfPosition.setText(value.toString());
+    }
+
+    public void setSpeed(Integer value) {
+        jtfSpeed.setText(value.toString());
     }
 
-    public Integer getValue() {
-        return Integer.parseInt(jTextField.getText());
+    public Integer getPosition() {
+        return Integer.parseInt(jtfPosition.getText());
+    }
+    public Integer getSpeed() {
+        return Integer.parseInt(jtfSpeed.getText());
     }
+
+
 }

+ 45 - 27
src/main/java/uraxis/toolbar/MyToolbarContribution.java

@@ -5,13 +5,10 @@ import com.ur.urcap.api.contribution.toolbar.swing.SwingToolbarContribution;
 import uraxis.Activator;
 
 import javax.swing.*;
-import java.awt.Component;
-import java.awt.Dimension;
-import java.awt.Font;
+import java.awt.*;
 import java.awt.event.ActionEvent;
-import java.util.Date;
-import java.util.Locale;
-import java.util.Random;
+import java.util.*;
+import java.util.Timer;
 
 class MyToolbarContribution implements SwingToolbarContribution {
     private static final int VERTICAL_SPACE = 10;
@@ -19,6 +16,8 @@ class MyToolbarContribution implements SwingToolbarContribution {
 
     private final ToolbarContext context;
     private JLabel demoToolStatus;
+    private Timer uiTimer;
+
 
     MyToolbarContribution(ToolbarContext context) {
         this.context = context;
@@ -26,11 +25,28 @@ class MyToolbarContribution implements SwingToolbarContribution {
 
     @Override
     public void openView() {
-        demoToolStatus.setText("<HTML>" + get3rdPartyStatus() + "</HTML>");
+
+        //UI updates from non-GUI threads must use EventQueue.invokeLater (or SwingUtilities.invokeLater)
+        uiTimer = new Timer(true);
+        uiTimer.schedule(new TimerTask() {
+            @Override
+            public void run() {
+                EventQueue.invokeLater(new Runnable() {
+                    @Override
+                    public void run() {
+                        demoToolStatus.setText("<HTML>" + get3rdPartyStatus() + "</HTML>");
+
+                    }
+                });
+            }
+        }, 0, 1000);
+
+
     }
 
     @Override
     public void closeView() {
+        uiTimer.cancel();
     }
 
     public void buildUI(JPanel jPanel) {
@@ -53,51 +69,51 @@ class MyToolbarContribution implements SwingToolbarContribution {
 
     private Box createButtons() {
         Box box = Box.createHorizontalBox();
-        JButton left100 = new JButton("<<<100");
+        JButton left100 = new JButton("<<<1000");
         left100.addActionListener(new AbstractAction() {
             @Override
             public void actionPerformed(ActionEvent e) {
-                Activator.daemonInterface.rel(-100);
+                Activator.daemonInterface.rel(-1000, 20);
             }
         });
         box.add(left100);
-        JButton left10 = new JButton("<<10");
+        JButton left10 = new JButton("<<100");
         left10.addActionListener(new AbstractAction() {
             @Override
             public void actionPerformed(ActionEvent e) {
-                Activator.daemonInterface.rel(-10);
+                Activator.daemonInterface.rel(-100, 20);
             }
         });
         box.add(left10);
-        JButton left1 = new JButton("<1");
+        JButton left1 = new JButton("<10");
         left1.addActionListener(new AbstractAction() {
             @Override
             public void actionPerformed(ActionEvent e) {
-                Activator.daemonInterface.rel(-1);
+                Activator.daemonInterface.rel(-10, 20);
             }
         });
         box.add(left1);
-        JButton right1 = new JButton("1>");
+        JButton right1 = new JButton("10>");
         right1.addActionListener(new AbstractAction() {
             @Override
             public void actionPerformed(ActionEvent e) {
-                Activator.daemonInterface.rel(1);
+                Activator.daemonInterface.rel(10, 20);
             }
         });
         box.add(right1);
-        JButton right10 = new JButton("10>>");
+        JButton right10 = new JButton("100>>");
         right10.addActionListener(new AbstractAction() {
             @Override
             public void actionPerformed(ActionEvent e) {
-                Activator.daemonInterface.rel(10);
+                Activator.daemonInterface.rel(100, 20);
             }
         });
         box.add(right10);
-        JButton right100 = new JButton("100>>>");
+        JButton right100 = new JButton("1000>>>");
         right100.addActionListener(new AbstractAction() {
             @Override
             public void actionPerformed(ActionEvent e) {
-                Activator.daemonInterface.rel(100);
+                Activator.daemonInterface.rel(1000, 20);
             }
         });
         box.add(right100);
@@ -112,12 +128,12 @@ class MyToolbarContribution implements SwingToolbarContribution {
 //        pane1.setText("<HTML>This is a sample URCap Toolbar contribution. Feel free to use this as an example for creating new contributions.</HTML>");
 //        pane1.setBackground(infoBox.getBackground());
 //        infoBox.add(pane1);
-
-        JLabel pane2 = new JLabel();
-        Locale locale = context.getAPIProvider().getSystemAPI().getSystemSettings().getLocalization().getLocale();
-        pane2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
-        pane2.setText("<HTML>Currently, the robot is configured to use the Locale: " + locale.getDisplayName() + "</HTML>");
-        infoBox.add(pane2);
+//
+//        JLabel pane2 = new JLabel();
+//        Locale locale = context.getAPIProvider().getSystemAPI().getSystemSettings().getLocalization().getLocale();
+//        pane2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
+//        pane2.setText("<HTML>Currently, the robot is configured to use the Locale: " + locale.getDisplayName() + "</HTML>");
+//        infoBox.add(pane2);
 
         demoToolStatus = new JLabel();
         demoToolStatus.setText("<HTML>" + get3rdPartyStatus() +"</HTML>");
@@ -132,7 +148,9 @@ class MyToolbarContribution implements SwingToolbarContribution {
 
     private String get3rdPartyStatus() {
         Date now = new Date();
-        int number = new Random().nextInt(10) + 20;
-        return  String.format("Tool status reading: %d, read at %tF %tT.", number, now, now);
+        int curPos=Activator.daemonInterface.getpos();
+        String curStatus=Activator.daemonInterface.getstatus();
+
+        return  String.format("Position: %d, read at %tF %tT.<br/>%s", curPos, now, now, curStatus);
     }
 }

+ 4 - 2
src/main/resources/uraxis/installation.html

@@ -25,8 +25,10 @@
 			<label for="textIP">Daemon IP</label>
 			<input id="textIP" type="text" style="font-size: 18px;" /><br/>
 			<label for="textIP">Daemon Port</label>
-			<input id="textPort" type="text" style="font-size: 18px;" />
-			<input id="btnEnableDaemon" type="button" style="font-size: 18px;" />
+			<input id="textPort" type="text" style="font-size: 18px;" /><br/>
+            <input id="btnReady" type="button" style="font-size: 18px;" />
+
+            <input id="btnEnableDaemon" type="button" style="font-size: 18px;" />
 			<input id="btnDisableDaemon" type="button" style="font-size: 18px;" />
 			<br>
 			<label  id="lblStatus" style="width: 400px;height: 200px;vertical-align: top"></label>