Skip to content

Commit 93c1e43

Browse files
committed
#161 fixes for large number and core renderer
1 parent 76f5026 commit 93c1e43

File tree

8 files changed

+133
-14
lines changed

8 files changed

+133
-14
lines changed

examples/arduino32/simpleU8g2/ThemeMonoBordered.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ color_t defaultItemPaletteMono[] = {1, 0, 1, 1};
88

99
void installMonoBorderedTheme(GraphicsDeviceRenderer& bgr, const MenuFontDef& itemFont, const MenuFontDef& titleFont, bool needEditingIcons) {
1010
bgr.setDisplayDimensions(bgr.getDeviceDrawable()->getDisplayDimensions().x, bgr.getDeviceDrawable()->getDisplayDimensions().y);
11+
1112
auto& factory = bgr.getGraphicsPropertiesFactory();
1213

1314
factory.setSelectedColors(0, 1);

examples/arduino32/simpleU8g2/simpleU8g2.emf

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,83 @@
146146
"localOnly": false,
147147
"visible": true
148148
}
149+
},
150+
{
151+
"parentId": 0,
152+
"type": "subMenu",
153+
"item": {
154+
"secured": false,
155+
"name": "Extras",
156+
"variableName": "Extras",
157+
"id": 10,
158+
"eepromAddress": -1,
159+
"readOnly": false,
160+
"localOnly": false,
161+
"visible": true
162+
}
163+
},
164+
{
165+
"parentId": 10,
166+
"type": "rgbItem",
167+
"defaultValue": "#DD55EEFF",
168+
"item": {
169+
"includeAlphaChannel": false,
170+
"name": "RGB",
171+
"variableName": "ExtrasRGB",
172+
"id": 11,
173+
"eepromAddress": -1,
174+
"readOnly": false,
175+
"localOnly": false,
176+
"visible": true
177+
}
178+
},
179+
{
180+
"parentId": 10,
181+
"type": "textItem",
182+
"defaultValue": "192.168.0.0",
183+
"item": {
184+
"textLength": 5,
185+
"itemType": "IP_ADDRESS",
186+
"name": "Ip",
187+
"variableName": "ExtrasIp",
188+
"id": 12,
189+
"eepromAddress": -1,
190+
"readOnly": false,
191+
"localOnly": false,
192+
"visible": true
193+
}
194+
},
195+
{
196+
"parentId": 10,
197+
"type": "textItem",
198+
"defaultValue": "14:00:00",
199+
"item": {
200+
"textLength": 5,
201+
"itemType": "TIME_24H",
202+
"name": "Time",
203+
"variableName": "ExtrasTime",
204+
"id": 13,
205+
"eepromAddress": -1,
206+
"readOnly": false,
207+
"localOnly": false,
208+
"visible": true
209+
}
210+
},
211+
{
212+
"parentId": 10,
213+
"type": "textItem",
214+
"defaultValue": "2022/1/1",
215+
"item": {
216+
"textLength": 5,
217+
"itemType": "GREGORIAN_DATE",
218+
"name": "Date",
219+
"variableName": "ExtrasDate",
220+
"id": 14,
221+
"eepromAddress": -1,
222+
"readOnly": false,
223+
"localOnly": false,
224+
"visible": true
225+
}
149226
}
150227
],
151228
"codeOptions": {

examples/arduino32/simpleU8g2/simpleU8g2.ino

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ void setup() {
2222
Wire.begin();
2323
Serial.begin(115200);
2424

25+
serlogF(SER_DEBUG, "Starting simple U8G2 demo");
26+
2527
// here we initialise the EEPROM class to 512 bytes of storage
2628
// don't commit often to this, it's in FLASH
2729
EEPROM.begin(512);
@@ -75,10 +77,9 @@ void CALLBACK_FUNCTION onSaveSettings(int id) {
7577

7678
// here is a brief example of how to show a dialog, usually for information
7779
// or yes/no answers.
78-
auto* dlg = renderer.getDialog();
79-
if(dlg && !dlg->isInUse()) {
80-
dlg->setButtons(BTNTYPE_NONE, BTNTYPE_OK);
81-
dlg->show(pgmCommittedToRom, false);
82-
dlg->copyIntoBuffer("just so you know");
83-
}
80+
withMenuDialogIfAvailable([] (MenuBasedDialog* dlg) {
81+
dlg->setButtons(BTNTYPE_NONE, BTNTYPE_OK);
82+
dlg->show(pgmCommittedToRom, false);
83+
dlg->copyIntoBuffer("just so you know");
84+
});
8485
}

examples/arduino32/simpleU8g2/simpleU8g2_menu.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,30 @@ U8g2Drawable gfxDrawable(&gfx, &Wire);
2020
GraphicsDeviceRenderer renderer(30, applicationInfo.name, &gfxDrawable);
2121

2222
// Global Menu Item declarations
23+
RENDERING_CALLBACK_NAME_INVOKE(fnExtrasDateRtCall, dateItemRenderFn, "Date", -1, NO_CALLBACK)
24+
DateFormattedMenuItem menuExtrasDate(fnExtrasDateRtCall, DateStorage(1, 1, 2022), 14, NULL);
25+
RENDERING_CALLBACK_NAME_INVOKE(fnExtrasTimeRtCall, timeItemRenderFn, "Time", -1, NO_CALLBACK)
26+
TimeFormattedMenuItem menuExtrasTime(fnExtrasTimeRtCall, TimeStorage(14, 00, 00, 0), 13, (MultiEditWireType)2, &menuExtrasDate);
27+
RENDERING_CALLBACK_NAME_INVOKE(fnExtrasIpRtCall, ipAddressRenderFn, "Ip", -1, NO_CALLBACK)
28+
IpAddressMenuItem menuExtrasIp(fnExtrasIpRtCall, IpAddressStorage(192, 168, 0, 0), 12, &menuExtrasTime);
29+
RENDERING_CALLBACK_NAME_INVOKE(fnExtrasRGBRtCall, rgbAlphaItemRenderFn, "RGB", -1, NO_CALLBACK)
30+
Rgb32MenuItem menuExtrasRGB(fnExtrasRGBRtCall, RgbColor32(221, 85, 238), 11, false, &menuExtrasIp);
31+
RENDERING_CALLBACK_NAME_INVOKE(fnExtrasRtCall, backSubItemRenderFn, "Extras", -1, NO_CALLBACK)
32+
const PROGMEM SubMenuInfo minfoExtras = { "Extras", 10, 0xffff, 0, NO_CALLBACK };
33+
BackMenuItem menuBackExtras(fnExtrasRtCall, &menuExtrasRGB);
34+
SubMenuItem menuExtras(&minfoExtras, &menuBackExtras, NULL);
2335
const PROGMEM AnyMenuInfo minfoSettingsSaveSettings = { "SaveSettings", 9, 0xffff, 0, onSaveSettings };
2436
ActionMenuItem menuSettingsSaveSettings(&minfoSettingsSaveSettings, NULL);
2537
RENDERING_CALLBACK_NAME_INVOKE(fnSettingsSerialNumberRtCall, largeNumItemRenderFn, "Serial Number", 7, NO_CALLBACK)
26-
EditableLargeNumberMenuItem menuSettingsSerialNumber(fnSettingsSerialNumberRtCall, 8, 8, 0, true, LargeFixedNumber(0U, 0U, false), &menuSettingsSaveSettings);
38+
EditableLargeNumberMenuItem menuSettingsSerialNumber(fnSettingsSerialNumberRtCall, LargeFixedNumber(8, 0, 0U, 0U, false), 8, true, &menuSettingsSaveSettings);
2739
RENDERING_CALLBACK_NAME_INVOKE(fnSettingsUserNameRtCall, textItemRenderFn, "User Name", 16, onNameChanged)
2840
TextMenuItem menuSettingsUserName(fnSettingsUserNameRtCall, "", 7, 5, &menuSettingsSerialNumber);
2941
const PROGMEM BooleanMenuInfo minfoSettingsSafetyLock = { "Safety lock", 6, 15, 1, NO_CALLBACK, NAMING_TRUE_FALSE };
3042
BooleanMenuItem menuSettingsSafetyLock(&minfoSettingsSafetyLock, false, &menuSettingsUserName);
3143
RENDERING_CALLBACK_NAME_INVOKE(fnSettingsRtCall, backSubItemRenderFn, "Settings", -1, NO_CALLBACK)
3244
const PROGMEM SubMenuInfo minfoSettings = { "Settings", 5, 0xffff, 0, NO_CALLBACK };
3345
BackMenuItem menuBackSettings(fnSettingsRtCall, &menuSettingsSafetyLock);
34-
SubMenuItem menuSettings(&minfoSettings, &menuBackSettings, NULL);
46+
SubMenuItem menuSettings(&minfoSettings, &menuBackSettings, &menuExtras);
3547
const PROGMEM AnyMenuInfo minfoStartToasting = { "Start toasting", 4, 0xffff, 0, onStartToasting };
3648
ActionMenuItem menuStartToasting(&minfoStartToasting, &menuSettings);
3749
const PROGMEM BooleanMenuInfo minfoFrozen = { "Frozen", 3, 6, 1, NO_CALLBACK, NAMING_YES_NO };

examples/arduino32/simpleU8g2/simpleU8g2_menu.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <tcMenu.h>
1616
#include "tcMenuU8g2.h"
1717
#include <RuntimeMenuItem.h>
18+
#include <ScrollChoiceMenuItem.h>
1819
#include <EditableLargeNumberMenuItem.h>
1920
#include <IoAbstraction.h>
2021
#include <ArduinoEEPROMAbstraction.h>
@@ -28,6 +29,12 @@ extern GraphicsDeviceRenderer renderer;
2829

2930

3031
// Global Menu Item exports
32+
extern DateFormattedMenuItem menuExtrasDate;
33+
extern TimeFormattedMenuItem menuExtrasTime;
34+
extern IpAddressMenuItem menuExtrasIp;
35+
extern Rgb32MenuItem menuExtrasRGB;
36+
extern BackMenuItem menuBackExtras;
37+
extern SubMenuItem menuExtras;
3138
extern ActionMenuItem menuSettingsSaveSettings;
3239
extern EditableLargeNumberMenuItem menuSettingsSerialNumber;
3340
extern TextMenuItem menuSettingsUserName;

src/BaseRenderers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void BaseMenuRenderer::exec() {
8383
// finally we render the menu if none of the above are true.
8484
if(dialog!=nullptr && dialog->isRenderNeeded()) {
8585
dialog->dialogRendering(menuMgr.getCurrentRangeValue(), renderFnPressType);
86-
} else if(dialog->isInUse()) {
86+
} else if(dialog!=nullptr && dialog->isInUse()) {
8787
displayTakenMode = NOT_TAKEN_OVER;
8888
render();
8989
}else if(displayTakenMode == NOT_TAKEN_OVER) {

src/EditableLargeNumberMenuItem.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ void LargeFixedNumber::setFromFloat(float value) {
8989
setValue(val, frc, neg);
9090
}
9191

92+
LargeFixedNumber::LargeFixedNumber(int totalDigits, int decimalPointIndex, uint32_t whole, uint32_t fraction, bool negative) {
93+
this->totalSize = totalDigits;
94+
this->fractionDp = decimalPointIndex;
95+
setValue(whole, fraction, negative);
96+
}
97+
9298
void EditableLargeNumberMenuItem::setLargeNumberFromString(const char* val) {
9399
int offset = 0;
94100
bool negative = false;

src/EditableLargeNumberMenuItem.h

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,21 @@ class LargeFixedNumber {
3232
uint8_t fractionDp = 0;
3333
public:
3434
/**
35-
* Create a default instance with decimal places set to 4 and total size 12.
35+
* Create a default instance which needs to be configured before use
3636
*/
3737
LargeFixedNumber() = default;
38-
LargeFixedNumber(uint32_t whole, uint32_t fraction, bool negative) {setValue(whole, fraction, negative);}
38+
39+
/**
40+
* Create a fully populated LargeFixedNumber giving the number of digits and the initial value
41+
* @param totalDigits the maximum digits to use
42+
* @param decimalPointIndex the number of decimal places
43+
* @param whole the whole value expressed as an unsigned integer
44+
* @param fraction the fractional part expressed as a unsigned integer
45+
* @param negative if the value is positive or negative
46+
*/
47+
LargeFixedNumber(int totalDigits, int decimalPointIndex, uint32_t whole, uint32_t fraction, bool negative);
48+
49+
LargeFixedNumber(const LargeFixedNumber& other) = default;
3950
LargeFixedNumber& operator=(const LargeFixedNumber& other) = default;
4051

4152
/**
@@ -48,6 +59,11 @@ class LargeFixedNumber {
4859
*/
4960
int decimalPointIndex() const { return fractionDp; }
5061

62+
/**
63+
* @return the total number of digits it can represent
64+
*/
65+
int getTotalDigits() const { return totalSize; }
66+
5167
/**
5268
* Set the number of decimal places and optionally the total size then zero out any currently held value. When
5369
* setting this value you should ensure that: fractionDp is not larger than 9, the difference between fractionDp
@@ -167,10 +183,9 @@ class EditableLargeNumberMenuItem : public EditableMultiPartMenuItem {
167183
LargeFixedNumber data;
168184
bool negativeAllowed;
169185
public:
170-
EditableLargeNumberMenuItem(RuntimeRenderingFn renderFn, uint16_t id, int maxDigits, int dps, bool allowNeg, const LargeFixedNumber& initial, MenuItem* next = nullptr)
171-
: EditableMultiPartMenuItem(MENUTYPE_LARGENUM_VALUE, id, maxDigits + (allowNeg ? 1 : 0), renderFn, next) {
186+
EditableLargeNumberMenuItem(RuntimeRenderingFn renderFn, const LargeFixedNumber& initial, uint16_t id, bool allowNeg, MenuItem* next = nullptr)
187+
: EditableMultiPartMenuItem(MENUTYPE_LARGENUM_VALUE, id, initial.getTotalDigits() + (allowNeg ? 1 : 0), renderFn, next) {
172188
data = initial;
173-
data.setPrecision(dps, maxDigits);
174189
negativeAllowed = allowNeg;
175190
}
176191

0 commit comments

Comments
 (0)