Skip to content

Commit af7b856

Browse files
committed
#564 #593 Support for RGB OLED 1351 using Adafruit library. Ensure I18n cleared when closed.
1 parent ff7b5b7 commit af7b856

3 files changed

Lines changed: 28 additions & 6 deletions

File tree

web-designer/tcmenu-code-generator/src/main/java/com/thecoderscorner/menu/editorui/generator/plugin/display/ColorAdafruitStarterPlugin.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import java.util.ArrayList;
1313
import java.util.List;
14+
import java.util.stream.Stream;
1415

1516
import static com.thecoderscorner.menu.editorui.generator.core.CreatorProperty.PropType.VARIABLE;
1617
import static com.thecoderscorner.menu.editorui.generator.core.HeaderDefinition.HeaderType;
@@ -26,9 +27,9 @@ protected ColorAdafruitStarterPlugin(JavaPluginGroup group, CodePluginManager ma
2627
requiredProperties = createRequiredProperties();
2728
var codePlugin = new CodePluginItem();
2829
codePlugin.setId("4dcb12ec-13d8-4466-b8b6-bd575eae4612");
29-
codePlugin.setDescription("AdafruitGFX quick start for color displays: ST77xx and ILI9341");
30+
codePlugin.setDescription("AdafruitGFX quick start for color displays: ST77xx/ILI9341/SSD1351");
3031
codePlugin.setConfig(group.getConfig());
31-
codePlugin.setExtendedDescription("Draw menus using AdafruitGFX library using our quick start for ST77xx and ILI9341. This version is a template that creates the display variable and configures it.");
32+
codePlugin.setExtendedDescription("Draw menus using AdafruitGFX library using our quick start for SSD1351, ST77xx and ILI9341. This version is a template that creates the display variable and configures it.");
3233
codePlugin.setThemeDescription(ThemeDescription.colorWithFont(FontMode.ADAFRUIT));
3334
codePlugin.setDocsLink("https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/tcmenu-plugins/adafruit_gfx-renderer-plugin/");
3435
codePlugin.setJavaImpl(this);
@@ -45,9 +46,10 @@ private List<CreatorProperty> createRequiredProperties() {
4546
separatorProperty("DISPLAY", "Display Information"),
4647
new CreatorProperty("DISPLAY_TYPE", "Display Type", "Choose the display type for your display",
4748
"Adafruit_ST7735", DISPLAY, VARIABLE, CannedPropertyValidators.choicesValidator(List.of(
48-
new ChoiceDescription("Adafruit_ST7735", "Adafruit ST7735 library"),
49-
new ChoiceDescription("Adafruit_ST7789", "Adafruit ST7789 library"),
50-
new ChoiceDescription("Adafruit_ILI9341", "Adafruit ILI9341 library")
49+
new ChoiceDescription("Adafruit_ST7735", "Adafruit ST7735 TFT library"),
50+
new ChoiceDescription("Adafruit_ST7789", "Adafruit ST7789 TFT library"),
51+
new ChoiceDescription("Adafruit_SSD1351", "Adafruit SSD1351 RGB-OLED library"),
52+
new ChoiceDescription("Adafruit_ILI9341", "Adafruit ILI9341 TFT library")
5153
), "Adafruit_ST7735"), ALWAYS_APPLICABLE),
5254
new CreatorProperty("DISPLAY_VARIABLE", "Display Variable Name", "The variable name available in your sketch", "display", DISPLAY, VARIABLE, CannedPropertyValidators.variableValidator(), ALWAYS_APPLICABLE),
5355
CreatorProperty.uintProperty("DISPLAY_WIDTH", "Display Width in Pixels", "Display width in pixels", DISPLAY, 320, 8192),
@@ -148,6 +150,7 @@ public List<CodeVariable> getVariables() {
148150
CodeVariable display = switch(displayType) {
149151
case "Adafruit_ST7735", "Adafruit_ST7789" -> st77xxVariable(displayType);
150152
case "Adafruit_ILI9341" -> ili9341Variable(displayType);
153+
case "Adafruit_SSD1351" -> ssd1351Variable(displayType);
151154
default -> throw new IllegalStateException("Unexpected value: " + displayType);
152155
};
153156

@@ -165,6 +168,19 @@ private CodeVariable ili9341Variable(String displayType) {
165168
VariableDefinitionMode.VARIABLE_AND_EXPORT, false, false, false, params, ALWAYS_APPLICABLE);
166169
}
167170

171+
private CodeVariable ssd1351Variable(String displayType) {
172+
boolean hwSpi = findPropOrFail("DISPLAY_DATA_PIN").equals("-1");
173+
174+
List<CodeParameter> stdParams = standardSpiConfigurationParams(hwSpi);
175+
List<CodeParameter> dispSizeParams = List.of(
176+
CodeParameter.unNamedValue(findPropOrFail("DISPLAY_WIDTH")),
177+
CodeParameter.unNamedValue(findPropOrFail("DISPLAY_HEIGHT"))
178+
);
179+
var params = Stream.concat(dispSizeParams.stream(), stdParams.stream()).toList();
180+
return new CodeVariable(findPropOrFail("DISPLAY_VARIABLE"), displayType,
181+
VariableDefinitionMode.VARIABLE_AND_EXPORT, false, false, false, params, ALWAYS_APPLICABLE);
182+
}
183+
168184
private CodeVariable st77xxVariable(String displayType) {
169185
boolean hwSpi = findPropOrFail("DISPLAY_DATA_PIN").equals("-1");
170186

web-designer/tcmenugen/src/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {IoExpanderComponent} from "./generator/IoExpanderComponent";
1414
import ReleaseNotes from "./releaseNotes";
1515
import {get, set} from 'idb-keyval';
1616
import fontEdIcon from './img/font-editor-example.jpg'
17-
import {i18nStateHasChanged} from "./generator/I18nImpls";
17+
import {closedI18n, i18nStateHasChanged, resetI18n} from "./generator/I18nImpls";
1818

1919
const TC_MENU_STORAGE_KEY = "tcMenuTurboProject";
2020
const TC_MENU_POLICY_KEY = "tcMenuTurboPolicyAccepted";
@@ -114,6 +114,7 @@ export function setCurrentlyOpenProject(proj: MenuTreeWithCodeOptions | null, di
114114
} else {
115115
localStorage.removeItem(TC_MENU_STORAGE_KEY);
116116
globalDirectoryHandle = null;
117+
closedI18n();
117118
}
118119
projectListeners.forEach(l => l(proj));
119120
}

web-designer/tcmenugen/src/generator/I18nImpls.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ export async function getInternationalization(): Promise<I18nHandler> {
4848
}
4949
}
5050

51+
export function closedI18n() {
52+
globalI18nHandler = NOT_INITIALIZED_I18N;
53+
i18nRehydrationPromise = null;
54+
}
55+
5156
export function resetI18n() {
5257
console.log("Remove I18N support for a new project");
5358
let currentlyOpenProject = getCurrentlyOpenProject();

0 commit comments

Comments
 (0)