Skip to content
Snippets Groups Projects
Commit 8f2619bb authored by Lucas Stratmann's avatar Lucas Stratmann
Browse files

Wiring, Resetbutton, Potilabel

parent 71e38c8f
No related branches found
No related tags found
No related merge requests found
Showing
with 196 additions and 20 deletions
...@@ -8,7 +8,7 @@ import tec.letsgoing.ardublock.simulator.simcode.SimCode; ...@@ -8,7 +8,7 @@ import tec.letsgoing.ardublock.simulator.simcode.SimCode;
/** /**
* @author Lucas * @author Lucas
* * Führt das Unterprogramm mit dem Namen aus.
*/ */
public class CodeExecuteFunction extends SimCode { public class CodeExecuteFunction extends SimCode {
private String name; private String name;
......
...@@ -11,7 +11,7 @@ import tec.letsgoing.ardublock.simulator.simcode.SimCode; ...@@ -11,7 +11,7 @@ import tec.letsgoing.ardublock.simulator.simcode.SimCode;
/** /**
* @author Lucas * @author Lucas
* * Erstellt ein Unterprogramm.
*/ */
public class SimCodeFunction { public class SimCodeFunction {
private String name; private String name;
......
...@@ -9,7 +9,9 @@ import tec.letsgoing.ardublock.simulator.simcode.datatypes.SimTypeInt; ...@@ -9,7 +9,9 @@ import tec.letsgoing.ardublock.simulator.simcode.datatypes.SimTypeInt;
import tec.letsgoing.ardublock.simulator.simcode.functions.SimCodeFunction; import tec.letsgoing.ardublock.simulator.simcode.functions.SimCodeFunction;
/** /**
* @author Lucas //TODO Block Beschreibung realtiv zu Ardublock * Liest den analogen Wert vom Pin [0V=0;5V=1023]
* @author Lucas
*
*/ */
public class CodeAnalogRead extends SimCode { public class CodeAnalogRead extends SimCode {
private SimTypeInt pin; private SimTypeInt pin;
......
...@@ -10,7 +10,7 @@ import tec.letsgoing.ardublock.simulator.simcode.functions.SimCodeFunction; ...@@ -10,7 +10,7 @@ import tec.letsgoing.ardublock.simulator.simcode.functions.SimCodeFunction;
/** /**
* @author Lucas * @author Lucas
* * PWM-Ausgang Wert[0-255] zuweisen
*/ */
public class CodeAnalogWrite extends SimCode { public class CodeAnalogWrite extends SimCode {
private SimTypeInt pin; private SimTypeInt pin;
......
...@@ -10,6 +10,7 @@ import tec.letsgoing.ardublock.simulator.simcode.datatypes.SimTypeInt; ...@@ -10,6 +10,7 @@ import tec.letsgoing.ardublock.simulator.simcode.datatypes.SimTypeInt;
import tec.letsgoing.ardublock.simulator.simcode.functions.SimCodeFunction; import tec.letsgoing.ardublock.simulator.simcode.functions.SimCodeFunction;
/** /**
* Liest den digitalen Wert des Pins ein [HIGH/LOW]
* @author Lucas * @author Lucas
* *
*/ */
......
...@@ -11,7 +11,7 @@ import tec.letsgoing.ardublock.simulator.simcode.functions.SimCodeFunction; ...@@ -11,7 +11,7 @@ import tec.letsgoing.ardublock.simulator.simcode.functions.SimCodeFunction;
/** /**
* @author Lucas * @author Lucas
* * Ausgang eines digitalen Ausgangs festlegen (HIGH/LOW)
*/ */
public class CodeDigitalWrite extends SimCode { public class CodeDigitalWrite extends SimCode {
SimTypeInt pin; SimTypeInt pin;
......
...@@ -3,11 +3,16 @@ ...@@ -3,11 +3,16 @@
*/ */
package tec.letsgoing.ardublock.simulator.view; package tec.letsgoing.ardublock.simulator.view;
import java.awt.BasicStroke;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Container; import java.awt.Container;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font; import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Stroke;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.Vector; import java.util.Vector;
...@@ -33,6 +38,7 @@ import tec.letsgoing.ardublock.simulator.view.modules.Poti; ...@@ -33,6 +38,7 @@ import tec.letsgoing.ardublock.simulator.view.modules.Poti;
import tec.letsgoing.ardublock.simulator.view.modules.RGB; import tec.letsgoing.ardublock.simulator.view.modules.RGB;
/** /**
* Verwaltet die graphische Oberfläche.
* @author Lucas * @author Lucas
* *
*/ */
...@@ -45,17 +51,32 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -45,17 +51,32 @@ public class GUI extends JFrame implements Runnable, ActionListener {
public GUI(Simulator simu) { public GUI(Simulator simu) {
super("ArdubBlock Simulator"); super("ArdubBlock Simulator");
// TODO Module geben Pin Positionen
modules[0] = new RGB(new ImageIcon(getToolkit().getImage(GUI.class.getResource("/img/PM31_RGB_LED.png")))); modules[0] = new RGB(new ImageIcon(getToolkit().getImage(GUI.class.getResource("/img/PM31_RGB_LED.png"))));
modules[1] = new Button(new ImageIcon(getToolkit().getImage(GUI.class.getResource("/img/PM26_Taster.png"))),new ImageIcon(getToolkit().getImage(GUI.class.getResource("/img/Taster_Off.png"))),new ImageIcon(getToolkit().getImage(GUI.class.getResource("/img/Taster_On.png")))); modules[1] = new Button(new ImageIcon(getToolkit().getImage(GUI.class.getResource("/img/PM26_Taster.png"))),new ImageIcon(getToolkit().getImage(GUI.class.getResource("/img/Taster_Off.png"))),new ImageIcon(getToolkit().getImage(GUI.class.getResource("/img/Taster_On.png"))));
modules[2] = new Poti(new ImageIcon(getToolkit().getImage(GUI.class.getResource("/img/PM24_Potentiometer.png")))); modules[2] = new Poti(new ImageIcon(getToolkit().getImage(GUI.class.getResource("/img/PM24_Potentiometer.png"))));
modules[3] = new ArduinoUno(new ImageIcon(getToolkit().getImage(GUI.class.getResource("/img/ArduinoUno.png")))); modules[3] = new ArduinoUno(new ImageIcon(getToolkit().getImage(GUI.class.getResource("/img/ArduinoUno.png"))),simu);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false); this.setResizable(false);
Container mainPane = this.getContentPane(); Container mainPane = this.getContentPane();
JPanel modulPanel = new JPanel(new BorderLayout()); JPanel modulPanel = new JPanel(new BorderLayout()) {
@Override
public void paint(Graphics g) {
super.paint(g);
for (int i =-1 ; i<2;i++) {
g.setColor(Color.BLACK);
g.fillRect(i*294+261, 183, 60, 5);
g.setColor(Color.RED);
g.fillRect(i*294+261, 211, 60, 5);
}
drawConnections(g);
}
};
modulPanel.add(modules[0].getPane(), BorderLayout.WEST); modulPanel.add(modules[0].getPane(), BorderLayout.WEST);
modulPanel.add(modules[1].getPane(), BorderLayout.CENTER); modulPanel.add(modules[1].getPane(), BorderLayout.CENTER);
modulPanel.add(modules[2].getPane(), BorderLayout.EAST); modulPanel.add(modules[2].getPane(), BorderLayout.EAST);
...@@ -65,7 +86,8 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -65,7 +86,8 @@ public class GUI extends JFrame implements Runnable, ActionListener {
mainPane.add(createControlPanel(simu), BorderLayout.LINE_END); mainPane.add(createControlPanel(simu), BorderLayout.LINE_END);
mainPane.add(createSerialLog(), BorderLayout.PAGE_END); mainPane.add(createSerialLog(), BorderLayout.PAGE_END);
this.pack(); this.pack();
//this.setLocation(-1000, 0); Code to Run the Window on seconds screen System.out.println(modules[2].getPane().getLocation());
//this.setLocation(-1300, 0); //FIXME Code to Run the Window on second screen
this.setVisible(true); this.setVisible(true);
} }
...@@ -130,6 +152,24 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -130,6 +152,24 @@ public class GUI extends JFrame implements Runnable, ActionListener {
return panel; return panel;
} }
private void drawConnections(Graphics g) {
int[] assignment= {11,10,9,5,4,3,19};
g.setColor(Color.ORANGE);
Vector<Point> pinArduino=modules[3].getPinPos();
Point posArduino=modules[3].getPosition();
int counter=0;
Stroke roundLine=new BasicStroke(5,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
for (int i=0;i<3;i++) {
Vector<Point> pos =modules[i].getPinPos();
for (Point p:pos) {
Graphics2D g2 = (Graphics2D) g;
g2.setStroke(roundLine);
g2.drawLine(p.x+modules[i].getPosition().x, p.y+modules[i].getPosition().y, pinArduino.get(assignment[counter]).x+posArduino.x, pinArduino.get(assignment[counter]).y+posArduino.y);
counter++;
}
}
}
public void run() { public void run() {
while (!stopFlag) { while (!stopFlag) {
try { try {
......
...@@ -8,16 +8,23 @@ import java.awt.Dimension; ...@@ -8,16 +8,23 @@ import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Image; import java.awt.Image;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JToggleButton;
import tec.letsgoing.ardublock.simulator.Simulator;
import tec.letsgoing.ardublock.simulator.arduino.Arduino; import tec.letsgoing.ardublock.simulator.arduino.Arduino;
import tec.letsgoing.ardublock.simulator.arduino.Pin; import tec.letsgoing.ardublock.simulator.arduino.Pin;
import tec.letsgoing.ardublock.simulator.view.GUI; import tec.letsgoing.ardublock.simulator.view.GUI;
/** /**
* Modul für einen Arduino Uno
* @author Lucas * @author Lucas
* *
*/ */
...@@ -26,15 +33,16 @@ public class ArduinoUno extends Modul { ...@@ -26,15 +33,16 @@ public class ArduinoUno extends Modul {
private boolean ledOn; private boolean ledOn;
private int led13 = 0; private int led13 = 0;
public ArduinoUno(ImageIcon _icon) { public ArduinoUno(ImageIcon _icon,Simulator simu) {
int locx=100;
// TODO Arduino mittig anordnen int locy=50;
layerpane.setPreferredSize(new Dimension(587, 418)); layerpane.setPreferredSize(new Dimension(587+locx, 418+locy));//587,418
JLabel chiplabel = new JLabel(); JLabel chiplabel = new JLabel();
ImageIcon chipIcon = _icon; ImageIcon chipIcon = _icon;
chipIcon = new ImageIcon(chipIcon.getImage().getScaledInstance(587, 418, Image.SCALE_SMOOTH)); chipIcon = new ImageIcon(chipIcon.getImage().getScaledInstance(587, 418, Image.SCALE_SMOOTH));
chiplabel.setIcon(chipIcon); chiplabel.setIcon(chipIcon);
chiplabel.setSize(587, 418); chiplabel.setSize(587, 418);
chiplabel.setLocation(locx, locy);
layerpane.add(chiplabel, 0); layerpane.add(chiplabel, 0);
JLabel labelPower = new JLabel() { JLabel labelPower = new JLabel() {
...@@ -50,7 +58,7 @@ public class ArduinoUno extends Modul { ...@@ -50,7 +58,7 @@ public class ArduinoUno extends Modul {
}; };
labelPower.setLocation(504, 126); labelPower.setLocation(504+locx, 126+locy);
labelPower.setSize(20, 20); labelPower.setSize(20, 20);
layerpane.add(labelPower, 0); layerpane.add(labelPower, 0);
...@@ -64,10 +72,26 @@ public class ArduinoUno extends Modul { ...@@ -64,10 +72,26 @@ public class ArduinoUno extends Modul {
}; };
label13.setLocation(257, 89); label13.setLocation(257+locx, 89+locy);
label13.setSize(20, 20); label13.setSize(20, 20);
layerpane.add(label13, 0); layerpane.add(label13, 0);
JButton button = new JButton();
button.setSize(70, 70);
button.setActionCommand("reset");
button.addActionListener(simu);
button.setOpaque(false);
button.setContentAreaFilled(false);
button.setBorderPainted(false);
JLabel labelButton = new JLabel();
labelButton.add(button);
labelButton.setSize(60, 51);
labelButton.setLocation(64+locx, 1+locy);
layerpane.add(labelButton,0);
calculatePinPos(locx,locy);
} }
public void updateModul(Pin pin) { public void updateModul(Pin pin) {
...@@ -90,4 +114,34 @@ public class ArduinoUno extends Modul { ...@@ -90,4 +114,34 @@ public class ArduinoUno extends Modul {
return true; return true;
} }
private void calculatePinPos(int locx,int locy) {
Vector<Point> pins=new Vector<Point>();
int offset=0;
for (int i=15;i>1;i--) {
if (i<8)offset=-11;
pins.add(new Point(i*20+locx+246+offset,locy+19));
}
for (int i=0;i<6;i++) {
pins.add(new Point(i*20+locx+447,locy+397));
}
//Code to check the Pin Pos
/*JLabel label;
for (Point pin:pins) {
label= new JLabel() {
@Override
public void paintComponent(Graphics g) {
g.setColor(Color.RED);
g.fillRect(0, 0, 10, 10);
}
};
label.setLocation(pin.x,pin.y);
label.setSize(10, 10);
layerpane.add(label, 0);
}*/
this.setPinPos(pins);
}
} }
...@@ -3,9 +3,14 @@ ...@@ -3,9 +3,14 @@
*/ */
package tec.letsgoing.ardublock.simulator.view.modules; package tec.letsgoing.ardublock.simulator.view.modules;
import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JToggleButton; import javax.swing.JToggleButton;
...@@ -14,6 +19,7 @@ import tec.letsgoing.ardublock.simulator.arduino.Arduino; ...@@ -14,6 +19,7 @@ import tec.letsgoing.ardublock.simulator.arduino.Arduino;
import tec.letsgoing.ardublock.simulator.arduino.Pin; import tec.letsgoing.ardublock.simulator.arduino.Pin;
/** /**
* Modul mit 3 Toogle Buttons
* @author Lucas * @author Lucas
* *
*/ */
...@@ -64,7 +70,7 @@ public class Button extends Modul implements ActionListener { ...@@ -64,7 +70,7 @@ public class Button extends Modul implements ActionListener {
layerpane.add(label1, 0); layerpane.add(label1, 0);
layerpane.add(label2, 0); layerpane.add(label2, 0);
layerpane.add(label3, 0); layerpane.add(label3, 0);
calculatePinPos();
} }
public void updateModul(Pin pin) { public void updateModul(Pin pin) {
...@@ -110,4 +116,12 @@ public class Button extends Modul implements ActionListener { ...@@ -110,4 +116,12 @@ public class Button extends Modul implements ActionListener {
pins.get(pin).setValue(value); pins.get(pin).setValue(value);
} }
private void calculatePinPos() {
Vector<Point> pins=new Vector<Point>();
for (int i=0;i<3;i++) {
pins.add(new Point(i*30+117,235));
}
this.setPinPos(pins);
}
} }
...@@ -15,6 +15,7 @@ import tec.letsgoing.ardublock.simulator.arduino.Arduino; ...@@ -15,6 +15,7 @@ import tec.letsgoing.ardublock.simulator.arduino.Arduino;
import tec.letsgoing.ardublock.simulator.arduino.Pin; import tec.letsgoing.ardublock.simulator.arduino.Pin;
/** /**
* Oberklasse für alle Module
* @author Lucas * @author Lucas
* *
*/ */
...@@ -23,6 +24,7 @@ public abstract class Modul implements Observer { ...@@ -23,6 +24,7 @@ public abstract class Modul implements Observer {
private Point position; private Point position;
protected Vector<Pin> pins = new Vector<Pin>(); protected Vector<Pin> pins = new Vector<Pin>();
protected JLayeredPane layerpane = new JLayeredPane(); protected JLayeredPane layerpane = new JLayeredPane();
protected Vector<Point> pinPos=new Vector<Point>();
public void setState(boolean State) { public void setState(boolean State) {
active = State; active = State;
...@@ -37,7 +39,8 @@ public abstract class Modul implements Observer { ...@@ -37,7 +39,8 @@ public abstract class Modul implements Observer {
} }
public Point getPosition() { public Point getPosition() {
return position; //return position;
return layerpane.getLocation();
} }
public void update(Observable Observable, Object arg1) { public void update(Observable Observable, Object arg1) {
...@@ -56,6 +59,14 @@ public abstract class Modul implements Observer { ...@@ -56,6 +59,14 @@ public abstract class Modul implements Observer {
pins.add(_pin); pins.add(_pin);
} }
public Vector<Point> getPinPos() {
return pinPos;
}
public void setPinPos(Vector<Point> _pins) {
pinPos=_pins;
}
public JLayeredPane getPane() { public JLayeredPane getPane() {
return layerpane; return layerpane;
} }
......
...@@ -3,7 +3,15 @@ ...@@ -3,7 +3,15 @@
*/ */
package tec.letsgoing.ardublock.simulator.view.modules; package tec.letsgoing.ardublock.simulator.view.modules;
import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.util.Hashtable;
import java.util.Vector;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
...@@ -15,10 +23,11 @@ import tec.letsgoing.ardublock.simulator.arduino.Arduino; ...@@ -15,10 +23,11 @@ import tec.letsgoing.ardublock.simulator.arduino.Arduino;
import tec.letsgoing.ardublock.simulator.arduino.Pin; import tec.letsgoing.ardublock.simulator.arduino.Pin;
/** /**
* Modul mit einem Potentiometer
* @author Lucas * @author Lucas
* *
*/ */
public class Poti extends Modul implements ChangeListener { public class Poti extends Modul implements ChangeListener, MouseWheelListener {
int value = 0; int value = 0;
JSlider slider; JSlider slider;
...@@ -33,10 +42,19 @@ public class Poti extends Modul implements ChangeListener { ...@@ -33,10 +42,19 @@ public class Poti extends Modul implements ChangeListener {
slider.setMajorTickSpacing(256); slider.setMajorTickSpacing(256);
slider.setMinorTickSpacing(64); slider.setMinorTickSpacing(64);
slider.setPaintTicks(true); slider.setPaintTicks(true);
//Create the label table
Hashtable<Integer,JLabel> labelTable = new Hashtable<Integer,JLabel>();
labelTable.put( new Integer( 10 ), new JLabel("0 V") );
labelTable.put( new Integer( 512 ), new JLabel("2.5 V") );
labelTable.put( new Integer( 1023 ), new JLabel("5 V") );
slider.setLabelTable( labelTable );
slider.setPaintLabels(true); slider.setPaintLabels(true);
slider.setPreferredSize(new Dimension(180,50)); slider.setPreferredSize(new Dimension(180,50));
slider.setOpaque(false); slider.setOpaque(false);
slider.addChangeListener(this); slider.addChangeListener(this);
slider.addMouseWheelListener(this);
JPanel sliderPanel=new JPanel(); JPanel sliderPanel=new JPanel();
sliderPanel.add(slider); sliderPanel.add(slider);
...@@ -46,6 +64,9 @@ public class Poti extends Modul implements ChangeListener { ...@@ -46,6 +64,9 @@ public class Poti extends Modul implements ChangeListener {
layerpane.add(chiplabel, 0); layerpane.add(chiplabel, 0);
layerpane.add(sliderPanel,0); layerpane.add(sliderPanel,0);
calculatePinPos();
} }
...@@ -67,4 +88,23 @@ public class Poti extends Modul implements ChangeListener { ...@@ -67,4 +88,23 @@ public class Poti extends Modul implements ChangeListener {
pins.get(0).setValue(slider.getValue()); pins.get(0).setValue(slider.getValue());
} }
@Override
public void mouseWheelMoved(MouseWheelEvent arg0) {
int notches = arg0.getWheelRotation();
if (notches > 0) {
slider.setValue(slider.getValue()+10);
} else {
slider.setValue(slider.getValue()-10);
}
}
private void calculatePinPos() {
Vector<Point> pins=new Vector<Point>();
pins.add(new Point(30+117,235));
this.setPinPos(pins);
}
} }
...@@ -7,6 +7,9 @@ import java.awt.Color; ...@@ -7,6 +7,9 @@ import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point;
import java.util.Vector;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JLabel; import javax.swing.JLabel;
...@@ -14,6 +17,7 @@ import tec.letsgoing.ardublock.simulator.arduino.Arduino; ...@@ -14,6 +17,7 @@ import tec.letsgoing.ardublock.simulator.arduino.Arduino;
import tec.letsgoing.ardublock.simulator.arduino.Pin; import tec.letsgoing.ardublock.simulator.arduino.Pin;
/** /**
* Modul mit einer RGB LED
* @author Lucas * @author Lucas
* *
*/ */
...@@ -44,6 +48,8 @@ public class RGB extends Modul { ...@@ -44,6 +48,8 @@ public class RGB extends Modul {
ledlabel.setLocation(107, 37); ledlabel.setLocation(107, 37);
ledlabel.setSize(200, 200); ledlabel.setSize(200, 200);
layerpane.add(ledlabel, 0); layerpane.add(ledlabel, 0);
calculatePinPos();
} }
public void updateModul(Pin pin) { public void updateModul(Pin pin) {
...@@ -72,4 +78,12 @@ public class RGB extends Modul { ...@@ -72,4 +78,12 @@ public class RGB extends Modul {
return true; return true;
} }
private void calculatePinPos() {
Vector<Point> pins=new Vector<Point>();
for (int i=0;i<3;i++) {
pins.add(new Point(i*30+117,235));
}
this.setPinPos(pins);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment