taler-mdb

GNU Taler Extensions and Integrations
Log | Files | Refs | Submodules | README | LICENSE

commit 71f42ce9d750d52b47a829faff0d25847dd08cf0
parent 417e41ac1d3fa7a2cd17475af34862d4332f47bf
Author: Boss Marco <bossm8@students.bfh.ch>
Date:   Sat, 16 Nov 2019 09:06:53 +0100

when no display, show on stdout

Diffstat:
Msrc/main.c | 129++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 78 insertions(+), 51 deletions(-)

diff --git a/src/main.c b/src/main.c @@ -197,10 +197,15 @@ show_qrcode (const char *uri) char *upper; size_t xOff; size_t yOff; + size_t width; + size_t height; + unsigned int scale; + + if (0 < qrDisplay.devicefd) + scale = 8; + else + scale = 1; - size_t width = qrDisplay.var_info.xres; - size_t height = qrDisplay.var_info.yres; - const unsigned int scale = 8; const unsigned int n_channels = 3; qri = QRinput_new2 (0, QR_ECLEVEL_M); @@ -257,21 +262,42 @@ show_qrcode (const char *uri) QRcode_free (qrc); QRinput_free (qri); - /* show the qrcode */ - xOff = (height - size) / 2; - yOff = (width - size) / 2; - for (size_t row = xOff; row < height; row++) + if (0 < qrDisplay.devicefd) { - for (size_t col = yOff; col < width; col++) + width = qrDisplay.var_info.xres; + height = qrDisplay.var_info.yres; + /* show the qrcode */ + xOff = (height - size) / 2; + yOff = (width - size) / 2; + for (size_t row = xOff; row < height; row++) { - if (((row - xOff) < size)&&((col - yOff) < size)) + for (size_t col = yOff; col < width; col++) + { + if (((row - xOff) < size)&&((col - yOff) < size)) + { + for (unsigned int c = 0; c < n_channels; c++) + { + qrDisplay.memory[(row * width + col)] = + pixels[((row - xOff) * size + (col - yOff)) * n_channels + c]; + } + } + } + } + } + else + { + /* show on stdout */ + for (size_t row = 0; row < size; row++) + { + for (size_t col = 0; col < size; col++) { for (unsigned int c = 0; c < n_channels; c++) { - qrDisplay.memory[(row * width + col)] = - pixels[((row - xOff) * size + (col - yOff)) * n_channels + c]; + printf ("%c", (pixels[(row * size + col) * n_channels + c] == 0x00 ? + '#' : ' ')); } } + printf ("\n"); } } @@ -1057,59 +1083,60 @@ run (void *cls, /* open the framebuffer device */ qrDisplay.devicefd = open (FRAMEBUFFER_DEVICE, O_RDWR); - if (0 > qrDisplay.devicefd) + if (0 < qrDisplay.devicefd) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "open(), could not open framebuffer device %s", - FRAMEBUFFER_DEVICE); - return; - } + /* read information about the screen */ + ioctl (qrDisplay.devicefd, + FBIOGET_VSCREENINFO, + &qrDisplay.var_info); - /* read information about the screen */ - ioctl (qrDisplay.devicefd, - FBIOGET_VSCREENINFO, - &qrDisplay.var_info); + /* store current screeninfo for reset */ + memcpy (&qrDisplay.orig_vinfo, + &qrDisplay.var_info, + sizeof(struct fb_var_screeninfo)); - /* store current screeninfo for reset */ - memcpy (&qrDisplay.orig_vinfo, - &qrDisplay.var_info, - sizeof(struct fb_var_screeninfo)); + if (8 != qrDisplay.var_info.bits_per_pixel) + { + /* Change variable info to 8bit per pixel */ + qrDisplay.var_info.bits_per_pixel = 8; + if (0 > ioctl (qrDisplay.devicefd, + FBIOPUT_VSCREENINFO, + &qrDisplay.var_info)) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Error setting display bpp to 8\n"); + return; + } + } - if (8 != qrDisplay.var_info.bits_per_pixel) - { - /* Change variable info to 8bit per pixel */ - qrDisplay.var_info.bits_per_pixel = 8; + /* Get fixed screen information */ if (0 > ioctl (qrDisplay.devicefd, - FBIOPUT_VSCREENINFO, - &qrDisplay.var_info)) + FBIOGET_FSCREENINFO, + &qrDisplay.fix_info)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Error setting display bpp to 8\n"); + "Error reading fixed display information\n"); return; } - } - /* Get fixed screen information */ - if (0 > ioctl (qrDisplay.devicefd, - FBIOGET_FSCREENINFO, - &qrDisplay.fix_info)) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Error reading fixed display information\n"); - return; + /* get pointer onto frame buffer */ + qrDisplay.memory = (uint8_t *) mmap (NULL, + qrDisplay.fix_info.smem_len, + PROT_READ | PROT_WRITE, MAP_SHARED, + qrDisplay.devicefd, + 0); + if (0 > qrDisplay.devicefd) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "failed to map display memory\n"); + return; + } } - - /* get pointer onto frame buffer */ - qrDisplay.memory = (uint8_t *) mmap (NULL, - qrDisplay.fix_info.smem_len, - PROT_READ | PROT_WRITE, MAP_SHARED, - qrDisplay.devicefd, - 0); - if (0 > qrDisplay.devicefd) + else { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "failed to map display memory\n"); - return; + "open(), could not open framebuffer device %s\n", + FRAMEBUFFER_DEVICE); } #endif