Initial commit

This commit is contained in:
jaseg 2025-05-09 20:09:18 +02:00
commit 456edbd46f
7 changed files with 161 additions and 0 deletions

73
src/main.cpp Normal file
View file

@ -0,0 +1,73 @@
#include <Arduino.h>
#include <base64.h>
#include <qrcode.h>
#include <esp_adc_cal.h>
#include <esp_pm.h>
#include <Toggle.h>
#include <esp_system.h>
#include <esp_task_wdt.h>
#include <mbedtls/md.h>
#include <SPIFFS.h>
#include <StreamString.h>
#include <time.h>
#include "main.h"
size_t qr_w = 0;
uint16_t qr_img[128*128];
int qr_version = 4;
int qr_scale = 3;
Toggle tog_a, tog_b;
void setup() {
Serial.begin(115200);
ledcSetup(backlightChannel, 12000, 8);
ledcAttachPin(TFT_BL, backlightChannel);
ledcWrite(backlightChannel, 255);
tft.init();
tft.fillScreen(TFT_BLACK);
tog_a(0);
tog_b(35);
SPIFFS.begin(true);
tft.fillScreen(TFT_RED);
QRCode qrcode;
uint8_t *qr_buf = new uint8_t[qrcode_getBufferSize(qr_version)];
qrcode_initText(&qrcode, qr_buf, qr_version, ECC_LOW, "otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example");
qr_w = qrcode.size * qr_scale;
for (int y=0; y<qrcode.size; y++) {
for (int sy=0; sy<qr_scale; sy++) {
for(int x=0; x<qrcode.size; x++) {
for (int sx=0; sx<qr_scale; sx++) {
qr_img[x*qr_scale + sx +qr_w*(y*qr_scale + sy)] = qrcode_getModule(&qrcode, x, y) ? TFT_BLACK : TFT_WHITE;
}
}
}
}
delete qr_buf;
tft.fillScreen(TFT_BLACK);
tft.startWrite();
tft.pushImage((TFT_WIDTH - qr_w)/2, (TFT_HEIGHT - qr_w)/2, qr_w, qr_w, (uint16_t*)qr_img);
tft.endWrite();
}
int flag = 0;
void loop() {
flag = !flag;
/*
tft.fillScreen(flag ? TFT_RED : TFT_BLUE);
tft.startWrite();
tft.pushImage(0, 0, qr_w, qr_w, (uint16_t*)qr_img);
tft.endWrite();
*/
delay(1000);
}