ricmoo / QRCode

QR code generation library in C, optimized for low-power devices, such as Arduino.
Other
656 stars 204 forks source link

QR code type 10 or higher not scanable #32

Open vdneut opened 3 years ago

vdneut commented 3 years ago

The qr codes generated and displayed on a 320x480 TFT / Arduino MEGA can be scanned using an average qr-code scanner app, up to type 9. Using type 10 or higher, the app does not scan the code.

qrcode_initText retruns 0 (zero). Seems to be ok.

See code below, including the output: type 9 is working and type 10 is not working

Not sure if it is something I did wrong, or any other reason. Help is greatly appreciated!

Kind regards

#include "qrcode.h"
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
#include <SPI.h>          // f.k. for Arduino-1.5.2
#include "Adafruit_GFX.h"// Hardware-specific library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#define BLACK   0x0000
#define WHITE   0xFFFF

void setup() {
    int qr_return;
    // Create the QR code
    QRCode qrcode;
    uint8_t qrcodeData9[qrcode_getBufferSize(9)]; 

    qrcode_initText(&qrcode, qrcodeData9, 9, 0, "https://a.nl?b=HelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHel0123456789");

    uint16_t ID = tft.readID(); //
    tft.begin(ID);
    tft.fillScreen(WHITE);

    uint8_t qr_size = 5;
    uint8_t qr_top = 20;
    uint8_t qr_left = (320 / 2) - int((qrcode.size * qr_size) / 2);  // Center

    // Each line of modules
    for (uint8_t y = 0; y < qrcode.size; y++) {
        // Each horizontal module
        for (uint8_t x = 0; x < qrcode.size; x++) {
          if (qrcode_getModule(&qrcode, x, y)) {

            tft.fillRect(qr_left + (qr_size * x), qr_top + (qr_size * y), qr_size, qr_size, BLACK);
          }
        }
    }

    uint8_t qrcodeData10[qrcode_getBufferSize(10)]; 
    qrcode_initText(&qrcode, qrcodeData10, 10, 0, "https://a.nl?b=HelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHel0123456789");

    qr_left = (320 / 2) - int((qrcode.size * qr_size) / 2);  // Center
    tft.fillScreen(WHITE);
    // Each line of modules
    for (uint8_t y = 0; y < qrcode.size; y++) {
        // Each horizontal module
        for (uint8_t x = 0; x < qrcode.size; x++) {
          if (qrcode_getModule(&qrcode, x, y)) {

            tft.fillRect(qr_left + (qr_size * x), qr_top + (qr_size * y), qr_size, qr_size, BLACK);
          }
        }
    }
}

void loop() {

}

Type 9 is working typ9-works

Type 10 is not working type10-not-working

vdneut commented 2 years ago

Status: not solved

And did some digging and found that LOCK_VERSION could be set to 10 and create smaller arrays (it might be a memory problem?). But no effect.

Has anyone tested this with type 10 or higher?

To be complete, I include the arrays for type 10:

`#elif LOCK_VERSION == 10

static const int16_t NUM_ERROR_CORRECTION_CODEWORDS[4] = { 130, 72, 224, 192 };

static const int8_t NUM_ERROR_CORRECTION_BLOCKS[4] = { 5, 4, 8, 8 };

static const uint16_t NUM_RAW_DATA_MODULES = 2768; `

vdneut commented 2 years ago

Status: Solved Within function getModeBits() in qrcode.c Change unsigned int modeInfo = 0x7bbb80a; Into unsigned long modeInfo = 0x7bbb80a; To avoid truncation of 0x7bbb80a. To reproduce: use the int and compile with warning level high or 'all'. @ricmoo or @per1234 could you please solve this bug in the library? Regards