Skip to content

Commit a6ea464

Browse files
committed
M5H@ck initial commit
Initial commit
1 parent 92aef34 commit a6ea464

7 files changed

Lines changed: 5035 additions & 0 deletions

File tree

MFRC522_I2C.cpp

Lines changed: 1751 additions & 0 deletions
Large diffs are not rendered by default.

MFRC522_I2C.h

Lines changed: 407 additions & 0 deletions
Large diffs are not rendered by default.

binaries/m5hack_esp32.bin

1.1 MB
Binary file not shown.

images.h

Lines changed: 2613 additions & 0 deletions
Large diffs are not rendered by default.

m5hack.ino

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#include <M5Stack.h>
2+
#include <M5ez.h>
3+
#include <ezTime.h>
4+
#include <Wire.h>
5+
6+
#include "MFRC522_I2C.h"
7+
#include "images.h"
8+
9+
#define MAIN_DECLARED
10+
11+
// 0x28 is i2c address on SDA. Check your address with i2cscanner if not match.
12+
MFRC522 mfrc522(0x28); // Create MFRC522 instance.
13+
14+
void setup() {
15+
#include <themes/default.h>
16+
#include <themes/dark.h>
17+
18+
// RFID init
19+
Serial.begin(115200); // Initialize serial communications with the PC
20+
Wire.begin(); // Initialize I2C
21+
mfrc522.PCD_Init(); // Init MFRC522
22+
23+
M5.Speaker.setVolume(1);
24+
M5.Speaker.update();
25+
26+
ezt::setDebug(INFO);
27+
ez.begin();
28+
}
29+
30+
void loop() {
31+
ezMenu mainmenu("Spawnrider M5H@ck");
32+
mainmenu.txtSmall();
33+
mainmenu.addItem("RFID Tools", menu_rfid);
34+
mainmenu.addItem("WIFI Tools", menu_not_implemented);
35+
mainmenu.addItem("Built-in wifi & other settings", ez.settings.menu);
36+
mainmenu.addItem("M5H@ck settings", menu_m5hack);
37+
mainmenu.upOnFirst("last|up");
38+
mainmenu.downOnLast("first|down");
39+
mainmenu.run();
40+
}
41+
42+
void menu_rfid() {
43+
ezMenu rfidmenu("RFID Tools");
44+
rfidmenu.txtSmall();
45+
rfidmenu.addItem("Get UID", rfid_tools);
46+
rfidmenu.addItem("Reader infos", show_reader_infos);
47+
rfidmenu.addItem("Back");
48+
rfidmenu.upOnFirst("last|up");
49+
rfidmenu.downOnLast("first|down");
50+
rfidmenu.run();
51+
}
52+
53+
void rfid_tools() {
54+
ez.screen.clear();
55+
56+
char cardUid[15];
57+
int i = 0;
58+
do {
59+
if(i > 10) return;
60+
M5.Lcd.println("Put the NFC Card on the reader...");
61+
// Look for new cards, and select one if present
62+
delay(500);
63+
i++;
64+
} while (! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial());
65+
66+
// Now a card is selected. The UID and SAK is in mfrc522.uid.
67+
//M5.Speaker.beep();
68+
69+
// Dump UID
70+
Serial.print(F("Card UID:"));
71+
for (byte i = 0; i < mfrc522.uid.size; i++) {
72+
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
73+
Serial.print(mfrc522.uid.uidByte[i], HEX);
74+
sprintf(&cardUid[i * 2], "%02X", mfrc522.uid.uidByte[i]);
75+
//M5.Lcd.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
76+
//M5.Lcd.print(mfrc522.uid.uidByte[i], HEX);
77+
}
78+
Serial.println();
79+
80+
ez.msgBox("Card UID", cardUid);
81+
}
82+
83+
void show_reader_infos() {
84+
// Get the MFRC522 software version
85+
byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
86+
Serial.print(F("MFRC522 Software Version: 0x"));
87+
Serial.print(v, HEX);
88+
if (v == 0x91) {
89+
Serial.print(F(" = v1.0"));
90+
ez.msgBox("MFRC522 Software Version", "Version v1.0");
91+
} else if (v == 0x92){
92+
Serial.print(F(" = v2.0"));
93+
ez.msgBox("MFRC522 Software Version", "Version v2.0");
94+
} else {
95+
Serial.print(F(" (unknown)"));
96+
ez.msgBox("MFRC522 Software Version", "Unknown version");
97+
}
98+
Serial.println("");
99+
// When 0x00 or 0xFF is returned, communication probably failed
100+
if ((v == 0x00) || (v == 0xFF)) {
101+
Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));
102+
ez.msgBox("MFRC522 Software Version", "Communication failure, is the MFRC522 properly connected?");
103+
}
104+
}
105+
106+
void menu_not_implemented() {
107+
ez.msgBox("Not implemented", "To be implemented");
108+
}
109+
110+
void menu_m5hack() {
111+
ezMenu systemenu("Spawnrider M5H@ck");
112+
systemenu.txtSmall();
113+
systemenu.addItem("System Information", sysInfo);
114+
systemenu.addItem("WiFi Settings", ez.wifi.menu);
115+
systemenu.addItem("About M5H@ck", aboutM5Hack);
116+
systemenu.addItem("Updates via https", mainmenu_ota);
117+
systemenu.addItem("Power Off", powerOff);
118+
systemenu.addItem("Back");
119+
systemenu.upOnFirst("last|up");
120+
systemenu.downOnLast("first|down");
121+
systemenu.run();
122+
}
123+
124+
void mainmenu_ota() {
125+
if (ez.msgBox("Get OTA_https", "This will replace the current program with a new version from GitHub.", "Cancel#OK#") == "OK") {
126+
ezProgressBar progress_bar("OTA update in progress", "Downloading ...", "Abort");
127+
#include "raw_githubusercontent_com.h" // the root certificate is now in const char * root_cert
128+
ESP.restart();
129+
if (ez.wifi.update("https://raw.githubusercontent.com/ropg/M5ez/master/compiled_binaries/OTA_https.bin", root_cert, &progress_bar)) {
130+
ez.msgBox("Over The Air updater", "OTA download successful. Reboot to new firmware", "Reboot");
131+
ESP.restart();
132+
} else {
133+
ez.msgBox("OTA error", ez.wifi.updateError(), "OK");
134+
}
135+
}
136+
}
137+
138+
void powerOff() {
139+
m5.powerOFF();
140+
}
141+
142+
void aboutM5Hack() {
143+
ez.msgBox("About M5H@ck", "M5H@ck was written by | Yohann Ciurlik | | https://spawnrider.net");
144+
}

