gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-mdb] 55/93: better solution, still bugs


From: gnunet
Subject: [taler-taler-mdb] 55/93: better solution, still bugs
Date: Mon, 18 Nov 2019 21:13:18 +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 62c43ee9b56097dcb78caddf21f678fb1234909b
Author: Boss Marco <address@hidden>
AuthorDate: Fri Nov 15 09:38:51 2019 +0100

    better solution, still bugs
---
 src/main.c | 95 ++++++++++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 65 insertions(+), 30 deletions(-)

diff --git a/src/main.c b/src/main.c
index 4d43a86..5b4eb37 100644
--- a/src/main.c
+++ b/src/main.c
@@ -134,6 +134,19 @@ struct PaymentActivity
   int wallet_has_uri;
 };
 
+struct Display
+{
+  int devicefd;
+
+  uint16_t *memory;
+
+  struct fb_var_screeninfo orig_vinfo;
+
+  struct fb_var_screeninfo var_info;
+
+  struct fb_fix_screeninfo fix_info;
+};
+
 
 static nfc_context *context;
 
@@ -159,6 +172,8 @@ static struct PaymentActivity *payment_activity;
 
 static struct Product *products;
 
+static struct Display qrDisplay;
+
 static unsigned int products_length;
 
 
@@ -182,50 +197,61 @@ show_qrcode (const char *uri)
   /* 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)
+  qrDisplay.devicefd = open (FRAMEBUFFER_DEVICE,
+                             O_RDWR);
+  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 (fbfd,
+  ioctl (qrDisplay.devicefd,
          FBIOGET_VSCREENINFO,
-         &screeninfo);
+         &qrDisplay.var_info);
+
+  /* store current screeninfo for reset */
+  memcpy (&qrDisplay.orig_vinfo,
+          &qrDisplay.var_info,
+          sizeof(struct fb_var_screeninfo));
 
-  /* cancel if the resolution is not 16 bit per pixel */
-  size_t bitspp = screeninfo.bits_per_pixel;
-  if (bitspp != 16)
+  if (qrDisplay.var_info.bits_per_pixel != 16)
   {
-    printf ("Color depth = %ld bits per pixel\n", bitspp);
-    printf ("Change the color depth to 16 bits per pixel\n");
-    close (fbfd);
-    return;
+    /* Change variable info to 8bit per pixel */
+    qrDisplay.var_info.bits_per_pixel = 16;
+    if (0 > ioctl (qrDisplay.devicefd,
+                   FBIOPUT_VSCREENINFO,
+                   &qrDisplay.var_info))
+    {
+      printf ("Error setting variable information.\n");
+      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)
+  /* Get fixed screen information */
+  if (0 > ioctl (qrDisplay.devicefd,
+                 FBIOGET_FSCREENINFO,
+                 &qrDisplay.fix_info))
   {
-    close (fbfd);
+    printf ("Error reading fixed information.\n");
     return;
   }
 
   /* get pointer onto frame buffer */
-  uint16_t *data = (uint16_t *) mmap (NULL,
-                                      width * height * bytespp,
-                                      PROT_READ | PROT_WRITE, MAP_SHARED,
-                                      fbfd,
-                                      0);
+  qrDisplay.memory = (uint16_t *) mmap (NULL,
+                                        qrDisplay.fix_info.smem_len,
+                                        PROT_READ | PROT_WRITE, MAP_SHARED,
+                                        qrDisplay.devicefd,
+                                        0);
+  if (0 > qrDisplay.devicefd)
+  {
+    printf ("failed to map display memory\n");
+    return;
+  }
 
   qri = QRinput_new2 (0, QR_ECLEVEL_M);
   if (NULL == qri)
@@ -275,13 +301,15 @@ 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)) ? 0xFFFF : 0;
+          (0 == (qrc->data[off] & 1)) ? 0xFFFF : 0x0000;
     }
   /* FIXME ? free errors */
   // QRcode_free (qrc);
   // QRinput_free (qri);
 
   /* show the qrcode */
+  size_t width = qrDisplay.var_info.xres;
+  size_t height = qrDisplay.var_info.yres;
   int xOff = (height - size) / 2;
   int yOff = (width - size) / 2;
   for (size_t row = xOff; row < height; row++)
@@ -292,7 +320,7 @@ show_qrcode (const char *uri)
       {
         for (unsigned int c = 0; c < n_channels; c++)
         {
-          data[(row * width + col)] =
+          qrDisplay.memory[(row * width + col)] =
             pixels[((row - xOff) * size + (col - yOff)) * n_channels + c];
         }
       }
@@ -300,11 +328,18 @@ show_qrcode (const char *uri)
   }
 
   /* free the data  */
-  /* FIXME error */
-  munmap (data, width * height * bytespp);
+  munmap (qrDisplay.memory,
+          qrDisplay.fix_info.smem_len);
+  /* reset original state */
+  if (0 > ioctl (qrDisplay.devicefd,
+                 FBIOPUT_VSCREENINFO,
+                 &qrDisplay.orig_vinfo))
+  {
+    printf ("Error re-setting variable information.\n");
+  }
 
   /* close device */
-  close (fbfd);
+  close (qrDisplay.devicefd);
 
   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]