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

Rumblepad code generation cleaned up.

parent 4b45c699
No related branches found
No related tags found
No related merge requests found
Showing
with 158 additions and 217 deletions
...@@ -15,38 +15,18 @@ ...@@ -15,38 +15,18 @@
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad; package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.funcCall;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.platform.language.executable.ReceiverExecutableBase;
import org.fortiss.af3.platform.raspberry.model.rumblepad.DPadLeft; import org.fortiss.af3.platform.raspberry.model.rumblepad.DPadLeft;
/** Executable for {@link DPadLeft}. */ /** Executable for {@link DPadLeft}. */
public class DPadLeftExecutable extends ReceiverExecutableBase<DPadLeft> { public class DPadLeftExecutable extends ButtonExecutableBase<DPadLeft> {
/** Constructor. */ /** Constructor. */
public DPadLeftExecutable(DPadLeft modelElement) { public DPadLeftExecutable(DPadLeft modelElement) {
super(modelElement); super(modelElement);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public IExpressionTerm getInitialization() { @Override
return funcCall("rp_init"); protected String getButtonIdentifier() {
} return "RUMBLEPAD_BUTTON_DPAD_LEFT";
/** {@inheritDoc} */
public IExpressionTerm getNoValGuardAccessor(InputPort logicalSignal) {
return funcCall("rp_btnDPadLeft_is_noval");
}
/** {@inheritDoc} */
public IExpressionTerm getTermination() {
return funcCall("rp_term");
}
/** {@inheritDoc} */
public IExpressionTerm getValueReadAccessor(InputPort logicalSignal) {
return funcCall("rp_btnDPadLeft_read");
} }
} }
...@@ -15,38 +15,18 @@ ...@@ -15,38 +15,18 @@
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad; package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.funcCall;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.platform.language.executable.ReceiverExecutableBase;
import org.fortiss.af3.platform.raspberry.model.rumblepad.DPadRight; import org.fortiss.af3.platform.raspberry.model.rumblepad.DPadRight;
/** Executable for {@link DPadRight}. */ /** Executable for {@link DPadRight}. */
public class DPadRightExecutable extends ReceiverExecutableBase<DPadRight> { public class DPadRightExecutable extends ButtonExecutableBase<DPadRight> {
/** Constructor. */ /** Constructor. */
public DPadRightExecutable(DPadRight modelElement) { public DPadRightExecutable(DPadRight modelElement) {
super(modelElement); super(modelElement);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public IExpressionTerm getInitialization() { @Override
return funcCall("rp_init"); protected String getButtonIdentifier() {
} return "RUMBLEPAD_BUTTON_DPAD_RIGHT";
/** {@inheritDoc} */
public IExpressionTerm getNoValGuardAccessor(InputPort logicalSignal) {
return funcCall("rp_btnDPadRight_is_noval");
}
/** {@inheritDoc} */
public IExpressionTerm getTermination() {
return funcCall("rp_term");
}
/** {@inheritDoc} */
public IExpressionTerm getValueReadAccessor(InputPort logicalSignal) {
return funcCall("rp_btnDPadRight_read");
} }
} }
...@@ -15,38 +15,18 @@ ...@@ -15,38 +15,18 @@
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad; package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.funcCall;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.platform.language.executable.ReceiverExecutableBase;
import org.fortiss.af3.platform.raspberry.model.rumblepad.DPadUp; import org.fortiss.af3.platform.raspberry.model.rumblepad.DPadUp;
/** Executable for {@link DPadUp}. */ /** Executable for {@link DPadUp}. */
public class DPadUpExecutable extends ReceiverExecutableBase<DPadUp> { public class DPadUpExecutable extends ButtonExecutableBase<DPadUp> {
/** Constructor. */ /** Constructor. */
public DPadUpExecutable(DPadUp modelElement) { public DPadUpExecutable(DPadUp modelElement) {
super(modelElement); super(modelElement);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public IExpressionTerm getInitialization() { @Override
return funcCall("rp_init"); protected String getButtonIdentifier() {
} return "RUMBLEPAD_BUTTON_DPAD_UP";
/** {@inheritDoc} */
public IExpressionTerm getNoValGuardAccessor(InputPort logicalSignal) {
return funcCall("rp_btnDPadUp_is_noval");
}
/** {@inheritDoc} */
public IExpressionTerm getTermination() {
return funcCall("rp_term");
}
/** {@inheritDoc} */
public IExpressionTerm getValueReadAccessor(InputPort logicalSignal) {
return funcCall("rp_btnDPadUp_read");
} }
} }
...@@ -15,34 +15,18 @@ ...@@ -15,34 +15,18 @@
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad; package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.funcCall;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.platform.language.executable.ReceiverExecutableBase;
import org.fortiss.af3.platform.raspberry.model.rumblepad.L2_Position; import org.fortiss.af3.platform.raspberry.model.rumblepad.L2_Position;
/** Executable for {@link L2_Position}. */ /** Executable for {@link L2_Position}. */
public class L2PositionExecutable extends ReceiverExecutableBase<L2_Position> { public class L2PositionExecutable extends StickExecutableBase<L2_Position> {
/** Constructor. */ /** Constructor. */
public L2PositionExecutable(L2_Position modelElement) { public L2PositionExecutable(L2_Position modelElement) {
super(modelElement); super(modelElement);
} }
public IExpressionTerm getInitialization() { /** {@inheritDoc} */
return funcCall("rp_init"); @Override
} protected String getAxisIdentifier() {
return "RUMBLEPAD_AXIS_L2";
public IExpressionTerm getNoValGuardAccessor(InputPort logicalSignal) {
return funcCall("rp_btnL2_Position_is_noval");
}
public IExpressionTerm getTermination() {
return funcCall("rp_term");
}
public IExpressionTerm getValueReadAccessor(InputPort logicalSignal) {
return funcCall("rp_btnL2_Position_read");
} }
} }
...@@ -15,34 +15,18 @@ ...@@ -15,34 +15,18 @@
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad; package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.funcCall;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.platform.language.executable.ReceiverExecutableBase;
import org.fortiss.af3.platform.raspberry.model.rumblepad.Left_StickX_Position; import org.fortiss.af3.platform.raspberry.model.rumblepad.Left_StickX_Position;
/** Executable for {@link Left_StickX_Position}. */ /** Executable for {@link Left_StickX_Position}. */
public class Left_StickXExecutable extends ReceiverExecutableBase<Left_StickX_Position> { public class Left_StickXExecutable extends StickExecutableBase<Left_StickX_Position> {
/** Constructor. */ /** Constructor. */
public Left_StickXExecutable(Left_StickX_Position modelElement) { public Left_StickXExecutable(Left_StickX_Position modelElement) {
super(modelElement); super(modelElement);
} }
public IExpressionTerm getInitialization() { /** {@inheritDoc} */
return funcCall("rp_init"); @Override
} protected String getAxisIdentifier() {
return "RUMBLEPAD_AXIS_LEFT_STICK_HORIZONTAL";
public IExpressionTerm getNoValGuardAccessor(InputPort logicalSignal) {
return funcCall("rp_btnLX_is_noval");
}
public IExpressionTerm getTermination() {
return funcCall("rp_term");
}
public IExpressionTerm getValueReadAccessor(InputPort logicalSignal) {
return funcCall("rp_btnLX_read");
} }
} }
...@@ -15,34 +15,18 @@ ...@@ -15,34 +15,18 @@
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad; package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.funcCall;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.platform.language.executable.ReceiverExecutableBase;
import org.fortiss.af3.platform.raspberry.model.rumblepad.Left_StickY_Position; import org.fortiss.af3.platform.raspberry.model.rumblepad.Left_StickY_Position;
/** Executable for {@link Left_StickY_Position}. */ /** Executable for {@link Left_StickY_Position}. */
public class Left_StickYExecutable extends ReceiverExecutableBase<Left_StickY_Position> { public class Left_StickYExecutable extends StickExecutableBase<Left_StickY_Position> {
/** Constructor. */ /** Constructor. */
public Left_StickYExecutable(Left_StickY_Position modelElement) { public Left_StickYExecutable(Left_StickY_Position modelElement) {
super(modelElement); super(modelElement);
} }
public IExpressionTerm getInitialization() { /** {@inheritDoc} */
return funcCall("rp_init"); @Override
} protected String getAxisIdentifier() {
return "RUMBLEPAD_AXIS_LEFT_STICK_VERTICAL";
public IExpressionTerm getNoValGuardAccessor(InputPort logicalSignal) {
return funcCall("rp_btnLY_is_noval");
}
public IExpressionTerm getTermination() {
return funcCall("rp_term");
}
public IExpressionTerm getValueReadAccessor(InputPort logicalSignal) {
return funcCall("rp_btnLY_read");
} }
} }
...@@ -15,34 +15,18 @@ ...@@ -15,34 +15,18 @@
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad; package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.funcCall;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.platform.language.executable.ReceiverExecutableBase;
import org.fortiss.af3.platform.raspberry.model.rumblepad.R2_Position; import org.fortiss.af3.platform.raspberry.model.rumblepad.R2_Position;
/** Executable for {@link R2_Position}. */ /** Executable for {@link R2_Position}. */
public class R2PositionExecutable extends ReceiverExecutableBase<R2_Position> { public class R2PositionExecutable extends StickExecutableBase<R2_Position> {
/** Constructor. */ /** Constructor. */
public R2PositionExecutable(R2_Position modelElement) { public R2PositionExecutable(R2_Position modelElement) {
super(modelElement); super(modelElement);
} }
public IExpressionTerm getInitialization() { /** {@inheritDoc} */
return funcCall("rp_init"); @Override
} protected String getAxisIdentifier() {
return "RUMBLEPAD_AXIS_R2";
public IExpressionTerm getNoValGuardAccessor(InputPort logicalSignal) {
return funcCall("rp_btnR2_Position_is_noval");
}
public IExpressionTerm getTermination() {
return funcCall("rp_term");
}
public IExpressionTerm getValueReadAccessor(InputPort logicalSignal) {
return funcCall("rp_btnR2_Position_read");
} }
} }
...@@ -15,34 +15,18 @@ ...@@ -15,34 +15,18 @@
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad; package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.funcCall;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.platform.language.executable.ReceiverExecutableBase;
import org.fortiss.af3.platform.raspberry.model.rumblepad.Right_StickX_Position; import org.fortiss.af3.platform.raspberry.model.rumblepad.Right_StickX_Position;
/** Executable for {@link Right_StickX_Position}. */ /** Executable for {@link Right_StickX_Position}. */
public class Right_StickXExecutable extends ReceiverExecutableBase<Right_StickX_Position> { public class Right_StickXExecutable extends StickExecutableBase<Right_StickX_Position> {
/** Constructor. */ /** Constructor. */
public Right_StickXExecutable(Right_StickX_Position modelElement) { public Right_StickXExecutable(Right_StickX_Position modelElement) {
super(modelElement); super(modelElement);
} }
public IExpressionTerm getInitialization() { /** {@inheritDoc} */
return funcCall("rp_init"); @Override
} protected String getAxisIdentifier() {
return "RUMBLEPAD_AXIS_RIGHT_STICK_HORIZONTAL";
public IExpressionTerm getNoValGuardAccessor(InputPort logicalSignal) {
return funcCall("rp_btnRX_is_noval");
}
public IExpressionTerm getTermination() {
return funcCall("rp_term");
}
public IExpressionTerm getValueReadAccessor(InputPort logicalSignal) {
return funcCall("rp_btnRX_read");
} }
} }
...@@ -15,34 +15,18 @@ ...@@ -15,34 +15,18 @@
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad; package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.funcCall;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.platform.language.executable.ReceiverExecutableBase;
import org.fortiss.af3.platform.raspberry.model.rumblepad.Right_StickY_Position; import org.fortiss.af3.platform.raspberry.model.rumblepad.Right_StickY_Position;
/** Executable for {@link Right_StickY_Position}. */ /** Executable for {@link Right_StickY_Position}. */
public class Right_StickYExecutable extends ReceiverExecutableBase<Right_StickY_Position> { public class Right_StickYExecutable extends StickExecutableBase<Right_StickY_Position> {
/** Constructor. */ /** Constructor. */
public Right_StickYExecutable(Right_StickY_Position modelElement) { public Right_StickYExecutable(Right_StickY_Position modelElement) {
super(modelElement); super(modelElement);
} }
public IExpressionTerm getInitialization() { /** {@inheritDoc} */
return funcCall("rp_init"); @Override
} protected String getAxisIdentifier() {
return "RUMBLEPAD_AXIS_RIGHT_STICK_VERTICAL";
public IExpressionTerm getNoValGuardAccessor(InputPort logicalSignal) {
return funcCall("rp_btnRY_is_noval");
}
public IExpressionTerm getTermination() {
return funcCall("rp_term");
}
public IExpressionTerm getValueReadAccessor(InputPort logicalSignal) {
return funcCall("rp_btnRY_read");
} }
} }
/*-------------------------------------------------------------------------+
| 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.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.library.PiHALLibraryExecutableBase;
import org.fortiss.af3.platform.raspberry.model.rumblepad.RumblepadPackage;
/**
* Base class for all executables of the rumblepad.
*
* @author hoelzl
*/
abstract class RumblepadExecutableBase<T extends EObject> extends PiHALLibraryExecutableBase<T>
implements ISingletonInitializableExecutable {
/** Constructor. */
public RumblepadExecutableBase(T modelElement) {
super(modelElement);
}
/** {@inheritDoc} */
@Override
public final IExpressionTerm getInitialization() {
return rawString("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");
}
/** {@inheritDoc} */
@Override
public final String getSingletonInitializationIdentifier() {
// use EMF package as singleton identifier
return RumblepadPackage.eNS_URI;
}
/** {@inheritDoc} */
@Override
public final String getHeaderFileName() {
return "rumblepad.h";
}
}
...@@ -16,38 +16,28 @@ ...@@ -16,38 +16,28 @@
package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad; 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.funcCall;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.intConst;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.component.model.OutputPort; import org.fortiss.af3.component.model.OutputPort;
import org.fortiss.af3.expression.model.terms.FunctionCall;
import org.fortiss.af3.expression.model.terms.IExpressionTerm; import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.platform.language.executable.TransmitterExecutableBase; import org.fortiss.af3.platform.language.executable.IWritableExecutable;
import org.fortiss.af3.platform.raspberry.model.rumblepad.SimpleRumbleFeature; import org.fortiss.af3.platform.raspberry.model.rumblepad.SimpleRumbleFeature;
/** Executable for {@link SimpleRumbleFeature}. */ /** Executable for {@link SimpleRumbleFeature}. */
public class SimpleRumbleFeatureExecutable extends TransmitterExecutableBase<SimpleRumbleFeature> { public class SimpleRumbleFeatureExecutable extends RumblepadExecutableBase<SimpleRumbleFeature>
implements IWritableExecutable {
/** Constructor. */ /** Constructor. */
public SimpleRumbleFeatureExecutable(SimpleRumbleFeature modelElement) { public SimpleRumbleFeatureExecutable(SimpleRumbleFeature modelElement) {
super(modelElement); super(modelElement);
} }
/** {@inheritDoc} */
public IExpressionTerm getInitialization() {
return funcCall("rp_init");
}
/** {@inheritDoc} */
public IExpressionTerm getNoValGuardAccessor(InputPort logicalSignal) {
return funcCall("rp_simpleRumble_is_noval");
}
/** {@inheritDoc} */
public IExpressionTerm getTermination() {
return funcCall("rp_term");
}
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public IExpressionTerm getValueWriteAccessor(OutputPort logicalSignal, IExpressionTerm value) { public IExpressionTerm getValueWriteAccessor(OutputPort logicalSignal, IExpressionTerm value) {
return funcCall("rp_simpleRumble_write"); FunctionCall fc = funcCall("rumblepad_set_rumble", value, value);
fc.getArguments().add(intConst(500));
fc.getArguments().add(intConst(0));
return fc;
} }
} }
/*-------------------------------------------------------------------------+
| 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.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;
/**
* Base class for executables reading rumblepad sticks and axis inputs.
*
* @author hoelzl
*/
abstract class StickExecutableBase<T extends EObject> extends RumblepadExecutableBase<T> implements
IReadableExecutable {
/** Constructor. */
public StickExecutableBase(T modelElement) {
super(modelElement);
}
/** {@inheritDoc} */
@Override
public final IExpressionTerm getValueReadAccessor(InputPort logicalSignal) {
return funcCall("rumblepad_get_axis_position", rawString(getAxisIdentifier()));
}
/** Returns the axis identifier as defined in {@code rumblepad.h}. */
protected abstract String getAxisIdentifier();
}
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