Skip to content

Commit 012e5cf

Browse files
author
dave
committed
#561 eInk GxEPD2 and Adafruit plugin have common base.
1 parent a520506 commit 012e5cf

8 files changed

Lines changed: 45 additions & 32 deletions

File tree

tcMenuGenerator/src/main/java/com/thecoderscorner/menu/editorui/generator/plugin/BaseJavaPluginItem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ protected String findPropOrFail(String s) {
2727
.getLatestValue();
2828
}
2929

30-
protected CodeVariable basicGraphicsDeviceVariable(int sizeBuffer) {
30+
protected CodeVariable basicGraphicsDeviceVariable(String drawableName, int sizeBuffer) {
3131
return new CodeVariable("renderer", "GraphicsDeviceRenderer", VariableDefinitionMode.VARIABLE_AND_EXPORT, false, false, false, List.of(
3232
CodeParameter.unNamedValue(sizeBuffer),
3333
CodeParameter.unNamedValue("applicationInfo.name"),
34-
CodeParameter.unNamedValue("&drawable")
34+
CodeParameter.unNamedValue("&" + drawableName)
3535
), ALWAYS_APPLICABLE);
3636
}
3737

tcMenuGenerator/src/main/java/com/thecoderscorner/menu/editorui/generator/plugin/display/CommonAdafruitDisplayPlugin.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
package com.thecoderscorner.menu.editorui.generator.plugin.display;
22

33
import com.thecoderscorner.menu.editorui.generator.core.SubSystem;
4+
import com.thecoderscorner.menu.editorui.generator.parameters.CodeParameter;
45
import com.thecoderscorner.menu.editorui.generator.plugin.BaseJavaPluginItem;
6+
import com.thecoderscorner.menu.editorui.generator.plugin.CodeVariable;
7+
import com.thecoderscorner.menu.editorui.generator.plugin.VariableDefinitionMode;
58

69
import java.io.IOException;
10+
import java.util.ArrayList;
711

812
public abstract class CommonAdafruitDisplayPlugin extends BaseJavaPluginItem {
913
protected CommonAdafruitDisplayPlugin(SubSystem subsystem) {
1014
super(subsystem);
1115
}
1216

17+
18+
protected CodeVariable adafruitDrawableVariable(boolean mono) {
19+
var drawableParams = new ArrayList<CodeParameter>();
20+
drawableParams.add(CodeParameter.unNamedValue("&${DISPLAY_VARIABLE}"));
21+
if(!mono) {
22+
drawableParams.add(CodeParameter.unNamedValue(findPropOrFail("DISPLAY_BUFFER_SIZE")));
23+
}
24+
25+
return new CodeVariable("${DISPLAY_VARIABLE}Drawable", "AdafruitDrawable",
26+
VariableDefinitionMode.VARIABLE_ONLY, false, false, false, drawableParams, ALWAYS_APPLICABLE);
27+
}
28+
1329
protected String getTransactionCode(boolean memBuffer) {
1430
if(memBuffer) {
1531
return DEFAULT_MONO_TRANSACTION_CODE;

tcMenuGenerator/src/main/java/com/thecoderscorner/menu/editorui/generator/plugin/display/GxEPD2SimplePluginImpl.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ private List<CreatorProperty> createRequiredProperties() {
164164
new CreatorProperty("EINK_RESET_DELAY", "Reset delay", "Some boards require a custom reset delay, see library docs",
165165
"10", SubSystem.DISPLAY, PropType.VARIABLE, CannedPropertyValidators.uintValidator(100), ALWAYS_APPLICABLE),
166166
new CreatorProperty("EINK_RESET_PULLDOWN", "Pull down reset", "Some boards use pull-down reset, see library docs",
167-
"false", SubSystem.DISPLAY, PropType.VARIABLE, CannedPropertyValidators.boolValidator(), ALWAYS_APPLICABLE)
167+
"false", SubSystem.DISPLAY, PropType.VARIABLE, CannedPropertyValidators.boolValidator(), ALWAYS_APPLICABLE),
168+
new CreatorProperty("DISPLAY_VARIABLE", "Display variable", "Display variable hidden",
169+
"display", SubSystem.DISPLAY, PropType.HIDDEN, CannedPropertyValidators.variableValidator(), ALWAYS_APPLICABLE)
168170
);
169171

170172
}
@@ -203,18 +205,16 @@ public List<CodeVariable> getVariables() {
203205
new CodeVariable("display", "TcGxEPD2", VariableDefinitionMode.VARIABLE_AND_EXPORT, false, false, false, List.of(
204206
CodeParameter.unNamedValue(findPropOrFail("DISPLAY_TYPE") + "(${DISPLAY_CS_PIN}, ${DISPLAY_DC_PIN}, ${DISPLAY_RESET_PIN}, ${DISPLAY_BUSY_PIN})")
205207
), ALWAYS_APPLICABLE),
206-
new CodeVariable("drawable", "TcMenuGxEPDeInk", VariableDefinitionMode.VARIABLE_AND_EXPORT, false, false, false, List.of(
207-
CodeParameter.unNamedValue("display")
208-
), ALWAYS_APPLICABLE),
209-
basicGraphicsDeviceVariable(30)
208+
adafruitDrawableVariable(true),
209+
basicGraphicsDeviceVariable(findPropOrFail("DISPLAY_VARIABLE") + "Drawable", 30)
210210
);
211211
}
212212

213213
@Override
214214
public List<HeaderDefinition> getHeaderDefinitions() {
215215
String displayType = findPropOrFail("DISPLAY_TYPE");
216216
return List.of(
217-
new HeaderDefinition(headerForDisplayType(displayType), HeaderType.GLOBAL, 1, ALWAYS_APPLICABLE),
217+
new HeaderDefinition(headerForDisplayType(displayType) + ".h", HeaderType.GLOBAL, 1, ALWAYS_APPLICABLE),
218218
new HeaderDefinition("TcMenuGxEPDeInk.h", HeaderType.GLOBAL, 2, ALWAYS_APPLICABLE)
219219
);
220220
}
@@ -241,6 +241,8 @@ public List<RequiredSourceFile> getRequiredSourceFiles() {
241241
new CodeReplacement("__TRANSACTION_CODE__", getTransactionCode(true), ALWAYS_APPLICABLE),
242242
new CodeReplacement("__TEXT_HANDLING_CODE__", DEFAULT_TEXT_FUNCTIONS, ALWAYS_APPLICABLE),
243243
new CodeReplacement("__POTENTIAL_EXTRA_TYPE_DATA__", typeDataForDisplay(), ALWAYS_APPLICABLE),
244+
new CodeReplacement("__ACTUAL_GENERATED_HDR__", "TcMenuGxEPDeInk.h", ALWAYS_APPLICABLE),
245+
new CodeReplacement("__EXTRA_VARIABLES__", "bool firstPageDone = false;", ALWAYS_APPLICABLE),
244246
new CodeReplacement("Adafruit_Header", headerForDisplayType(displayType), ALWAYS_APPLICABLE),
245247
new CodeReplacement("Adafruit_Driver", "TcGxEPD2", ALWAYS_APPLICABLE)
246248
);
@@ -264,27 +266,28 @@ private String typeDataForDisplay() {
264266
@Override
265267
protected String getTransactionCode(boolean memBuffer) {
266268
return """
269+
auto gr = reinterpret_cast<TcGxEPD2*>(graphics);
267270
if (isStarting && redrawNeeded) {
268-
display.setFullWindow();
271+
gr->setFullWindow();
269272
if (!firstPageDone) {
270273
firstPageDone = true;
271-
display.firstPage();
274+
gr->firstPage();
272275
}
273276
} else if (redrawNeeded) {
274-
display.nextPage();
277+
gr->nextPage();
275278
}
276279
""";
277280
}
278281

279282
private String headerForDisplayType(String displayType) {
280283
if(MONO_SCREEN_TYPES.contains(displayType)) {
281-
return "GxEPD2_BW.h";
284+
return "GxEPD2_BW";
282285
} else if(COL3_SCREEN_TYPES.contains(displayType)) {
283-
return "GxEPD2_3C.h";
286+
return "GxEPD2_3C";
284287
} else if(COL4_SCREEN_TYPES.contains(displayType)) {
285-
return "GxEPD2_4C.h";
288+
return "GxEPD2_4C";
286289
} else if(COL7_SCREEN_TYPES.contains(displayType)) {
287-
return "GxEPD2_7C.h";
290+
return "GxEPD2_7C";
288291
} else {
289292
throw new IllegalArgumentException("Unknown display type, please report this error" + displayType);
290293
}

tcMenuGenerator/src/main/java/com/thecoderscorner/menu/editorui/generator/plugin/display/SimpleAdafruitStarterPlugin.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,15 @@ public List<HeaderDefinition> getHeaderDefinitions() {
136136
@Override
137137
public List<RequiredSourceFile> getRequiredSourceFiles() {
138138
boolean mono = findPropOrFail("DISPLAY_TYPE").equals("Adafruit_PCD8544");
139+
var headerName = mono ? "tcMenuAdaFruitGfxMono.h" : "tcMenuAdaFruitGfx.h";
139140
var replacements = List.of(
140141
new CodeReplacement("__DISPLAY_HAS_MEMBUFFER__", Boolean.toString(mono), ALWAYS_APPLICABLE),
141142
new CodeReplacement("__TRANSACTION_CODE__", getTransactionCode(mono), ALWAYS_APPLICABLE),
142143
new CodeReplacement("__TEXT_HANDLING_CODE__", DEFAULT_TEXT_FUNCTIONS, ALWAYS_APPLICABLE),
143144
new CodeReplacement("__POTENTIAL_EXTRA_TYPE_DATA__", "", ALWAYS_APPLICABLE),
145+
new CodeReplacement("__ACTUAL_GENERATED_HDR__", headerName, ALWAYS_APPLICABLE),
146+
new CodeReplacement("__EXTRA_TYPE_DEFS_NEEDED__", "", ALWAYS_APPLICABLE),
147+
new CodeReplacement("__EXTRA_VARIABLES__", "", ALWAYS_APPLICABLE),
144148
new CodeReplacement("Adafruit_Header", findPropOrFail("DISPLAY_TYPE"), ALWAYS_APPLICABLE),
145149
new CodeReplacement("Adafruit_Driver", findPropOrFail("DISPLAY_TYPE"), ALWAYS_APPLICABLE)
146150
);
@@ -169,20 +173,8 @@ public List<CodeVariable> getVariables() {
169173
};
170174

171175
var mono = displayType.equals("Adafruit_PCD8544");
172-
173-
var drawableParams = new ArrayList<CodeParameter>();
174-
drawableParams.add(CodeParameter.unNamedValue("&${DISPLAY_VARIABLE}"));
175-
if(!mono) {
176-
drawableParams.add(CodeParameter.unNamedValue(findPropOrFail("DISPLAY_BUFFER_SIZE")));
177-
}
178-
179-
var drawable = new CodeVariable("${DISPLAY_VARIABLE}Drawable", "AdafruitDrawable",
180-
VariableDefinitionMode.VARIABLE_ONLY, false, false, false, drawableParams, ALWAYS_APPLICABLE);
181-
182-
var renderer = new CodeVariable("renderer", "GraphicsDeviceRenderer", VariableDefinitionMode.VARIABLE_AND_EXPORT, false, false, false, List.of(
183-
CodeParameter.unNamedValue("30"),
184-
CodeParameter.unNamedValue("applicationInfo.name"),
185-
CodeParameter.unNamedValue("&${DISPLAY_VARIABLE}Drawable")), ALWAYS_APPLICABLE);
176+
var drawable = adafruitDrawableVariable(mono);
177+
var renderer = basicGraphicsDeviceVariable(findPropOrFail("DISPLAY_VARIABLE") + "Drawable", 30);
186178
return List.of(display, drawable, renderer);
187179
}
188180

tcMenuGenerator/src/main/resources/plugin/display/adaSources/tcMenuAdaFruitGfx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414

1515
#include <ScrollChoiceMenuItem.h>
16-
#include "tcMenuAdaFruitGfx.h"
16+
#include "__ACTUAL_GENERATED_HDR__"
1717
#include <Adafruit_SPITFT.h>
1818
#include <tcUnicodeAdaGFX.h>
1919

tcMenuGenerator/src/main/resources/plugin/display/adaSources/tcMenuAdaFruitGfx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class AdafruitDrawable : public DeviceDrawable {
160160
const GFXfont* computedFont = nullptr;
161161
int16_t computedBaseline = 0;
162162
int16_t computedHeight = 0;
163+
__EXTRA_VARIABLES__
163164
protected:
164165
int spriteHeight = 0;
165166
public:

tcMenuGenerator/src/main/resources/plugin/display/adaSources/tcMenuAdaFruitGfxMono.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414

1515
#include <ScrollChoiceMenuItem.h>
16-
#include "tcMenuAdaFruitGfxMono.h"
16+
#include "__ACTUAL_GENERATED_HDR__"
1717
#include <tcUnicodeHelper.h>
1818
#include <tcUnicodeAdaGFX.h>
1919

tcMenuGenerator/src/main/resources/plugin/display/adaSources/tcMenuAdaFruitGfxMono.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ using namespace tcgfx;
4242
#define WHITE 0xffff
4343
#endif
4444

45-
__EXTRA_TYPE_DEFS_NEEDED__
45+
__POTENTIAL_EXTRA_TYPE_DATA__
4646

4747
extern const ConnectorLocalInfo applicationInfo;
4848

@@ -93,6 +93,7 @@ class AdafruitDrawable : public DeviceDrawable {
9393
const GFXfont* computedFont = nullptr;
9494
int16_t computedBaseline = 0;
9595
int16_t computedHeight = 0;
96+
__EXTRA_VARIABLES__
9697
public:
9798
explicit AdafruitDrawable() : graphics(nullptr) {}
9899
explicit AdafruitDrawable(Adafruit_GFX* graphics, int spriteHeight = 0) : graphics(graphics) {

0 commit comments

Comments
 (0)