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

Bugfixes und Kommentare

parent 86c82e27
No related branches found
No related tags found
No related merge requests found
Showing
with 259 additions and 74 deletions
......@@ -26,8 +26,7 @@ import tec.letsgoing.ardublock.simulator.view.GUI;
/**
* Diese Klasse verwaltet alle Elemente des Simulators. Sie ist geschrieben als
* Singelton. Daher wird die Instanz über getInstance geholt und der Konstruktor
* ist private.
*
* ist private.<br>
*
* Pinmapping: RGB: 9,10,11 Poti: A0 Button: 2,3,4
*
......@@ -35,27 +34,46 @@ import tec.letsgoing.ardublock.simulator.view.GUI;
*
*
*/
public class Simulator implements Runnable, ActionListener {
private static Simulator instance;
private Arduino arduino;
private GUI gui;
private Thread guiThread;
private Thread simuThread;
private Vector<SimCodeFunction> functionsCode = new Vector<SimCodeFunction>();
/**
* Privater Konstruktor der Klasse Simulator<br>
* Die Klasse ist als Singelton geschrieben, daher sollte diese Konstruktor nie
* direkt aufgerufen werden.
*/
private Simulator() {
createSubClasses();
}
/**
* Funktion um die Instanz des Simulators zu erhalten. <br>
* Da es sich um einen Singelton handelt ist die Instanz bei jedem Aufruf die
* gleiche.
*
* @return Instanz des Simulators
*/
public static synchronized Simulator getInstance() {
if (instance == null) {
instance = new Simulator();
} else {
instance.reload();
}
return instance;
}
/**
* Erzeugt die Instanzen für die Klassen GUI und Arduino und initialisiert
* diese.<br>
* Startet den GUI-Thread.
*
* @return true
*/
private boolean createSubClasses() {
gui = new GUI(this);
arduino = new Arduino(gui);
......@@ -67,6 +85,10 @@ public class Simulator implements Runnable, ActionListener {
return true;
}
/**
* Startet den Simulation<br>
* Wird durch den Play-Button gestartet.
*/
public void startSimu() {
arduino.setStop(false);
if (simuThread instanceof Thread) {
......@@ -85,17 +107,23 @@ public class Simulator implements Runnable, ActionListener {
}
/**
* Funktion welche vom Thread ausgeführt wird, nachdem Thread.start() ausgeführt
* wurde.<br>
* Aktiviert die Power-LED und führt die main-Funktion im Arduino aus.
*/
@Override
public void run() {
arduino.getPin(20).setValue(1023); // Power ON LED
arduino.setStop(false);
arduino.getFunction("main").run(arduino, null);
// while (!arduino.getStop()) {
// arduino.getFunction("loop").run(arduino, null);
// }
}
/**
* Stoppt die Ausführung des Simulators.<br>
* Ruft dabei einem mal die Thread.interrupt() auf, weswegen alle sleep Aufrufe
* eine Interrupt Execption abfangen müssen.
*/
public void stopSimu() {
arduino.setStop(true);
if (simuThread instanceof Thread) {
......@@ -106,7 +134,12 @@ public class Simulator implements Runnable, ActionListener {
}
// reload new code from Ardublock
/**
* Setzt den Simulator wieder in den Ausgangszustand zurück.
*
* @return true, wenn der Thread korrekt gestoppt wurde und false, wenn der
* Thread nicht korrekt beendet wurde.
*/
public boolean reload() {
if (simuThread instanceof Thread) {
stopSimu();
......@@ -115,6 +148,7 @@ public class Simulator implements Runnable, ActionListener {
} catch (InterruptedException e) {
// e.printStackTrace();
arduino.errorAbort("Thread Überwachung gestört - Bitte Programm neustarten");
return false;
}
}
Point locationWindow = gui.getLocation();
......@@ -130,7 +164,11 @@ public class Simulator implements Runnable, ActionListener {
return true;
}
// Function to reset the Arduino in the Simulation
/**
* Führt einen Reset des Arduinos aus und startet diesen neu.
*
* @return true
*/
public boolean reset() {
if (simuThread instanceof Thread) {
stopSimu();
......@@ -139,12 +177,21 @@ public class Simulator implements Runnable, ActionListener {
} catch (InterruptedException e) {
}
}
startSimu();
return true;
}
/**
* Fügt dem Simulator eine neue Funktion hinzu. Diese wird sogleich auch dem
* Arduino übergeben.<br>
* Note: Es werden Funktionen nur hinzugefügt und nicht überschrieben. Sollte
* eine alte Funktion überschrieben werden, sollte zuvor resetFunctions()
* aufgerufen werden.
*
* @param _functionsCode Ein SimCodeFunction Objekt, welches hinzugefügt werden
* soll
* @return true
*/
public boolean addFunctionsCode(SimCodeFunction _functionsCode) {
functionsCode.add(_functionsCode);
arduino.addFunction(_functionsCode);
......@@ -152,10 +199,13 @@ public class Simulator implements Runnable, ActionListener {
}
/**
* Function to Clear the Storage of saved Functions in Simulator-Class. After
* this a reload is needed to clear the Arduino.
* Funktion, welche den Funktionsspeicher in der Simulatorklasse und Arduino
* löscht.<br>
* Soll vor dem hochladen eines neuen Programms durchgeführt werden.<br>
* Vor dem ausführen muss der Simulator gestoppt werden, da sonst der Thread
* eine Nullpointer Exception hat.
*
* @return boolean=true if the functions where correctly reset
* @return true
*/
public boolean resetFunctions() {
functionsCode.clear();
......@@ -164,6 +214,10 @@ public class Simulator implements Runnable, ActionListener {
return true;
}
/**
* Funktion, welche die GUI Interaktion verarbeitet und die entsprechenden
* Funktionen startet.
*/
public void actionPerformed(ActionEvent arg0) {
String command = arg0.getActionCommand();
if (command == "go") {
......@@ -180,6 +234,8 @@ public class Simulator implements Runnable, ActionListener {
}
/**
* Demo-Main Funktion. Nicht Teil des normalen Simulators.
*
* @param args
* @throws InterruptedException
*/
......@@ -191,14 +247,14 @@ public class Simulator implements Runnable, ActionListener {
SimTypeBool b1 = new SimTypeBool(true);
SimTypeBool b0 = new SimTypeBool(false);
//SimTypeString s1 = new SimTypeString("CodeString Test");
//SimTypeInt d1 = new SimTypeInt(9);
// SimTypeString s1 = new SimTypeString("CodeString Test");
// SimTypeInt d1 = new SimTypeInt(9);
SimTypeInt d5 = new SimTypeInt(5);
SimTypeInt d3 = new SimTypeInt(0);
SimTypeInt d9 = new SimTypeInt(9);
SimTypeInt delay = new SimTypeInt(testdelay);
//SimTypeString s2 = new SimTypeString(d1);
//CodeAdd s5 = new CodeAdd(d1, d5);
// SimTypeString s2 = new SimTypeString(d1);
// CodeAdd s5 = new CodeAdd(d1, d5);
// testLoop.add(new CodeDigitalWrite(d2, b0));
// testLoop.add(new CodeDelay(delay));
......
......@@ -15,9 +15,6 @@ import tec.letsgoing.ardublock.simulator.view.GUI;
* Hardware
*
* @author Lucas
*
*
*
*/
public class Arduino {
private GUI gui;
......@@ -27,6 +24,10 @@ public class Arduino {
private long startTime = 0;
private volatile boolean stopFlag = false;
/**
* Konstruktor der Klasse Arduino.
* @param _gui Die GUI Instanz mit welcher die Hardware verknüpft wird.
*/
public Arduino(GUI _gui) {
gui = _gui;
for (int i = 0; i < 21; i++) {
......@@ -34,12 +35,23 @@ public class Arduino {
}
}
/**
* Erzeugt eine globale Variable.
* @param _name Name der Variable
* @param _value Wert der Variable
*/
public void createVariable(String _name, SimCode _value) {
vars.add(new Variable(_name));
vars.lastElement().setValue(_value);
}
/**
* Setzt eine globale Variable
* @param _name Name der Variable
* @param _value Wert der Variable
* @return true, wenn die Variable gesetzt wurde - false, wenn die Variable nicht vorhanden ist.
*/
public boolean setVariable(String _name, SimCode _value) {
for (Variable var : vars) {
if (var.getName().equals(_name)) {
......@@ -51,6 +63,12 @@ public class Arduino {
return false;
}
/**
* Liest den Wert einer globalen Variable.
* Sollte diese nicht existieren, so wird die Ausführung des Programms beendet.
* @param _name Name der Variable
* @return SimCode die Variable
*/
public SimCode readVariable(String _name) {
for (Variable var : vars) {
......@@ -63,6 +81,13 @@ public class Arduino {
return new SimTypeInt(0);
}
/**
* Die digitalWrite Funktion vom Arduino
* @param _pin
* @param _value boolean
* @return true, wenn Pin korrekt - false, wenn es sich um einen falschen Pin handelt.
*
*/
public boolean digitalWrite(int _pin, boolean _value) {
if (_pin > 19) {
this.errorAbort("Write auf Pin aufgerufen, welcher nicht existiert");
......@@ -75,6 +100,11 @@ public class Arduino {
return true;
}
/**
* Funktion um den digitalen Wert eines Pins zu lesen.
* @param _pin Nummer des Pins
* @return boolean des Pin-Wertes
*/
public boolean digitalRead(int _pin) {
if (_pin > 19) {
this.errorAbort("Read auf Pin aufgerufen, welcher nicht existiert");
......@@ -86,6 +116,12 @@ public class Arduino {
return false;
}
/**
* Funktion für die analoge PWM Ausgabe.
* @param _pin Anzusteuernder Pin
* @param _value PWM-Wert
* @return true, für PWM Pin - false für nicht PWM-Pin
*/
public boolean analogWrite(int _pin, int _value) {
int[] array = { 3, 5, 6, 9, 10, 11 };
for (int i = 0; i < 6; i++) {
......@@ -98,17 +134,31 @@ public class Arduino {
return false;
}
/**
* Funktion um den analogen Wert eines Pins zu lesen
* @param _pin Zahl ohne das Vorangestellte A
* @return Wert des Pins
*/
public int analogRead(int _pin) {
if (_pin > 5) {
this.errorAbort("AnalogRead auf nicht vorhandenen Pin angewendet");
}
return pins[_pin + 13].getValue();
return pins[_pin + 14].getValue();
}
/**
* Funktion um ein speziellen Pin als Objekt zu erhalten
* @param number Absolute Nummer des Pins
* @return Pin-Objekt
*/
public Pin getPin(int number) {
return pins[number];
}
/**
* Reset-Funktion welche alle Variabeln löscht und Pins zurücksetzt.
* @return true
*/
public boolean reset() {
vars = new Vector<Variable>();
......@@ -118,28 +168,52 @@ public class Arduino {
return true;
}
/**
* Löscht die im Arduino gespeicherten Funktionen
*/
public void resetFunctions() {
functions.clear();
}
/**
* Sendet einen Aufruf an die GUI für eine neue SerialPrint Zeile.
* @param content String welcher ausgegeben werden soll.
*/
public void serialPrint(String content) {
if (!stopFlag) {
gui.serialPrint(content);
}
}
/**
* Füge eine Funktion zum Funktionsspeicher hinzu
* @param function SimCodeFunction Objekt, welches hinzugefügt werden soll.
*/
public void addFunction(SimCodeFunction function) {
functions.add(function);
}
/**
* Speichere die aktuelle Zeit als startTime ab. <br>
* Dies wird benötigt, damit die Berechnung von millis() korrekt ist.
*/
public void setStartTime() {
startTime = System.currentTimeMillis();
}
/**
* Berechnung der vergangenen Millisekunden seit Programmstart
* @return Millisekunden seit Programmstart.
*/
public int getMillis() {
return (int) (System.currentTimeMillis() - startTime);
}
/**
* Rufe eine Funktion aus dem Funktionsspeicher des Arduino ab.
* @param name Name der gesuchten Funktion
* @return SimCodeFunction-Objekt dieser Funktion
*/
public SimCodeFunction getFunction(String name) {
for (SimCodeFunction function : functions) {
if (function.getName().equals(name)) {
......@@ -150,14 +224,26 @@ public class Arduino {
return null;
}
/**
* Setze das Stop-Flag auf einen boolean-Wert.
* @param value true für Ausführungsstop
*/
public void setStop(boolean value) {
stopFlag = value;
}
/**
* Lese das Stop-Flag
* @return Wert des Stop-Flag
*/
public boolean getStop() {
return stopFlag;
}
/**
* Funktion um die Ausführung intern zu beenden und eine Fehlermeldung im SerialLog anzuzeigen.
* @param error Fehlerbeschreibung für das SerialLog.
*/
public void errorAbort(String error) {
this.serialPrint("Fehler im Programm: " + error + " - Programm wird beendet\n");
this.setStop(true);
......
......@@ -18,6 +18,12 @@ import tec.letsgoing.ardublock.simulator.simcode.functions.SimCodeFunction;
*/
public abstract class SimCode {
/**
* Hauptaufruf, welcher während der Simulation ausgeführt wird. Dieser enthält die komplette Logik des Blocks.
* @param _arduino Die Instanz des Arduinos, damit Zugriffe auf die Hardware möglich sind.
* @param functionHead Aktueller Funktionskopf um lokale Variablen zu ermöglichen.
* @return Ein SimCode Objekt sollte eines als "Ergebnis" entstehen. Ansonsten null
*/
public abstract SimCode run(Arduino _arduino, SimCodeFunction functionHead);
public abstract String toString();
......
......@@ -9,7 +9,7 @@ import tec.letsgoing.ardublock.simulator.simcode.datatypes.SimTypeString;
import tec.letsgoing.ardublock.simulator.simcode.functions.SimCodeFunction;
/**
* Verbinde einen beliebigen Block mit einer Zeichenkette
* Verbinde zwei beliebige Blöcke miteinander zu einem String.
*
* @author Lucas
*
......
......@@ -33,7 +33,7 @@ public class CodeSerialPrint extends SimCode {
}
_arduino.serialPrint(content);
try {
Thread.sleep(1); // Übertragung benötigt Zeit und SPAM führt zu unresposivness.
Thread.sleep(1); // Übertragung benötigt Zeit und SPAM führt zu unresposivness der GUI
} catch (InterruptedException e) {
}
return null;
......
......@@ -32,7 +32,6 @@ public class CodeForCount extends SimCode {
// TODO For/While Mit Vars ausrüsten
@Override
public SimCode run(Arduino _arduino, SimCodeFunction functionHead) {
// TODO delete Var after completion
functionHead.createVariable(varname.toString(), new SimTypeInt(0));
for (int i = 0; i < count.run(_arduino, functionHead).getValue(); i++) {
functionHead.setVariable(varname.toString(), new SimTypeInt(i));
......
......@@ -31,7 +31,6 @@ public class CodeWhileMillis extends SimCode {
@Override
public SimCode run(Arduino _arduino, SimCodeFunction functionHead) {
// TODO Docu: Vergleich der Zeiten bis zum Überlauf zwischen C und Java
functionHead.createVariable(varname.toString(), new SimTypeInt(_arduino.getMillis()));
int startTime = _arduino.getMillis();
int dura = duration.run(_arduino, functionHead).getValue();
......
......@@ -44,18 +44,21 @@ import tec.letsgoing.ardublock.simulator.view.modules.RGB;
*
*/
public class GUI extends JFrame implements Runnable, ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
private static final int MAXIMUM_MESSAGES = 100;
private static final int MAXIMUM_MESSAGES = 100; //Anzahl der Seriellen Nachrichten
private Vector<String> serialprint = new Vector<String>();
private Modul[] modules = new Modul[4];
private volatile boolean stopFlag = false;
private JTextArea serialLog = new JTextArea();
/**
* Konstruktor der Klasse GUI
* @param simu Instanz des Simulators
*/
public GUI(Simulator simu) {
super("ArdubBlock Simulator");
//Konstruktor der Module
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"))),
......@@ -65,32 +68,21 @@ public class GUI extends JFrame implements Runnable, ActionListener {
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); //Vermutlich nicht gewünscht.
this.setResizable(false);
Container mainPane = this.getContentPane();
//Panel welches alle Module sowie die Verdrahtung enthält.
JPanel modulPanel = new JPanel(new BorderLayout()) {
/**
*
*/
private static final long serialVersionUID = 1L;
@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);
drawConnections(g); //Zeichne Verdrahtung
}
};
//Füge Module hinzu
modulPanel.add(modules[0].getPane(), BorderLayout.WEST);
modulPanel.add(modules[1].getPane(), BorderLayout.CENTER);
modulPanel.add(modules[2].getPane(), BorderLayout.EAST);
......@@ -100,12 +92,16 @@ public class GUI extends JFrame implements Runnable, ActionListener {
mainPane.add(createControlPanel(simu), BorderLayout.LINE_END);
mainPane.add(createSerialLog(), BorderLayout.PAGE_END);
this.pack();
// this.setLocation(-1300, 0); //FIXME Code to Run the Window on second screen
// this.setLocation(-1300, 0); //Möglichkeit die Renderingposition festzulegen
this.setVisible(true);
}
/**
* Erzeugt das Controlpanel mit den Steuerungsknöpfen
* @param simu Instanz des Simulators
* @return JPanel mit allen Knöpfen
*/
private JPanel createControlPanel(Simulator simu) {
JPanel controlPanel = new JPanel();
controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.Y_AXIS));
......@@ -138,10 +134,14 @@ public class GUI extends JFrame implements Runnable, ActionListener {
return controlPanel;
}
/**
* Erzeuge den Bereich mit dem SerialLog
* @return JPanel des SerialLogs
*/
private JPanel createSerialLog() {
JPanel panel = new JPanel(new BorderLayout());
JScrollPane scrollPane = new JScrollPane(serialLog);
serialLog.setRows(8);
serialLog.setRows(8); //Anzahl der Angezeigten Reihen
serialLog.setAutoscrolls(true);
serialLog.setForeground(Color.black);
serialLog.setBackground(Color.white);
......@@ -164,7 +164,21 @@ public class GUI extends JFrame implements Runnable, ActionListener {
return panel;
}
/**
* Zeichne alle Verdrahtungen, welcher über die Modulgrenzen hinausgehen.<br>
* Diese Funktion ist sehr "Hardgecoded" eine Änderung an den Pin Zuordnungen wird hier Probleme verursachen.
* @param g Graphics Instanz des Panels
*/
private void drawConnections(Graphics g) {
//Zeichne die Stromversorgung
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);
}
//Zeichne die Signalleitungen
int[] assignment = { 11, 10, 9, 4, 3,2 , 14 };
g.setColor(Color.ORANGE);
Vector<Point> pinArduino = modules[3].getPinPos();
......@@ -176,7 +190,7 @@ public class GUI extends JFrame implements Runnable, ActionListener {
for (Point p : pos) {
Graphics2D g2 = (Graphics2D) g;
g2.setStroke(roundLine);
if (counter > 5) {
if (counter > 5) { // Fall für die analoge Signalleitung
g2.drawLine(p.x + modules[i].getPosition().x, p.y + modules[i].getPosition().y,
p.x + modules[i].getPosition().x, pinArduino.get(assignment[counter]).y + posArduino.y-40);
g2.drawLine(p.x + modules[i].getPosition().x, pinArduino.get(assignment[counter]).y + posArduino.y-40,
......@@ -185,7 +199,7 @@ public class GUI extends JFrame implements Runnable, ActionListener {
g2.drawLine(pinArduino.get(assignment[counter]).x + posArduino.x, pinArduino.get(assignment[counter]).y + posArduino.y-40,
pinArduino.get(assignment[counter]).x + posArduino.x,
pinArduino.get(assignment[counter]).y + posArduino.y);
} else {
} else { //Alle anderen Signalleitungen
g2.drawLine(p.x + modules[i].getPosition().x, p.y + modules[i].getPosition().y,
p.x + modules[i].getPosition().x, p.y + modules[i].getPosition().y + 90 - (counter) * 10);
g2.drawLine(p.x + modules[i].getPosition().x,
......@@ -196,19 +210,19 @@ public class GUI extends JFrame implements Runnable, ActionListener {
p.y + modules[i].getPosition().y + 90 - (counter) * 10,
pinArduino.get(assignment[counter]).x + posArduino.x,
pinArduino.get(assignment[counter]).y + posArduino.y);
// 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++;
}
}
}
/**
*Funktion welche die GUI aktualisiert und auf 144Hz ausgelegt ist.
*/
public void run() {
while (!stopFlag) {
try {
Thread.sleep(7);
Thread.sleep(7); //144Hz
} catch (InterruptedException e) {
// e.printStackTrace();
......@@ -217,6 +231,11 @@ public class GUI extends JFrame implements Runnable, ActionListener {
}
}
/**
* Fügt eine neue Nachricht der SerialLog hinzu und löscht eventuell alte Nachrichten.
* @param content Auszugebener String
* @return true
*/
public boolean serialPrint(String content) {
serialprint.add(content);
if (serialprint.size() > MAXIMUM_MESSAGES) {
......@@ -230,6 +249,11 @@ public class GUI extends JFrame implements Runnable, ActionListener {
return true;
}
/**
* Verbindet alle Modulen mit ihren Pin Objekten auf dem Arduino.
* @param arduino Instanz der Arduinoklasse
* @return true
*/
public boolean connectPins(Arduino arduino) {
for (Modul modul : modules) {
modul.connect(arduino);
......
......@@ -31,9 +31,11 @@ public class ArduinoUno extends Modul {
private int led13 = 0;
public ArduinoUno(ImageIcon _icon, Simulator simu) {
//Offset für den Arduino um diesen mehr mittig zu platzieren.
int locx = 50;
int locy = 50;
layerpane.setPreferredSize(new Dimension(587 + locx, 418 + locy));// 587,418
layerpane.setPreferredSize(new Dimension(587 + locx, 418 + locy));
JLabel chiplabel = new JLabel();
ImageIcon chipIcon = _icon;
chipIcon = new ImageIcon(chipIcon.getImage().getScaledInstance(587, 418, Image.SCALE_SMOOTH));
......@@ -42,12 +44,9 @@ public class ArduinoUno extends Modul {
chiplabel.setLocation(locx, locy);
layerpane.add(chiplabel, 0);
//Label für die PowerLED
JLabel labelPower = new JLabel() {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void paintComponent(Graphics g) {
Graphics2D ga = (Graphics2D) g;
......@@ -64,12 +63,9 @@ public class ArduinoUno extends Modul {
labelPower.setSize(20, 20);
layerpane.add(labelPower, 0);
//Label für die Pin 13 LED
JLabel label13 = new JLabel() {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void paintComponent(Graphics g) {
Graphics2D ga = (Graphics2D) g;
......@@ -83,6 +79,7 @@ public class ArduinoUno extends Modul {
label13.setSize(20, 20);
layerpane.add(label13, 0);
//unsichtbarer Resetbutton
JButton button = new JButton();
button.setSize(70, 70);
button.setActionCommand("reset");
......@@ -132,7 +129,7 @@ public class ArduinoUno extends Modul {
for (int i = 0; i < 6; i++) {
pins.add(new Point(i * 20 + locx + 447, locy + 397));
}
// Code to check the Pin Pos
// Dieser Code malt kleine Rechtecke an die PinPositionen um sie besser zu überprüfen.
/*
* JLabel label; for (Point pin:pins) { label= new JLabel() {
*
......
......@@ -99,6 +99,9 @@ public class Button extends Modul implements ActionListener {
return true;
}
/**
* Funktion reagiert auf die Mausklicks und ändert das Icon
*/
public void actionPerformed(ActionEvent arg0) {
Integer pin = Integer.parseInt(arg0.getActionCommand());
boolean bool = ((JToggleButton) arg0.getSource()).isSelected();
......
......@@ -39,10 +39,12 @@ public abstract class Modul implements Observer {
}
public Point getPosition() {
// return position;
return layerpane.getLocation();
}
/**
*Funktion welche aufgerufen wird, sobald sich ein Pin ändert.
*/
public void update(Observable Observable, Object arg1) {
if (Observable instanceof Pin) {
for (Pin p : pins) {
......
......@@ -36,13 +36,13 @@ public class Poti extends Modul implements ChangeListener, MouseWheelListener {
ImageIcon chipIcon = _icon;
chiplabel.setIcon(chipIcon);
chiplabel.setSize(294, 294);
slider = new JSlider(JSlider.HORIZONTAL, 0, 1024, 512);
slider = new JSlider(JSlider.HORIZONTAL, 0, 1023, 512);
slider.setMajorTickSpacing(256);
slider.setMinorTickSpacing(64);
slider.setPaintTicks(true);
// Create the label table
//Erzeuge eine individuelle Slider Beschriftung
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"));
......@@ -79,14 +79,18 @@ public class Poti extends Modul implements ChangeListener, MouseWheelListener {
return true;
}
/**
* Funktion wird aufgerufen, wenn die Maus den Slider bewegt hat.
*/
@Override
public void stateChanged(ChangeEvent arg0) {
if (slider.getValue() == 1024)
slider.setValue(1023); // Kleiner Trick damit die 1024 angezeigt wird aber keinen Fehler verursacht
pins.get(0).setValue(slider.getValue());
}
/**
* Funktion wird aufgerufen, wenn das Mausrad bewegt wurde.
*/
@Override
public void mouseWheelMoved(MouseWheelEvent arg0) {
int notches = arg0.getWheelRotation();
......
......@@ -28,6 +28,7 @@ public class RGB extends Modul {
private int blueValue = 0;
public RGB(ImageIcon _icon) {
//Erstellen der JLayerPane für das Modul
layerpane.setPreferredSize(new Dimension(294, 294));
JLabel chiplabel = new JLabel();
ImageIcon chipIcon = _icon;
......@@ -35,10 +36,8 @@ public class RGB extends Modul {
chiplabel.setSize(294, 294);
layerpane.add(chiplabel, 1);
//Erzeuge ein JLabel welches das Leuchten der LED darstellt.
JLabel ledlabel = new JLabel() {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
......@@ -50,7 +49,8 @@ public class RGB extends Modul {
}
};
//Setze Position des Labels
ledlabel.setLocation(107, 37);
ledlabel.setSize(200, 200);
layerpane.add(ledlabel, 0);
......@@ -58,6 +58,9 @@ public class RGB extends Modul {
}
/**
* Funktion, welche die Pin Änderungen entgegen nimmt und verarbeitet.
*/
public void updateModul(Pin pin) {
if (pin == pins.get(0))
redValue = pin.getValue() / 4;
......@@ -67,6 +70,9 @@ public class RGB extends Modul {
greenValue = pin.getValue() / 4;
}
/**
* Verbindet das RGB Modul mit seinen 3 Pins am Arduino
*/
public boolean connect(Arduino arduino) {
// TODO Pins= R G B ? Aktuell RBG
Pin tmpPin = arduino.getPin(11);
......@@ -84,6 +90,9 @@ public class RGB extends Modul {
return true;
}
/**
* Funktion, welche die Positionen der Modulpins berechnet (in Pixeln für das Zeichnen der Verdrahtung)
*/
private void calculatePinPos() {
Vector<Point> pins = new Vector<Point>();
for (int i = 0; i < 3; i++) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment