gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-mdb] 59/93: when no display, show on stdout


From: gnunet
Subject: [taler-taler-mdb] 59/93: when no display, show on stdout
Date: Mon, 18 Nov 2019 21:13:22 +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 71f42ce9d750d52b47a829faff0d25847dd08cf0
Author: Boss Marco <address@hidden>
AuthorDate: Sat Nov 16 09:06:53 2019 +0100

    when no display, show on stdout
---
 src/main.c | 129 +++++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 78 insertions(+), 51 deletions(-)

diff --git a/src/main.c b/src/main.c
index 5059385..aa2342c 100644
--- 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
 

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



reply via email to

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