Skip to content

Commit

Permalink
Add argument to take QR code standard margin. ( thanks @GOB52 )
Browse files Browse the repository at this point in the history
  • Loading branch information
lovyan03 committed Nov 5, 2024
1 parent 330782d commit eec5c87
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/lgfx/v1/LGFXBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2575,7 +2575,7 @@ namespace lgfx

//----------------------------------------------------------------------------

void LGFXBase::qrcode(const char *string, int32_t x, int32_t y, int32_t w, uint8_t version) {
void LGFXBase::qrcode(const char *string, int32_t x, int32_t y, int32_t w, uint8_t version, bool margin) {
if (w == -1) {
w = std::min(width(), height()) * 9 / 10;
}
Expand All @@ -2592,6 +2592,16 @@ namespace lgfx
int_fast16_t thickness = w / qrcode.size;
int_fast16_t lineLength = qrcode.size * thickness;
int_fast16_t offset = (w - lineLength) >> 1;

if(margin) {
int_fast16_t mlen = thickness * 4; // Need 4 cell or greater margin
if(offset < mlen) {
thickness = (w - (mlen << 1)) / qrcode.size;
lineLength = qrcode.size * thickness;
offset = (w - lineLength) >> 1;
}
}

startWrite();
writeFillRect(x, y, w, offset, TFT_WHITE);
int_fast16_t dy = y + offset;
Expand Down
2 changes: 1 addition & 1 deletion src/lgfx/v1/LGFXBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ namespace lgfx
qrcode(string.c_str(), x, y, width, version);
}
#endif
void qrcode(const char *string, int32_t x = -1, int32_t y = -1, int32_t width = -1, uint8_t version = 1);
void qrcode(const char *string, int32_t x = -1, int32_t y = -1, int32_t width = -1, uint8_t version = 1,bool margin = false);

#define LGFX_FUNCTION_GENERATOR(drawImg, draw_img) \
protected: \
Expand Down

0 comments on commit eec5c87

Please sign in to comment.