Skip to content

Commit a0cb4c0

Browse files
committed
add qr, menu, settings
1 parent d3e15d0 commit a0cb4c0

File tree

8 files changed

+190
-8
lines changed

8 files changed

+190
-8
lines changed

.github/workflows/arduino.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
- --warnings="none"
3030
libraries: |
3131
- name: TFT_eSPI
32+
- name: QRCodeGenerator
3233
3334
- uses: actions/upload-artifact@v4
3435
with:

genericInstaller/100_config.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ String getConfigValue(String &fileContent, const char* name, String defaultValue
7676
endIndex = fileContent.length();
7777
}
7878
String value = fileContent.substring(index + strlen(name) + 1, endIndex);
79+
value.trim();
7980
if (config_boot_lock == 0) {
8081
Serial.println(String(name) + "=" + value);
8182
}

genericInstaller/200_wifi.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ void setupWifi() {
99
printHome();
1010
Serial.println("Connecting to WiFi...");
1111
WiFi.begin(config_wifi_ssid.c_str(), config_wifi_password.c_str());
12+
wifiLastReconnectAttempt = millis();
1213
}
1314

1415
void loopWifi() {

genericInstaller/300_tft.ino

Lines changed: 110 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ void printHome() {}
66
void printConfig() {}
77
void printBoot() {}
88
void printDeleteWarning() {}
9+
void printInstaller() {}
10+
void printMenu() {}
11+
void printQrCode(String data) {}
12+
void printSettings() {}
13+
void printInfo() {}
914
#else
1015
#include "config.h"
1116
#include <TFT_eSPI.h>
17+
#include <QRCodeGenerator.h>
1218

1319
#define LINE_HEIGHT 20
1420
#define PADDING_X 12
@@ -38,6 +44,7 @@ void setupTFT() {
3844
tft.setTextSize(5);
3945
tft.setCursor(PADDING_X, 58);
4046
tft.println("LNbits");
47+
delay(200);
4148
}
4249
void printTFT(String message, int x, int y) {
4350
tft.setTextSize(2);
@@ -113,18 +120,36 @@ void printHome() {
113120
tft.setCursor(VERSION_PADDING_X, FOOTER_PADDING_Y);
114121
tft.println(String(VERSION));
115122
if (wifi_connected) {
116-
printTFT("WiFi connected", PADDING_X, PADDING_Y);
123+
// printTFT("WiFi connected", PADDING_X, PADDING_Y);
117124
int8_t quality = getWifiQuality();
118125
drawWifiBars(196, HEADER_PADDING_Y, quality);
119126
} else {
120-
printTFT("No WiFi", PADDING_X, PADDING_Y);
127+
// printTFT("No WiFi", PADDING_X, PADDING_Y);
121128
drawWifiBars(196, HEADER_PADDING_Y, 0);
122129
}
123130
if (config_boot_lock == 1) {
124-
printTFT("BOOT LOCKED", PADDING_X, PADDING_Y + LINE_HEIGHT);
131+
// printTFT("BOOT LOCKED", PADDING_X, PADDING_Y + LINE_HEIGHT);
125132
drawKey(172, HEADER_PADDING_Y);
126133
} else {
127-
printTFT("BOOT UNLOCKED", PADDING_X, PADDING_Y + LINE_HEIGHT);
134+
// printTFT("BOOT UNLOCKED", PADDING_X, PADDING_Y + LINE_HEIGHT);
135+
}
136+
137+
switch (currentScreen) {
138+
case SCREEN_HOME:
139+
printMenu();
140+
break;
141+
case SCREEN_QR:
142+
printQrCode("[email protected]");
143+
break;
144+
case SCREEN_SETTINGS:
145+
printSettings();
146+
break;
147+
case SCREEN_INFO:
148+
printInfo();
149+
break;
150+
default:
151+
Serial.println("Switches to screen" + String(currentScreen));
152+
break;
128153
}
129154
}
130155

@@ -136,4 +161,85 @@ void printDeleteWarning() {
136161
printTFT("TO ERASE", PADDING_X, 63);
137162
printTFT("CONFIG", PADDING_X, 84);
138163
}
164+
165+
void printMenu() {
166+
// Draw menu items
167+
int y = PADDING_Y;
168+
tft.setTextSize(2);
169+
tft.setCursor(PADDING_X, y);
170+
if (currentMenuItem == SCREEN_QR) tft.setTextColor(TFT_YELLOW); else tft.setTextColor(TFT_WHITE);
171+
tft.println("Show QR Code");
172+
173+
y += LINE_HEIGHT;
174+
tft.setCursor(PADDING_X, y);
175+
if (currentMenuItem == SCREEN_SETTINGS) tft.setTextColor(TFT_YELLOW); else tft.setTextColor(TFT_WHITE);
176+
tft.println("Settings");
177+
178+
y += LINE_HEIGHT;
179+
tft.setCursor(PADDING_X, y);
180+
if (currentMenuItem == SCREEN_INFO) tft.setTextColor(TFT_YELLOW); else tft.setTextColor(TFT_WHITE);
181+
tft.println("Device Info");
182+
}
183+
184+
void printQrCode(String data)
185+
{
186+
const int brightness = 200; // 0-255
187+
uint16_t qrScreenBgColour = tft.color565(brightness, brightness, brightness);
188+
tft.fillScreen(qrScreenBgColour);
189+
const char *qrDataChar = data.c_str();
190+
191+
QRCode qrcoded;
192+
uint8_t qrcodeData[qrcode_getBufferSize(20)];
193+
qrcode_initText(&qrcoded, qrcodeData, 6, 0, qrDataChar);
194+
195+
unsigned int pixSize = 3;
196+
unsigned int offsetTop = 5;
197+
unsigned int offsetLeft = 65;
198+
199+
for (uint8_t y = 0; y < qrcoded.size; y++)
200+
{
201+
for (uint8_t x = 0; x < qrcoded.size; x++)
202+
{
203+
if (qrcode_getModule(&qrcoded, x, y))
204+
{
205+
tft.fillRect(offsetLeft + pixSize * x, offsetTop + pixSize * y, pixSize, pixSize, TFT_BLACK);
206+
}
207+
else
208+
{
209+
tft.fillRect(offsetLeft + pixSize * x, offsetTop + pixSize * y, pixSize, pixSize, qrScreenBgColour);
210+
}
211+
}
212+
}
213+
}
214+
215+
void printInfo() {
216+
tft.setTextSize(3);
217+
tft.setTextColor(TFT_WHITE);
218+
tft.setCursor(PADDING_X, 14);
219+
tft.println("Info");
220+
tft.setTextSize(2);
221+
tft.setCursor(PADDING_X, 52);
222+
tft.println("WiFi: " + String(config_wifi_ssid));
223+
tft.setCursor(PADDING_X, 72);
224+
tft.println("IP: " + String(WiFi.localIP().toString()));
225+
tft.setCursor(PADDING_X, 92);
226+
tft.println("LED Pin: " + String(config_led_pin));
227+
}
228+
229+
void printSettings() {
230+
tft.setTextSize(3);
231+
tft.setTextColor(TFT_WHITE);
232+
tft.setCursor(PADDING_X, 14);
233+
tft.println("Settings");
234+
tft.setTextSize(2);
235+
int y = 52;
236+
tft.setCursor(PADDING_X, y);
237+
if (currentSetting == SETTING_ENABLE_BLINK) tft.setTextColor(TFT_YELLOW); else tft.setTextColor(TFT_WHITE);
238+
tft.println("Enable Blink: " + String(enable_blink ? "YES" : "NO"));
239+
y += LINE_HEIGHT;
240+
tft.setCursor(PADDING_X, y);
241+
if (currentSetting == SETTING_BOOT_LOCK) tft.setTextColor(TFT_YELLOW); else tft.setTextColor(TFT_WHITE);
242+
tft.println("Bootlock: " + String(config_boot_lock == 1 ? "LOCKED" : "UNLOCKED"));
243+
}
244+
139245
#endif

genericInstaller/400_buttons.ino

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,72 @@ void setupButtons() {
1313
}
1414

1515
void loopButtons() {
16-
1716
if (bothPressed > 0 && digitalRead(BTN_1) == HIGH && digitalRead(BTN_2) == HIGH) {
1817
Serial.println("Both buttons released after " + String(millis() - bothPressed) + " ms");
1918
bothPressed = 0;
2019
executedUnlock = false;
2120
showWarning = false;
2221
printHome();
2322
} else if (firstPressed > 0 && digitalRead(BTN_1) == HIGH) {
24-
Serial.println("Button 1 released after " + String(millis() - firstPressed) + " ms");
23+
// button 1 released after
24+
const int releaseTime = millis() - firstPressed;
25+
Serial.println("Button 1 released after " + String(releaseTime) + " ms");
2526
firstPressed = 0;
27+
switch (currentScreen) {
28+
case SCREEN_HOME:
29+
currentMenuItem++;
30+
// last screen in enum is SCREEN_INFO, first is SCREEN_QR
31+
if (currentMenuItem > SCREEN_INFO) currentMenuItem = SCREEN_QR;
32+
break;
33+
case SCREEN_QR:
34+
Serial.println("Show QR Code press");
35+
break;
36+
case SCREEN_SETTINGS:
37+
if (releaseTime < 500) {
38+
currentSetting++;
39+
if (currentSetting > SETTING_BOOT_LOCK) currentSetting = SETTING_ENABLE_BLINK;
40+
} else {
41+
// long press, toggle setting
42+
switch (currentSetting) {
43+
case SETTING_ENABLE_BLINK:
44+
enable_blink = !enable_blink;
45+
Serial.println("Enable blink: " + String(enable_blink));
46+
break;
47+
case SETTING_BOOT_LOCK:
48+
if (config_boot_lock == 1) {
49+
config_boot_lock = 0;
50+
} else {
51+
config_boot_lock = 1;
52+
}
53+
Serial.println("Boot lock: " + String(config_boot_lock));
54+
writeConfig();
55+
break;
56+
}
57+
}
58+
break;
59+
Serial.println("Show QR Code press");
60+
break;
61+
default:
62+
Serial.println("Other screen press 1");
63+
break;
64+
}
65+
printHome();
2666
} else if (secondPressed > 0 && digitalRead(BTN_2) == HIGH) {
2767
Serial.println("Button 2 released after " + String(millis() - secondPressed) + " ms");
2868
secondPressed = 0;
69+
switch (currentScreen) {
70+
// toggle through menu items
71+
case SCREEN_HOME:
72+
Serial.println("Go to selected menu item: " + String(currentMenuItem));
73+
currentScreen = currentMenuItem;
74+
break;
75+
// cancel and go back to home screen
76+
default:
77+
Serial.println("Cancel from screen " + String(currentScreen));
78+
currentScreen = SCREEN_HOME;
79+
break;
80+
}
81+
printHome();
2982
}
3083

3184
if (digitalRead(BTN_1) == LOW && digitalRead(BTN_2) == LOW) {

genericInstaller/500_menu.ino

Whitespace-only changes.

genericInstaller/genericInstaller.ino

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@ int config_led_pin;
77
int config_boot_lock;
88

99
int wifi_connected = false;
10+
int enable_blink = true;
11+
12+
// enum for menu items
13+
enum Screen {
14+
SCREEN_HOME,
15+
SCREEN_QR,
16+
SCREEN_SETTINGS,
17+
SCREEN_INFO,
18+
};
19+
20+
int currentMenuItem = SCREEN_QR;
21+
int currentScreen = SCREEN_HOME;
22+
23+
// settings menu
24+
enum SettingsMenu {
25+
SETTING_ENABLE_BLINK,
26+
SETTING_BOOT_LOCK,
27+
};
28+
int currentSetting = SETTING_ENABLE_BLINK;
29+
1030

1131
void setup() {
1232
Serial.begin(115200);
@@ -24,7 +44,7 @@ void loop() {
2444
loopButtons();
2545

2646
// blink led or backlight on tdisplay
27-
blinkLed(config_led_pin);
47+
if (enable_blink) blinkLed(config_led_pin);
2848
}
2949

3050
int lastBlink = 0;

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ arduino-cli core update-index
77
# also change in release workflow
88
arduino-cli core install esp32:esp32
99
arduino-cli upgrade
10-
arduino-cli lib install TFT_eSPI
10+
arduino-cli lib install TFT_eSPI QrCodeGenerator

0 commit comments

Comments
 (0)