gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-mdb] branch master updated: added cancel button via gpio


From: gnunet
Subject: [taler-taler-mdb] branch master updated: added cancel button via gpio
Date: Fri, 27 Dec 2019 12:35:40 +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.

The following commit(s) were added to refs/heads/master by this push:
     new 04e8be6  added cancel button via gpio
04e8be6 is described below

commit 04e8be6f8f49e86366b6a0957b0c8d056c749c88
Author: Boss Marco <address@hidden>
AuthorDate: Fri Dec 27 12:35:33 2019 +0100

    added cancel button via gpio
---
 src/main.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 86 insertions(+), 4 deletions(-)

diff --git a/src/main.c b/src/main.c
index c62c352..9ffabce 100644
--- a/src/main.c
+++ b/src/main.c
@@ -192,20 +192,20 @@ along with
 /* Session Commands */
 /* Refer to the mdb interface specifications v4.2 p.131 */
 #define READER_BEGIN_SESSION "03"
-#define READER_FUNDS_AVAILABLE "FFFF"
+#define READER_FUNDS_AVAILABLE "000A"
 #define READER_END_SESSION "07"
 
 /* Vend Commands */
 /* Refer to the mdb interface specifications v4.2 p.134 */
 #define READER_VEND_APPROVE "05"
-#define READER_VEND_AMOUNT "0001"
+#define READER_VEND_AMOUNT "FFFE"
 #define READER_VEND_DENIED "06"
 
 /* Revalue */
 #define READER_REVALUE_APPROVED "0D"
 #define READER_REVALUE_APPROVED "0D"
 #define READER_REVALUE_LIMIT "0F"
-#define READER_REVALUE_LIMIT_AMOUNT "FFFF"
+#define READER_REVALUE_LIMIT_AMOUNT "FFFE"
 
 /* Cancelled Command */
 #define READER_CANCELLED "08"
@@ -426,7 +426,6 @@ struct Display
   struct fb_fix_screeninfo fix_info;
 };
 
-
 /**
  * DLL of pending refund operations.
  */
@@ -480,6 +479,8 @@ static int in_shutdown;
  */
 static struct GNUNET_SCHEDULER_Task *keyboard_task;
 
+static struct GNUNET_SCHEDULER_Task *cancelbutton_task;
+
 /**
  * Curl context for communication with taler backend
  */
@@ -600,6 +601,11 @@ static char backlight_on = '1';
  */
 static char backlight_off = '0';
 
+struct CancelButton
+{
+  int cancelbuttonfd;
+};
+static struct CancelButton cancelButton;
 /**
  * Name of the UART device with the MDB (i.e. /dev/ttyAMA0).
  */
@@ -1349,6 +1355,8 @@ proposal_cb (void *cls,
                                           pa);
 }
 
+static void
+start_read_cancel_button ();
 
 /**
  * @brief Launch a new order
@@ -1413,6 +1421,8 @@ launch_payment (struct Product *product)
     GNUNET_free (pa);
     return NULL;
   }
+  if (0 > cancelButton.cancelbuttonfd)
+    start_read_cancel_button ();
   return pa;
 }
 
@@ -1619,6 +1629,36 @@ read_keyboard_command (void *cls)
   start_read_keyboard ();
 }
 
+static void
+cancel_button_pressed (void *cls)
+{
+  (void) cls;
+  char value;
+  cancelbutton_task = NULL;
+
+  read (cancelButton.cancelbuttonfd, &value, 1);
+  lseek (cancelButton.cancelbuttonfd, 0, SEEK_SET);
+  if ( '1' == value )
+  {
+    if (GNUNET_NO == payment_activity->paid)
+    {
+      mdb.cmd = &denyVend;
+    }
+    else
+    {
+      mdb.cmd = &endSession;
+      mdb.session_running = GNUNET_NO;
+    }
+    run_mdb_event_loop ();
+    cleanup_payment (payment_activity);
+    payment_activity = NULL;
+  }
+  else
+  {
+    start_read_cancel_button ();
+  }
+}
+
 
 /**
  * @brief Wait for a keyboard input
@@ -1658,6 +1698,18 @@ start_read_keyboard ()
                                                   NULL);
 }
 
+static void
+start_read_cancel_button ()
+{
+  struct GNUNET_DISK_FileHandle fh = { cancelButton.cancelbuttonfd };
+
+  GNUNET_assert (NULL == cancelbutton_task);
+  cancelbutton_task = GNUNET_SCHEDULER_add_read_file (
+    GNUNET_TIME_UNIT_FOREVER_REL,
+    &fh,
+    &cancel_button_pressed,
+    NULL);
+}
 
 /**
  * @brief Send data to the vmc via the uart bus
@@ -2517,6 +2569,36 @@ run (void *cls,
                  GNUNET_CURL_append_header (ctx,
                                             authorization));
 
+  /* open gpio pin for cance button */
+  cancelButton.cancelbuttonfd = open ("/sys/class/gpio/export",
+                                      O_WRONLY);
+  if (0 > cancelButton.cancelbuttonfd)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Unable to open /gpio/export for cancel button\n");
+  }
+  (void) write (cancelButton.cancelbuttonfd, "17", 2);
+  close (cancelButton.cancelbuttonfd);
+
+  cancelButton.cancelbuttonfd = open ("/sys/class/gpio/gpio17/direction",
+                                      O_WRONLY);
+  if (0 > cancelButton.cancelbuttonfd)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Unable to open /gpio/gpio17/direction for cancel button\n");
+  }
+  (void) write (cancelButton.cancelbuttonfd, "in", 2);
+  close (cancelButton.cancelbuttonfd);
+
+  cancelButton.cancelbuttonfd = open ("/sys/class/gpio/gpio17/value",
+                                      O_RDONLY);
+  if (0 > cancelButton.cancelbuttonfd)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Unable to open /gpio/gpio17/value for cancel button\n");
+  }
+
+
 #if HAVE_QRENCODE_H
   /* open the framebuffer device */
   qrDisplay.devicefd = open (framebuffer_device_filename,

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



reply via email to

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