Skip to content

Commit

Permalink
Fix simulator to run blinking leds example
Browse files Browse the repository at this point in the history
  • Loading branch information
mbats committed Jun 19, 2015
1 parent bc86d79 commit 6506817
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 5 deletions.
3 changes: 2 additions & 1 deletion plugins/fr.obeo.dsl.arduino.design/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ Require-Bundle: org.eclipse.ui,
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: com.google.common.collect
Export-Package: fr.obeo.dsl.arduino.design
Export-Package: fr.obeo.dsl.arduino.design,
fr.obeo.dsl.arduino.design.services
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<arduino:Project xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:arduino="http://www.obeo.fr/arduino">
<modules xsi:type="arduino:OutputModule" name="White LED" image="dfrobot/white_led.jpg" level="true"/>
<modules xsi:type="arduino:InputModule" name="Push button 1" image="dfrobot/push_button.jpg"/>
<modules xsi:type="arduino:OutputModule" name="Red LED" image="dfrobot/res_led.jpg" level="true"/>
<modules xsi:type="arduino:OutputModule" name="Red LED" image="dfrobot/red_led.jpg" level="true"/>
<modules xsi:type="arduino:OutputModule" name="Blue LED" image="dfrobot/blue_led.jpg" level="true"/>
<modules xsi:type="arduino:InputModule" name="Push button 2" image="dfrobot/push_button.jpg"/>
<modules xsi:type="arduino:OutputModule" name="Buzzer" image="dfrobot/buzzer.jpg"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<featureCustomizations xsi:type="description:EReferenceCustomization" applyOnAll="true" referenceName="strokeColor" value="//@userColorsPalettes[name='Arduino%20Palette']/@entries[name='level%20intencity']"/>
<featureCustomizations xsi:type="description:EReferenceCustomization" applyOnAll="true" referenceName="borderColor" value="//@userColorsPalettes[name='Arduino%20Palette']/@entries[name='level%20intencity']"/>
<featureCustomizations xsi:type="description:EAttributeCustomization" applyOnAll="true" attributeName="borderSizeComputationExpression" value="1"/>
<featureCustomizations xsi:type="description:EAttributeCustomization" attributeName="workspacePath" value="service:getSimulatingImage">
<appliedOn href="viewpoint:/fr.obeo.dsl.arduino.design/Arduino#//@ownedViewpoints[name='Arduino']/@ownedRepresentations[name='Hardware']/@defaultLayer/@nodeMappings[name='HW_Module']/@style"/>
</featureCustomizations>
</vsmElementCustomizations>
</customization>
</layers>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package fr.obeo.dsl.arduino.simulator.design.services;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.emf.ecore.EObject;
import org.osgi.framework.Bundle;

import fr.obeo.dsl.arduino.ArduinoUtils;
import fr.obeo.dsl.arduino.Connector;
import fr.obeo.dsl.arduino.Module;
import fr.obeo.dsl.arduino.Pin;
import fr.obeo.dsl.arduino.Platform;
import fr.obeo.dsl.arduino.design.services.ArduinoServices;
import fr.obeo.dsl.arduino.simulator.Simulator;
import fr.obeo.dsl.arduino.simulator.design.launcher.LauncherDelegate;
import fr.obeo.dsl.debug.ide.sirius.ui.services.AbstractDSLDebuggerServices;
Expand Down Expand Up @@ -124,4 +131,34 @@ public int getLevel(Platform platform) {
return 0;
}

public String getSimulatingImage(Module module) {
int level = getLevel(module);
String imageName = getImageLevel(module, level);
Bundle bundle = org.eclipse.core.runtime.Platform
.getBundle("fr.obeo.dsl.arduino.simulator.design");
URL fileURL = bundle.getEntry("images/" + imageName);
File file;
try {
file = new File(FileLocator.resolve(fileURL).toURI());
if (!file.exists()) {
ArduinoServices service = new ArduinoServices();
return service.getImage(module);
}
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return "fr.obeo.dsl.arduino.simulator.design/images/" + imageName;
}

private String getImageLevel(Module module, int level) {
String imageName = module.getImage().substring(0,
module.getImage().indexOf(".jpg"))
+ "_" + level + ".jpg";
return imageName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private Integer getStatusValue(Status status) {
public Object caseSensor(Sensor sensor) {
final Pin pin = ArduinoUtils.getPin(simulator.getProject(),
sensor.getModule());
return simulator.getPinLevel(pin);
return interpretObjectValueToBoolean(simulator.getPinLevel(pin));
}

@Override
Expand Down Expand Up @@ -171,7 +171,7 @@ public Object caseWhile(While _while) {
@Override
public Object caseIf(If _if) {
final Instruction first = _if.getInstructions().get(0);
if (Boolean.TRUE.equals(_if.getCondition())) {
if (Boolean.TRUE.equals(doSwitch(_if.getCondition()))) {
Instruction current = first;
while (current != null) {
doSwitch(current);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.eclipse.emf.ecore.EObject;

import fr.obeo.dsl.arduino.Connector;
import fr.obeo.dsl.arduino.Pin;
import fr.obeo.dsl.arduino.Variable;
import fr.obeo.dsl.arduino.util.ArduinoSwitch;
Expand Down Expand Up @@ -53,7 +54,9 @@ public void setup() throws SimulationStoppedException {
Iterator<EObject> it = simulator.getProject().eAllContents();
while (it.hasNext()) {
EObject eObj = it.next();
if (eObj instanceof Variable || eObj instanceof Pin) {
System.out.println(eObj);
if (eObj instanceof Variable || eObj instanceof Pin
|| eObj instanceof Connector) {
doSwitch(eObj);
}
}
Expand All @@ -67,8 +70,16 @@ public Void caseVariable(Variable variable) {

@Override
public Void casePin(Pin pin) {
System.out.println("Init : " + pin);
simulator.setPinLevel(pin, Integer.valueOf(0));
return null;
}

@Override
public Void caseConnector(Connector connector) {
System.out.println("Init : " + connector.getPin());
simulator.setPinLevel(connector.getPin(), Integer.valueOf(0));
return null;
}

}

0 comments on commit 6506817

Please sign in to comment.