commit 82126b9d0c1b640bd59a21dfa97677ded686fd4d
parent eca20f0a874ebb73e55c243882c10c44b5e50b9e
Author: Boss Marco <bossm8@students.bfh.ch>
Date: Fri, 15 Nov 2019 21:58:32 +0100
stick to convention
Diffstat:
| M | src/main.c | | | 176 | +++++++++++++++++++++++++++++++++++++++++++++---------------------------------- |
1 file changed, 100 insertions(+), 76 deletions(-)
diff --git a/src/main.c b/src/main.c
@@ -106,15 +106,17 @@ static const uint8_t get_data[] = { 0x00, 0xCA, 0x01, 0x00, 0x00, 0x00 };
struct Product
{
struct TALER_Amount price;
+
char *description;
+
char *number;
+
char key;
};
struct PaymentActivity
{
-
struct TALER_MERCHANT_ProposalOperation *po;
struct TALER_MERCHANT_CheckPaymentOperation *cpo;
@@ -193,65 +195,14 @@ show_qrcode (const char *uri)
uint8_t *pixels;
unsigned int size;
char *upper;
+ size_t xOff;
+ size_t yOff;
+ 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;
- /* open the framebuffer device */
- 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 (qrDisplay.devicefd,
- FBIOGET_VSCREENINFO,
- &qrDisplay.var_info);
-
- /* store current screeninfo for reset */
- memcpy (&qrDisplay.orig_vinfo,
- &qrDisplay.var_info,
- sizeof(struct fb_var_screeninfo));
-
- if (qrDisplay.var_info.bits_per_pixel != 8)
- {
- /* Change variable info to 8bit per pixel */
- qrDisplay.var_info.bits_per_pixel = 8;
- if (0 > ioctl (qrDisplay.devicefd,
- FBIOPUT_VSCREENINFO,
- &qrDisplay.var_info))
- {
- printf ("Error setting variable information.\n");
- return;
- }
- }
-
- /* Get fixed screen information */
- if (0 > ioctl (qrDisplay.devicefd,
- FBIOGET_FSCREENINFO,
- &qrDisplay.fix_info))
- {
- printf ("Error reading fixed 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)
- {
- printf ("failed to map display memory\n");
- return;
- }
-
qri = QRinput_new2 (0, QR_ECLEVEL_M);
if (NULL == qri)
{
@@ -307,10 +258,8 @@ show_qrcode (const char *uri)
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;
+ xOff = (height - size) / 2;
+ yOff = (width - size) / 2;
for (size_t row = xOff; row < height; row++)
{
for (size_t col = yOff; col < width; col++)
@@ -326,20 +275,6 @@ show_qrcode (const char *uri)
}
}
- /* free the data */
- 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 (qrDisplay.devicefd);
-
GNUNET_free (pixels);
}
@@ -381,10 +316,23 @@ cleanup_payment (struct PaymentActivity *pa)
GNUNET_SCHEDULER_cancel (pa->task);
if (NULL != pa->delay_task)
GNUNET_SCHEDULER_cancel (pa->delay_task);
- /* FIXME - cont. also abort when nfc device gets disconnected (maybe this is ok? because nfc is mandatory) */
GNUNET_free_non_null (pa->taler_pay_uri);
GNUNET_free_non_null (pa->order_id);
GNUNET_free (pa);
+
+#if HAVE_QRENCODE_H
+ if (NULL != qrDisplay.memory)
+ {
+ for (size_t row = 0; row < qrDisplay.var_info.yres; row++)
+ {
+ for (size_t col = 0; col < qrDisplay.var_info.xres; col++)
+ {
+ qrDisplay.memory[(row * qrDisplay.var_info.yres + col)] = 0xFF;
+ }
+ }
+ }
+ /* FIXME: dimm background light of display */
+#endif
}
@@ -421,6 +369,23 @@ shutdown_task (void *cls)
GNUNET_CURL_gnunet_rc_destroy (rc);
rc = NULL;
}
+ if (NULL != qrDisplay.memory)
+ {
+ /* free the display data */
+ munmap (qrDisplay.memory,
+ qrDisplay.fix_info.smem_len);
+ /* reset original state */
+ if (0 > ioctl (qrDisplay.devicefd,
+ FBIOPUT_VSCREENINFO,
+ &qrDisplay.orig_vinfo))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "failed to reset originial display state\n");
+ }
+
+ /* close device */
+ close (qrDisplay.devicefd);
+ }
if (NULL != products)
{
for (unsigned int i = 0; i < products_length; i++)
@@ -689,7 +654,6 @@ check_payment_cb (void *cls,
{
fprintf (stderr,
"FIXME: yield product here!\n");
- /* FIXME: hide QR code here! */
/* FIXME: later: continue to offer Internet UNTIL
NFC device disconnects (if NFC connected) */
cleanup_payment (pa);
@@ -1089,6 +1053,66 @@ run (void *cls,
GNUNET_assert (GNUNET_OK ==
GNUNET_CURL_append_header (ctx,
authorization));
+#if HAVE_QRENCODE_H
+ /* open the framebuffer device */
+ 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 (qrDisplay.devicefd,
+ FBIOGET_VSCREENINFO,
+ &qrDisplay.var_info);
+
+ /* 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;
+ }
+ }
+
+ /* 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;
+ }
+#endif
+
start_read_keyboard ();
}