flipperzero-firmware/applications/examples/u8g2_qrcode.c

71 lines
2.0 KiB
C
Raw Normal View History

#include "u8g2/u8g2.h"
#include "qrcode/qrcode.h"
#include "flipper.h"
void u8g2_DrawPixelSize(u8g2_t* u8g2, uint8_t x, uint8_t y, uint8_t size) {
for(uint8_t px = 0; px < size; px++) {
for(uint8_t py = 0; py < size; py++) {
u8g2_DrawPixel(u8g2, x + px, y + py);
}
}
}
void u8g2_qrcode(void* p) {
FuriRecordSubscriber* log = get_default_log();
// open record
Core api concept (#144) * add input debounce code from old fw * exampl of input api * change input API to get/release * revert input API to read * pointer instead of instance * add input API description * add display API * rewrite display names * migrate to valuemanager * add LED API * add closing brakets * add sound api * fix led api * basic api * rename API pages * change pubsub implementation * move FURI AC -> flapp, add valuemutex example, add valuemanager implementation * pubsub usage example * user led example * update example * simplify input * add composed display * add SPI/GPIO and CC1101 bus * change cc1101 api * spi api and devices * spi api and devices * move SPI to page, add GPIO * not block pin open * backlight API and more * add minunit tests * fix logging * ignore unexisting time service on embedded targets * fix warning, issue with printf * Deprecate furi_open and furi_close (#167) Rename existing furi_open and furi_close to deprecated version * add exitcode * migrate to printf * indicate test by leds * add testing description * rename furi.h * wip basic api * add valuemutex, pubsub, split files * add value expanders * value mutex realization and tests * valuemutex test added to makefile * do not build unimplemented files * fix build furmware target f2 * redesigned minunit tests to allow testing in separate files * test file for valuemutex minunit testing * minunit partial test valuemutex * local cmsis_os2 mutex bindings * implement furi open/create, tests * migrate concurrent_access to ValueMutex * add spi header * Lib: add mlib submodule. Co-authored-by: rusdacent <rusdacentx0x08@gmail.com> Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
2020-10-13 08:22:43 +00:00
FuriRecordSubscriber* fb_record = furi_open_deprecated("u8g2_fb", false, false, NULL, NULL, NULL);
// Allocate a chunk of memory to store the QR code
// https://github.com/ricmoo/QRCode
// we init version 1, 21x21 px, 16 alphanumeric chars with
// QUARTILE error correction
const uint8_t qr_version = 1;
const uint8_t qr_error_correction = ECC_QUARTILE;
const uint8_t qr_x = 32;
const uint8_t qr_y = 0;
const uint8_t qr_size = 3;
// The structure to manage the QR code
QRCode qrcode;
// QR Code init
uint8_t qrcodeBytes[qrcode_getBufferSize(qr_version)];
qrcode_initText(&qrcode, qrcodeBytes, qr_version, qr_error_correction, "HELLO FLIPPER");
if(fb_record == NULL) {
fuprintf(log, "[widget] cannot create fb record\n");
furiac_exit(NULL);
}
u8g2_t* fb = furi_take(fb_record);
// clear display
if(fb != NULL) {
u8g2_ClearBuffer(fb);
}
while(1) {
if(fb != NULL) {
// draw qr code
for(uint8_t y = 0; y < qrcode.size; y++) {
for(uint8_t x = 0; x < qrcode.size; x++) {
if(qrcode_getModule(&qrcode, x, y)) {
u8g2_SetDrawColor(fb, 1);
u8g2_DrawPixelSize(fb, qr_x + x * qr_size, qr_y + y * qr_size, qr_size);
} else {
u8g2_SetDrawColor(fb, 0);
u8g2_DrawPixelSize(fb, qr_x + x * qr_size, qr_y + y * qr_size, qr_size);
}
}
}
} else {
furiac_exit(NULL);
}
furi_commit(fb_record);
delay(1);
}
}