summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorMaurus Cuelenaere <mcuelenaere@gmail.com>2009-06-16 17:04:47 +0000
committerMaurus Cuelenaere <mcuelenaere@gmail.com>2009-06-16 17:04:47 +0000
commitb8435f54464fd50c145d321b118d773ea05ef6a2 (patch)
treea514bbe44e41c454dfca56184376209787c40268 /apps
parentb1a60934c5d178842ec3bec83a3e5286410cab7d (diff)
downloadrockbox-b8435f54464fd50c145d321b118d773ea05ef6a2.tar.gz
rockbox-b8435f54464fd50c145d321b118d773ea05ef6a2.zip
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.lang57
-rw-r--r--apps/lang/nederlands.lang57
-rw-r--r--apps/menus/display_menu.c29
-rw-r--r--apps/menus/settings_menu.c18
-rw-r--r--apps/screens.c82
-rw-r--r--apps/screens.h5
-rw-r--r--apps/settings.c1
-rw-r--r--apps/settings.h1
-rw-r--r--apps/settings_list.c50
9 files changed, 276 insertions, 24 deletions
diff --git a/apps/lang/english.lang b/apps/lang/english.lang
index 09cbdbfc09..da09e3c49a 100644
--- a/apps/lang/english.lang
+++ b/apps/lang/english.lang
@@ -12405,7 +12405,7 @@
12405</phrase> 12405</phrase>
12406<phrase> 12406<phrase>
12407 id: LANG_TOUCHSCREEN_MODE 12407 id: LANG_TOUCHSCREEN_MODE
12408 desc: in Settings -> General -> System menu 12408 desc: in Settings -> General -> Display -> Touchscreen Settings
12409 user: core 12409 user: core
12410 <source> 12410 <source>
12411 *: none 12411 *: none
@@ -12422,7 +12422,7 @@
12422</phrase> 12422</phrase>
12423<phrase> 12423<phrase>
12424 id: LANG_TOUCHSCREEN_GRID 12424 id: LANG_TOUCHSCREEN_GRID
12425 desc: in Settings -> General -> System menu 12425 desc: in Settings -> General -> Display -> Touchscreen Settings
12426 user: core 12426 user: core
12427 <source> 12427 <source>
12428 *: none 12428 *: none
@@ -12439,7 +12439,7 @@
12439</phrase> 12439</phrase>
12440<phrase> 12440<phrase>
12441 id: LANG_TOUCHSCREEN_POINT 12441 id: LANG_TOUCHSCREEN_POINT
12442 desc: in Settings -> General -> System menu 12442 desc: in Settings -> General -> Display -> Touchscreen Settings
12443 user: core 12443 user: core
12444 <source> 12444 <source>
12445 *: none 12445 *: none
@@ -12502,3 +12502,54 @@
12502 swcodec: "Speed" 12502 swcodec: "Speed"
12503 </voice> 12503 </voice>
12504</phrase> 12504</phrase>
12505<phrase>
12506 id: LANG_TOUCHSCREEN_SETTINGS
12507 desc: in Settings -> General -> Display menu
12508 user: core
12509 <source>
12510 *: none
12511 touchscreen: "Touchscreen Settings"
12512 </source>
12513 <dest>
12514 *: none
12515 touchscreen: "Touchscreen Settings"
12516 </dest>
12517 <voice>
12518 *: none
12519 touchscreen: "Touchscreen Settings"
12520 </voice>
12521</phrase>
12522<phrase>
12523 id: LANG_TOUCHSCREEN_CALIBRATE
12524 desc: in Settings -> General -> Display -> Touchscreen Settings
12525 user: core
12526 <source>
12527 *: none
12528 touchscreen: "Calibrate"
12529 </source>
12530 <dest>
12531 *: none
12532 touchscreen: "Calibrate"
12533 </dest>
12534 <voice>
12535 *: none
12536 touchscreen: "Calibrate"
12537 </voice>
12538</phrase>
12539<phrase>
12540 id: LANG_TOUCHSCREEN_RESET_CALIBRATION
12541 desc: in Settings -> General -> Display -> Touchscreen Settings
12542 user: core
12543 <source>
12544 *: none
12545 touchscreen: "Reset Calibration"
12546 </source>
12547 <dest>
12548 *: none
12549 touchscreen: "Reset Calibration"
12550 </dest>
12551 <voice>
12552 *: none
12553 touchscreen: "Reset Calibration"
12554 </voice>
12555</phrase>
diff --git a/apps/lang/nederlands.lang b/apps/lang/nederlands.lang
index 2d476d1d14..e73839926f 100644
--- a/apps/lang/nederlands.lang
+++ b/apps/lang/nederlands.lang
@@ -12335,7 +12335,7 @@
12335</phrase> 12335</phrase>
12336<phrase> 12336<phrase>
12337 id: LANG_TOUCHSCREEN_MODE 12337 id: LANG_TOUCHSCREEN_MODE
12338 desc: in Settings -> General -> System menu 12338 desc: in Settings -> General -> Display -> Touchscreen Settings
12339 user: core 12339 user: core
12340 <source> 12340 <source>
12341 *: none 12341 *: none
@@ -12352,7 +12352,7 @@
12352</phrase> 12352</phrase>
12353<phrase> 12353<phrase>
12354 id: LANG_TOUCHSCREEN_GRID 12354 id: LANG_TOUCHSCREEN_GRID
12355 desc: in Settings -> General -> System menu 12355 desc: in Settings -> General -> Display -> Touchscreen Settings
12356 user: core 12356 user: core
12357 <source> 12357 <source>
12358 *: none 12358 *: none
@@ -12369,7 +12369,7 @@
12369</phrase> 12369</phrase>
12370<phrase> 12370<phrase>
12371 id: LANG_TOUCHSCREEN_POINT 12371 id: LANG_TOUCHSCREEN_POINT
12372 desc: in Settings -> General -> System menu 12372 desc: in Settings -> General -> Display -> Touchscreen Settings
12373 user: core 12373 user: core
12374 <source> 12374 <source>
12375 *: none 12375 *: none
@@ -12432,3 +12432,54 @@
12432 swcodec: "Snelheid" 12432 swcodec: "Snelheid"
12433 </voice> 12433 </voice>
12434</phrase> 12434</phrase>
12435<phrase>
12436 id: LANG_TOUCHSCREEN_SETTINGS
12437 desc: in Settings -> General -> Display menu
12438 user: core
12439 <source>
12440 *: none
12441 touchscreen: "Touchscreen Settings"
12442 </source>
12443 <dest>
12444 *: none
12445 touchscreen: "Touchscreen instellingen"
12446 </dest>
12447 <voice>
12448 *: none
12449 touchscreen: "Touchscreen instellingen"
12450 </voice>
12451</phrase>
12452<phrase>
12453 id: LANG_TOUCHSCREEN_CALIBRATE
12454 desc: in Settings -> General -> Display -> Touchscreen Settings
12455 user: core
12456 <source>
12457 *: none
12458 touchscreen: "Calibrate"
12459 </source>
12460 <dest>
12461 *: none
12462 touchscreen: "Kalibreer"
12463 </dest>
12464 <voice>
12465 *: none
12466 touchscreen: "Kalibreer"
12467 </voice>
12468</phrase>
12469<phrase>
12470 id: LANG_TOUCHSCREEN_RESET_CALIBRATION
12471 desc: in Settings -> General -> Display -> Touchscreen Settings
12472 user: core
12473 <source>
12474 *: none
12475 touchscreen: "Reset Calibration"
12476 </source>
12477 <dest>
12478 *: none
12479 touchscreen: "Kalibratie terugzetten"
12480 </dest>
12481 <voice>
12482 *: none
12483 touchscreen: "Kalibratie terugzetten"
12484 </voice>
12485</phrase>
diff --git a/apps/menus/display_menu.c b/apps/menus/display_menu.c
index a015be3a23..aee9c1828d 100644
--- a/apps/menus/display_menu.c
+++ b/apps/menus/display_menu.c
@@ -36,6 +36,9 @@
36#include "talk.h" 36#include "talk.h"
37#include "lcd.h" 37#include "lcd.h"
38#include "lcd-remote.h" 38#include "lcd-remote.h"
39#ifdef HAVE_TOUCHSCREEN
40#include "screens.h"
41#endif
39 42
40#ifdef HAVE_BACKLIGHT 43#ifdef HAVE_BACKLIGHT
41static int filterfirstkeypress_callback(int action,const struct menu_item_ex *this_item) 44static 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,
496/***********************************/ 499/***********************************/
497 500
498 501
502#ifdef HAVE_TOUCHSCREEN
503static int touch_mode_callback(int action,const struct menu_item_ex *this_item)
504{
505 (void)this_item;
506 switch (action)
507 {
508 case ACTION_EXIT_MENUITEM: /* on exit */
509 touchscreen_set_mode(global_settings.touch_mode);
510 break;
511 }
512 return action;
513}
514MENUITEM_SETTING(touch_mode, &global_settings.touch_mode, touch_mode_callback);
515
516MENUITEM_FUNCTION(touchscreen_menu_calibrate, 0, ID2P(LANG_TOUCHSCREEN_CALIBRATE), calibrate,
517 NULL, NULL, Icon_NOICON);
518MENUITEM_FUNCTION(touchscreen_menu_reset_calibration, 0, ID2P(LANG_TOUCHSCREEN_RESET_CALIBRATION), reset_mapping,
519 NULL, NULL, Icon_NOICON);
520
521MAKE_MENU(touchscreen_menu, ID2P(LANG_TOUCHSCREEN_SETTINGS), NULL, Icon_NOICON, &touch_mode,
522 &touchscreen_menu_calibrate, &touchscreen_menu_reset_calibration);
523#endif
524
499 525
500MENUITEM_SETTING(codepage_setting, &global_settings.default_codepage, NULL); 526MENUITEM_SETTING(codepage_setting, &global_settings.default_codepage, NULL);
501 527
@@ -511,4 +537,7 @@ MAKE_MENU(display_menu, ID2P(LANG_DISPLAY),
511 &bars_menu, &peak_meter_menu, 537 &bars_menu, &peak_meter_menu,
512#endif 538#endif
513 &codepage_setting, 539 &codepage_setting,
540#ifdef HAVE_TOUCHSCREEN
541 &touchscreen_menu,
542#endif
514 ); 543 );
diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c
index 56a0178000..fdc775877a 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
265MENUITEM_SETTING(touchpad_sensitivity, &global_settings.touchpad_sensitivity, NULL); 265MENUITEM_SETTING(touchpad_sensitivity, &global_settings.touchpad_sensitivity, NULL);
266#endif 266#endif
267 267
268#ifdef HAVE_TOUCHSCREEN
269static int touch_mode_callback(int action,const struct menu_item_ex *this_item)
270{
271 (void)this_item;
272 switch (action)
273 {
274 case ACTION_EXIT_MENUITEM: /* on exit */
275 touchscreen_set_mode(global_settings.touch_mode);
276 break;
277 }
278 return action;
279}
280MENUITEM_SETTING(touch_mode, &global_settings.touch_mode, touch_mode_callback);
281#endif
282
283MAKE_MENU(system_menu, ID2P(LANG_SYSTEM), 268MAKE_MENU(system_menu, ID2P(LANG_SYSTEM),
284 0, Icon_System_menu, 269 0, Icon_System_menu,
285 &start_screen, 270 &start_screen,
@@ -315,9 +300,6 @@ MAKE_MENU(system_menu, ID2P(LANG_SYSTEM),
315#ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING 300#ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
316 &touchpad_sensitivity, 301 &touchpad_sensitivity,
317#endif 302#endif
318#ifdef HAVE_TOUCHSCREEN
319 &touch_mode,
320#endif
321 ); 303 );
322 304
323/* SYSTEM MENU */ 305/* SYSTEM MENU */
diff --git a/apps/screens.c b/apps/screens.c
index 096b81411e..829aa191e1 100644
--- a/apps/screens.c
+++ b/apps/screens.c
@@ -1019,3 +1019,85 @@ bool view_runtime(void)
1019 } 1019 }
1020 return false; 1020 return false;
1021} 1021}
1022
1023#ifdef HAVE_TOUCHSCREEN
1024static int get_sample(struct touchscreen_calibration *cal, int x, int y, int i,
1025 struct screen* screen)
1026{
1027 int action;
1028 short ts_x, ts_y;
1029
1030 /* Draw a cross */
1031 screen->drawline(x - 10, y, x - 2, y);
1032 screen->drawline(x + 2, y, x + 10, y);
1033 screen->drawline(x, y - 10, x, y - 2);
1034 screen->drawline(x, y + 2, x, y + 10);
1035 screen->update();
1036
1037 /* Wait for a touchscreen press */
1038 while(true)
1039 {
1040 action = get_action(CONTEXT_STD, TIMEOUT_BLOCK);
1041 if(action == ACTION_TOUCHSCREEN)
1042 {
1043 if(action_get_touchscreen_press(&ts_x, &ts_y) == BUTTON_REL)
1044 break;
1045 }
1046 else if(action == ACTION_STD_CANCEL)
1047 return -1;
1048 }
1049
1050 cal->x[i][0] = ts_x;
1051 cal->y[i][0] = ts_y;
1052 cal->x[i][1] = x;
1053 cal->y[i][1] = y;
1054
1055 return 0;
1056}
1057
1058
1059int calibrate(void)
1060{
1061 short points[3][2] = {
1062 {LCD_WIDTH/10, LCD_HEIGHT/10},
1063 {7*LCD_WIDTH/8, LCD_HEIGHT/2},
1064 {LCD_WIDTH/2, 7*LCD_HEIGHT/8}
1065 };
1066 struct screen* screen = &screens[SCREEN_MAIN];
1067 enum touchscreen_mode old_mode = touchscreen_get_mode();
1068 struct touchscreen_calibration cal;
1069 int i, ret = 0;
1070 bool statusbar = global_settings.statusbar; /* hide the statusbar */
1071
1072 global_settings.statusbar = false;
1073 touchscreen_disable_mapping(); /* set raw mode */
1074 touchscreen_set_mode(TOUCHSCREEN_POINT);
1075 for(i=0; i<3; i++)
1076 {
1077 screen->clear_display();
1078
1079 if(get_sample(&cal, points[i][0], points[i][1], i, screen))
1080 {
1081 ret = -1;
1082 break;
1083 }
1084 }
1085
1086 if(ret == 0)
1087 touchscreen_calibrate(&cal);
1088 else
1089 touchscreen_reset_mapping();
1090 memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter));
1091 touchscreen_set_mode(old_mode);
1092 global_settings.statusbar = statusbar;
1093
1094 return ret;
1095}
1096
1097int reset_mapping(void)
1098{
1099 touchscreen_reset_mapping();
1100 memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter));
1101 return 0;
1102}
1103#endif
diff --git a/apps/screens.h b/apps/screens.h
index eb613fc178..38fef14d60 100644
--- a/apps/screens.h
+++ b/apps/screens.h
@@ -50,5 +50,10 @@ bool shutdown_screen(void);
50bool browse_id3(void); 50bool browse_id3(void);
51bool view_runtime(void); 51bool view_runtime(void);
52 52
53#ifdef HAVE_TOUCHSCREEN
54int calibrate(void);
55int reset_mapping(void);
56#endif
57
53#endif 58#endif
54 59
diff --git a/apps/settings.c b/apps/settings.c
index 9594bd164e..3219dbbf12 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -966,6 +966,7 @@ void settings_apply(bool read_disk)
966 966
967#ifdef HAVE_TOUCHSCREEN 967#ifdef HAVE_TOUCHSCREEN
968 touchscreen_set_mode(global_settings.touch_mode); 968 touchscreen_set_mode(global_settings.touch_mode);
969 memcpy(&calibration_parameters, &global_settings.ts_calibration_data, sizeof(struct touchscreen_parameter));
969#endif 970#endif
970 971
971 /* This should stay last */ 972 /* This should stay last */
diff --git a/apps/settings.h b/apps/settings.h
index 6ccaeed92e..ef5a62013d 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -730,6 +730,7 @@ struct user_settings
730 730
731#ifdef HAVE_TOUCHSCREEN 731#ifdef HAVE_TOUCHSCREEN
732 int touch_mode; 732 int touch_mode;
733 struct touchscreen_parameter ts_calibration_data;
733#endif 734#endif
734 735
735 /* If values are just added to the end, no need to bump plugin API 736 /* 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 74e2cab3cd..dcad718ee5 100644
--- a/apps/settings_list.c
+++ b/apps/settings_list.c
@@ -53,6 +53,10 @@
53#include "iap.h" 53#include "iap.h"
54#endif 54#endif
55#include "statusbar.h" 55#include "statusbar.h"
56#ifdef HAVE_TOUCHSCREEN
57#include "touchscreen.h"
58#include "ctype.h" /* For isspace() */
59#endif
56 60
57#define NVRAM(bytes) (bytes<<F_NVRAM_MASK_SHIFT) 61#define NVRAM(bytes) (bytes<<F_NVRAM_MASK_SHIFT)
58/** NOTE: NVRAM_CONFIG_VERSION is in settings_list.h 62/** NOTE: NVRAM_CONFIG_VERSION is in settings_list.h
@@ -452,6 +456,48 @@ static void qs_set_default(void* setting, void* defaultval)
452 find_setting(defaultval, (int*)setting); 456 find_setting(defaultval, (int*)setting);
453} 457}
454#endif 458#endif
459#ifdef HAVE_TOUCHSCREEN
460static void tsc_load_from_cfg(void* setting, char*value)
461{
462 struct touchscreen_parameter *var = (struct touchscreen_parameter*) setting;
463
464 /* Replacement for sscanf(value, "%d ..., &var->A, ...); */
465 int vals[7], count = 0;
466 while(*value != 0 && count < 7)
467 {
468 if(isspace(*value))
469 value++;
470 else
471 {
472 vals[count++] = atoi(value);
473 while(!isspace(*value))
474 value++;
475 }
476 }
477 var->A = vals[0];
478 var->B = vals[1];
479 var->C = vals[2];
480 var->D = vals[3];
481 var->E = vals[4];
482 var->F = vals[5];
483 var->divider = vals[6];
484}
485
486static char* tsc_write_to_cfg(void* setting, char*buf, int buf_len)
487{
488 const struct touchscreen_parameter *var = (const struct touchscreen_parameter*) setting;
489 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);
490 return buf;
491}
492static bool tsc_is_changed(void* setting, void* defaultval)
493{
494 return memcmp(setting, defaultval, sizeof(struct touchscreen_parameter)) != 0;
495}
496static void tsc_set_default(void* setting, void* defaultval)
497{
498 memcpy(setting, defaultval, sizeof(struct touchscreen_parameter));
499}
500#endif
455const struct settings_list settings[] = { 501const struct settings_list settings[] = {
456 /* sound settings */ 502 /* sound settings */
457 SOUND_SETTING(F_NO_WRAP,volume, LANG_VOLUME, "volume", SOUND_VOLUME), 503 SOUND_SETTING(F_NO_WRAP,volume, LANG_VOLUME, "volume", SOUND_VOLUME),
@@ -1470,6 +1516,10 @@ const struct settings_list settings[] = {
1470 CHOICE_SETTING(0, touch_mode, LANG_TOUCHSCREEN_MODE, TOUCHSCREEN_BUTTON, 1516 CHOICE_SETTING(0, touch_mode, LANG_TOUCHSCREEN_MODE, TOUCHSCREEN_BUTTON,
1471 "touchscreen mode", "point,grid", NULL, 2, 1517 "touchscreen mode", "point,grid", NULL, 2,
1472 ID2P(LANG_TOUCHSCREEN_POINT), ID2P(LANG_TOUCHSCREEN_GRID)), 1518 ID2P(LANG_TOUCHSCREEN_POINT), ID2P(LANG_TOUCHSCREEN_GRID)),
1519 CUSTOM_SETTING(0, ts_calibration_data, -1,
1520 &default_calibration_parameters, "touchscreen calibration",
1521 tsc_load_from_cfg, tsc_write_to_cfg,
1522 tsc_is_changed, tsc_set_default),
1473#endif 1523#endif
1474 OFFON_SETTING(0, prevent_skip, LANG_PREVENT_SKIPPING, false, "prevent track skip", NULL), 1524 OFFON_SETTING(0, prevent_skip, LANG_PREVENT_SKIPPING, false, "prevent track skip", NULL),
1475}; 1525};