Skip to content

Commit aab5cf4

Browse files
committed
Added Lcd darw QRCode method
1 parent 0413821 commit aab5cf4

File tree

5 files changed

+1013
-1
lines changed

5 files changed

+1013
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <M5Stack.h>
2+
3+
void setup() {
4+
M5.begin();
5+
6+
// Display QRCode
7+
M5.Lcd.qrcode("http://www.m5stack.com");
8+
// M5.Lcd.qrcode(const char *string, uint16_t x = 50, uint16_t y = 10, uint8_t width = 220, uint8_t version = 6);
9+
}
10+
11+
void loop() {
12+
}

src/utility/Display.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2944,6 +2944,37 @@ void ILI9341::drawJpgFile(fs::FS &fs, const char *path, uint16_t x, uint16_t y,
29442944
file.close();
29452945
}
29462946

2947+
2948+
#include "qrcode.h"
2949+
void ILI9341::qrcode(const char *string, uint16_t x, uint16_t y, uint8_t width, uint8_t version) {
2950+
2951+
// Create the QR code
2952+
QRCode qrcode;
2953+
uint8_t qrcodeData[qrcode_getBufferSize(version)];
2954+
qrcode_initText(&qrcode, qrcodeData, version, 0, string);
2955+
2956+
// Top quiet zone
2957+
uint8_t thickness = width / qrcode.size;
2958+
uint16_t lineLength = qrcode.size * thickness;
2959+
uint8_t xOffset = x + (width-lineLength)/2;
2960+
uint8_t yOffset = y + (width-lineLength)/2;
2961+
fillRect(x, y, width, width, TFT_WHITE);
2962+
2963+
for (uint8_t y = 0; y < qrcode.size; y++) {
2964+
for (uint8_t x = 0; x < qrcode.size; x++) {
2965+
uint8_t q = qrcode_getModule(&qrcode, x, y);
2966+
if (q) fillRect(x * thickness + xOffset, y * thickness + yOffset, thickness, thickness, TFT_BLACK);
2967+
}
2968+
}
2969+
}
2970+
2971+
void ILI9341::qrcode(const String &string, uint16_t x, uint16_t y, uint8_t width, uint8_t version) {
2972+
int16_t len = string.length() + 2;
2973+
char buffer[len];
2974+
string.toCharArray(buffer, len);
2975+
qrcode(buffer, x, y, width, version);
2976+
}
2977+
29472978
/**************************************************************************
29482979
**
29492980
** GBK character support

src/utility/Display.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,9 @@ class ILI9341 : public Print
574574
writePixels(uint16_t *colors, uint32_t len),
575575
drawJpg(const uint8_t *jpg_data, size_t jpg_len, uint16_t x = 0, uint16_t y = 0, uint16_t maxWidth = 0, uint16_t maxHeight = 0, uint16_t offX = 0, uint16_t offY = 0, jpeg_div_t scale = JPEG_DIV_NONE),
576576
drawJpgFile(fs::FS &fs, const char *path, uint16_t x = 0, uint16_t y = 0, uint16_t maxWidth = 0, uint16_t maxHeight = 0, uint16_t offX = 0, uint16_t offY = 0, jpeg_div_t scale = JPEG_DIV_NONE),
577-
drawBmpFile(fs::FS &fs, const char *path, uint16_t x = 0, uint16_t y = 0, uint16_t maxWidth = 0, uint16_t maxHeight = 0, uint16_t offX = 0, uint16_t offY = 0);
577+
drawBmpFile(fs::FS &fs, const char *path, uint16_t x = 0, uint16_t y = 0, uint16_t maxWidth = 0, uint16_t maxHeight = 0, uint16_t offX = 0, uint16_t offY = 0),
578+
qrcode(const char *string, uint16_t x = 50, uint16_t y = 10, uint8_t width = 220, uint8_t version = 6),
579+
qrcode(const String &string, uint16_t x = 50, uint16_t y = 10, uint8_t width = 220, uint8_t version = 6);
578580

579581

580582
virtual size_t write(uint8_t);

0 commit comments

Comments
 (0)