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

UML Update, Code cleanup

parent 53d22d47
No related branches found
No related tags found
No related merge requests found
No preview for this file type
...@@ -135,8 +135,8 @@ public class Arduino { ...@@ -135,8 +135,8 @@ public class Arduino {
int[] array = { 3, 5, 6, 9, 10, 11 }; int[] array = { 3, 5, 6, 9, 10, 11 };
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
if (_pin == array[i]) { if (_pin == array[i]) {
pins[_pin].setValue((int) (_value * (1024.0/256.0))); pins[_pin].setValue((int) (_value * (1024.0 / 256.0)));
//System.out.println(_value + " multi " + (int)(_value * (1024.0/256.0))); // System.out.println(_value + " multi " + (int)(_value * (1024.0/256.0)));
return true; return true;
} }
} }
......
...@@ -28,10 +28,7 @@ public class Pin extends Observable { ...@@ -28,10 +28,7 @@ public class Pin extends Observable {
} }
public void setValue(int _value) { public void setValue(int _value) {
if (_value > 1023) _value = _value % 1024;
//TODO: check by Lucas
//_value = 1023;
_value = _value%1024;
if (_value < 0) if (_value < 0)
_value = 0; _value = 0;
value = _value; value = _value;
......
...@@ -26,16 +26,14 @@ public class CodeConnectString extends SimCode { ...@@ -26,16 +26,14 @@ public class CodeConnectString extends SimCode {
@Override @Override
public SimTypeString run(Arduino _arduino, SimCode functionHead) { public SimTypeString run(Arduino _arduino, SimCode functionHead) {
if(block1 != null && block2 != null) { if (block1 != null && block2 != null) {
out = "" + block1.run(_arduino, functionHead).toString() + " " + block2.run(_arduino, functionHead).toString(); out = "" + block1.run(_arduino, functionHead).toString() + " "
} + block2.run(_arduino, functionHead).toString();
else if(block1 == null && block2 != null) { } else if (block1 == null && block2 != null) {
out = "" + block2.run(_arduino, functionHead).toString(); out = "" + block2.run(_arduino, functionHead).toString();
} } else if (block1 != null && block2 == null) {
else if(block1 != null && block2 == null) {
out = "" + block1.run(_arduino, functionHead).toString(); out = "" + block1.run(_arduino, functionHead).toString();
} } else {
else {
out = ""; out = "";
} }
return new SimTypeString(out); return new SimTypeString(out);
...@@ -43,7 +41,7 @@ public class CodeConnectString extends SimCode { ...@@ -43,7 +41,7 @@ public class CodeConnectString extends SimCode {
@Override @Override
public String toString() { public String toString() {
return out; return out;
} }
} }
...@@ -13,7 +13,7 @@ import tec.letsgoing.ardublock.simulator.simcode.SimCode; ...@@ -13,7 +13,7 @@ import tec.letsgoing.ardublock.simulator.simcode.SimCode;
* *
*/ */
public class SimTypeBool extends SimCode { public class SimTypeBool extends SimCode {
boolean value = false; private boolean value = false;
private SimCode followBlock; private SimCode followBlock;
public SimTypeBool(boolean _value) { public SimTypeBool(boolean _value) {
......
...@@ -58,7 +58,7 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -58,7 +58,7 @@ public class GUI extends JFrame implements Runnable, ActionListener {
*/ */
public GUI(Simulator simu) { public GUI(Simulator simu) {
super("ArduBlock Simulator"); super("ArduBlock Simulator");
// Konstruktor der Module // Konstruktor der Module
modules[0] = new RGB(new ImageIcon(getToolkit() modules[0] = new RGB(new ImageIcon(getToolkit()
.getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/PM31_RGB_LED.png")))); .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/PM31_RGB_LED.png"))));
......
...@@ -15,7 +15,6 @@ import javax.swing.JLabel; ...@@ -15,7 +15,6 @@ import javax.swing.JLabel;
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.simcode.datatypes.SimTypeInt;
/** /**
* Modul mit einer RGB LED * Modul mit einer RGB LED
...@@ -45,13 +44,17 @@ public class RGB extends Modul { ...@@ -45,13 +44,17 @@ public class RGB extends Modul {
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
Graphics2D ga = (Graphics2D) g; Graphics2D ga = (Graphics2D) g;
int transparancy = (int) (Math.max(redValue, Math.max(greenValue, blueValue)) * 0.9); int transparancy = (int) (Math.max(redValue, Math.max(greenValue, blueValue)) * 0.9);
int tredValue=0,tgreenValue=0,tblueValue=0; int tredValue = 0, tgreenValue = 0, tblueValue = 0;
if (transparancy!=0) { if (transparancy != 0) {
if(redValue>0)tredValue=map(redValue); if (redValue > 0)
if(greenValue>0)tgreenValue=map(greenValue); tredValue = map(redValue);
if(blueValue>0)tblueValue=map(blueValue); if (greenValue > 0)
tgreenValue = map(greenValue);
if (blueValue > 0)
tblueValue = map(blueValue);
} }
//System.out.println(tredValue+" "+ tgreenValue+" "+ tblueValue+" "+ transparancy); // System.out.println(tredValue+" "+ tgreenValue+" "+ tblueValue+" "+
// transparancy);
ga.setPaint(new Color(tredValue, tgreenValue, tblueValue, transparancy)); ga.setPaint(new Color(tredValue, tgreenValue, tblueValue, transparancy));
ga.fillOval(0, 0, 73, 73); ga.fillOval(0, 0, 73, 73);
} }
...@@ -71,13 +74,12 @@ public class RGB extends Modul { ...@@ -71,13 +74,12 @@ public class RGB extends Modul {
*/ */
public void updateModul(Pin pin) { public void updateModul(Pin pin) {
if (pin == pins.get(0)) if (pin == pins.get(0))
redValue = pin.getValue() / 4; redValue = pin.getValue() / 4;
if (pin == pins.get(1)) if (pin == pins.get(1))
blueValue = pin.getValue() / 4; blueValue = pin.getValue() / 4;
if (pin == pins.get(2)) if (pin == pins.get(2))
greenValue = pin.getValue() / 4; greenValue = pin.getValue() / 4;
} }
/** /**
...@@ -99,11 +101,11 @@ public class RGB extends Modul { ...@@ -99,11 +101,11 @@ public class RGB extends Modul {
return true; return true;
} }
public int map(int v) {
float vL=0,vH=255,tL=200,tH=255; private int map(int v) {
float vL = 0, vH = 255, tL = 200, tH = 255;
return (int) (((v - vL) / (vH - vL)) * (tH - tL) + tL); return (int) (((v - vL) / (vH - vL)) * (tH - tL) + tL);
} }
/** /**
* Funktion, welche die Positionen der Modulpins berechnet (in Pixeln für das * Funktion, welche die Positionen der Modulpins berechnet (in Pixeln für das
......
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