Skip to content
Snippets Groups Projects
Commit 71eb4f67 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

Rebuilt single RasPi unit generator with new architecture.

parent 56d63df9
No related branches found
No related tags found
No related merge requests found
Showing
with 582 additions and 841 deletions
......@@ -4,6 +4,6 @@ CanTransmissionCatalog.java ec4637eda80234429a9f382a37713588a0fbb83a RED
ConsoleOutputExecutable.java 5b8c50f2236ad49958a0a0b599a7e60265a6fc06 YELLOW
HeaderCopyGenerator.java 18239a3adae35256e32dad19df9d8f38acbf7e66 RED
MultiUnitMainGenerator.java 458754b89c2d79db3fee08baa444424772e40fb7 RED
PWMActuatorExecutable.java 9068846c7ff04c034da6493067fcebf73051de98 YELLOW
RaspberryPIExecutable.java f94071537e9596817e7895cf79e4202d24224087 RED
SingleUnitMainGenerator.java e1df0d82804fd0622b97ecde827844da30370e14 RED
PWMActuatorExecutable.java 3273e75ecbb8e41984e8b66cfe8f16bc87256150 YELLOW
RaspberryPIExecutable.java cafff8199da9cc59688289c9c26097e6872e9702 RED
SingleUnitMainGenerator.java 9ae8b9a5d40c1415720a7bcad2378376474ca70b RED
......@@ -15,21 +15,16 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.funcCall;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.intConst;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.stringConst;
import org.fortiss.af3.component.model.OutputPort;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.platform.language.executable.IInitializableExecutable;
import org.fortiss.af3.platform.language.executable.ITerminatableExecutable;
import org.fortiss.af3.platform.language.executable.IWritableExecutable;
import org.fortiss.af3.platform.raspberry.generator.executable.framework.IInitializationExecutable;
import org.fortiss.af3.platform.raspberry.generator.executable.framework.ITerminationExecutable;
import org.fortiss.af3.platform.raspberry.generator.executable.framework.IWriteableExecutable;
import org.fortiss.af3.platform.raspberry.generator.executable.library.PiHALLibraryExecutableBase;
import org.fortiss.af3.platform.raspberry.model.ActuatorPWM;
/** Executable for {@link ActuatorPWM}. */
public class PWMActuatorExecutable extends PiHALLibraryExecutableBase<ActuatorPWM> implements
IInitializableExecutable, IWritableExecutable, ITerminatableExecutable {
IInitializationExecutable, IWriteableExecutable, ITerminationExecutable {
/** Constructor. */
public PWMActuatorExecutable(ActuatorPWM modelElement) {
super(modelElement);
......@@ -37,25 +32,38 @@ public class PWMActuatorExecutable extends PiHALLibraryExecutableBase<ActuatorPW
/** {@inheritDoc} */
@Override
public IExpressionTerm getInitialization() {
return funcCall("temp_actuator_initialize", stringConst("/dev/ttyACM0"));
public String getHeaderFileName() {
return "temp_actuator.h";
}
/** {@inheritDoc} */
@Override
public IExpressionTerm getTermination() {
return funcCall("temp_actuator_terminate");
public String getVariableDeclaration(String prefix) {
return "int " + prefix + "actuator_pwm = -1;\n";
}
/** {@inheritDoc} */
@Override
public IExpressionTerm getValueWriteAccessor(OutputPort logicalSignal, IExpressionTerm value) {
return funcCall("temp_actuator_set_target", intConst(modelElement.getChannelID()), value);
public String getInitializationCode(String prefix) {
return prefix + "actuator_pwm = temp_actuator_initialize(\"/dev/ttyACM0\");\n";
}
/** {@inheritDoc} */
@Override
public String getHeaderFileName() {
return "temp_actuator.h";
public String getTerminationCode(String prefix) {
return "temp_actuator_terminate();\n";
}
/** {@inheritDoc} */
@Override
public String getWriteCode(String prefix, OutputPort logicalSignal, String value) {
return "temp_actuator_set_target(" + prefix + "actuator_pwm, " +
modelElement.getChannelID() + ", " + value + ");\n";
}
/** {@inheritDoc} */
@Override
public String getNoValWriteCode(String prefix, OutputPort logicalSignal) {
return null;
}
}
......@@ -28,8 +28,10 @@ import static org.fortiss.tooling.kernel.utils.TransformationUtils.createTransfo
import static org.fortiss.tooling.kernel.utils.TransformationUtils.createTransformedObjectWithoutExceptionFor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.conqat.lib.commons.collections.Pair;
......@@ -84,6 +86,9 @@ public class RaspberryPIExecutable extends ExecutionUnitExecutableBase<Raspberry
private CanTransmissionCatalog canCatalog;
/** The list of atomic components deployed on this execution unit. */
private List<Component> atomics = new ArrayList<>();
/** The map from platform elements to executables. */
private Map<PlatformConnectorUnit, ExecutableBase<?>> platformConnector2ExecutableBase =
new HashMap<>();
// code generator output
/** The C source package produced by this generator. */
......@@ -105,10 +110,10 @@ public class RaspberryPIExecutable extends ExecutionUnitExecutableBase<Raspberry
try {
addEclipseCProjectFiles();
addConfigureAndMakedefsFiles();
addPlatformElementsCode(deployedPorts);
Set<String> headers = addPlatformElementsCode(deployedPorts);
addDataDictionaryCode();
addLogicalComponentCode(deployedComponents);
addMainFile(deployedComponents, deployedPorts);
addMainFile(deployedComponents, deployedPorts, headers);
} catch(Exception ex) {
error(AF3PlatformRaspberryActivator.getDefault(), ex.getMessage(), ex);
ex.printStackTrace();
......@@ -116,8 +121,12 @@ public class RaspberryPIExecutable extends ExecutionUnitExecutableBase<Raspberry
return generatorResult;
}
/** Adds the libraries and header files required by the used platform elements. */
private void addPlatformElementsCode(List<Pair<PlatformConnectorUnit, Port>> deployedPorts) {
/**
* Adds the libraries and header files required by the used platform elements and returns the
* set of header file names.
*/
private Set<String> addPlatformElementsCode(
List<Pair<PlatformConnectorUnit, Port>> deployedPorts) {
Set<String> includedHeaders = new HashSet<>();
Set<String> includedSources = new HashSet<>();
Set<String> includedLibraries = new HashSet<>();
......@@ -125,6 +134,7 @@ public class RaspberryPIExecutable extends ExecutionUnitExecutableBase<Raspberry
PlatformConnectorUnit pcu = pair.getFirst();
ExecutableBase<?> executable =
createTransformedObjectWithoutExceptionFor(pcu, ExecutableBase.class, context);
platformConnector2ExecutableBase.put(pcu, executable);
if(executable instanceof IRasPiHeaderExecutable) {
IRasPiHeaderExecutable headerExec = (IRasPiHeaderExecutable)executable;
if(!includedHeaders.contains(headerExec.getHeaderFileName())) {
......@@ -153,6 +163,7 @@ public class RaspberryPIExecutable extends ExecutionUnitExecutableBase<Raspberry
// ignore library file, since it is already included
}
}
return includedHeaders;
}
/** Initializes the generator result source package. */
......@@ -228,7 +239,7 @@ public class RaspberryPIExecutable extends ExecutionUnitExecutableBase<Raspberry
/** Creates the main file by using the {@link SingleUnitMainGenerator} helper class. */
private void addMainFile(List<Pair<ExecutionUnit, Component>> deployedComponents,
List<Pair<PlatformConnectorUnit, Port>> deployedPorts) {
List<Pair<PlatformConnectorUnit, Port>> deployedPorts, Set<String> headers) {
CSourcePackage srcGenPack = (CSourcePackage)generatorResult.getSrcGenPackage();
if(canCatalog != null) {
MultiUnitMainGenerator mg =
......@@ -238,7 +249,7 @@ public class RaspberryPIExecutable extends ExecutionUnitExecutableBase<Raspberry
} else {
SingleUnitMainGenerator mg =
new SingleUnitMainGenerator(modelElement, deployedComponents, deployedPorts,
context);
platformConnector2ExecutableBase, headers, context);
srcGenPack.addUnit(mg.createSingleUnitMain());
}
}
......
IInitializationExecutable.java 1633bcca794b274fe27bb009ff18f7a7acecd79e YELLOW
IRasPiHeaderExecutable.java f14b5714e7b982e097f6ac6e95eb91223a30d048 YELLOW
IRasPiLibraryBasedExecutable.java cf3548f22185e666fdcf6d4658b783734c0e5e8e YELLOW
IRasPiSourceBasedExecutable.java 79646213964346ace17013f5c8df5de13dafb1f0 YELLOW
ISingletonInitializableExecutable.java 64e05ca55f07855b4b241ee48810fbe3e9d6ad22 YELLOW
IReadableExecutable.java 14fdbe86fd5a31f1fe073da4c77f4ea1675e293e YELLOW
ISingletonInitializationExecutable.java f654ebf031b805e10ef6e0f0fbf3df179b20e20e YELLOW
ITerminationExecutable.java 61a81fcc3be00df33cf96e764d03686a423abcd9 YELLOW
IWriteableExecutable.java 9bbb6b6644f69e3b3ba9255862b89d79bcc00c2c YELLOW
/*-------------------------------------------------------------------------+
| Copyright 2018 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable.framework;
import org.fortiss.af3.platform.language.executable.ExecutableBase;
/**
* Interface for {@link ExecutableBase}s, which require initialization including static variables in
* the main program (e.g. a Unix file descriptor).
*
* @author hoelzl
*/
public interface IInitializationExecutable {
/**
* Returns the variable declarations needed by this executable. The prefix is given by the code
* generator to ensure uniqueness of variables for platform elements of the same type.
*/
String getVariableDeclaration(String prefix);
/** Returns the initialization code. */
String getInitializationCode(String prefix);
}
/*-------------------------------------------------------------------------+
| Copyright 2018 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable.framework;
import org.fortiss.af3.component.model.InputPort;
/**
* Executable for platform elements that can be written (e.g. actuators and busses).
*
* @author hoelzl
*/
public interface IReadableExecutable {
/** Returns the read code for the given port. */
String getReadCode(String prefix, InputPort logicalSignal);
/**
* Returns the read code to determine whether the value of the platform element is NoVal. May
* return {@code null}, to indicate that NoVal is not supported.
*/
String getNoValReadCode(String prefix, InputPort logicalSignal);
}
......@@ -15,17 +15,22 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable.framework;
import org.fortiss.af3.platform.language.executable.IInitializableExecutable;
/**
* Interface implemented by platform-specific executables, which need
* initialization during system start-up. In contrast to {@link IInitializableExecutable},
* initialization during system start-up. In contrast to {@link IInitializationExecutable},
* if there are more than one actuator or sensor with the singleton identifier, the
* initialization is only included once in the generated code.
* common initialization code is only included once in the generated code and it is included before
* all other initialization code.
*
* @author hoelzl
*/
public interface ISingletonInitializableExecutable extends IInitializableExecutable {
public interface ISingletonInitializationExecutable {
/** Returns the singleton identifier. */
String getSingletonInitializationIdentifier();
/** Returns the code to initialize local variables used by the initialization code. */
String getSingletonVariableDeclarationCode();
/** Returns the common initialization code. */
String getSingletonInitializationCode();
}
/*-------------------------------------------------------------------------+
| Copyright 2018 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable.framework;
import org.fortiss.af3.platform.language.executable.ExecutableBase;
/**
* Interface for {@link ExecutableBase}s, which require to be terminated during program shutdown.
*
* @author hoelzl
*/
public interface ITerminationExecutable {
/** Returns an termination code. */
String getTerminationCode(String prefix);
}
/*-------------------------------------------------------------------------+
| Copyright 2018 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable.framework;
import org.fortiss.af3.component.model.OutputPort;
/**
* Executable for platform elements that can be written (e.g. actuators and busses).
*
* @author hoelzl
*/
public interface IWriteableExecutable {
/** Returns the write code for the given port. */
String getWriteCode(String prefix, OutputPort logicalSignal, String value);
/**
* Returns the write code for the given port if the value to be written is NoVal. May return
* {@code null}, to indicate that NoVal is not supported.
*/
String getNoValWriteCode(String prefix, OutputPort logicalSignal);
}
......@@ -2,14 +2,14 @@ Button1Executable.java 4419314d71af50239cf6933a83a0f652614cf368 YELLOW
Button2Executable.java 3af03ceea3aa09178fe88fe630c94282de0b72f2 YELLOW
Button3Executable.java 964fbe4e0b5282ab617c4be2bed31afa8b4f394f YELLOW
Button4Executable.java 53db1cce9e3dfface4027f883586bf90638cd4ff YELLOW
ButtonExecutableBase.java 02e5bb6aa21183fc9444ec1874c67660908a55d2 YELLOW
ButtonExecutableBase.java e8f53ecacbd60802fd37314d5c46989f83314ad3 YELLOW
ButtonL1Executable.java ab68cddae1d323ff0ecd7956133c44d1ef0f9168 YELLOW
ButtonL2Executable.java 336b9d8d26a682b701f7a2ca078369c9cc621fbb YELLOW
ButtonR1Executable.java 700ef701ed77a0d3f8141166fe647ac5cd4ad570 YELLOW
ButtonR2Executable.java 9b4acdc37505f41c60d8216c92bcbd3f43a2ccec YELLOW
GamepadExecutableBase.java 5b769ad3d004d5b9c2ced63258a6d63eb6c41579 YELLOW
GamepadExecutableBase.java e79e9e5823e14a15f62c8a18a4025241896e998c YELLOW
Left_StickXExecutable.java c3e7f28f44fa27bd79e14ed7e60f44be2dc5a9ab YELLOW
Left_StickYExecutable.java f81cc1e3124eb712507825bc54e7d0f633fde640 YELLOW
Right_StickXExecutable.java ade165c88d0c6758efa167e5ba445eff87a0fd79 YELLOW
Right_StickYExecutable.java 891ea877d8c3f4bab6072a02b17bb92a6caa055d YELLOW
StickExecutableBase.java 970b8645af2ab59b9a4f8286f59e27fa38f6c1c0 YELLOW
StickExecutableBase.java 7f1fb5e30585fdb3cbafe06e3e4311cbc0f5bf21 YELLOW
......@@ -15,13 +15,9 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable.gamepad;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.funcCall;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.rawString;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.platform.language.executable.IReadableExecutable;
import org.fortiss.af3.platform.raspberry.generator.executable.framework.IReadableExecutable;
/**
* Base class for executables reading gamepad buttons.
......@@ -37,8 +33,14 @@ abstract class ButtonExecutableBase<T extends EObject> extends GamepadExecutable
/** {@inheritDoc} */
@Override
public final IExpressionTerm getValueReadAccessor(InputPort logicalSignal) {
return funcCall("gamepad_get_button_state", rawString(getButtonIdentifier()));
public final String getReadCode(String prefix, InputPort logicalSignal) {
return "gamepad_get_button_state(" + getButtonIdentifier() + ");\n";
}
/** {@inheritDoc} */
@Override
public final String getNoValReadCode(String prefix, InputPort logicalSignal) {
return null;
}
/** Returns the button identifier as defined in {@code gamepad.h}. */
......
......@@ -15,11 +15,8 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable.gamepad;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.rawString;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.platform.raspberry.generator.executable.framework.ISingletonInitializableExecutable;
import org.fortiss.af3.platform.raspberry.generator.executable.framework.ISingletonInitializationExecutable;
import org.fortiss.af3.platform.raspberry.generator.executable.library.PiHALLibraryExecutableBase;
import org.fortiss.af3.platform.raspberry.model.gamepad.GamepadPackage;
......@@ -29,7 +26,7 @@ import org.fortiss.af3.platform.raspberry.model.gamepad.GamepadPackage;
* @author hoelzl
*/
abstract class GamepadExecutableBase<T extends EObject> extends PiHALLibraryExecutableBase<T>
implements ISingletonInitializableExecutable {
implements ISingletonInitializationExecutable {
/** Constructor. */
public GamepadExecutableBase(T modelElement) {
super(modelElement);
......@@ -37,13 +34,19 @@ abstract class GamepadExecutableBase<T extends EObject> extends PiHALLibraryExec
/** {@inheritDoc} */
@Override
public final IExpressionTerm getInitialization() {
return rawString("gamepad_configuration_t* gamepad_config = malloc(sizeof(gamepad_configuration_t));\n"
public final String getSingletonInitializationCode() {
return "gamepad_configuration_t* gamepad_config = malloc(sizeof(gamepad_configuration_t));\n"
+ "gamepad_config->device_id = \"/dev/input/js0\";\n"
+ "gamepad_config->waiting_sleep_in_micros = 250;\n"
+ "gamepad_config->axis_callback = NULL;\n"
+ "gamepad_config->button_callback = NULL;"
+ "gamepad_initialize(gamepad_config);\n\n");
+ "gamepad_initialize(gamepad_config);\n\n";
}
/** {@inheritDoc} */
@Override
public final String getSingletonVariableDeclarationCode() {
return "";
}
/** {@inheritDoc} */
......
......@@ -15,13 +15,9 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable.gamepad;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.funcCall;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.rawString;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.platform.language.executable.IReadableExecutable;
import org.fortiss.af3.platform.raspberry.generator.executable.framework.IReadableExecutable;
/**
* Base class for executables reading gamepad sticks.
......@@ -37,8 +33,14 @@ abstract class StickExecutableBase<T extends EObject> extends GamepadExecutableB
/** {@inheritDoc} */
@Override
public final IExpressionTerm getValueReadAccessor(InputPort logicalSignal) {
return funcCall("gamepad_get_axis_position", rawString(getAxisIdentifier()));
public final String getReadCode(String prefix, InputPort logicalSignal) {
return "gamepad_get_axis_position(" + getAxisIdentifier() + ");\n";
}
/** {@inheritDoc} */
@Override
public String getNoValReadCode(String prefix, InputPort logicalSignal) {
return null;
}
/** Returns the axis identifier as defined in {@code gamepad.h}. */
......
ButtonAExecutable.java bbcb151d851b1b3d3e97b7e11b790fa13559fd96 YELLOW
ButtonBExecutable.java d659e04dc60cba0808bd2fceae22fcbc1bd203a9 YELLOW
ButtonExecutableBase.java fd0f182816404870725255efeebfbc07c22a8295 YELLOW
ButtonExecutableBase.java 168dede764665f721862d2b7aed3a5de5668c1f1 YELLOW
ButtonHomeExecutable.java e3a19a82d2cafd3bc75b6a7fc1a75df5656df48c YELLOW
ButtonL1Executable.java 68fac6c2abc7ea40eb7cc16839677a4cdc24111a YELLOW
ButtonL3Executable.java 2d04b51ee7ab822419140cf69821bbcbcfded359 YELLOW
......@@ -20,6 +20,6 @@ Left_StickYExecutable.java cc2b36f9bca913dc1956f34495cf9c77acb13c88 YELLOW
R2PositionExecutable.java 19f778392841d02d281fd856564b75e1333dffaa YELLOW
Right_StickXExecutable.java 97656a2ae56a70eac88153b123f2cd9c584af967 YELLOW
Right_StickYExecutable.java f3d942123ca47d0ddbf32f4f46bfaf2b21732653 YELLOW
RumblepadExecutableBase.java 35438b51af2212c2e169fb7008e9fe45c9b1aef6 YELLOW
RumblepadExecutableBase.java 876ab9c58e37837b273bfcbbc62233ca4d0576cc YELLOW
SimpleRumbleFeatureExecutable.java 413b6fb3f5847f0d09f52341c98b95f74c352016 YELLOW
StickExecutableBase.java 372150ca78a1ee736bbb2910b266ca05d52aa04f YELLOW
StickExecutableBase.java 7004e20d199bec82752b870db259786602db9766 YELLOW
......@@ -15,13 +15,9 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.funcCall;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.rawString;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.platform.language.executable.IReadableExecutable;
import org.fortiss.af3.platform.raspberry.generator.executable.framework.IReadableExecutable;
/**
* Base class for executables reading rumblepad buttons.
......@@ -37,8 +33,14 @@ abstract class ButtonExecutableBase<T extends EObject> extends RumblepadExecutab
/** {@inheritDoc} */
@Override
public final IExpressionTerm getValueReadAccessor(InputPort logicalSignal) {
return funcCall("rumblepad_get_button_state", rawString(getButtonIdentifier()));
public final String getReadCode(String prefix, InputPort logicalSignal) {
return "rumblepad_get_button_state(" + getButtonIdentifier() + ");\n";
}
/** {@inheritDoc} */
@Override
public final String getNoValReadCode(String prefix, InputPort logicalSignal) {
return null;
}
/** Returns the button identifier as defined in {@code rumblepad.h}. */
......
......@@ -15,11 +15,8 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.rawString;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.platform.raspberry.generator.executable.framework.ISingletonInitializableExecutable;
import org.fortiss.af3.platform.raspberry.generator.executable.framework.ISingletonInitializationExecutable;
import org.fortiss.af3.platform.raspberry.generator.executable.library.PiHALLibraryExecutableBase;
import org.fortiss.af3.platform.raspberry.model.rumblepad.RumblepadPackage;
......@@ -29,7 +26,7 @@ import org.fortiss.af3.platform.raspberry.model.rumblepad.RumblepadPackage;
* @author hoelzl
*/
abstract class RumblepadExecutableBase<T extends EObject> extends PiHALLibraryExecutableBase<T>
implements ISingletonInitializableExecutable {
implements ISingletonInitializationExecutable {
/** Constructor. */
public RumblepadExecutableBase(T modelElement) {
super(modelElement);
......@@ -37,13 +34,19 @@ abstract class RumblepadExecutableBase<T extends EObject> extends PiHALLibraryEx
/** {@inheritDoc} */
@Override
public final IExpressionTerm getInitialization() {
return rawString("rumblepad_configuration_t* rumblepad_config = malloc(sizeof(rumblepad_configuration_t));\n"
public final String getSingletonVariableDeclarationCode() {
return null;
}
/** {@inheritDoc} */
@Override
public final String getSingletonInitializationCode() {
return "rumblepad_configuration_t* rumblepad_config = malloc(sizeof(rumblepad_configuration_t));\n"
+ "rumblepad_config->device_id = \"/dev/input/js0\";\n"
+ "rumblepad_config->waiting_sleep_in_micros = 50;\n"
+ "rumblepad_config->axis_callback = NULL;\n"
+ "rumblepad_config->button_callback = NULL;"
+ "rumblepad_initialize(rumblepad_config);\n\n");
+ "rumblepad_initialize(rumblepad_config);\n\n";
}
/** {@inheritDoc} */
......
......@@ -15,13 +15,9 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.funcCall;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.rawString;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.platform.language.executable.IReadableExecutable;
import org.fortiss.af3.platform.raspberry.generator.executable.framework.IReadableExecutable;
/**
* Base class for executables reading rumblepad sticks and axis inputs.
......@@ -37,8 +33,14 @@ abstract class StickExecutableBase<T extends EObject> extends RumblepadExecutabl
/** {@inheritDoc} */
@Override
public final IExpressionTerm getValueReadAccessor(InputPort logicalSignal) {
return funcCall("rumblepad_get_axis_position", rawString(getAxisIdentifier()));
public final String getReadCode(String prefix, InputPort logicalSignal) {
return "rumblepad_get_axis_position(" + getAxisIdentifier() + ");\n";
}
/** {@inheritDoc} */
@Override
public final String getNoValReadCode(String prefix, InputPort logicalSignal) {
return null;
}
/** Returns the axis identifier as defined in {@code rumblepad.h}. */
......
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