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
This commit is contained in:
parent
7c623d577b
commit
aba5c47dd6
3 changed files with 55 additions and 7 deletions
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in a new issue