use of com.thecoderscorner.menu.editorui.generator.parameters.expander.CustomDeviceExpander in project tcMenu by davetcc.
the class IoExpanderDefinitionTest method testCustomDeviceExpander.
@Test
public void testCustomDeviceExpander() {
var device = IoExpanderDefinition.fromString("customIO:superDuper").orElseThrow();
assertThat(device).isInstanceOf(CustomDeviceExpander.class);
var custom = (CustomDeviceExpander) device;
assertEquals("superDuper", custom.getVariableName());
assertEquals("superDuper", custom.getId());
assertEquals("Custom IO: superDuper", custom.getNicePrintableName());
assertThat(custom.generateCode()).isEmpty();
assertThat(custom.generateGlobal()).isEmpty();
assertEquals("extern IoAbstractionRef superDuper;", custom.generateExport().orElseThrow());
assertThat(custom.generateHeader()).contains(new HeaderDefinition("IoAbstraction.h", GLOBAL, PRIORITY_NORMAL, new AlwaysApplicable()));
assertEquals("customIO:superDuper", custom.toString());
var device2 = IoExpanderDefinition.fromString("anotherExpander").orElseThrow();
assertThat(device2).isInstanceOf(CustomDeviceExpander.class);
assertEquals("anotherExpander", device2.getVariableName());
assertNotEquals(custom, device2);
var device3 = IoExpanderDefinition.fromString("customIO:superDuper").orElseThrow();
assertEquals(custom, device3);
}
use of com.thecoderscorner.menu.editorui.generator.parameters.expander.CustomDeviceExpander in project tcMenu by davetcc.
the class ArduinoGeneratorTest method runConversionWith.
@SuppressWarnings("unchecked")
private void runConversionWith(EmbeddedPlatform platform, String templateToUse, boolean recursiveName) throws IOException {
ArduinoSketchFileAdjuster adjuster = Mockito.mock(ArduinoSketchFileAdjuster.class);
MenuTree tree = buildSimpleTreeReadOnly();
ArduinoLibraryInstaller installer = Mockito.mock(ArduinoLibraryInstaller.class);
when(installer.statusOfAllLibraries()).thenReturn(new LibraryStatus(true, true, true, true));
var standardOptions = new CodeGeneratorOptionsBuilder().withPlatform(ARDUINO32.getBoardId()).withEepromDefinition(new AVREepromDefinition()).withAuthenticationDefinition(new EepromAuthenticatorDefinition(100, 3)).withExpanderDefinitions(new IoExpanderDefinitionCollection(List.of(new CustomDeviceExpander("123")))).withAppName("app").withNewId(UUID.fromString("4490f2fb-a48b-4c89-b6e5-7f557e5f6faf")).withRecursiveNaming(recursiveName).codeOptions();
ArduinoGenerator generator = new ArduinoGenerator(adjuster, installer, platform);
var firstPlugin = pluginConfig.getPlugins().get(0);
firstPlugin.getProperties().stream().filter(p -> p.getName().equals("SWITCH_IODEVICE")).findFirst().ifPresent(p -> p.setLatestValue("io23017"));
assertTrue(generator.startConversion(projectDir, pluginConfig.getPlugins(), tree, List.of(), standardOptions));
VariableNameGenerator gen = new VariableNameGenerator(tree, false, Set.of());
assertEquals("GenState", gen.makeNameToVar(generateItemWithName("Gen &^%State")));
assertEquals("ChannelÖôóò", gen.makeNameToVar(generateItemWithName("ChannelÖôóò")));
var cppGenerated = new String(Files.readAllBytes(projectDir.resolve(projectDir.getFileName() + "_menu.cpp")));
var hGenerated = new String(Files.readAllBytes(projectDir.resolve(projectDir.getFileName() + "_menu.h")));
var pluginGeneratedH = new String(Files.readAllBytes(projectDir.resolve("source.h")));
var pluginGeneratedCPP = new String(Files.readAllBytes(projectDir.resolve("source.cpp")));
var cppTemplate = new String(Objects.requireNonNull(getClass().getResourceAsStream(templateToUse + ".cpp")).readAllBytes());
var hTemplate = new String(Objects.requireNonNull(getClass().getResourceAsStream(templateToUse + ".h")).readAllBytes());
cppGenerated = cppGenerated.replaceAll("#include \"tcmenu[^\"]*\"", "replacedInclude");
cppTemplate = cppTemplate.replaceAll("#include \"tcmenu[^\"]*\"", "replacedInclude");
// these files should line up. IF they do not because of the change in the ArduinoGenerator,
// then make sure the change is good before adjusting the templates.
assertEqualsIgnoringCRLF(cppTemplate, cppGenerated);
assertEqualsIgnoringCRLF(hTemplate, hGenerated);
assertEqualsIgnoringCRLF("CPP_FILE_CONTENT 10 otherKey", pluginGeneratedCPP);
assertEqualsIgnoringCRLF("H_FILE_CONTENT 10 otherKey", pluginGeneratedH);
Mockito.verify(adjuster).makeAdjustments(any(BiConsumer.class), eq(projectDir.resolve(projectDir.resolve(projectDir.getFileName() + ".ino")).toString()), eq(projectDir.getFileName().toString()), anyCollection());
}
use of com.thecoderscorner.menu.editorui.generator.parameters.expander.CustomDeviceExpander in project tcMenu by davetcc.
the class GenerateCodeDialog method ensureIoFullyDeclared.
private void ensureIoFullyDeclared(CodePluginItem pluginItem) {
logger.log(INFO, "Checking for unmapped IO devices: " + pluginItem.getDescription());
var codeOptions = project.getGeneratorOptions();
// find any IO device declarations that do not match to an entry in the expanders
var anyIoWithoutEntries = pluginItem.getProperties().stream().filter(prop -> prop.getValidationRules() instanceof IoExpanderPropertyValidationRules).filter(prop -> codeOptions.getExpanderDefinitions().getDefinitionById(prop.getLatestValue()).isEmpty()).toList();
// nothing to do if list is empty
if (anyIoWithoutEntries.isEmpty()) {
logger.log(INFO, "All IO devices mapped");
return;
}
var allExpanders = new HashSet<>(codeOptions.getExpanderDefinitions().getAllExpanders());
// now we iterate through the unmapped expanders, which must be from prior to the automated support.
for (var customIo : anyIoWithoutEntries) {
if (StringHelper.isStringEmptyOrNull(customIo.getLatestValue())) {
// for empty strings, the previous assumption was using device IO. This is now explicitly defined
// as deviceIO
customIo.setLatestValue(InternalDeviceExpander.DEVICE_ID);
logger.log(INFO, "Device being mapped as internal: " + customIo.getLatestValue());
} else {
// otherwise, previously the assumption was using a custom defined expander in the sketch, now we'll
// actually add that to the sketch.
allExpanders.add(new CustomDeviceExpander(customIo.getLatestValue()));
logger.log(INFO, "Device being mapped as custom: " + customIo.getLatestValue());
}
}
project.setGeneratorOptions(new CodeGeneratorOptionsBuilder().withExisting(codeOptions).withExpanderDefinitions(new IoExpanderDefinitionCollection(allExpanders)).codeOptions());
logger.log(INFO, "Done mapping all IO devices");
}
Aggregations