Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

plugins: Add touch API to plugin API and revamp touchscreen test

Change-Id: Iefb658693b03e0cda43e2a9fc93086485e790b4e

authored by

Aidan MacDonald and committed by
Solomon Peachy
e2363b0e 8aae7238

+279 -71
+14
apps/plugin.c
··· 852 852 #ifdef USB_ENABLE_AUDIO 853 853 usb_audio_get_playing, 854 854 #endif 855 + #ifdef HAVE_TOUCHSCREEN 856 + action_get_touch_event, 857 + action_gesture_reset, 858 + action_gesture_get_event_in_vp, 859 + action_gesture_get_event, 860 + action_gesture_is_valid, 861 + action_gesture_is_pressed, 862 + gesture_reset, 863 + gesture_process, 864 + gesture_get_event_in_vp, 865 + gesture_vel_reset, 866 + gesture_vel_process, 867 + gesture_vel_get, 868 + #endif 855 869 }; 856 870 857 871 static int plugin_buffer_handle;
+19
apps/plugin.h
··· 74 74 #include "thread.h" 75 75 #include "button.h" 76 76 #include "action.h" 77 + #include "gesture.h" 77 78 #include "load_code.h" 78 79 #include "usb.h" 79 80 #include "font.h" ··· 996 997 bool (*yesno_pop_confirm)(const char* text); 997 998 #ifdef USB_ENABLE_AUDIO 998 999 bool (*usb_audio_get_playing)(void); 1000 + #endif 1001 + #ifdef HAVE_TOUCHSCREEN 1002 + int (*action_get_touch_event)(struct touchevent *ev); 1003 + void (*action_gesture_reset)(void); 1004 + bool (*action_gesture_get_event_in_vp)(struct gesture_event *gevt, 1005 + const struct viewport *vp); 1006 + bool (*action_gesture_get_event)(struct gesture_event *gevt); 1007 + bool (*action_gesture_is_valid)(void); 1008 + bool (*action_gesture_is_pressed)(void); 1009 + void (*gesture_reset)(struct gesture *g); 1010 + void (*gesture_process)(struct gesture *g, const struct touchevent *ev); 1011 + bool (*gesture_get_event_in_vp)(struct gesture *g, 1012 + struct gesture_event *gevt, 1013 + const struct viewport *vp); 1014 + void (*gesture_vel_reset)(struct gesture_vel *gv); 1015 + void (*gesture_vel_process)(struct gesture_vel *gv, 1016 + const struct touchevent *ev); 1017 + bool (*gesture_vel_get)(struct gesture_vel *gv, int *xvel, int *yvel); 999 1018 #endif 1000 1019 }; 1001 1020
+246 -71
apps/plugins/test_touchscreen.c
··· 50 50 # error "No keymap defined!" 51 51 #endif 52 52 53 - /* plugin entry point */ 54 - enum plugin_status plugin_start(const void* parameter) 53 + static bool usb_exit = false; 54 + 55 + static const struct button_mapping tstest_context[] = { 56 + {ACTION_STD_OK, TOUCHSCREEN_TOGGLE, BUTTON_NONE}, 57 + {ACTION_STD_CANCEL, TOUCHSCREEN_QUIT, BUTTON_NONE}, 58 + LAST_ITEM_IN_LIST, 59 + }; 60 + 61 + static const struct button_mapping *get_context_map(int context) 55 62 { 56 - int button = 0; 57 - enum touchscreen_mode mode = TOUCHSCREEN_BUTTON; 63 + (void)context; 64 + return tstest_context; 65 + } 58 66 59 - /* standard stuff */ 60 - (void)parameter; 61 - 62 - rb->touchscreen_set_mode(mode); 67 + static void draw_tsbutton_rect(int x, int y) 68 + { 69 + int x0 = x*LCD_WIDTH/3; 70 + int y0 = y*LCD_HEIGHT/3; 71 + int x1 = (x+1)*LCD_WIDTH/3; 72 + int y1 = (y+1)*LCD_HEIGHT/3; 63 73 64 - /* wait until user closes plugin */ 65 - do 74 + rb->lcd_set_foreground(LCD_RGBPACK(0xc0, 0, 0)); 75 + rb->lcd_fillrect(x0, y0, x1 - x0, y1 - y0); 76 + } 77 + 78 + static void draw_crosshair(int x, int y, unsigned fg) 79 + { 80 + rb->lcd_set_foreground(fg); 81 + rb->lcd_hline(x-7, x+7, y); 82 + rb->lcd_vline(x, y-7, y+7); 83 + } 84 + 85 + static void tstest_button_mode(void) 86 + { 87 + rb->splashf(HZ, "Button mode test"); 88 + rb->touchscreen_set_mode(TOUCHSCREEN_BUTTON); 89 + 90 + int button = BUTTON_NONE; 91 + while (true) 66 92 { 67 - short x = 0; 68 - short y = 0; 69 - bool draw_rect = false; 70 - 93 + rb->lcd_clear_display(); 94 + 95 + if ((button & BUTTON_TOPLEFT) && !(button & BUTTON_REL)) 96 + draw_tsbutton_rect(0, 0); 97 + if ((button & BUTTON_TOPMIDDLE) && !(button & BUTTON_REL)) 98 + draw_tsbutton_rect(1, 0); 99 + if ((button & BUTTON_TOPRIGHT) && !(button & BUTTON_REL)) 100 + draw_tsbutton_rect(2, 0); 101 + if ((button & BUTTON_MIDLEFT) && !(button & BUTTON_REL)) 102 + draw_tsbutton_rect(0, 1); 103 + if ((button & BUTTON_CENTER) && !(button & BUTTON_REL)) 104 + draw_tsbutton_rect(1, 1); 105 + if ((button & BUTTON_MIDRIGHT) && !(button & BUTTON_REL)) 106 + draw_tsbutton_rect(2, 1); 107 + if ((button & BUTTON_BOTTOMLEFT) && !(button & BUTTON_REL)) 108 + draw_tsbutton_rect(0, 2); 109 + if ((button & BUTTON_BOTTOMMIDDLE) && !(button & BUTTON_REL)) 110 + draw_tsbutton_rect(1, 2); 111 + if ((button & BUTTON_BOTTOMRIGHT) && !(button & BUTTON_REL)) 112 + draw_tsbutton_rect(2, 2); 113 + 114 + rb->lcd_update(); 115 + 116 + if (button & TOUCHSCREEN_QUIT) 117 + break; 118 + if (rb->default_event_handler(button) == SYS_USB_CONNECTED) 119 + { 120 + usb_exit = true; 121 + break; 122 + } 123 + 71 124 button = rb->button_get(true); 125 + } 126 + } 72 127 73 - if (button & BUTTON_TOPLEFT) 128 + static void tstest_pointing_mode(void) 129 + { 130 + struct touchevent tevent; 131 + 132 + rb->splashf(HZ, "Pointing mode test"); 133 + rb->touchscreen_set_mode(TOUCHSCREEN_POINT); 134 + 135 + rb->lcd_clear_display(); 136 + rb->lcd_update(); 137 + 138 + while (true) 139 + { 140 + int action = rb->get_custom_action(CONTEXT_PLUGIN, TIMEOUT_BLOCK, 141 + get_context_map); 142 + if (action == ACTION_TOUCHSCREEN) 74 143 { 75 - draw_rect = true; 76 - x = 0; y = 0; 144 + rb->lcd_clear_display(); 145 + rb->action_get_touch_event(&tevent); 146 + draw_crosshair(tevent.x, tevent.y, LCD_RGBPACK(0, 0xc0, 0)); 147 + rb->lcd_update(); 77 148 } 78 - else if (button & BUTTON_TOPMIDDLE) 149 + else if (action == ACTION_STD_CANCEL) 79 150 { 80 - draw_rect = true; 81 - x = LCD_WIDTH/3; y = 0; 151 + break; 82 152 } 83 - else if (button & BUTTON_TOPRIGHT) 153 + else if (rb->default_event_handler(action) == SYS_USB_CONNECTED) 154 + { 155 + usb_exit = true; 156 + break; 157 + } 158 + } 159 + } 160 + 161 + static void tstest_gesture(void) 162 + { 163 + static const char *const gesture_names[] = { 164 + [GESTURE_NONE] = "none", 165 + [GESTURE_TAP] = "tap", 166 + [GESTURE_LONG_PRESS] = "long press", 167 + [GESTURE_HOLD] = "hold", 168 + [GESTURE_DRAGSTART] = "dragstart", 169 + [GESTURE_DRAG] = "drag", 170 + [GESTURE_RELEASE] = "release", 171 + }; 172 + 173 + struct gesture_event gevt; 174 + int gevent_array[10]; 175 + int gevent_count = 0; 176 + 177 + rb->splashf(HZ, "Gesture test"); 178 + rb->touchscreen_set_mode(TOUCHSCREEN_POINT); 179 + 180 + rb->lcd_clear_display(); 181 + rb->lcd_update(); 182 + 183 + while (true) 184 + { 185 + int action = rb->get_custom_action(CONTEXT_PLUGIN, TIMEOUT_BLOCK, 186 + get_context_map); 187 + if (action == ACTION_TOUCHSCREEN) 84 188 { 85 - draw_rect = true; 86 - x = 2*(LCD_WIDTH/3); y = 0; 189 + rb->lcd_clear_display(); 190 + 191 + if (rb->action_gesture_get_event_in_vp(&gevt, NULL)) 192 + { 193 + if (gevt.id == GESTURE_NONE) 194 + { 195 + gevent_array[gevent_count] = GESTURE_NONE; 196 + gevent_count = 1; 197 + } 198 + 199 + if (gevt.id != gevent_array[gevent_count-1]) 200 + { 201 + if (gevent_count < (int)ARRAYLEN(gevent_array)) 202 + { 203 + gevent_array[gevent_count] = gevt.id; 204 + gevent_count++; 205 + } 206 + } 207 + 208 + rb->lcd_set_foreground(LCD_RGBPACK(0xff, 0xff, 0xff)); 209 + for (int i = 0; i < gevent_count; ++i) 210 + rb->lcd_puts(0, i, gesture_names[gevent_array[i]]); 211 + 212 + draw_crosshair(gevt.x, gevt.y, LCD_RGBPACK(0, 0xc0, 0)); 213 + draw_crosshair(gevt.ox, gevt.oy, LCD_RGBPACK(0xc0, 0, 0)); 214 + } 215 + 216 + rb->lcd_update(); 87 217 } 88 - else if (button & BUTTON_MIDLEFT) 218 + else if (action == ACTION_STD_OK) 89 219 { 90 - draw_rect = true; 91 - x = 0; y = LCD_HEIGHT/3; 220 + rb->splashf(HZ, "Gesture reset"); 221 + rb->action_gesture_reset(); 222 + rb->lcd_clear_display(); 223 + rb->lcd_update(); 92 224 } 93 - else if (button & BUTTON_CENTER) 225 + else if (action == ACTION_STD_CANCEL) 94 226 { 95 - draw_rect = true; 96 - x = LCD_WIDTH/3; y = LCD_HEIGHT/3; 227 + break; 97 228 } 98 - else if (button & BUTTON_MIDRIGHT) 229 + else if (rb->default_event_handler(action) == SYS_USB_CONNECTED) 99 230 { 100 - draw_rect = true; 101 - x = 2*(LCD_WIDTH/3); y = LCD_HEIGHT/3; 231 + usb_exit = true; 232 + break; 102 233 } 103 - else if (button & BUTTON_BOTTOMLEFT) 234 + } 235 + } 236 + 237 + static void tstest_velocity(void) 238 + { 239 + struct touchevent tevent; 240 + struct gesture_vel gv; 241 + 242 + rb->splashf(HZ, "Velocity test"); 243 + rb->touchscreen_set_mode(TOUCHSCREEN_POINT); 244 + 245 + rb->lcd_clear_display(); 246 + rb->lcd_update(); 247 + 248 + rb->gesture_vel_reset(&gv); 249 + 250 + while (true) 251 + { 252 + int action = rb->get_custom_action(CONTEXT_PLUGIN, TIMEOUT_BLOCK, 253 + get_context_map); 254 + if (action == ACTION_TOUCHSCREEN) 104 255 { 105 - draw_rect = true; 106 - x = 0; y = 2*(LCD_HEIGHT/3); 256 + rb->lcd_clear_display(); 257 + rb->action_get_touch_event(&tevent); 258 + rb->gesture_vel_process(&gv, &tevent); 259 + 260 + int xvel, yvel; 261 + rb->gesture_vel_get(&gv, &xvel, &yvel); 262 + 263 + rb->lcd_set_foreground(LCD_RGBPACK(0xff, 0xff, 0xff)); 264 + rb->lcd_putsf(0, 0, "xvel=%4d yvel=%4d", xvel, yvel); 265 + 266 + draw_crosshair(tevent.x, tevent.y, LCD_RGBPACK(0, 0xc0, 0)); 267 + rb->lcd_update(); 268 + 269 + if (tevent.type == TOUCHEVENT_RELEASE) 270 + rb->gesture_vel_reset(&gv); 107 271 } 108 - else if (button & BUTTON_BOTTOMMIDDLE) 272 + else if (action == ACTION_STD_OK) 109 273 { 110 - draw_rect = true; 111 - x = LCD_WIDTH/3; y = 2*(LCD_HEIGHT/3); 274 + rb->splashf(HZ, "Velocity reset"); 275 + rb->gesture_vel_reset(&gv); 276 + rb->lcd_clear_display(); 277 + rb->lcd_update(); 112 278 } 113 - else if (button & BUTTON_BOTTOMRIGHT) 279 + else if (action == ACTION_STD_CANCEL) 114 280 { 115 - draw_rect = true; 116 - x = 2*(LCD_WIDTH/3); y = 2*(LCD_HEIGHT/3); 281 + break; 117 282 } 118 - 119 - if (button & TOUCHSCREEN_TOGGLE && (button & BUTTON_REL)) 283 + else if (rb->default_event_handler(action) == SYS_USB_CONNECTED) 120 284 { 121 - mode = (mode == TOUCHSCREEN_POINT) ? TOUCHSCREEN_BUTTON : TOUCHSCREEN_POINT; 122 - rb->touchscreen_set_mode(mode); 285 + usb_exit = true; 286 + break; 123 287 } 124 - 125 - if (button & BUTTON_REL) draw_rect = false; 288 + } 289 + } 126 290 127 - rb->lcd_clear_display(); 291 + /* plugin entry point */ 292 + enum plugin_status plugin_start(const void* parameter) 293 + { 294 + (void)parameter; 128 295 129 - if (draw_rect) 296 + int sel; 297 + MENUITEM_STRINGLIST(menu, "Touchscreen test", 298 + NULL, 299 + "Button mode test", 300 + "Pointing mode test", 301 + "Gesture test", 302 + "Velocity test", 303 + "Quit"); 304 + 305 + while (true) 306 + { 307 + rb->touchscreen_set_mode(rb->global_settings->touch_mode); 308 + switch (rb->do_menu(&menu, &sel, NULL, false)) 130 309 { 131 - rb->lcd_set_foreground(LCD_RGBPACK(0xc0, 0, 0)); 132 - rb->lcd_fillrect(x, y, LCD_WIDTH/3, LCD_HEIGHT/3); 133 - } 310 + case 0: 311 + tstest_button_mode(); 312 + break; 134 313 135 - if (draw_rect || button & BUTTON_TOUCHSCREEN) 136 - { 137 - intptr_t button_data = rb->button_get_data(); 138 - x = button_data >> 16; 139 - y = button_data & 0xffff; 314 + case 1: 315 + tstest_pointing_mode(); 316 + break; 140 317 141 - rb->lcd_set_foreground(LCD_RGBPACK(0, 0, 0xc0)); 142 - rb->lcd_fillrect(x-7, y-7, 14, 14); 143 - 144 - /* in stylus mode, show REL position in black */ 145 - if (mode == TOUCHSCREEN_POINT && (button & BUTTON_REL)) 146 - rb->lcd_set_foreground(LCD_BLACK); 147 - else 148 - rb->lcd_set_foreground(LCD_WHITE); 318 + case 2: 319 + tstest_gesture(); 320 + break; 321 + 322 + case 3: 323 + tstest_velocity(); 324 + break; 149 325 150 - rb->lcd_hline(x-5, x+5, y); 151 - rb->lcd_vline(x, y-5, y+5); 326 + default: 327 + return PLUGIN_OK; 152 328 } 153 - rb->lcd_update(); 154 329 155 - } while (button != TOUCHSCREEN_QUIT); 156 - 157 - return PLUGIN_OK; 330 + if (usb_exit) 331 + return PLUGIN_USB_CONNECTED; 332 + } 158 333 }