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/screens.c | |
parent | b1a60934c5d178842ec3bec83a3e5286410cab7d (diff) | |
download | rockbox-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/screens.c')
-rw-r--r-- | apps/screens.c | 82 |
1 files changed, 82 insertions, 0 deletions
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 | ||
1024 | static 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 | |||
1059 | int 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 | |||
1097 | int 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 | ||