Skip to content

Commit

Permalink
tests/pkg_qr-code-generator: extend with disp_dev API
Browse files Browse the repository at this point in the history
  • Loading branch information
aabadie committed May 10, 2021
1 parent 08ae972 commit a941fe5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/pkg_qr-code-generator/Makefile.board.dep
@@ -0,0 +1,5 @@
# Boards with a screen can use disp_dev
ifneq (,$(filter stm32f429i-disc% pinetime adafruit-clue,$(BOARD)))
USEMODULE += auto_init_screen
USEMODULE += disp_dev
endif
40 changes: 40 additions & 0 deletions tests/pkg_qr-code-generator/main.c
Expand Up @@ -24,10 +24,18 @@
#include <stdint.h>
#include "qrcodegen.h"

#ifdef MODULE_DISP_DEV
#include "disp_dev.h"
#endif

#ifndef MESSAGE_TO_ENCODE
#define MESSAGE_TO_ENCODE "unknown"
#endif

#ifndef IMG_SCALE
#define IMG_SCALE (9)
#endif

static uint8_t qr0[qrcodegen_BUFFER_LEN_FOR_VERSION(2)];
static uint8_t buffer[qrcodegen_BUFFER_LEN_FOR_VERSION(2)];

Expand All @@ -42,9 +50,41 @@ int main(void)
}

int size = qrcodegen_getSize(qr0);

#ifdef MODULE_DISP_DEV
/* Use the first screen */
disp_dev_reg_t *disp_dev = disp_dev_reg_find_screen(0);
if (!disp_dev) {
puts("No screen found!");
return -1;
}
disp_dev_backlight_on();

uint16_t white = UINT16_MAX;
uint16_t black = 0;
for (uint16_t y = 0; y < disp_dev_height(disp_dev->dev); ++y) {
for (uint16_t x = 0; x < disp_dev_width(disp_dev->dev); ++x) {
disp_dev_map(disp_dev->dev, x, x, y, y, &black);
}
}

const uint8_t w_offset = ( disp_dev_width(disp_dev->dev) - (size * IMG_SCALE)) / 2;
const uint8_t h_offset = ( disp_dev_height(disp_dev->dev) - (size * IMG_SCALE)) / 2;
#endif

for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
#ifdef MODULE_DISP_DEV
for (int w = x * IMG_SCALE; w < (x + 1) * IMG_SCALE; w++) {
for (int h = y * IMG_SCALE; h < (y + 1) * IMG_SCALE; h++) {
disp_dev_map(disp_dev->dev,
w + w_offset, w + w_offset, h + h_offset, h + h_offset,
(qrcodegen_getModule(qr0, x, y)) ? &white : &black);
}
}
#endif
printf("%s", qrcodegen_getModule(qr0, x, y) ? "██" : " ");

}
puts("");
}
Expand Down

0 comments on commit a941fe5

Please sign in to comment.