raw_githubusercontent_com.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// This is the root certificate include file for raw.githubusercontent.com
2+
// as obtained by the get_cert script on: Wed Aug 15 20:22:14 CEST 2018
3+
//
4+
//
5+
// Certificate info:
6+
// issuer= /C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV Root CA
7+
// notAfter=Oct 22 12:00:00 2028 GMT
8+
//
9+
10+
const char* root_cert = \
11+
"-----BEGIN CERTIFICATE-----\n" \
12+
"MIIEsTCCA5mgAwIBAgIQBOHnpNxc8vNtwCtCuF0VnzANBgkqhkiG9w0BAQsFADBs\n" \
13+
"MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" \
14+
"d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5j\n" \
15+
"ZSBFViBSb290IENBMB4XDTEzMTAyMjEyMDAwMFoXDTI4MTAyMjEyMDAwMFowcDEL\n" \
16+
"MAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3\n" \
17+
"LmRpZ2ljZXJ0LmNvbTEvMC0GA1UEAxMmRGlnaUNlcnQgU0hBMiBIaWdoIEFzc3Vy\n" \
18+
"YW5jZSBTZXJ2ZXIgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2\n" \
19+
"4C/CJAbIbQRf1+8KZAayfSImZRauQkCbztyfn3YHPsMwVYcZuU+UDlqUH1VWtMIC\n" \
20+
"Kq/QmO4LQNfE0DtyyBSe75CxEamu0si4QzrZCwvV1ZX1QK/IHe1NnF9Xt4ZQaJn1\n" \
21+
"itrSxwUfqJfJ3KSxgoQtxq2lnMcZgqaFD15EWCo3j/018QsIJzJa9buLnqS9UdAn\n" \
22+
"4t07QjOjBSjEuyjMmqwrIw14xnvmXnG3Sj4I+4G3FhahnSMSTeXXkgisdaScus0X\n" \
23+
"sh5ENWV/UyU50RwKmmMbGZJ0aAo3wsJSSMs5WqK24V3B3aAguCGikyZvFEohQcft\n" \
24+
"bZvySC/zA/WiaJJTL17jAgMBAAGjggFJMIIBRTASBgNVHRMBAf8ECDAGAQH/AgEA\n" \
25+
"MA4GA1UdDwEB/wQEAwIBhjAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIw\n" \
26+
"NAYIKwYBBQUHAQEEKDAmMCQGCCsGAQUFBzABhhhodHRwOi8vb2NzcC5kaWdpY2Vy\n" \
27+
"dC5jb20wSwYDVR0fBEQwQjBAoD6gPIY6aHR0cDovL2NybDQuZGlnaWNlcnQuY29t\n" \
28+
"L0RpZ2lDZXJ0SGlnaEFzc3VyYW5jZUVWUm9vdENBLmNybDA9BgNVHSAENjA0MDIG\n" \
29+
"BFUdIAAwKjAoBggrBgEFBQcCARYcaHR0cHM6Ly93d3cuZGlnaWNlcnQuY29tL0NQ\n" \
30+
"UzAdBgNVHQ4EFgQUUWj/kK8CB3U8zNllZGKiErhZcjswHwYDVR0jBBgwFoAUsT7D\n" \
31+
"aQP4v0cB1JgmGggC72NkK8MwDQYJKoZIhvcNAQELBQADggEBABiKlYkD5m3fXPwd\n" \
32+
"aOpKj4PWUS+Na0QWnqxj9dJubISZi6qBcYRb7TROsLd5kinMLYBq8I4g4Xmk/gNH\n" \
33+
"E+r1hspZcX30BJZr01lYPf7TMSVcGDiEo+afgv2MW5gxTs14nhr9hctJqvIni5ly\n" \
34+
"/D6q1UEL2tU2ob8cbkdJf17ZSHwD2f2LSaCYJkJA69aSEaRkCldUxPUd1gJea6zu\n" \
35+
"xICaEnL6VpPX/78whQYwvwt/Tv9XBZ0k7YXDK/umdaisLRbvfXknsuvCnQsH6qqF\n" \
36+
"0wGjIChBWUMo0oHjqvbsezt3tkBigAVBRQHvFwY+3sAzm2fTYS5yh+Rp/BIAV0Ae\n" \
37+
"cPUeybQ=\n" \
38+
"-----END CERTIFICATE-----\n";

