Mapping pin templating (#5052)

* replace ___

* new jar

* Add test
This commit is contained in:
David Holdeman 2023-02-11 21:46:04 -06:00 committed by GitHub
parent b32bda8275
commit 121f36c307
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 3 deletions

Binary file not shown.

View File

@ -154,10 +154,13 @@ public class PinoutLogic {
Object pinId = pin.get("id");
Object pinClass = pin.get("class");
Object pinName = pin.get("pin");
String pinTsName = (String) pin.get("ts_name");
Object pinTsName = pin.get("ts_name");
if (pinId == null || pinClass == null || pinTsName == null) {
continue;
}
if (pinName != null) {
pinTsName = pinTsName.toString().replace("___", pinName.toString());
}
if (pinId instanceof ArrayList) {
ArrayList<String> pinIds = (ArrayList<String>) pinId;
if (!(pinClass instanceof ArrayList))
@ -167,14 +170,14 @@ public class PinoutLogic {
throw new IllegalStateException(pinName + ": id array length should match class array length: " + pinId + " vs " + pinClassArray);
for (int i = 0; i < pinIds.size(); i++) {
String id = pinIds.get(i);
addPinToList(id, pinTsName, pinClassArray.get(i));
addPinToList(id, (String) pinTsName, pinClassArray.get(i));
}
} else if (pinId instanceof String) {
String pinIdString = (String) pinId;
if (pinIdString.length() == 0) {
throw new IllegalStateException("Unexpected empty ID field");
}
addPinToList(pinIdString, pinTsName, (String) pinClass);
addPinToList(pinIdString, (String) pinTsName, (String) pinClass);
} else {
throw new IllegalStateException("Unexpected type of ID field: " + pinId.getClass().getSimpleName());
}

View File

@ -39,6 +39,31 @@ public class PinoutLogicIntegratedTest {
}
@Test
public void testTemplate() throws IOException {
runPinoutTest("pins:\n" +
" - pin: 1\n" +
" id: [E11, E11]\n" +
" class: [event_inputs, switch_inputs]\n" +
" function: Digital trigger/switch input for instance Hall type CAM\n" +
" ts_name: ___ - Digital 2\n" +
" type: din",
"//DO NOT EDIT MANUALLY, let automation work hard.\n" +
"\n" +
"// auto-generated by PinoutLogic.java based on key\n" +
"#include \"pch.h\"\n" +
"\n" +
"// see comments at declaration in pin_repository.h\n" +
"const char * getBoardSpecificPinName(brain_pin_e brainPin) {\n" +
"\tswitch(brainPin) {\n" +
"\t\tcase Gpio::E11: return \"1 - Digital 2\";\n" +
"\t\tdefault: return nullptr;\n" +
"\t}\n" +
"\treturn nullptr;\n" +
"}\n");
}
private static void runPinoutTest(String inputYaml, String expected) throws IOException {
StringWriter testWriter = new StringWriter();