aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoss Marco <bossm8@students.bfh.ch>2019-12-27 12:35:33 +0100
committerBoss Marco <bossm8@students.bfh.ch>2019-12-27 12:35:33 +0100
commit04e8be6f8f49e86366b6a0957b0c8d056c749c88 (patch)
tree185337127930ab7d3e375d414a1c0c9aeca9815c
parentcc99602c0b53301c6f33ec46b5d492186ad24672 (diff)
downloadtaler-mdb-04e8be6f8f49e86366b6a0957b0c8d056c749c88.tar.gz
taler-mdb-04e8be6f8f49e86366b6a0957b0c8d056c749c88.tar.bz2
taler-mdb-04e8be6f8f49e86366b6a0957b0c8d056c749c88.zip
added cancel button via gpio
-rw-r--r--src/main.c90
1 files 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,