diff options
Diffstat (limited to 'firmware/target/hosted/android/button-android.c')
-rw-r--r-- | firmware/target/hosted/android/button-android.c | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/firmware/target/hosted/android/button-android.c b/firmware/target/hosted/android/button-android.c index 1172880908..50e347e714 100644 --- a/firmware/target/hosted/android/button-android.c +++ b/firmware/target/hosted/android/button-android.c | |||
@@ -22,12 +22,15 @@ | |||
22 | 22 | ||
23 | #include <jni.h> | 23 | #include <jni.h> |
24 | #include <stdbool.h> | 24 | #include <stdbool.h> |
25 | #include "button.h" | ||
26 | #include "buttonmap.h" | ||
25 | #include "config.h" | 27 | #include "config.h" |
26 | #include "kernel.h" | 28 | #include "kernel.h" |
27 | #include "system.h" | 29 | #include "system.h" |
28 | #include "touchscreen.h" | 30 | #include "touchscreen.h" |
29 | 31 | ||
30 | static int last_y, last_x; | 32 | static int last_y, last_x; |
33 | static int last_btns; | ||
31 | 34 | ||
32 | static enum { | 35 | static enum { |
33 | STATE_UNKNOWN, | 36 | STATE_UNKNOWN, |
@@ -35,7 +38,6 @@ static enum { | |||
35 | STATE_DOWN, | 38 | STATE_DOWN, |
36 | } last_state = STATE_UNKNOWN; | 39 | } last_state = STATE_UNKNOWN; |
37 | 40 | ||
38 | |||
39 | /* | 41 | /* |
40 | * this writes in an interrupt-like fashion the last pixel coordinates | 42 | * this writes in an interrupt-like fashion the last pixel coordinates |
41 | * that the user pressed on the screen */ | 43 | * that the user pressed on the screen */ |
@@ -64,13 +66,45 @@ Java_org_rockbox_RockboxFramebuffer_touchHandler(JNIEnv*env, jobject this, | |||
64 | last_state = STATE_UP; | 66 | last_state = STATE_UP; |
65 | } | 67 | } |
66 | 68 | ||
69 | /* | ||
70 | * this writes in an interrupt-like fashion the button events that the user | ||
71 | * generated by pressing/releasing them to a variable */ | ||
72 | JNIEXPORT bool JNICALL | ||
73 | Java_org_rockbox_RockboxFramebuffer_buttonHandler(JNIEnv*env, jobject this, | ||
74 | int keycode, bool state) | ||
75 | { | ||
76 | (void)env; | ||
77 | (void)this; | ||
78 | |||
79 | int button = key_to_button(keycode); | ||
80 | |||
81 | if (button == BUTTON_NONE) | ||
82 | return false; | ||
83 | |||
84 | if (state) | ||
85 | last_btns |= button; | ||
86 | else | ||
87 | last_btns &= ~button; | ||
88 | |||
89 | return true; | ||
90 | } | ||
91 | |||
67 | void button_init_device(void) | 92 | void button_init_device(void) |
68 | { | 93 | { |
69 | } | 94 | } |
70 | 95 | ||
71 | int button_read_device(int *data) | 96 | int button_read_device(int *data) |
72 | { | 97 | { |
73 | /* get grid button/coordinates based on the current touchscreen mode */ | 98 | int btn = last_btns; |
74 | int btn = touchscreen_to_pixels(last_x, last_y, data); | 99 | /* Get grid button/coordinates based on the current touchscreen mode |
75 | return (last_state == STATE_DOWN ? btn : 0); | 100 | * |
101 | * Caveat: the caller seemingly depends on *data always being filled with | ||
102 | * the last known touchscreen position, so always call | ||
103 | * touchscreen_to_pixels() */ | ||
104 | int touch = touchscreen_to_pixels(last_x, last_y, data); | ||
105 | |||
106 | if (last_state == STATE_DOWN) | ||
107 | btn |= touch; | ||
108 | |||
109 | return btn; | ||
76 | } | 110 | } |