Skip to content

Commit e14525c

Browse files
committed
#229 theme builder example from latest designer
1 parent 944731f commit e14525c

File tree

12 files changed

+390
-141
lines changed

12 files changed

+390
-141
lines changed

examples/esp/esp32Amplifier/ThemeCoolBlueModern.h

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Cool blue modern theme by TheCodersCorner.com. This is part of the standard themes shipped with TcMenu.
3+
* This file will not be updated by the designer, you can edit.
4+
*/
5+
#ifndef THEME_COOL_BLUE
6+
#define THEME_COOL_BLUE
7+
8+
#include <graphics/TcThemeBuilder.h>
9+
10+
const color_t coolBlueTitlePalette[] = {RGB(0,0,0), RGB(20,132,255), RGB(192,192,192), RGB(64, 64, 64)};
11+
const color_t coolBlueItemPalette[] = {RGB(255, 255, 255), RGB(0,64,135), RGB(20,133,255), RGB(31,100,178)};
12+
const color_t coolBlueActionPalette[] = {RGB(255, 255, 255), RGB(0,45,120), RGB(20,133,255), RGB(31,100,178)};
13+
14+
#define ACTION_BORDER_WIDTH 0
15+
#define USE_SLIDER_FOR_ANALOG 1
16+
17+
/**
18+
* This is one of the stock themes, you can modify it to meet your requirements, and it will not be updated by tcMenu
19+
* Designer unless you delete it. This sets up the fonts, spacing and padding for all items.
20+
* @param gr the graphical renderer
21+
* @param itemFont the font for items
22+
* @param titleFont the font for titles
23+
* @param needEditingIcons if editing icons are needed
24+
*/
25+
void installCoolBlueModernTheme(GraphicsDeviceRenderer& gr, const MenuFontDef& itemFont, const MenuFontDef& titleFont,
26+
bool needEditingIcons, BaseGraphicalRenderer::TitleMode titleMode, bool useUnicode) {
27+
28+
TcThemeBuilder themeBuilder(gr);
29+
30+
themeBuilder.dimensionsFromRenderer()
31+
.withSelectedColors(RGB(31, 88, 100), RGB(255, 255, 255))
32+
.withItemPadding(MenuPadding(4, 3, 4, 3))
33+
.withTitlePadding(MenuPadding(4, 3, 4, 3))
34+
.withRenderingSettings(titleMode, USE_SLIDER_FOR_ANALOG)
35+
.withPalette(coolBlueItemPalette)
36+
.withNativeFont(itemFont.fontData, itemFont.fontMag)
37+
.withSpacing(2);
38+
39+
if(needEditingIcons) {
40+
themeBuilder.withStandardMedResCursorIcons();
41+
}
42+
43+
if(useUnicode) {
44+
themeBuilder.enableTcUnicode();
45+
}
46+
47+
themeBuilder.defaultItemProperties()
48+
.withJustification(GridPosition::JUSTIFY_TITLE_LEFT_VALUE_RIGHT)
49+
.apply();
50+
51+
themeBuilder.defaultTitleProperties()
52+
.withJustification(GridPosition::JUSTIFY_CENTER_WITH_VALUE)
53+
.withNativeFont(titleFont.fontData, titleFont.fontMag)
54+
.withPalette(coolBlueTitlePalette)
55+
.withSpacing(3)
56+
.apply();
57+
58+
59+
themeBuilder.defaultActionProperties()
60+
.withJustification(GridPosition::JUSTIFY_CENTER_WITH_VALUE)
61+
.withPalette(coolBlueActionPalette)
62+
.withBorder(MenuBorder(ACTION_BORDER_WIDTH))
63+
.apply();
64+
65+
themeBuilder.apply();
66+
}
67+
68+
#endif //THEME_COOL_BLUE

