summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/android/button-android.c
diff options
context:
space:
mode:
authorMaurus Cuelenaere <mcuelenaere@gmail.com>2010-08-16 20:12:06 +0000
committerMaurus Cuelenaere <mcuelenaere@gmail.com>2010-08-16 20:12:06 +0000
commit934a5a5808c7a0b0dff469ad2c3a523e78a4ef4b (patch)
tree0aec8be568bea16b68ac87086387ba73089d931f /firmware/target/hosted/android/button-android.c
parente726e53da68d3ff53a79023d5dc5cfcc020fb864 (diff)
downloadrockbox-934a5a5808c7a0b0dff469ad2c3a523e78a4ef4b.tar.gz
rockbox-934a5a5808c7a0b0dff469ad2c3a523e78a4ef4b.zip
Android port: add support for hardware keys
* Forward Java KeyEvents to C layer and translate them to Rockbox BUTTON_*. * Add a basic Android keymap git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27832 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/hosted/android/button-android.c')
-rw-r--r--firmware/target/hosted/android/button-android.c42
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
30static int last_y, last_x; 32static int last_y, last_x;
33static int last_btns;
31 34
32static enum { 35static 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 */
72JNIEXPORT bool JNICALL
73Java_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
67void button_init_device(void) 92void button_init_device(void)
68{ 93{
69} 94}
70 95
71int button_read_device(int *data) 96int 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}