This commit is contained in:
parent
b4e3bb63ef
commit
fc9ed9ca43
Binary file not shown.
|
@ -162,7 +162,7 @@ public class ConfigDefinition {
|
|||
break;
|
||||
case KEY_BOARD_NAME:
|
||||
String boardName = args[i + 1];
|
||||
pinoutLogic = PinoutLogic.create(boardName);
|
||||
pinoutLogic = PinoutLogic.create(boardName, PinoutLogic.CONFIG_BOARDS);
|
||||
if (pinoutLogic != null)
|
||||
state.inputFiles.addAll(pinoutLogic.getInputFiles());
|
||||
break;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.devexperts.logging.Logging;
|
||||
import com.rusefi.enum_reader.Value;
|
||||
import com.rusefi.util.SystemOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -8,12 +9,15 @@ import org.yaml.snakeyaml.Yaml;
|
|||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import static com.devexperts.logging.Logging.getLogging;
|
||||
import static com.rusefi.VariableRegistry.FULL_JAVA_ENUM;
|
||||
import static com.rusefi.VariableRegistry.ENUM_SUFFIX;
|
||||
import static com.rusefi.output.JavaSensorsConsumer.quote;
|
||||
|
||||
public class PinoutLogic {
|
||||
private static final String CONFIG_BOARDS = "config/boards/";
|
||||
private static final Logging log = getLogging(PinoutLogic.class);
|
||||
|
||||
public static final String CONFIG_BOARDS = "config/boards/";
|
||||
private static final String CONNECTORS = "/connectors";
|
||||
private static final String QUOTED_NONE = quote("NONE");
|
||||
public static final String QUOTED_INVALID = quote(VariableRegistry.INVALID);
|
||||
|
@ -22,9 +26,10 @@ public class PinoutLogic {
|
|||
private final String boardName;
|
||||
private final ArrayList<PinState> globalList = new ArrayList<>();
|
||||
private final Map</*id*/String, /*tsName*/String> tsNameById = new TreeMap<>();
|
||||
|
||||
private final StringBuilder header = new StringBuilder("//DO NOT EDIT MANUALLY, let automation work hard.\n\n");
|
||||
|
||||
public PinoutLogic(String boardName, File[] boardYamlFiles) {
|
||||
log.info(boardName + ": " + Arrays.toString(boardYamlFiles));
|
||||
this.boardName = boardName;
|
||||
this.boardYamlFiles = boardYamlFiles;
|
||||
}
|
||||
|
@ -48,6 +53,7 @@ public class PinoutLogic {
|
|||
PinType listPinType = PinType.find(className);
|
||||
String pinType = listPinType.getPinType();
|
||||
EnumsReader.EnumState enumList = state.enumsReader.getEnums().get(pinType);
|
||||
Objects.requireNonNull(enumList, "Enum for " + pinType);
|
||||
for (Map.Entry<String, Value> kv : enumList.entrySet()) {
|
||||
if (kv.getKey().equals(id)) {
|
||||
int index = kv.getValue().getIntValue();
|
||||
|
@ -171,22 +177,28 @@ public class PinoutLogic {
|
|||
globalList.add(thisPin);
|
||||
}
|
||||
|
||||
public static PinoutLogic create(String boardName) {
|
||||
String dirPath = PinoutLogic.CONFIG_BOARDS + boardName + PinoutLogic.CONNECTORS;
|
||||
public static void main(String[] args) throws IOException {
|
||||
PinoutLogic logic = create("hellen-gm-e67","../../firmware/config/boards/hellen/");
|
||||
logic.readFiles();
|
||||
log.info(logic.toString());
|
||||
|
||||
registerPins(logic.globalList, new VariableRegistry(), new ReaderState());
|
||||
}
|
||||
|
||||
public static PinoutLogic create(String boardName, String rootFolder) {
|
||||
String dirPath = rootFolder + boardName + PinoutLogic.CONNECTORS;
|
||||
File dirName = new File(dirPath);
|
||||
FilenameFilter filter = (f, name) -> name.endsWith(".yaml");
|
||||
File[] boardYamlFiles = dirName.listFiles(filter);
|
||||
if (boardYamlFiles == null)
|
||||
if (boardYamlFiles == null) {
|
||||
log.info("No yaml files in " + dirPath);
|
||||
return null;
|
||||
}
|
||||
return new PinoutLogic(boardName, boardYamlFiles);
|
||||
}
|
||||
|
||||
public void registerBoardSpecificPinNames(VariableRegistry registry, ReaderState state) throws IOException {
|
||||
StringBuilder header = new StringBuilder("//DO NOT EDIT MANUALLY, let automation work hard.\n\n");
|
||||
for (File yamlFile : boardYamlFiles) {
|
||||
header.append("// auto-generated by PinoutLogic.java based on " + yamlFile + "\n");
|
||||
readMetaInfo(yamlFile);
|
||||
}
|
||||
readFiles();
|
||||
registerPins(globalList, registry, state);
|
||||
|
||||
try (FileWriter getTsNameByIdFile = new FileWriter(PinoutLogic.CONFIG_BOARDS + boardName + PinoutLogic.CONNECTORS + File.separator + "generated_ts_name_by_pin.cpp")) {
|
||||
|
@ -210,6 +222,14 @@ public class PinoutLogic {
|
|||
}
|
||||
}
|
||||
|
||||
private void readFiles() throws IOException {
|
||||
for (File yamlFile : boardYamlFiles) {
|
||||
header.append("// auto-generated by PinoutLogic.java based on " + yamlFile + "\n");
|
||||
readMetaInfo(yamlFile);
|
||||
}
|
||||
log.info("Got from " + boardYamlFiles.length + " file(s): " + this);
|
||||
}
|
||||
|
||||
public List<String> getInputFiles() {
|
||||
List<String> result = new ArrayList<>();
|
||||
for (File yamlFile : boardYamlFiles) {
|
||||
|
@ -244,5 +264,23 @@ public class PinoutLogic {
|
|||
public String getPinClass() {
|
||||
return pinClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PinState{" +
|
||||
"id='" + id + '\'' +
|
||||
", pinTsName='" + pinTsName + '\'' +
|
||||
", pinClass='" + pinClass + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PinoutLogic{" +
|
||||
"boardName='" + boardName + '\'' +
|
||||
", globalList=" + globalList +
|
||||
", tsNameById=" + tsNameById +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue