Add target tree files (lcd, tick timer, pcm, buttons and stubs).
[kugel-rb.git] / firmware / target / hosted / android / button-android.c
blob0cac35fa25a9520650eaf84891ac89c841331388
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (c) 2010 Thomas Martitz
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 #include <jni.h>
24 #include <stdbool.h>
25 #include "config.h"
26 #include "kernel.h"
27 #include "system.h"
29 static long last_touch;
30 static int last_y, last_x;
32 static enum {
33 STATE_UNKNOWN,
34 STATE_UP,
35 STATE_DOWN,
36 } last_state = STATE_UNKNOWN;
40 * this writes in an interrupt-like fashion the last pixel coordinates
41 * that the user pressed on the screen */
42 JNIEXPORT void JNICALL
43 Java_org_rockbox_RockboxFramebuffer_pixelHandler(JNIEnv*env, jobject this,
44 int x, int y)
46 last_x = x;
47 last_y = y;
48 last_touch = current_tick;
52 * this notifies us in an interrupt-like fashion whether the user just
53 * began or stopped the touch action */
54 JNIEXPORT void JNICALL
55 Java_org_rockbox_RockboxFramebuffer_touchHandler(JNIEnv*env, jobject this,
56 int down)
58 if (down)
59 last_state = STATE_DOWN;
60 else
61 last_state = STATE_UP;
64 void button_init_device(void)
66 last_touch = current_tick;
69 int button_read_device(int *data)
71 /* get grid button/coordinates based on the current touchscreen mode */
72 int btn = touchscreen_to_pixels(last_x, last_y, data);
73 if (last_state == STATE_DOWN)
75 return btn;
77 else
79 *data = last_x = last_y = 0;
80 return 0;