summaryrefslogtreecommitdiff
path: root/apps/plugins/lib/pluginlib_touchscreen.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2012-01-27 00:12:03 +0100
committerThomas Martitz <kugel@rockbox.org>2012-01-27 09:15:05 +0100
commitaba5c47dd6369a3612be4165a16054ebd6d74af3 (patch)
tree38f9340683618d117f6e7d9de5a6b5b8fd3ad798 /apps/plugins/lib/pluginlib_touchscreen.c
parent7c623d577beea6fce3eadaa697d5e6835d820bdf (diff)
downloadrockbox-aba5c47dd6369a3612be4165a16054ebd6d74af3.zip
rockbox-aba5c47dd6369a3612be4165a16054ebd6d74af3.tar.gz
rockbox-aba5c47dd6369a3612be4165a16054ebd6d74af3.tar.bz2
rockbox-aba5c47dd6369a3612be4165a16054ebd6d74af3.tar.xz
pluginlib_touchscreen: Rework API to offer wait-for-button APIs.
The old touchscreen_get() needed an external button_get() call. Now two APIs are added that do this call internally. This way they behave similar to get_action. The old API is preserved (but renamed) since it's used in reversi. Change-Id: I24902c64a357f2fdd7d0c2f5371cbfd20f34f1c8
Diffstat (limited to 'apps/plugins/lib/pluginlib_touchscreen.c')
-rw-r--r--apps/plugins/lib/pluginlib_touchscreen.c51
1 files changed, 47 insertions, 4 deletions
diff --git a/apps/plugins/lib/pluginlib_touchscreen.c b/apps/plugins/lib/pluginlib_touchscreen.c
index eca76a6..8c746e1 100644
--- a/apps/plugins/lib/pluginlib_touchscreen.c
+++ b/apps/plugins/lib/pluginlib_touchscreen.c
@@ -23,28 +23,31 @@
#include "plugin.h"
#include "pluginlib_touchscreen.h"
+#include "pluginlib_exit.h"
/*******************************************************************************
* Touchbutton functions: These functions allow the plugin to specify a button
* location that, in turn gets mapped to a button press return value.
******************************************************************************/
-/* touchbutton_get:
+/* touchbutton_check_button:
* This function checks the touchbutton structure passed to it for hits. When
- * one is found it returns action.
+ * one is found it returns action. It doesn't block because it doesn't actually
+ * call button_get. You need to call it before and pass its result.
* inputs:
* struct touchbutton *data: This is intended to be an array of
* touchbuttons of size num_buttons. Each element in the array defines
* one button.
* int button: This is the button return value from a button_get() call.
- * It is used to determine REPEAT/RELEASE events.
+ * It is used to determine REPEAT/RELEASE events. This way
+ * this function can be mixed with other buttons
* int num_buttons: This tells touchbutton_get how many elements are in
* data.
* return:
* If a touch occured over one of the defined buttons, return action, else
* return 0.
*/
-int touchbutton_get(struct touchbutton *data, int button, int num_buttons) {
+int touchbutton_check_button(int button, struct touchbutton *data, int num_buttons) {
short x,y;
/* Get the x/y location of the button press, this is set by button_get when
@@ -71,6 +74,46 @@ int touchbutton_get(struct touchbutton *data, int button, int num_buttons) {
return 0;
}
+/* touchbutton_get_w_tmo:
+ * This function checks the touchbutton structure passed to it for hits. When
+ * one is found it returns the corresponding action.
+ * inputs:
+ * struct touchbutton *data: This is intended to be an array of
+ * touchbuttons of size num_buttons. Each element in the array defines
+ * one button.
+ * int tmo: Timeout when waiting for input.
+ * int num_buttons: This tells touchbutton_get how many elements are in
+ * data.
+ * return:
+ * If a touch occured over one of the defined buttons, return action, else
+ * return 0.
+ */
+int touchbutton_get_w_tmo(int tmo, struct touchbutton *data, int num_buttons)
+{
+ int btn = rb->button_get_w_tmo(tmo);
+ int result = touchbutton_check_button(btn, data, num_buttons);
+ exit_on_usb(result);
+ return result;
+}
+
+/* touchbutton_get:
+ * This function checks the touchbutton structure passed to it for hits. When
+ * one is found it returns the corresponding action.
+ * inputs:
+ * struct touchbutton *data: This is intended to be an array of
+ * touchbuttons of size num_buttons. Each element in the array defines
+ * one button.
+ * int num_buttons: This tells touchbutton_get how many elements are in
+ * data.
+ * return:
+ * If a touch occured over one of the defined buttons, return action, else
+ * return 0.
+ */
+int touchbutton_get(struct touchbutton *data, int num_buttons)
+{
+ return touchbutton_get_w_tmo(TIMEOUT_BLOCK, data, num_buttons);
+}
+
/* touchbutton_draw:
* This function draws the button with the associated text as long as the
* invisible flag is not set. Support for pixmaps needs to be added.