diff options
| author | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2009-06-16 17:04:47 +0000 |
|---|---|---|
| committer | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2009-06-16 17:04:47 +0000 |
| commit | b8435f54464fd50c145d321b118d773ea05ef6a2 (patch) | |
| tree | a514bbe44e41c454dfca56184376209787c40268 /apps | |
| parent | b1a60934c5d178842ec3bec83a3e5286410cab7d (diff) | |
| download | rockbox-b8435f54464fd50c145d321b118d773ea05ef6a2.zip rockbox-b8435f54464fd50c145d321b118d773ea05ef6a2.tar.gz rockbox-b8435f54464fd50c145d321b118d773ea05ef6a2.tar.bz2 rockbox-b8435f54464fd50c145d321b118d773ea05ef6a2.tar.xz | |
Touchscreen targets: add calibration screen + rewrite calibration driver (FS#10295)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21312 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/lang/english.lang | 57 | ||||
| -rw-r--r-- | apps/lang/nederlands.lang | 57 | ||||
| -rw-r--r-- | apps/menus/display_menu.c | 29 | ||||
| -rw-r--r-- | apps/menus/settings_menu.c | 18 | ||||
| -rw-r--r-- | apps/screens.c | 82 | ||||
| -rw-r--r-- | apps/screens.h | 5 | ||||
| -rw-r--r-- | apps/settings.c | 1 | ||||
| -rw-r--r-- | apps/settings.h | 1 | ||||
| -rw-r--r-- | apps/settings_list.c | 50 |
9 files changed, 276 insertions, 24 deletions
diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 09cbdbf..da09e3c 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang @@ -12405,7 +12405,7 @@ </phrase> <phrase> id: LANG_TOUCHSCREEN_MODE - desc: in Settings -> General -> System menu + desc: in Settings -> General -> Display -> Touchscreen Settings user: core <source> *: none @@ -12422,7 +12422,7 @@ </phrase> <phrase> id: LANG_TOUCHSCREEN_GRID - desc: in Settings -> General -> System menu + desc: in Settings -> General -> Display -> Touchscreen Settings user: core <source> *: none @@ -12439,7 +12439,7 @@ </phrase> <phrase> id: LANG_TOUCHSCREEN_POINT - desc: in Settings -> General -> System menu + desc: in Settings -> General -> Display -> Touchscreen Settings user: core <source> *: none @@ -12502,3 +12502,54 @@ swcodec: "Speed" </voice> </phrase> +<phrase> + id: LANG_TOUCHSCREEN_SETTINGS + desc: in Settings -> General -> Display menu + user: core + <source> + *: none + touchscreen: "Touchscreen Settings" + </source> + <dest> + *: none + touchscreen: "Touchscreen Settings" + </dest> + <voice> + *: none + touchscreen: "Touchscreen Settings" + </voice> +</phrase> +<phrase> + id: LANG_TOUCHSCREEN_CALIBRATE + desc: in Settings -> General -> Display -> Touchscreen Settings + user: core + <source> + *: none + touchscreen: "Calibrate" + </source> + <dest> + *: none + touchscreen: "Calibrate" + </dest> + <voice> + *: none + touchscreen: "Calibrate" + </voice> +</phrase> +<phrase> + id: LANG_TOUCHSCREEN_RESET_CALIBRATION + desc: in Settings -> General -> Display -> Touchscreen Settings + user: core + <source> + *: none + touchscreen: "Reset Calibration" + </source> + <dest> + *: none + touchscreen: "Reset Calibration" + </dest> + <voice> + *: none + touchscreen: "Reset Calibration" + </voice> +</phrase> diff --git a/apps/lang/nederlands.lang b/apps/lang/nederlands.lang index 2d476d1..e738399 100644 --- a/apps/lang/nederlands.lang +++ b/apps/lang/nederlands.lang @@ -12335,7 +12335,7 @@ </phrase> <phrase> id: LANG_TOUCHSCREEN_MODE - desc: in Settings -> General -> System menu + desc: in Settings -> General -> Display -> Touchscreen Settings user: core <source> *: none @@ -12352,7 +12352,7 @@ </phrase> <phrase> id: LANG_TOUCHSCREEN_GRID - desc: in Settings -> General -> System menu + desc: in Settings -> General -> Display -> Touchscreen Settings user: core <source> *: none @@ -12369,7 +12369,7 @@ </phrase> <phrase> id: LANG_TOUCHSCREEN_POINT - desc: in Settings -> General -> System menu + desc: in Settings -> General -> Display -> Touchscreen Settings user: core <source> *: none @@ -12432,3 +12432,54 @@ swcodec: "Snelheid" </voice> </phrase> +<phrase> + id: LANG_TOUCHSCREEN_SETTINGS + desc: in Settings -> General -> Display menu + user: core + <source> + *: none + touchscreen: "Touchscreen Settings" + </source> + <dest> + *: none + touchscreen: "Touchscreen instellingen" + </dest> + <voice> + *: none + touchscreen: "Touchscreen instellingen" + </voice> +</phrase> +<phrase> + id: LANG_TOUCHSCREEN_CALIBRATE + desc: in Settings -> General -> Display -> Touchscreen Settings + user: core + <source> + *: none + touchscreen: "Calibrate" + </source> + <dest> + *: none + touchscreen: "Kalibreer" + </dest> + <voice> + *: none + touchscreen: "Kalibreer" + </voice> +</phrase> +<phrase> + id: LANG_TOUCHSCREEN_RESET_CALIBRATION + desc: in Settings -> General -> Display -> Touchscreen Settings + user: core + <source> + *: none + touchscreen: "Reset Calibration" + </source> + <dest> + *: none + touchscreen: "Kalibratie terugzetten" + </dest> + <voice> + *: none + touchscreen: "Kalibratie terugzetten" + </voice> +</phrase> diff --git a/apps/menus/display_menu.c b/apps/menus/display_menu.c index a015be3..aee9c18 100644 --- a/apps/menus/display_menu.c +++ b/apps/menus/display_menu.c @@ -36,6 +36,9 @@ #include "talk.h" #include "lcd.h" #include "lcd-remote.h" +#ifdef HAVE_TOUCHSCREEN +#include "screens.h" +#endif #ifdef HAVE_BACKLIGHT static int filterfirstkeypress_callback(int action,const struct menu_item_ex *this_item) @@ -496,6 +499,29 @@ MAKE_MENU(peak_meter_menu, ID2P(LANG_PM_MENU), NULL, Icon_NOICON, /***********************************/ +#ifdef HAVE_TOUCHSCREEN +static int touch_mode_callback(int action,const struct menu_item_ex *this_item) +{ + (void)this_item; + switch (action) + { + case ACTION_EXIT_MENUITEM: /* on exit */ + touchscreen_set_mode(global_settings.touch_mode); + break; + } + return action; +} +MENUITEM_SETTING(touch_mode, &global_settings.touch_mode, touch_mode_callback); + +MENUITEM_FUNCTION(touchscreen_menu_calibrate, 0, ID2P(LANG_TOUCHSCREEN_CALIBRATE), calibrate, + NULL, NULL, Icon_NOICON); +MENUITEM_FUNCTION(touchscreen_menu_reset_calibration, 0, ID2P(LANG_TOUCHSCREEN_RESET_CALIBRATION), reset_mapping, + NULL, NULL, Icon_NOICON); + +MAKE_MENU(touchscreen_menu, ID2P(LANG_TOUCHSCREEN_SETTINGS), NULL, Icon_NOICON, &touch_mode, + &touchscreen_menu_calibrate, &touchscreen_menu_reset_calibration); +#endif + MENUITEM_SETTING(codepage_setting, &global_settings.default_codepage, NULL); @@ -511,4 +537,7 @@ MAKE_MENU(display_menu, ID2P(LANG_DISPLAY), &bars_menu, &peak_meter_menu, #endif &codepage_setting, +#ifdef HAVE_TOUCHSCREEN + &touchscreen_menu, +#endif ); diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c index 56a0178..fdc7758 100644 --- a/apps/menus/settings_menu.c +++ b/apps/menus/settings_menu.c @@ -265,21 +265,6 @@ MENUITEM_SETTING(buttonlight_brightness, &global_settings.buttonlight_brightness MENUITEM_SETTING(touchpad_sensitivity, &global_settings.touchpad_sensitivity, NULL); #endif -#ifdef HAVE_TOUCHSCREEN -static int touch_mode_callback(int action,const struct menu_item_ex *this_item) -{ - (void)this_item; - switch (action) - { - case ACTION_EXIT_MENUITEM: /* on exit */ - touchscreen_set_mode(global_settings.touch_mode); - break; - } - return action; -} -MENUITEM_SETTING(touch_mode, &global_settings.touch_mode, touch_mode_callback); -#endif - MAKE_MENU(system_menu, ID2P(LANG_SYSTEM), 0, Icon_System_menu, &start_screen, @@ -315,9 +300,6 @@ MAKE_MENU(system_menu, ID2P(LANG_SYSTEM), #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING &touchpad_sensitivity, #endif -#ifdef HAVE_TOUCHSCREEN - &touch_mode, -#endif ); /* SYSTEM MENU */ diff --git a/apps/screens.c b/apps/screens.c index 096b814..829aa19 100644 --- a/apps/screens.c +++ b/apps/screens.c @@ -1019,3 +1019,85 @@ bool view_runtime(void) } return false; } + +#ifdef HAVE_TOUCHSCREEN +static int get_sample(struct touchscreen_calibration *cal, int x, int y, int i, + struct screen* screen) +{ + int action; + short ts_x, ts_y; + + /* Draw a cross */ + screen->drawline(x - 10, y, x - 2, y); + screen->drawline(x + 2, y, x + 10, y); + screen->drawline(x, y - 10, x, y - 2); + screen->drawline(x, y + 2, x, y + 10); + screen->update(); + + /* Wait for a touchscreen press */ + while(true) + { + action = get_action(CONTEXT_STD, TIMEOUT_BLOCK); + if(action == ACTION_TOUCHSCREEN) + { + if(action_get_touchscreen_press(&ts_x, &ts_y) == BUTTON_REL) + break; + } + else if(action == ACTION_STD_CANCEL) + return -1; + } + + cal->x[i][0] = ts_x; + cal->y[i][0] = ts_y; + cal->x[i][1] = x; + cal->y[i][1] = y; + + return 0; +} + + +int calibrate(void) +{ + short points[3][2] = { + {LCD_WIDTH/10, LCD_HEIGHT/10}, + {7*LCD_WIDTH/8, LCD_HEIGHT/2}, + {LCD_WIDTH/2, 7*LCD_HEIGHT/8} + }; + struct screen* screen = &screens[SCREEN_MAIN]; + enum touchscreen_mode old_mode = touchscreen_get_mode(); + struct touchscreen_calibration cal; + int i, ret = 0; + bool statusbar = global_settings.statusbar; /* hide the statusbar */ + + global_settings.statusbar = false; + touchscreen_disable_mapping(); /* set raw mode */ + touchscreen_set_mode(TOUCHSCREEN_POINT); + for(i=0; i<3; i++) + { + screen->clear_display(); + + if(get_sample(&cal, points[i][0], points[i][1], i, screen)) + { + ret = -1; + break; + } + } + + if(ret == 0) + touchscreen_calibrate(&cal); + else + touchscreen_reset_mapping(); + memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter)); + touchscreen_set_mode(old_mode); + global_settings.statusbar = statusbar; + + return ret; +} + +int reset_mapping(void) +{ + touchscreen_reset_mapping(); + memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter)); + return 0; +} +#endif diff --git a/apps/screens.h b/apps/screens.h index eb613fc..38fef14 100644 --- a/apps/screens.h +++ b/apps/screens.h @@ -50,5 +50,10 @@ bool shutdown_screen(void); bool browse_id3(void); bool view_runtime(void); +#ifdef HAVE_TOUCHSCREEN +int calibrate(void); +int reset_mapping(void); +#endif + #endif diff --git a/apps/settings.c b/apps/settings.c index 9594bd1..3219dbb 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -966,6 +966,7 @@ void settings_apply(bool read_disk) #ifdef HAVE_TOUCHSCREEN touchscreen_set_mode(global_settings.touch_mode); + memcpy(&calibration_parameters, &global_settings.ts_calibration_data, sizeof(struct touchscreen_parameter)); #endif /* This should stay last */ diff --git a/apps/settings.h b/apps/settings.h index 6ccaeed..ef5a620 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -730,6 +730,7 @@ struct user_settings #ifdef HAVE_TOUCHSCREEN int touch_mode; + struct touchscreen_parameter ts_calibration_data; #endif /* If values are just added to the end, no need to bump plugin API diff --git a/apps/settings_list.c b/apps/settings_list.c index 74e2cab..dcad718 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -53,6 +53,10 @@ #include "iap.h" #endif #include "statusbar.h" +#ifdef HAVE_TOUCHSCREEN +#include "touchscreen.h" +#include "ctype.h" /* For isspace() */ +#endif #define NVRAM(bytes) (bytes<<F_NVRAM_MASK_SHIFT) /** NOTE: NVRAM_CONFIG_VERSION is in settings_list.h @@ -452,6 +456,48 @@ static void qs_set_default(void* setting, void* defaultval) find_setting(defaultval, (int*)setting); } #endif +#ifdef HAVE_TOUCHSCREEN +static void tsc_load_from_cfg(void* setting, char*value) +{ + struct touchscreen_parameter *var = (struct touchscreen_parameter*) setting; + + /* Replacement for sscanf(value, "%d ..., &var->A, ...); */ + int vals[7], count = 0; + while(*value != 0 && count < 7) + { + if(isspace(*value)) + value++; + else + { + vals[count++] = atoi(value); + while(!isspace(*value)) + value++; + } + } + var->A = vals[0]; + var->B = vals[1]; + var->C = vals[2]; + var->D = vals[3]; + var->E = vals[4]; + var->F = vals[5]; + var->divider = vals[6]; +} + +static char* tsc_write_to_cfg(void* setting, char*buf, int buf_len) +{ + const struct touchscreen_parameter *var = (const struct touchscreen_parameter*) setting; + snprintf(buf, buf_len, "%d %d %d %d %d %d %d", var->A, var->B, var->C, var->D, var->E, var->F, var->divider); + return buf; +} +static bool tsc_is_changed(void* setting, void* defaultval) +{ + return memcmp(setting, defaultval, sizeof(struct touchscreen_parameter)) != 0; +} +static void tsc_set_default(void* setting, void* defaultval) +{ + memcpy(setting, defaultval, sizeof(struct touchscreen_parameter)); +} +#endif const struct settings_list settings[] = { /* sound settings */ SOUND_SETTING(F_NO_WRAP,volume, LANG_VOLUME, "volume", SOUND_VOLUME), @@ -1470,6 +1516,10 @@ const struct settings_list settings[] = { CHOICE_SETTING(0, touch_mode, LANG_TOUCHSCREEN_MODE, TOUCHSCREEN_BUTTON, "touchscreen mode", "point,grid", NULL, 2, ID2P(LANG_TOUCHSCREEN_POINT), ID2P(LANG_TOUCHSCREEN_GRID)), + CUSTOM_SETTING(0, ts_calibration_data, -1, + &default_calibration_parameters, "touchscreen calibration", + tsc_load_from_cfg, tsc_write_to_cfg, + tsc_is_changed, tsc_set_default), #endif OFFON_SETTING(0, prevent_skip, LANG_PREVENT_SKIPPING, false, "prevent track skip", NULL), }; |