summaryrefslogtreecommitdiff
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
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
-rw-r--r--apps/plugins/lib/pluginlib_touchscreen.c51
-rw-r--r--apps/plugins/lib/pluginlib_touchscreen.h9
-rw-r--r--apps/plugins/reversi/reversi-gui.c2
3 files changed, 55 insertions, 7 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.
diff --git a/apps/plugins/lib/pluginlib_touchscreen.h b/apps/plugins/lib/pluginlib_touchscreen.h
index f278765..dbd944c 100644
--- a/apps/plugins/lib/pluginlib_touchscreen.h
+++ b/apps/plugins/lib/pluginlib_touchscreen.h
@@ -40,8 +40,13 @@ struct touchbutton {
fb_data *pixmap; /* Currently unused, but will allow for a graphic */
};
-/* Get: tests for a button press and returns action. */
-int touchbutton_get(struct touchbutton *data, int button, int num_buttons);
+/* Check: tests if the result of button_get() beloned to a touch button */
+int touchbutton_check_button(int button, struct touchbutton *data, int num_buttons);
+/* Wait: Wait for input and return the corresponding action */
+int touchbutton_get(struct touchbutton *data, int num_buttons);
+/* Wait with timeout */
+int touchbutton_get_w_tmo(int timeout, struct touchbutton *data, int num_buttons);
+
/* Draw: Draws all visible buttons */
void touchbutton_draw(struct touchbutton *data, int num_buttons);
diff --git a/apps/plugins/reversi/reversi-gui.c b/apps/plugins/reversi/reversi-gui.c
index 5b5705c..e25aa5f 100644
--- a/apps/plugins/reversi/reversi-gui.c
+++ b/apps/plugins/reversi/reversi-gui.c
@@ -688,7 +688,7 @@ enum plugin_status plugin_start(const void *parameter) {
/* The touchscreen buttons can act as true buttons so OR them in */
#ifdef HAVE_TOUCHSCREEN
- button |= touchbutton_get(reversi_buttons, button, TOUCHBUTTON_COUNT);
+ button |= touchbutton_check_button(button, reversi_buttons, TOUCHBUTTON_COUNT);
#endif
/* All of these button presses wait for the release event */