Skip to content

Commit

Permalink
Merge pull request #105 from rennancockles/main
Browse files Browse the repository at this point in the history
fix qrcode and add more options
  • Loading branch information
pr3y authored Aug 2, 2024
2 parents 2a5ca0e + 11f6c43 commit c831a29
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 30 deletions.
86 changes: 56 additions & 30 deletions src/modules/others/qrcode_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,73 @@
#include "core/mykeyboard.h"


struct QRCODESTR {
char name[19];
String url;
};
uint16_t crc_ccitt_update(uint16_t crc, uint8_t data) {
crc = (uint8_t)(crc >> 8) | (crc << 8);
crc ^= data;
crc ^= (uint8_t)(crc & 0xff) >> 4;
crc ^= crc << 12;
crc ^= (crc & 0x00ff) << 5;
return crc;
}


String calculate_crc(String input) {
size_t len = input.length();
uint8_t *data = (uint8_t *)input.c_str();
uint16_t crc = 0xffff;

for (size_t i = 0; i < len; i++) {
crc = crc_ccitt_update(crc, data[i]);
}

String crc_str = String(crc, HEX);
crc_str.toUpperCase();
while (crc_str.length() < 4) crc_str = "0" + crc_str; // Pad with zeros if needed

return crc_str;
}


void qrcode_display(String qrcodeUrl) {
// Fetch current brightness
EEPROM.begin(EEPROMSIZE);
int oldBrightness = EEPROM.read(2);
EEPROM.end(); // Free EEPROM memory
QRcode qrcode (&tft);
QRcode qrcode(&tft);
qrcode.init();

tft.fillScreen(TFT_WHITE);
// Set max brightness for better readability
setBrightness(100);

qrcode.create(qrcodeUrl);
while(!checkEscPress() and !checkSelPress()) {
delay(100);
}
while(!checkEscPress() && !checkSelPress()) delay(100);
tft.fillScreen(BGCOLOR);
}

// Restore user brightness config
setBrightness(oldBrightness);
void custom_qrcode() {
String message = keyboard("", 100, "QRCode text:");
return qrcode_display(message);
}

void qrcode_menu() {
options = {};
QRCODESTR qrcodes[] = {
{ "Bruce AP", "WIFI:T:WPA;S:BruceNet;P:brucenet;;"},
{ "Rickroll", "https://youtu.be/dQw4w9WgXcQ" },
{ "HackerTyper", "https://hackertyper.net/" },
{ "ZomboCom", "https://html5zombo.com/" },
};
void pix_qrcode() {
String key = keyboard("", 25, "PIX Key:");
String key_length = key.length() >= 10 ? String(key.length()) : "0" + String(key.length());
String amount = keyboard("1000.00", 10, "Int amount:");
amount = String(amount.toFloat());
String amount_length = amount.length() >= 10 ? String(amount.length()) : "0" + String(amount.length());

for(int i=0; i<4; i++) {
options.push_back({qrcodes[i].name, [&]() { qrcode_display(qrcodes[i].url); }});
}
String data0 = "0014BR.GOV.BCB.PIX01" + key_length + key;

options.push_back({"Main menu", [=]() { backToMenu(); }});
String pix_code = "00020126" + String(data0.length()) + data0 + "52040000530398654" + amount_length + amount + "5802BR5909Bruce PIX6014Rio de Janeiro62070503***6304";
String crc = calculate_crc(pix_code);

return qrcode_display(pix_code + crc);
}

void qrcode_menu() {
options = {
{"Bruce AP", [=]() { qrcode_display("WIFI:T:WPA;S:BruceNet;P:brucenet;;"); }},
{"Bruce Repo", [=]() { qrcode_display("https://github.com/pr3y/Bruce"); }},
{"Rickroll", [=]() { qrcode_display("https://youtu.be/dQw4w9WgXcQ"); }},
{"HackerTyper", [=]() { qrcode_display("https://hackertyper.net/"); }},
{"ZomboCom", [=]() { qrcode_display("https://html5zombo.com/"); }},
{"PIX", [=]() { pix_qrcode(); }},
{"Custom", [=]() { custom_qrcode(); }},
{"Main menu", [=]() { backToMenu(); }},
};

delay(200);
loopOptions(options);
Expand Down
2 changes: 2 additions & 0 deletions src/modules/others/qrcode_menu.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
void qrcode_display(String qrcodeUrl);
void custom_qrcode();
void pix_qrcode();
void qrcode_menu();

0 comments on commit c831a29

Please sign in to comment.