Added QR code to AP mode.

This commit is contained in:
Jonas Diemer 2025-12-23 14:49:29 +01:00
parent d45739b08b
commit bf06f7eb82

View File

@ -4,9 +4,11 @@
#include <ESPmDNS.h> #include <ESPmDNS.h>
#include <GfxRenderer.h> #include <GfxRenderer.h>
#include <InputManager.h> #include <InputManager.h>
#include <WiFi.h>
#include <cstdint>
#include <QrCode.h> #include <QrCode.h>
#include <WiFi.h>
#include <cstddef>
#include <cstdint>
#include "NetworkModeSelectionActivity.h" #include "NetworkModeSelectionActivity.h"
#include "WifiSelectionActivity.h" #include "WifiSelectionActivity.h"
@ -338,26 +340,25 @@ void CrossPointWebServerActivity::render() const {
} }
} }
void drawQRCode(GfxRenderer& renderer, const int x, const int y, void drawQRCode(GfxRenderer& renderer, const int x, const int y, const std::string& data) {
uint8_t* qrcodeBytes, const std::string& data, int size) {
// Implementation of QR code calculation // Implementation of QR code calculation
// The structure to manage the QR code // The structure to manage the QR code
QRCode qrcode; QRCode qrcode;
uint8_t qrcodeBytes[qrcode_getBufferSize(3)]; uint8_t qrcodeBytes[qrcode_getBufferSize(4)];
Serial.printf("QR Code:\n"); Serial.printf("[%lu] [WEBACT] QR Code (%lu): %s\n", millis(), data.length(), data.c_str());
qrcode_initText(&qrcode, qrcodeBytes, 3, ECC_LOW, data.c_str()); qrcode_initText(&qrcode, qrcodeBytes, 4, ECC_LOW, data.c_str());
const uint8_t px = 6; // pixels per module const uint8_t px = 6; // pixels per module
for (uint8_t cy = 0; cy < qrcode.size; cy++) { for (uint8_t cy = 0; cy < qrcode.size; cy++) {
for (uint8_t cx = 0; cx < qrcode.size; cx++) { for (uint8_t cx = 0; cx < qrcode.size; cx++) {
if (qrcode_getModule(&qrcode, cx, cy)) { if (qrcode_getModule(&qrcode, cx, cy)) {
// Serial.print("**"); // Serial.print("**");
renderer.fillRect(x + px*cx, y + px*cy, px, px, true); renderer.fillRect(x + px * cx, y + px * cy, px, px, true);
} else { } else {
// Serial.print(" "); // Serial.print(" ");
}
} }
Serial.print("\n"); }
// Serial.print("\n");
} }
} }
@ -371,7 +372,7 @@ void CrossPointWebServerActivity::renderServerRunning() const {
if (isApMode) { if (isApMode) {
// AP mode display - center the content block // AP mode display - center the content block
const int startY = 55; int startY = 55;
renderer.drawCenteredText(UI_FONT_ID, startY, "Hotspot Mode", true, BOLD); renderer.drawCenteredText(UI_FONT_ID, startY, "Hotspot Mode", true, BOLD);
@ -381,6 +382,13 @@ void CrossPointWebServerActivity::renderServerRunning() const {
renderer.drawCenteredText(SMALL_FONT_ID, startY + LINE_SPACING * 2, "Connect your device to this WiFi network", renderer.drawCenteredText(SMALL_FONT_ID, startY + LINE_SPACING * 2, "Connect your device to this WiFi network",
true, REGULAR); true, REGULAR);
renderer.drawCenteredText(SMALL_FONT_ID, startY + LINE_SPACING * 3,
"or scan QR code with your phone to connect to Wifi.", true, REGULAR);
// Show QR code for URL
std::string wifiConfig = std::string("WIFI:T:WPA;S:") + connectedSSID + ";P:" + "" + ";;";
drawQRCode(renderer, (480 - 6 * 33) / 2, startY + LINE_SPACING * 4, wifiConfig);
startY += 6 * 29 + 3 * LINE_SPACING;
// Show primary URL (hostname) // Show primary URL (hostname)
std::string hostnameUrl = std::string("http://") + AP_HOSTNAME + ".local/"; std::string hostnameUrl = std::string("http://") + AP_HOSTNAME + ".local/";
renderer.drawCenteredText(UI_FONT_ID, startY + LINE_SPACING * 3, hostnameUrl.c_str(), true, BOLD); renderer.drawCenteredText(UI_FONT_ID, startY + LINE_SPACING * 3, hostnameUrl.c_str(), true, BOLD);
@ -388,8 +396,12 @@ void CrossPointWebServerActivity::renderServerRunning() const {
// Show IP address as fallback // Show IP address as fallback
std::string ipUrl = "or http://" + connectedIP + "/"; std::string ipUrl = "or http://" + connectedIP + "/";
renderer.drawCenteredText(SMALL_FONT_ID, startY + LINE_SPACING * 4, ipUrl.c_str(), true, REGULAR); renderer.drawCenteredText(SMALL_FONT_ID, startY + LINE_SPACING * 4, ipUrl.c_str(), true, REGULAR);
renderer.drawCenteredText(SMALL_FONT_ID, startY + LINE_SPACING * 5, "Open this URL in your browser", true, REGULAR); renderer.drawCenteredText(SMALL_FONT_ID, startY + LINE_SPACING * 5, "Open this URL in your browser", true, REGULAR);
// Show QR code for URL
renderer.drawCenteredText(SMALL_FONT_ID, startY + LINE_SPACING * 6, "or scan QR code with your phone:", true,
REGULAR);
drawQRCode(renderer, (480 - 6 * 33) / 2, startY + LINE_SPACING * 7, hostnameUrl);
} else { } else {
// STA mode display (original behavior) // STA mode display (original behavior)
const int startY = 65; const int startY = 65;
@ -413,11 +425,10 @@ void CrossPointWebServerActivity::renderServerRunning() const {
renderer.drawCenteredText(SMALL_FONT_ID, startY + LINE_SPACING * 4, "Open this URL in your browser", true, REGULAR); renderer.drawCenteredText(SMALL_FONT_ID, startY + LINE_SPACING * 4, "Open this URL in your browser", true, REGULAR);
// Show QR code for easy scanning // Show QR code for URL
// array of pixels for QR code, version 3 = 29x29 drawQRCode(renderer, (480 - 6 * 33) / 2, startY + LINE_SPACING * 6, webInfo);
drawQRCode(renderer, (480-6*29)/2, startY + LINE_SPACING * 6, qrcodeBytes, webInfo, webInfo.length()); renderer.drawCenteredText(SMALL_FONT_ID, startY + LINE_SPACING * 5, "or scan QR code with your phone:", true,
renderer.drawCenteredText(SMALL_FONT_ID, startY + LINE_SPACING * 5, "or scan QR code with your phone:", true, REGULAR); REGULAR);
} }
renderer.drawCenteredText(SMALL_FONT_ID, pageHeight - 30, "Press BACK to exit", true, REGULAR); renderer.drawCenteredText(SMALL_FONT_ID, pageHeight - 30, "Press BACK to exit", true, REGULAR);