helping kinetis

This commit is contained in:
rusefillc 2023-01-16 16:39:08 -05:00
parent 41167a2c9e
commit 72713de50a
6 changed files with 23 additions and 7 deletions

View File

@ -62,6 +62,7 @@ Usages:
prepend: integration/rusefi_config.txt
output_name: boost
constexpr: "engine->boostController"
conditional_compilation: "EFI_BOOST_CONTROL"
- name: ac_control
java: AcControl.java

Binary file not shown.

View File

@ -85,7 +85,7 @@ public class LiveDataProcessor {
}
interface EntryHandler {
void onEntry(String name, String javaName, String folder, String prepend, boolean withCDefines, String[] outputNames, String constexpr) throws IOException;
void onEntry(String name, String javaName, String folder, String prepend, boolean withCDefines, String[] outputNames, String constexpr, String conditional) throws IOException;
}
private int handleYaml(Map<String, Object> data) throws IOException {
@ -101,7 +101,7 @@ public class LiveDataProcessor {
EntryHandler handler = new EntryHandler() {
@Override
public void onEntry(String name, String javaName, String folder, String prepend, boolean withCDefines, String[] outputNames, String constexpr) throws IOException {
public void onEntry(String name, String javaName, String folder, String prepend, boolean withCDefines, String[] outputNames, String constexpr, String conditional) throws IOException {
// TODO: use outputNames
int startingPosition = javaSensorsConsumer.sensorTsPosition;
@ -133,6 +133,7 @@ public class LiveDataProcessor {
state.addDestination((state1, structure) -> sdCardFieldsConsumer.handleEndStruct(state1, structure));
outputValueConsumer.currentSectionPrefix = constexpr;
outputValueConsumer.conditional = conditional;
state.addDestination((state1, structure) -> outputValueConsumer.handleEndStruct(state1, structure));
state.addDestination(new ConfigurationConsumer() {
@ -162,6 +163,7 @@ public class LiveDataProcessor {
String folder = (String) entry.get("folder");
String prepend = (String) entry.get("prepend");
String constexpr = (String) entry.get("constexpr");
String conditional = (String) entry.get("conditional_compilation");
Boolean withCDefines = (Boolean) entry.get("withCDefines");
// Defaults to false if not specified
withCDefines = withCDefines != null && withCDefines;
@ -180,7 +182,7 @@ public class LiveDataProcessor {
nameList.toArray(outputNamesArr);
}
handler.onEntry(name, java, folder, prepend, withCDefines, outputNamesArr, constexpr);
handler.onEntry(name, java, folder, prepend, withCDefines, outputNamesArr, constexpr, conditional);
String enumName = "LDS_" + name;
String type = name + "_s"; // convention

View File

@ -127,7 +127,7 @@ public class GetConfigValueConsumer implements ConfigurationConsumer {
public String getCompleteGetterBody() {
StringBuilder switchBody = new StringBuilder();
StringBuilder getterBody = GetOutputValueConsumer.getGetters(switchBody, variables);
StringBuilder getterBody = GetOutputValueConsumer.getGetters(switchBody, variables, null);
String fullSwitch = wrapSwitchStatement(switchBody);

View File

@ -1,7 +1,6 @@
package com.rusefi.output;
import com.rusefi.ConfigField;
import com.rusefi.ConfigFieldImpl;
import com.rusefi.ReaderState;
import com.rusefi.TypesHelper;
import com.rusefi.core.Pair;
@ -20,6 +19,7 @@ import static com.rusefi.output.GetConfigValueConsumer.getCompareName;
/**
* here we generate C++ code needed for https://github.com/rusefi/rusefi/wiki/Lua-Scripting#getoutputname implementation
*
* @see GetConfigValueConsumer
*/
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
@ -28,6 +28,7 @@ public class GetOutputValueConsumer implements ConfigurationConsumer {
private final String fileName;
public String currentSectionPrefix = "engine->outputChannels";
public String conditional;
public GetOutputValueConsumer(String fileName) {
this.fileName = fileName;
@ -69,7 +70,7 @@ public class GetOutputValueConsumer implements ConfigurationConsumer {
public String getContent() {
StringBuilder switchBody = new StringBuilder();
StringBuilder getterBody = getGetters(switchBody, getterPairs);
StringBuilder getterBody = getGetters(switchBody, getterPairs, conditional);
String fullSwitch = wrapSwitchStatement(switchBody);
@ -89,17 +90,22 @@ public class GetOutputValueConsumer implements ConfigurationConsumer {
}
@NotNull
static StringBuilder getGetters(StringBuilder switchBody, List<? extends Pair<String, String>> getterPairs) {
static StringBuilder getGetters(StringBuilder switchBody, List<? extends Pair<String, String>> getterPairs, String conditional) {
HashMap<Integer, AtomicInteger> hashConflicts = getHashConflicts(getterPairs);
StringBuilder getterBody = new StringBuilder();
for (Pair<String, String> pair : getterPairs) {
String returnLine = "\t\treturn " + pair.second + ";\n";
String before = conditional == null ? "" : "#if " + conditional + "\n";
String after = conditional == null ? "" : "#endif\n";
int hash = HashUtil.hash(pair.first);
if (hashConflicts.get(hash).get() == 1) {
switchBody.append(before);
switchBody.append("\t\tcase " + hash + ":\n");
switchBody.append("\t" + returnLine);
switchBody.append(after);
} else {
getterBody.append(getCompareName(pair.first));
getterBody.append(returnLine);

View File

@ -142,6 +142,7 @@ public class OutputsTest {
ReaderStateImpl state = new ReaderStateImpl();
GetOutputValueConsumer outputValueConsumer = new GetOutputValueConsumer(null);
outputValueConsumer.conditional = "EFI_BOOST_CONTROL";
state.readBufferedReader(test, (outputValueConsumer));
assertEquals(
"#include \"pch.h\"\n" +
@ -149,12 +150,18 @@ public class OutputsTest {
"float getOutputValueByName(const char *name) {\n" +
"\tint hash = djb2lowerCase(name);\n" +
"\tswitch(hash) {\n" +
"#if EFI_BOOST_CONTROL\n" +
"\t\tcase -1571463185:\n" +
"\t\t\treturn engine->outputChannels.issue_294_31;\n" +
"#endif\n" +
"#if EFI_BOOST_CONTROL\n" +
"\t\tcase -298185774:\n" +
"\t\t\treturn engine->outputChannels.enableFan1WithAc;\n" +
"#endif\n" +
"#if EFI_BOOST_CONTROL\n" +
"\t\tcase -709106787:\n" +
"\t\t\treturn engine->outputChannels.hwChannel;\n" +
"#endif\n" +
"\t}\n" +
"\treturn EFI_ERROR_CODE;\n" +
"}\n", outputValueConsumer.getContent());