Skip to content

Commit de67391

Browse files
committed
#217 in progress support for encryption
1 parent 28687f8 commit de67391

File tree

10 files changed

+977
-0
lines changed

10 files changed

+977
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef TCMENU_THEME_MONO_INVERSE
2+
#define TCMENU_THEME_MONO_INVERSE
3+
4+
color_t defaultItemPaletteMono[] = {1, 0, 1, 1};
5+
color_t defaultTitlePaletteMono[] = {0, 1, 0, 0};
6+
7+
#define TITLE_PADDING 1
8+
#define TITLE_SPACING 0
9+
10+
void installMonoInverseTitleTheme(GraphicsDeviceRenderer& bgr, const MenuFontDef& itemFont, const MenuFontDef& titleFont, bool needEditingIcons) {
11+
bgr.setDisplayDimensions(bgr.getDeviceDrawable()->getDisplayDimensions().x, bgr.getDeviceDrawable()->getDisplayDimensions().y);
12+
auto& factory = bgr.getGraphicsPropertiesFactory();
13+
14+
factory.setSelectedColors(0, 2);
15+
16+
MenuPadding titlePadding(TITLE_PADDING);
17+
MenuPadding itemPadding(1);
18+
int titleHeight = bgr.heightForFontPadding(titleFont.fontData, titleFont.fontMag, titlePadding);
19+
int itemHeight = bgr.heightForFontPadding(itemFont.fontData, itemFont.fontMag, itemPadding);
20+
21+
factory.addImageToCache(DrawableIcon(SPECIAL_ID_EDIT_ICON, Coord(8, 6),DrawableIcon::ICON_XBITMAP, loResEditingIcon));
22+
factory.addImageToCache(DrawableIcon(SPECIAL_ID_ACTIVE_ICON, Coord(8, 6),DrawableIcon::ICON_XBITMAP, loResActiveIcon));
23+
24+
factory.setDrawingPropertiesDefault(ItemDisplayProperties::COMPTYPE_TITLE, defaultTitlePaletteMono, titlePadding, titleFont.fontData, titleFont.fontMag,
25+
TITLE_SPACING, titleHeight + 1, GridPosition::JUSTIFY_TITLE_LEFT_WITH_VALUE, MenuBorder(0));
26+
factory.setDrawingPropertiesDefault(ItemDisplayProperties::COMPTYPE_ITEM, defaultItemPaletteMono, itemPadding, itemFont.fontData, itemFont.fontMag,
27+
1, itemHeight, GridPosition::JUSTIFY_TITLE_LEFT_VALUE_RIGHT , MenuBorder(0));
28+
factory.setDrawingPropertiesDefault(ItemDisplayProperties::COMPTYPE_ACTION, defaultItemPaletteMono, itemPadding, itemFont.fontData, itemFont.fontMag,
29+
1, itemHeight, GridPosition::JUSTIFY_TITLE_LEFT_WITH_VALUE, MenuBorder(0));
30+
31+
tcgfx::ConfigurableItemDisplayPropertiesFactory::refreshCache();
32+
}
33+
34+
#endif //TCMENU_THEME_MONO_INVERSE
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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 "EthernetTransport.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 EthernetTagValTransport::available() {
20+
return client && client.connected();
21+
}
22+
23+
bool EthernetTagValTransport::connected() {
24+
return client && client.connected();
25+
}
26+
27+
void EthernetTagValTransport::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 EthernetTagValTransport::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 EthernetTagValTransport::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 EthernetInitialisation::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+
this->server->begin();
110+
initialised = true;
111+
return initialised;
112+
}
113+
114+
bool EthernetInitialisation::attemptNewConnection(BaseRemoteServerConnection *remoteServerConnection) {
115+
auto client = server->available();
116+
if(client) {
117+
serdebugF("Client found");
118+
auto* tvCon = reinterpret_cast<TagValueRemoteServerConnection*>(remoteServerConnection);
119+
reinterpret_cast<EthernetTagValTransport*>(tvCon->transport())->setClient(client);
120+
return true;
121+
}
122+
return false;
123+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
* @file EthernetTransport.h
8+
*
9+
* Ethernet remote capability plugin. This file is a plugin file and should not be directly edited,
10+
* it will be replaced each time the project is built. If you want to edit this file in place,
11+
* make sure to rename it first.
12+
*/
13+
14+
#ifndef TCMENU_ETHERNETTRANSPORT_H_
15+
#define TCMENU_ETHERNETTRANSPORT_H_
16+
17+
#include <RemoteConnector.h>
18+
#include <TaskManager.h>
19+
#include <STM32Ethernet.h>
20+
#include <tcUtil.h>
21+
#include <remote/BaseRemoteComponents.h>
22+
23+
#ifndef ETHERNET_BUFFER_SIZE
24+
#define ETHERNET_BUFFER_SIZE 0
25+
#endif
26+
27+
#if ETHERNET_BUFFER_SIZE > 0
28+
#include <remote/BaseBufferedRemoteTransport.h>
29+
#endif
30+
31+
namespace tcremote {
32+
33+
#if ETHERNET_BUFFER_SIZE > 0
34+
35+
/**
36+
* An implementation of TagValueTransport that is able to read and write via a buffer to sockets.
37+
*/
38+
class EthernetTagValTransport : public tcremote::BaseBufferedRemoteTransport {
39+
private:
40+
EthernetClient client;
41+
public:
42+
EthernetTagValTransport() : BaseBufferedRemoteTransport(BUFFER_MESSAGES_TILL_FULL, ETHERNET_BUFFER_SIZE, MAX_VALUE_LEN) { }
43+
~EthernetTagValTransport() override = default;
44+
void setClient(EthernetClient cl) { this->client = cl; }
45+
46+
int fillReadBuffer(uint8_t* data, int maxSize) override;
47+
void flush() override;
48+
bool available() override;
49+
bool connected() override;
50+
void close() override;
51+
};
52+
53+
#else // ethernet buffering not needed
54+
55+
/**
56+
* An implementation of TagValueTransport that is able to read and write using sockets.
57+
*/
58+
class EthernetTagValTransport : public TagValueTransport {
59+
private:
60+
EthernetClient client;
61+
public:
62+
EthernetTagValTransport() : TagValueTransport(TagValueTransportType::TVAL_UNBUFFERED) {};
63+
~EthernetTagValTransport() override = default;
64+
void setClient(EthernetClient client) { this->client = client; }
65+
66+
int writeChar(char data) override ;
67+
int writeStr(const char* data) override;
68+
void flush() override;
69+
bool available() override;
70+
bool connected() override;
71+
uint8_t readByte() override;
72+
bool readAvailable() override;
73+
void close() override;
74+
};
75+
76+
#endif // ethernet buffering check
77+
78+
/**
79+
* This class provides the initialisation and connection generation logic for ethernet connections.
80+
*/
81+
class EthernetInitialisation : public DeviceInitialisation {
82+
private:
83+
EthernetServer *server;
84+
public:
85+
explicit EthernetInitialisation(EthernetServer* server) : server(server) {}
86+
87+
bool attemptInitialisation() override;
88+
89+
bool attemptNewConnection(BaseRemoteServerConnection *transport) override;
90+
};
91+
92+
/**
93+
* This function converts from a RSSI (Radio Strength indicator)
94+
* measurement into a series of icons (of the ones we have defined
95+
* in the stock icons. The input is the RSSI figure in dB as an
96+
* integer.
97+
* @param strength the signal strength (usually negative) as an int
98+
* @return a state that can be used with the standard wifi TitleWidget
99+
*/
100+
int fromWiFiRSSITo4StateIndicator(int strength);
101+
102+
} // namespace tcremote
103+
104+
#ifndef TC_MANUAL_NAMESPACING
105+
using namespace tcremote;
106+
#endif // TC_MANUAL_NAMESPACING
107+
108+
#endif /* TCMENU_ETHERNETTRANSPORT_H_ */
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
The code in this file uses open source libraries provided by thecoderscorner
3+
4+
DO NOT EDIT THIS FILE, IT WILL BE GENERATED EVERY TIME YOU USE THE UI DESIGNER
5+
INSTEAD EITHER PUT CODE IN YOUR SKETCH OR CREATE ANOTHER SOURCE FILE.
6+
7+
All the variables you may need access to are marked extern in this file for easy
8+
use elsewhere.
9+
*/
10+
11+
// Generated for STM32Duino by TcMenu 4.3.0-SNAPSHOT on 2024-07-27T07:53:35.721721700Z.
12+
13+
#include <tcMenu.h>
14+
#include "stm32DuinoOneButton_menu.h"
15+
#include "../ThemeMonoInverse.h"
16+
#include <Fonts/OpenSansRegular8pt.h>
17+
18+
// Global variable declarations
19+
const ConnectorLocalInfo applicationInfo = { "One Button", "4fe6e85d-2bbd-4d19-84e5-5d6746883028" };
20+
HalStm32EepromAbstraction glBspRom;
21+
EepromAuthenticatorManager authManager(4);
22+
U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI gfx(U8G2_R0, PF13, PD15, PF12);
23+
U8g2Drawable gfxDrawable(&gfx);
24+
GraphicsDeviceRenderer renderer(30, applicationInfo.name, &gfxDrawable);
25+
TcOneButtonHandler oneButtonHandler(USER_BTN, 250);
26+
27+
// Global Menu Item declarations
28+
const char enumStrSettingsEnumProp_0[] = "Item1";
29+
const char enumStrSettingsEnumProp_1[] = "Item2";
30+
const char enumStrSettingsEnumProp_2[] = "Item3";
31+
const char* const enumStrSettingsEnumProp[] = { enumStrSettingsEnumProp_0, enumStrSettingsEnumProp_1, enumStrSettingsEnumProp_2 };
32+
const EnumMenuInfo minfoSettingsEnumProp = { "EnumProp", 24, 0xffff, 2, NO_CALLBACK, enumStrSettingsEnumProp };
33+
EnumMenuItem menuSettingsEnumProp(&minfoSettingsEnumProp, 0, nullptr, INFO_LOCATION_PGM);
34+
const AnalogMenuInfo minfoSettingsIntProp = { "IntProp", 23, 0xffff, 10, NO_CALLBACK, 0, 1, "A" };
35+
AnalogMenuItem menuSettingsIntProp(&minfoSettingsIntProp, 0, &menuSettingsEnumProp, INFO_LOCATION_PGM);
36+
const BooleanMenuInfo minfoSettingsOption = { "Option", 22, 0xffff, 1, NO_CALLBACK, NAMING_TRUE_FALSE };
37+
BooleanMenuItem menuSettingsOption(&minfoSettingsOption, false, &menuSettingsIntProp, INFO_LOCATION_PGM);
38+
const SubMenuInfo minfoSettings = { "Settings", 21, 0xffff, 0, NO_CALLBACK };
39+
BackMenuItem menuBackSettings(&minfoSettings, &menuSettingsOption, INFO_LOCATION_PGM);
40+
SubMenuItem menuSettings(&minfoSettings, &menuBackSettings, nullptr, INFO_LOCATION_PGM);
41+
const AnalogMenuInfo minfoTemp = { "Temp", 20, 0xffff, 100, NO_CALLBACK, 0, 1, "%" };
42+
AnalogMenuItem menuTemp(&minfoTemp, 0, &menuSettings, INFO_LOCATION_PGM);
43+
const AnyMenuInfo minfoPressMe = { "Press Me", 19, 0xffff, 0, onPressMe };
44+
ActionMenuItem menuPressMe(&minfoPressMe, &menuTemp, INFO_LOCATION_PGM);
45+
46+
void setupMenu() {
47+
// First we set up eeprom and authentication (if needed).
48+
setSizeBasedEEPROMStorageEnabled(false);
49+
glBspRom.initialise(0);
50+
menuMgr.setEepromRef(&glBspRom);
51+
authManager.initialise(menuMgr.getEepromAbstraction(), 150);
52+
menuMgr.setAuthenticator(&authManager);
53+
// Code generated by plugins and new operators.
54+
gfx.begin();
55+
renderer.setUpdatesPerSecond(5);
56+
switches.init(internalDigitalIo(), SWITCHES_POLL_EVERYTHING, false);
57+
menuMgr.initWithoutInput(&renderer, &menuPressMe);
58+
oneButtonHandler.start();
59+
renderer.setTitleMode(BaseGraphicalRenderer::NO_TITLE);
60+
renderer.setUseSliderForAnalog(false);
61+
renderer.enableTcUnicode();
62+
installMonoInverseTitleTheme(renderer, MenuFontDef(&OpenSansRegular8pt, 0), MenuFontDef(&OpenSansRegular8pt, 0), true);
63+
}
64+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
The code in this file uses open source libraries provided by thecoderscorner
3+
4+
DO NOT EDIT THIS FILE, IT WILL BE GENERATED EVERY TIME YOU USE THE UI DESIGNER
5+
INSTEAD EITHER PUT CODE IN YOUR SKETCH OR CREATE ANOTHER SOURCE FILE.
6+
7+
All the variables you may need access to are marked extern in this file for easy
8+
use elsewhere.
9+
*/
10+
11+
#ifndef MENU_GENERATED_CODE_H
12+
#define MENU_GENERATED_CODE_H
13+
14+
#include <Arduino.h>
15+
#include <tcMenu.h>
16+
#include <tcUnicodeHelper.h>
17+
#include "tcMenuU8g2.h"
18+
#include <extras/TcOneButtonHandler.h>
19+
#include <IoAbstraction.h>
20+
#include <EepromItemStorage.h>
21+
#include <mbed/HalStm32EepromAbstraction.h>
22+
#include <RemoteAuthentication.h>
23+
24+
// variables we declare that you may need to access
25+
extern const PROGMEM ConnectorLocalInfo applicationInfo;
26+
extern U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI gfx;
27+
extern U8g2Drawable gfxDrawable;
28+
extern GraphicsDeviceRenderer renderer;
29+
extern TcOneButtonHandler oneButtonHandler;
30+
extern const UnicodeFont OpenSansRegular8pt[];
31+
32+
// Any externals needed by IO expanders, EEPROMs etc
33+
34+
35+
// Global Menu Item exports
36+
extern EnumMenuItem menuSettingsEnumProp;
37+
extern AnalogMenuItem menuSettingsIntProp;
38+
extern BooleanMenuItem menuSettingsOption;
39+
extern BackMenuItem menuBackSettings;
40+
extern SubMenuItem menuSettings;
41+
extern AnalogMenuItem menuTemp;
42+
extern ActionMenuItem menuPressMe;
43+
44+
// Provide a wrapper to get hold of the root menu item and export setupMenu
45+
inline MenuItem& rootMenuItem() { return menuPressMe; }
46+
void setupMenu();
47+
48+
// Callback functions must always include CALLBACK_FUNCTION after the return type
49+
#define CALLBACK_FUNCTION
50+
51+
void CALLBACK_FUNCTION onPressMe(int id);
52+
53+
#endif // MENU_GENERATED_CODE_H

0 commit comments

Comments
 (0)