z-sysinfo.ino

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
*
3+
* This is a "z-sketch". It means you can run this sketch on its own, or use it as a sub-sketch of some bigger program
4+
* See the M5ez user manual under z-sketches at https://github.com/ropg/M5ez
5+
*
6+
*/
7+
8+
#ifndef MAIN_DECLARED
9+
10+
#include <M5Stack.h>
11+
#include <M5ez.h>
12+
13+
void setup() {
14+
ez.begin();
15+
sysInfo();
16+
}
17+
18+
void loop() {
19+
20+
}
21+
22+
String exit_button = "";
23+
24+
#else
25+
26+
String exit_button = "Exit";
27+
28+
#endif // #ifndef MAIN_DECLARED
29+
30+
31+
32+
void sysInfo() {
33+
sysInfoPage1();
34+
while(true) {
35+
String btn = ez.buttons.poll();
36+
if (btn == "up") sysInfoPage1();
37+
if (btn == "down") sysInfoPage2();
38+
if (btn == "Exit") break;
39+
}
40+
}
41+
42+
#include <SPIFFS.h>
43+
44+
void sysInfoPage1() {
45+
const byte tab = 120;
46+
ez.screen.clear();
47+
ez.header.show("System Info (1/2)");
48+
ez.buttons.show("#" + exit_button + "#down");
49+
ez.canvas.font(&FreeSans9pt7b);
50+
ez.canvas.lmargin(10);
51+
ez.canvas.println("");
52+
ez.canvas.print("CPU freq:"); ez.canvas.x(tab); ez.canvas.println(String(ESP.getCpuFreqMHz()) + " MHz");
53+
ez.canvas.print("CPU cores:"); ez.canvas.x(tab); ez.canvas.println("2"); // :)
54+
ez.canvas.print("Chip rev.:"); ez.canvas.x(tab); ez.canvas.println(String(ESP.getChipRevision()));
55+
ez.canvas.print("Flash speed:"); ez.canvas.x(tab); ez.canvas.println(String(ESP.getFlashChipSpeed() / 1000000) + " MHz");
56+
ez.canvas.print("Flash size:"); ez.canvas.x(tab); ez.canvas.println(String(ESP.getFlashChipSize() / 1000000) + " MB");
57+
ez.canvas.print("ESP SDK:"); ez.canvas.x(tab); ez.canvas.println(String(ESP.getSdkVersion()));
58+
ez.canvas.print("M5ez:"); ez.canvas.x(tab); ez.canvas.println(String(ez.version()));
59+
}
60+
61+
void sysInfoPage2() {
62+
const String SD_Type[5] = {"NONE", "MMC", "SD", "SDHC", "UNKNOWN"};
63+
const byte tab = 140;
64+
ez.screen.clear();
65+
ez.header.show("System Info (2/2)");
66+
ez.buttons.show("up#" + exit_button + "#");
67+
ez.canvas.font(&FreeSans9pt7b);
68+
ez.canvas.lmargin(10);
69+
ez.canvas.println("");
70+
ez.canvas.print("Free RAM:"); ez.canvas.x(tab); ez.canvas.println(String((long)ESP.getFreeHeap()) + " bytes");
71+
ez.canvas.print("Min. free seen:"); ez.canvas.x(tab); ez.canvas.println(String((long)esp_get_minimum_free_heap_size()) + " bytes");
72+
const int sd_type = SD.cardType();
73+
74+
SPIFFS.begin();
75+
ez.canvas.print("SPIFFS size:"); ez.canvas.x(tab); ez.canvas.println(String((long)SPIFFS.totalBytes()) + " bytes");
76+
ez.canvas.print("SPIFFS used:"); ez.canvas.x(tab); ez.canvas.println(String((long)SPIFFS.usedBytes()) + " bytes");
77+
ez.canvas.print("SD type:"); ez.canvas.x(tab); ez.canvas.println(SD_Type[sd_type]);
78+
if (sd_type != 0) {
79+
ez.canvas.print("SD size:"); ez.canvas.x(tab); ez.canvas.println(String((long)SD.cardSize() / 1000000) + " MB");
80+
ez.canvas.print("SD used:"); ez.canvas.x(tab); ez.canvas.println(String((long)SD.usedBytes() / 1000000) + " MB");
81+
}
82+
}

0 commit comments

Comments
 (0)