Skip to content

Commit 7ca95dd

Browse files
author
dave
committed
#74 #55 addition of scroll, rgb and runtime sub menus
Submenus can now be created at runtime, and their names can be changed. Scroll provides for enums in EEPROM, RAM and by CUSTOM delegate. RGB items can edit 24 bit colours with optional alpha channel. In progress, tested on AVR.
1 parent f65e855 commit 7ca95dd

26 files changed

+1725
-380
lines changed

examples/colorTftEthernet32/colorTftEthernet.emf

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"lastEdited": {
3-
"seconds": 1601464065,
3+
"seconds": 1602516900,
44
"nanos": 0
55
},
66
"codeOptions": {
@@ -256,6 +256,61 @@
256256
"naming": "ON_OFF"
257257
}
258258
},
259+
{
260+
"parentId": 4,
261+
"type": "",
262+
"item": null
263+
},
264+
{
265+
"parentId": 4,
266+
"type": "",
267+
"item": null
268+
},
269+
{
270+
"parentId": 4,
271+
"type": "subMenu",
272+
"item": {
273+
"name": "Rom Values",
274+
"eepromAddress": -1,
275+
"id": 20,
276+
"readOnly": false,
277+
"localOnly": false,
278+
"visible": true,
279+
"secured": false
280+
}
281+
},
282+
{
283+
"parentId": 20,
284+
"type": "",
285+
"item": null
286+
},
287+
{
288+
"parentId": 20,
289+
"type": "textItem",
290+
"item": {
291+
"name": "Item Text",
292+
"eepromAddress": -1,
293+
"id": 21,
294+
"readOnly": false,
295+
"localOnly": false,
296+
"visible": true,
297+
"itemType": "PLAIN_TEXT",
298+
"textLength": 10
299+
}
300+
},
301+
{
302+
"parentId": 20,
303+
"type": "actionMenu",
304+
"item": {
305+
"name": "Save item",
306+
"eepromAddress": -1,
307+
"id": 23,
308+
"readOnly": false,
309+
"localOnly": false,
310+
"visible": true,
311+
"functionName": "onSaveItem"
312+
}
313+
},
259314
{
260315
"parentId": 0,
261316
"type": "subMenu",

examples/colorTftEthernet32/colorTftEthernet32.ino

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,11 @@ void CALLBACK_FUNCTION onTakeDisplay(int id) {
223223
starting = true;
224224
renderer.takeOverDisplay(myRenderCallback);
225225
}
226+
227+
void CALLBACK_FUNCTION onRgbChanged(int id) {
228+
// TODO - your menu change code
229+
}
230+
231+
void CALLBACK_FUNCTION onSaveItem(int id) {
232+
// TODO - your menu change code
233+
}

examples/colorTftEthernet32/colorTftEthernet32.ino.backup

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <RemoteMenuItem.h>
77
#include <Fonts/FreeSans9pt7b.h>
88
#include <Ethernet.h>
9+
#include <SPI.h>
910

1011
// contains the graphical widget title components.
1112
#include "stockIcons/wifiAndConnectionIcons16x12.h"
@@ -24,13 +25,7 @@ byte mac[] = {
2425
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
2526
};
2627

27-
#define TFT_CS 6
28-
#define TFT_RST 3
29-
#define TFT_DC 7
30-
31-
Adafruit_ST7735 gfx = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
32-
33-
// we also want to customise the colours and menu spacing. So we create this config object too
28+
// we want to customise the colours and menu spacing. So we create this config object too
3429
// which we initialise during the setup method.
3530
AdaColorGfxMenuConfig colorConfig;
3631

@@ -48,8 +43,6 @@ IoAbstractionRef io8574 = ioFrom8574(0x20, 0); // on addr 0x20 and interrupt pin
4843
// and we create an analog device with enhanced range because we are using a 32bit board.
4944
ArduinoAnalogDevice analogDevice(12, 10);
5045

51-
float fractionsPerUnit;
52-
5346
// Here we create two additional menus, that will be added manually to handle the connectivity
5447
// status and authentication keys. In a future version these will be added to th desinger.
5548
RemoteMenuItem menuRemoteMonitor(1001, 2);
@@ -109,10 +102,6 @@ void onCommsChange(CommunicationInfo info) {
109102
}
110103

111104
void setup() {
112-
// we are responsible for setting up the initial graphics
113-
gfx.initR(INITR_BLACKTAB);
114-
gfx.setRotation(1);
115-
116105
// we used an i2c device (io8574) so must initialise wire too
117106
Wire.begin();
118107

@@ -133,7 +122,6 @@ void setup() {
133122
// and set up the dac on the 32 bit board.
134123
analogDevice.initPin(A0, DIR_OUT);
135124
analogDevice.initPin(A1, DIR_IN);
136-
fractionsPerUnit = ((float)analogDevice.getMaximumRange(DIR_IN, A1)) / 5.0;
137125

138126
// we have our own graphics configuration. it must be initialised
139127
// before calling setupMenu..
@@ -165,8 +153,8 @@ void setup() {
165153

166154
taskManager.scheduleFixedRate(2250, [] {
167155
Serial.print(".");
168-
float a1Value = analogDevice.getCurrentValue(A1);
169-
menuVoltA1.setFloatValue(a1Value / fractionsPerUnit);
156+
float a1Value = analogDevice.getCurrentFloat(A1);
157+
menuVoltA1.setFloatValue(a1Value * 3.3);
170158
});
171159
}
172160

@@ -175,10 +163,11 @@ void loop() {
175163
}
176164

177165
void writeToDac() {
178-
float volts = menuVoltage.getCurrentValue() / 2.0;
179-
float curr = menuCurrent.getCurrentValue() / 100.0;
180-
float total = volts * curr;
181-
analogDevice.setCurrentValue(A0, (unsigned int)total);
166+
float volts = menuVoltage.getAsFloatingPointValue();
167+
float curr = menuCurrent.getAsFloatingPointValue();
168+
169+
float total = (volts / 64.0) * (curr / 2.0);
170+
analogDevice.setCurrentFloat(A0, (unsigned int)total);
182171
menuVoltA0.setFloatValue(total);
183172
}
184173

@@ -199,12 +188,38 @@ void CALLBACK_FUNCTION onSaveRom(int /*id*/) {
199188
menuMgr.save(eeprom);
200189
}
201190

191+
bool starting = true;
202192

193+
void myRenderCallback(unsigned int encoderVal, RenderPressMode pressType) {
194+
if(pressType == RPRESS_HELD)
195+
{
196+
// if the encoder / select button is held, we go back to the menu.
197+
renderer.giveBackDisplay();
198+
}
199+
else if(starting)
200+
{
201+
// you need to handle the clearing and preparation of the display when you're first called.
202+
// the easiest way is to set a flag such as this and then prepare the display.
203+
starting = false;
204+
switches.getEncoder()->changePrecision(1000, 500);
205+
gfx.setCursor(0, 0);
206+
gfx.fillRect(0, 0, gfx.width(), gfx.height(), BLACK);
207+
gfx.setFont(nullptr);
208+
gfx.setTextSize(2);
209+
gfx.print("Encoder ");
210+
}
211+
else
212+
{
213+
GFXcanvas1 canvas(100, 20);
214+
canvas.fillScreen(BLACK);
215+
canvas.setCursor(0,0);
216+
canvas.print(encoderVal);
217+
canvas.setTextSize(2);
218+
gfx.drawBitmap(0, 35, canvas.getBuffer(), 100, 20, WHITE, BLACK);
219+
}
220+
}
203221

204-
205-
206-
207-
208-
209-
210-
222+
void CALLBACK_FUNCTION onTakeDisplay(int id) {
223+
starting = true;
224+
renderer.takeOverDisplay(myRenderCallback);
225+
}

examples/colorTftEthernet32/colorTftEthernet32_menu.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ const SubMenuInfo minfoStatus = { "Status", 7, 0xFFFF, 0, NO_CALLBACK };
3737
RENDERING_CALLBACK_NAME_INVOKE(fnStatusRtCall, backSubItemRenderFn, "Status", -1, NO_CALLBACK)
3838
BackMenuItem menuBackStatus(fnStatusRtCall, &menuVoltA0);
3939
SubMenuItem menuStatus(&minfoStatus, &menuBackStatus, &menuConnectivity);
40+
const AnyMenuInfo minfoSaveItem = { "Save item", 23, 0xFFFF, 0, onSaveItem };
41+
ActionMenuItem menuSaveItem(&minfoSaveItem, NULL);
42+
RENDERING_CALLBACK_NAME_INVOKE(fnItemTextRtCall, textItemRenderFn, "Item Text", -1, NO_CALLBACK)
43+
TextMenuItem menuItemText(fnItemTextRtCall, 21, 10, &menuSaveItem);
44+
const SubMenuInfo minfoRomValues = { "Rom Values", 20, 0xFFFF, 0, NO_CALLBACK };
45+
RENDERING_CALLBACK_NAME_INVOKE(fnRomValuesRtCall, backSubItemRenderFn, "Rom Values", -1, NO_CALLBACK)
46+
BackMenuItem menuBackRomValues(fnRomValuesRtCall, &menuItemNo);
47+
SubMenuItem menuRomValues(&minfoRomValues, &menuBackRomValues, NULL);
4048
const BooleanMenuInfo minfoTempCheck = { "Temp Check", 13, 9, 1, NO_CALLBACK, NAMING_ON_OFF };
4149
BooleanMenuItem menuTempCheck(&minfoTempCheck, false, NULL);
4250
const AnyMenuInfo minfoHiddenItem = { "Hidden item", 16, 0xFFFF, 0, NO_CALLBACK };
@@ -46,7 +54,7 @@ BooleanMenuItem menuSCircuitProtect(&minfoSCircuitProtect, false, &menuHiddenIte
4654
const SubMenuInfo minfoAdvanced = { "Advanced", 11, 0xFFFF, 0, NO_CALLBACK };
4755
RENDERING_CALLBACK_NAME_INVOKE(fnAdvancedRtCall, backSubItemRenderFn, "Advanced", -1, NO_CALLBACK)
4856
BackMenuItem menuBackAdvanced(fnAdvancedRtCall, &menuSCircuitProtect);
49-
SubMenuItem menuAdvanced(&minfoAdvanced, &menuBackAdvanced, NULL);
57+
SubMenuItem menuAdvanced(&minfoAdvanced, &menuBackAdvanced, &menuRGB);
5058
const AnyMenuInfo minfoSaveAll = { "Save all", 10, 0xFFFF, 0, onSaveRom };
5159
ActionMenuItem menuSaveAll(&minfoSaveAll, &menuAdvanced);
5260
const BooleanMenuInfo minfoPwrDelay = { "Pwr Delay", 5, 0xFFFF, 1, NO_CALLBACK, NAMING_YES_NO };

examples/colorTftEthernet32/colorTftEthernet32_menu.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ extern SubMenuItem menuConnectivity;
4141
extern FloatMenuItem menuVoltA1;
4242
extern FloatMenuItem menuVoltA0;
4343
extern SubMenuItem menuStatus;
44+
void CALLBACK_FUNCTION onSaveItem(int id);
45+
extern ActionMenuItem menuSaveItem;
46+
extern TextMenuItem menuItemText;
47+
extern SubMenuItem menuRomValues;
4448
extern BooleanMenuItem menuTempCheck;
4549
extern ActionMenuItem menuHiddenItem;
4650
extern BooleanMenuItem menuSCircuitProtect;

examples/colorTftEthernet32/tcMenuAdaFruitGfx.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ class AdaGfxDialog : public BaseDialog {
9999
void drawButton(Adafruit_GFX* gfx, AdaColorGfxMenuConfig* config, const char* title, uint8_t num, bool active);
100100
};
101101

102+
/**
103+
* Provides the extents of the text as a Coord which is easier to work with.
104+
* @param graphics the graphics object as a pointer
105+
* @param text the text to measure
106+
* @param x starting location X
107+
* @param y starting location Y
108+
* @return the coord object containing width and height
109+
*/
110+
Coord textExtents(Adafruit_GFX* graphics, const char* text, int16_t x, int16_t y);
111+
102112
/**
103113
* The default graphics configuration for Ada GFX that needs no fonts and uses reasonable spacing options
104114
* for 100 - 150 dpi displays.

0 commit comments

Comments
 (0)