gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-mdb] 54/93: first (half working) qrcode


From: gnunet
Subject: [taler-taler-mdb] 54/93: first (half working) qrcode
Date: Mon, 18 Nov 2019 21:13:17 +0100

This is an automated email from the git hooks/post-receive script.

marco-boss pushed a commit to branch master
in repository taler-mdb.

commit 9d728f5d22639166791e8fdbc90e80f46de33e3d
Author: Boss Marco <address@hidden>
AuthorDate: Thu Nov 14 22:37:10 2019 +0100

    first (half working) qrcode
---
 src/main.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 90 insertions(+), 6 deletions(-)

diff --git a/src/main.c b/src/main.c
index 5e727e1..4d43a86 100644
--- a/src/main.c
+++ b/src/main.c
@@ -47,6 +47,14 @@ along with
 #include <taler/taler_json_lib.h>
 #include <taler/taler_merchant_service.h>
 
+/* for adafruit pitft display */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <linux/fb.h>
+
 /**
  * Disable i18n support.
  */
@@ -77,6 +85,10 @@ along with
 /* curl auth header */
 #define SNACK_CURL_AUTH_HEADER "Authorization"
 
+/**
+ * @brief FRAMEBUFFER_DEVICE framebuffer device to diplay qr code
+ */
+const char *FRAMEBUFFER_DEVICE = "/dev/fb1";
 
 /* Wallet AID */
 static const uint8_t taler_aid[] = { 0xF0, 0x00, 0x54, 0x41, 0x4c, 0x45, 0x52 
};
@@ -163,11 +175,57 @@ show_qrcode (const char *uri)
 {
   QRinput *qri;
   QRcode *qrc;
-  uint8_t *pixels;
+  uint16_t *pixels;
   unsigned int size;
   char *upper;
-  const unsigned int scale = 3;
+
+  /* FIXME ? SEGSEV on line 277 when size >= 5 */
+  const unsigned int scale = 4;
   const unsigned int n_channels = 3;
+  struct fb_var_screeninfo screeninfo;
+
+  /* open the framebuffer device */
+  int fbfd = open (FRAMEBUFFER_DEVICE,
+                   O_RDWR);
+  if (0 > fbfd)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "open(), could not open framebuffer device %s",
+                FRAMEBUFFER_DEVICE);
+  }
+
+  /* read information about the screen */
+  ioctl (fbfd,
+         FBIOGET_VSCREENINFO,
+         &screeninfo);
+
+  /* cancel if the resolution is not 16 bit per pixel */
+  size_t bitspp = screeninfo.bits_per_pixel;
+  if (bitspp != 16)
+  {
+    printf ("Color depth = %ld bits per pixel\n", bitspp);
+    printf ("Change the color depth to 16 bits per pixel\n");
+    close (fbfd);
+    return;
+  }
+
+  size_t width  = screeninfo.xres;
+  size_t height = screeninfo.yres;
+  size_t bytespp = bitspp / 8;
+
+  /* Check if uint16_t has the same size as a pixel */
+  if (sizeof(uint16_t) != bytespp)
+  {
+    close (fbfd);
+    return;
+  }
+
+  /* get pointer onto frame buffer */
+  uint16_t *data = (uint16_t *) mmap (NULL,
+                                      width * height * bytespp,
+                                      PROT_READ | PROT_WRITE, MAP_SHARED,
+                                      fbfd,
+                                      0);
 
   qri = QRinput_new2 (0, QR_ECLEVEL_M);
   if (NULL == qri)
@@ -217,11 +275,37 @@ show_qrcode (const char *uri)
         (x * qrc->width / size) + (y * qrc->width / size) * qrc->width;
       for (unsigned int c = 0; c < n_channels; c++)
         pixels[(y * size + x) * n_channels + c] =
-          (0 == (qrc->data[off] & 1)) ? 0xFF : 0;
+          (0 == (qrc->data[off] & 1)) ? 0xFFFF : 0;
     }
-  QRcode_free (qrc);
-  QRinput_free (qri);
-  // FIXME: use 'pixels'
+  /* FIXME ? free errors */
+  // QRcode_free (qrc);
+  // QRinput_free (qri);
+
+  /* show the qrcode */
+  int xOff = (height - size) / 2;
+  int yOff = (width - size) / 2;
+  for (size_t row = xOff; row < height; row++)
+  {
+    for (size_t col = yOff; col < width; col++)
+    {
+      if (((row - xOff) < size)&&((col - yOff) < size))
+      {
+        for (unsigned int c = 0; c < n_channels; c++)
+        {
+          data[(row * width + col)] =
+            pixels[((row - xOff) * size + (col - yOff)) * n_channels + c];
+        }
+      }
+    }
+  }
+
+  /* free the data  */
+  /* FIXME error */
+  munmap (data, width * height * bytespp);
+
+  /* close device */
+  close (fbfd);
+
   GNUNET_free (pixels);
 }
 

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]