summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/android/button-android.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/android/button-android.c')
-rw-r--r--firmware/target/hosted/android/button-android.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/firmware/target/hosted/android/button-android.c b/firmware/target/hosted/android/button-android.c
new file mode 100644
index 0000000000..67e8ca1f89
--- /dev/null
+++ b/firmware/target/hosted/android/button-android.c
@@ -0,0 +1,87 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2010 Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22
23#include <jni.h>
24#include <stdbool.h>
25#include "config.h"
26#include "kernel.h"
27#include "system.h"
28#include "touchscreen.h"
29
30static long last_touch;
31static int last_y, last_x;
32
33static enum {
34 STATE_UNKNOWN,
35 STATE_UP,
36 STATE_DOWN,
37} last_state = STATE_UNKNOWN;
38
39
40/*
41 * this writes in an interrupt-like fashion the last pixel coordinates
42 * that the user pressed on the screen */
43JNIEXPORT void JNICALL
44Java_org_rockbox_RockboxFramebuffer_pixelHandler(JNIEnv*env, jobject this,
45 int x, int y)
46{
47 (void)env;
48 (void)this;
49 last_x = x;
50 last_y = y;
51 last_touch = current_tick;
52}
53
54/*
55 * this notifies us in an interrupt-like fashion whether the user just
56 * began or stopped the touch action */
57JNIEXPORT void JNICALL
58Java_org_rockbox_RockboxFramebuffer_touchHandler(JNIEnv*env, jobject this,
59 int down)
60{
61 (void)env;
62 (void)this;
63 if (down)
64 last_state = STATE_DOWN;
65 else
66 last_state = STATE_UP;
67}
68
69void button_init_device(void)
70{
71 last_touch = current_tick;
72}
73
74int button_read_device(int *data)
75{
76 /* get grid button/coordinates based on the current touchscreen mode */
77 int btn = touchscreen_to_pixels(last_x, last_y, data);
78 if (last_state == STATE_DOWN)
79 {
80 return btn;
81 }
82 else
83 {
84 *data = last_x = last_y = 0;
85 return 0;
86 }
87}