knob_os/tools/qr_dump.cpp

26 lines
716 B
C++
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// 主机侧验证用:把 QR 矩阵打到 stdout,供 tools/qr_verify.py 与 python qrcode 比对。
// 只在开发机上编译,不进固件。
#include <stdio.h>
#include <string.h>
#include "../src/ui/QrCode.h"
int main(int argc, char** argv) {
if (argc < 2) {
fprintf(stderr, "usage: qr_dump <text>\n");
return 2;
}
static uint8_t buf[160 * 160];
int side = 0, mask = 0;
if (!ui::qrEncode(argv[1], buf, 160, side, mask)) {
printf("FAIL\n");
return 1;
}
printf("%d %d\n", side, mask);
for (int y = 0; y < side; y++) {
for (int x = 0; x < side; x++) putchar(buf[y * side + x] ? '1' : '0');
putchar('\n');
}
return 0;
}