summaryrefslogtreecommitdiff
path: root/apps/plugins/test_touchscreen.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/test_touchscreen.c')
-rw-r--r--apps/plugins/test_touchscreen.c141
1 files changed, 141 insertions, 0 deletions
diff --git a/apps/plugins/test_touchscreen.c b/apps/plugins/test_touchscreen.c
new file mode 100644
index 0000000000..84c8e96cb5
--- /dev/null
+++ b/apps/plugins/test_touchscreen.c
@@ -0,0 +1,141 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 Rob Purchase
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#include "plugin.h"
22
23PLUGIN_HEADER
24
25#if (CONFIG_KEYPAD == COWOND2_PAD)
26#define TOUCHSCREEN_QUIT BUTTON_POWER
27#define TOUCHSCREEN_TOGGLE BUTTON_MENU
28#elif (CONFIG_KEYPAD == MROBE500_PAD)
29#define TOUCHSCREEN_QUIT BUTTON_POWER
30#define TOUCHSCREEN_TOGGLE BUTTON_RC_MODE
31#endif
32
33static const struct plugin_api* rb;
34
35/* plugin entry point */
36enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
37{
38 int button = 0;
39 enum touchscreen_mode mode = TOUCHSCREEN_BUTTON;
40
41 /* standard stuff */
42 (void)parameter;
43 rb = api;
44
45 rb->touchscreen_set_mode(mode);
46
47 /* wait until user closes plugin */
48 do
49 {
50 short x = 0;
51 short y = 0;
52 bool draw_rect = false;
53
54 button = rb->button_get(true);
55
56 if (button & BUTTON_TOPLEFT)
57 {
58 draw_rect = true;
59 x = 0; y = 0;
60 }
61 else if (button & BUTTON_TOPMIDDLE)
62 {
63 draw_rect = true;
64 x = LCD_WIDTH/3; y = 0;
65 }
66 else if (button & BUTTON_TOPRIGHT)
67 {
68 draw_rect = true;
69 x = 2*(LCD_WIDTH/3); y = 0;
70 }
71 else if (button & BUTTON_MIDLEFT)
72 {
73 draw_rect = true;
74 x = 0; y = LCD_HEIGHT/3;
75 }
76 else if (button & BUTTON_CENTER)
77 {
78 draw_rect = true;
79 x = LCD_WIDTH/3; y = LCD_HEIGHT/3;
80 }
81 else if (button & BUTTON_MIDRIGHT)
82 {
83 draw_rect = true;
84 x = 2*(LCD_WIDTH/3); y = LCD_HEIGHT/3;
85 }
86 else if (button & BUTTON_BOTTOMLEFT)
87 {
88 draw_rect = true;
89 x = 0; y = 2*(LCD_HEIGHT/3);
90 }
91 else if (button & BUTTON_BOTTOMMIDDLE)
92 {
93 draw_rect = true;
94 x = LCD_WIDTH/3; y = 2*(LCD_HEIGHT/3);
95 }
96 else if (button & BUTTON_BOTTOMRIGHT)
97 {
98 draw_rect = true;
99 x = 2*(LCD_WIDTH/3); y = 2*(LCD_HEIGHT/3);
100 }
101
102 if (button & TOUCHSCREEN_TOGGLE && (button & BUTTON_REL))
103 {
104 mode = (mode == TOUCHSCREEN_POINT) ? TOUCHSCREEN_BUTTON : TOUCHSCREEN_POINT;
105 rb->touchscreen_set_mode(mode);
106 }
107
108 if (button & BUTTON_REL) draw_rect = false;
109
110 rb->lcd_clear_display();
111
112 if (draw_rect)
113 {
114 rb->lcd_set_foreground(LCD_RGBPACK(0xc0, 0, 0));
115 rb->lcd_fillrect(x, y, LCD_WIDTH/3, LCD_HEIGHT/3);
116 }
117
118 if (draw_rect || button & BUTTON_TOUCHSCREEN)
119 {
120 intptr_t button_data = rb->button_get_data();
121 x = button_data >> 16;
122 y = button_data & 0xffff;
123
124 rb->lcd_set_foreground(LCD_RGBPACK(0, 0, 0xc0));
125 rb->lcd_fillrect(x-7, y-7, 14, 14);
126
127 /* in stylus mode, show REL position in black */
128 if (mode == TOUCHSCREEN_POINT && (button & BUTTON_REL))
129 rb->lcd_set_foreground(LCD_BLACK);
130 else
131 rb->lcd_set_foreground(LCD_WHITE);
132
133 rb->lcd_hline(x-5, x+5, y);
134 rb->lcd_vline(x, y-5, y+5);
135 }
136 rb->lcd_update();
137
138 } while (button != TOUCHSCREEN_QUIT);
139
140 return PLUGIN_OK;
141}