examples/esp/esp32Amplifier/esp32Amplifier.emf

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,9 @@
470470
"lastDisplayUuid": "e6342680-6fab-4d1b-ac08-ce8dbfc0974c",
471471
"lastInputUuid": "183448ac-a717-4b2b-823d-ffc7c8140ab9",
472472
"lastRemoteUuids": [
473-
"46c30011-cac6-4598-a7b8-b0630d55daab"
473+
"B93C6ACA-F1A3-4FF3-87F1-07E4F2F1ED5A"
474474
],
475-
"lastThemeUuid": "850dc0a3-f534-47c2-94d8-1e64ff368a54",
475+
"lastThemeUuid": "1947F585-9D36-448C-8A80-B425686107BD",
476476
"applicationUUID": "4656c798-10c6-4110-8e03-b9c51ed8fffb",
477477
"applicationName": "ESP Amplifier",
478478
"lastProperties": [
@@ -612,28 +612,18 @@
612612
"subsystem": "INPUT"
613613
},
614614
{
615-
"name": "ESPWIFI_CONCURRENT_CONNECTIONS",
616-
"latestValue": "1",
617-
"subsystem": "REMOTE"
618-
},
619-
{
620-
"name": "ESPWIFI_LISTEN_PORT1",
621-
"latestValue": "3333",
615+
"name": "ETH_LIBRARY_TYPE",
616+
"latestValue": "ESP32_WIFI",
622617
"subsystem": "REMOTE"
623618
},
624619
{
625-
"name": "ESPWIFI_LISTEN_PORT2",
626-
"latestValue": "3334",
620+
"name": "REMOTE_IP_ADDRESS",
621+
"latestValue": "192.168.0.37",
627622
"subsystem": "REMOTE"
628623
},
629624
{
630-
"name": "ESPWIFI_LISTEN_PORT3",
631-
"latestValue": "3335",
632-
"subsystem": "REMOTE"
633-
},
634-
{
635-
"name": "ESPWIFI_BUFFERED",
636-
"latestValue": "true",
625+
"name": "REMOTE_PORT",
626+
"latestValue": "3333",
637627
"subsystem": "REMOTE"
638628
},
639629
{

examples/esp/esp32Amplifier/esp32Amplifier_menu.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
use elsewhere.
99
*/
1010

11+
// Generated for Arduino ESP32 by TcMenu 4.3.1-SNAPSHOT on 2024-08-31T08:17:44.237948Z.
12+
1113
#include <tcMenu.h>
1214
#include "esp32Amplifier_menu.h"
13-
#include "ThemeCoolBlueModern.h"
15+
#include "ThemeCoolBlueModernBuilder.h"
1416

1517
// Global variable declarations
1618
const PROGMEM ConnectorLocalInfo applicationInfo = { "ESP Amplifier", "4656c798-10c6-4110-8e03-b9c51ed8fffb" };
@@ -24,9 +26,9 @@ iotouch::ResistiveTouchInterrogator touchInterrogator(2, 33, 32, 0);
2426
iotouch::TouchOrientationSettings touchOrientation(true, false, true);
2527
MenuTouchScreenManager touchScreen(&touchInterrogator, &renderer, touchOrientation);
2628
tcextras::IoaTouchScreenCalibrator touchCalibrator(&touchScreen, &renderer, 400);
27-
ClientEthernetInitialisation ethernetInitialisation("192.168.0.37", 3333);
28-
ClientEthernetTagValTransport ethernetTransport;
29-
TagValueRemoteServerConnection ethernetConnection(ethernetTransport, ethernetInitialisation);
29+
ClientEthernetInitialisation clientEthInit("192.168.0.37", 3333);
30+
ClientEthernetTagValTransport clientEthTransport;
31+
TagValueRemoteServerConnection clientConnection(clientEthTransport, clientEthInit);
3032

3133
// Global Menu Item declarations
3234
const PROGMEM char pgmStrConnectivityAuthenticatorText[] = { "Authenticator" };
@@ -101,19 +103,17 @@ void setupMenu() {
101103
menuMgr.setAuthenticator(&authManager);
102104
// Now add any readonly, non-remote and visible flags.
103105
menuConnectivityIPAddress.setReadOnly(true);
104-
menuConnectivityAuthenticator.setLocalOnly(true);
105106
menuConnectivityIoTMonitor.setLocalOnly(true);
107+
menuConnectivityAuthenticator.setLocalOnly(true);
106108

107109
// Code generated by plugins and new operators.
108110
tft.begin();
109111
tft.setRotation(1);
110112
renderer.setUpdatesPerSecond(10);
111113
touchScreen.start();
112114
menuMgr.initWithoutInput(&renderer, &menuVolume);
113-
remoteServer.addConnection(&ethernetConnection);
114-
renderer.setTitleMode(BaseGraphicalRenderer::TITLE_ALWAYS);
115-
renderer.setUseSliderForAnalog(true);
116-
installCoolBlueModernTheme(renderer, MenuFontDef(nullptr, 4), MenuFontDef(nullptr, 4), false);
115+
remoteServer.addConnection(&clientConnection);
116+
installCoolBlueModernTheme(renderer, MenuFontDef(nullptr, 4), MenuFontDef(nullptr, 4), false, BaseGraphicalRenderer::TITLE_ALWAYS, false);
117117

118118
// We have an IoT monitor, register the server
119119
menuConnectivityIoTMonitor.setRemoteServer(remoteServer);

examples/esp/esp32Amplifier/esp32Amplifier_menu.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,8 @@ extern GraphicsDeviceRenderer renderer;
3535
extern iotouch::ResistiveTouchInterrogator touchInterrogator;
3636
extern MenuTouchScreenManager touchScreen;
3737
extern tcextras::IoaTouchScreenCalibrator touchCalibrator;
38-
extern WiFiServer server;
39-
extern ClientEthernetInitialisation ethernetInitialisation;
40-
41-
42-
extern EepromAuthenticatorManager authManager;
43-
44-
38+
extern ClientEthernetInitialisation clientEthInit;
39+
extern ClientEthernetTagValTransport clientEthTransport;
4540

4641
// Any externals needed by IO expanders, EEPROMs etc
4742

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* Copyright (c) 2018 https://www.thecoderscorner.com (Dave Cherry).
3+
* This product is licensed under an Apache license, see the LICENSE file in the top-level directory.
4+
*/
5+
6+
/**
7+
* Ethernet remote capability plugin. This file is a plugin file and should not be directly edited,
8+
* it will be replaced each time the project is built. If you want to edit this file in place,
9+
* make sure to rename it first.
10+
*/
11+
12+
#include "ClientEthernetTransport.h"
13+
#include <TaskManager.h>
14+
15+
using namespace tcremote;
16+
17+
#if ETHERNET_BUFFER_SIZE > 0 // we need buffering when dealing with Ethernet2
18+
19+
bool ClientEthernetTagValTransport::available() {
20+
return client && client.connected();
21+
}
22+
23+
bool ClientEthernetTagValTransport::connected() {
24+
return client && client.connected();
25+
}
26+
27+
void ClientEthernetTagValTransport::flush() {
28+
if(!client || writeBufferPos == 0) return;
29+
30+
if((int)client.write(writeBuffer, writeBufferPos) == writeBufferPos) {
31+
serdebugF2("Buffer written ", writeBufferPos);
32+
writeBufferPos = 0;
33+
client.flush();
34+
}
35+
else {
36+
writeBufferPos = 0;
37+
close();
38+
}
39+
}
40+
41+
int ClientEthernetTagValTransport::fillReadBuffer(uint8_t* dataBuffer, int maxData) {
42+
if(client && client.connected() && client.available()) {
43+
auto amt = client.read(dataBuffer, maxData);
44+
if(amt <= 0) {
45+
close();
46+
return 0;
47+
}
48+
serdebugF2("read to buffer ", amt);
49+
return amt;
50+
}
51+
return 0;
52+
}
53+
54+
void ClientEthernetTagValTransport::close() {
55+
serdebugF("socket close");
56+
BaseBufferedRemoteTransport::close();
57+
client.stop();
58+
}
59+
60+
#else // unbuffed client - requires library to support Nagle algorythm.
61+
62+
bool EthernetTagValTransport::available() {
63+
return client && client.connected();
64+
}
65+
66+
bool EthernetTagValTransport::connected() {
67+
return client && client.connected();
68+
}
69+
70+
int EthernetTagValTransport::writeChar(char data) {
71+
// only uncomment below for worst case debugging..
72+
// serdebug2("writing ", data);
73+
return client.write(data);
74+
}
75+
76+
int EthernetTagValTransport::writeStr(const char* data) {
77+
// only uncomment below for worst case debugging..
78+
// serdebug2("writing ", data);
79+
return client.write(data);
80+
}
81+
82+
void EthernetTagValTransport::flush() {
83+
if(client) client.flush();
84+
}
85+
86+
uint8_t EthernetTagValTransport::readByte() {
87+
return client.read();
88+
}
89+
90+
bool EthernetTagValTransport::readAvailable() {
91+
return client && client.connected() && client.available();
92+
}
93+
94+
void EthernetTagValTransport::close() {
95+
serdebugF("socket close");
96+
client.stop();
97+
currentField.msgType = UNKNOWN_MSG_TYPE;
98+
currentField.fieldType = FVAL_PROCESSING_AWAITINGMSG;
99+
}
100+
101+
#endif
102+
103+
bool ClientEthernetInitialisation::attemptInitialisation() {
104+
#ifdef ARDUINO_ARCH_STM32
105+
// we'll keep checking if the link is up before trying to initialise further
106+
if(Ethernet.linkStatus() == LinkOFF) return false;
107+
#endif
108+
serdebugF("Initialising server ");
109+
initialised = true;
110+
return initialised;
111+
}
112+
113+
bool ClientEthernetInitialisation::attemptNewConnection(BaseRemoteServerConnection *remoteServerConnection) {
114+
if(!checkBackoffPeriod()) return false;
115+
116+
client.connect(host, port);
117+
if(client.connected()) {
118+
serdebugF("Client found");
119+
auto* tvCon = reinterpret_cast<TagValueRemoteServerConnection*>(remoteServerConnection);
120+
reinterpret_cast<ClientEthernetTagValTransport*>(tvCon->transport())->setClient(client);
121+
return true;
122+
}
123+
return false;
124+
}
125+
126+
bool ClientEthernetInitialisation::checkBackoffPeriod() {
127+
if(backOffPeriod == 0) {
128+
backOffPeriod = DEFAULT_BACKOFF_PERIOD;
129+
return true;
130+
}
131+
backOffPeriod--;
132+
return false;
133+
}

0 commit comments

Comments
 (0)