Index: apps/touchscreen.c =================================================================== --- apps/touchscreen.c (revision 0) +++ apps/touchscreen.c (revision 0) @@ -0,0 +1,92 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2009 by Maurus Cuelenaere + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "config.h" +#include "action.h" +#include "lcd.h" +#include "system.h" +#include "touchscreen.h" + +static void get_sample(struct touchscreen_calibration *cal, int x, int y) +{ + static int index=0; + int action; + short ts_x, ts_y; + + /* Draw a cross */ + lcd_drawline(x - 10, y, x - 2, y); + lcd_drawline(x + 2, y, x + 10, y); + lcd_drawline(x, y - 10, x, y - 2); + lcd_drawline(x, y + 2, x, y + 10); + lcd_update(); + + do + { + action = get_action(CONTEXT_STD, TIMEOUT_BLOCK); + if(action == ACTION_TOUCHSCREEN) + { + action_get_touchscreen_press(&ts_x, &ts_y); + break; + } + } + while(action != ACTION_STD_CANCEL); + + cal->x[index] = ts_x; + cal->y[index] = ts_y; + cal->xfb[index] = x; + cal->yfb[index] = y; + index++; +} + + +int calibrate(void) +{ + int points[3][2] = { + {LCD_WIDTH/10, LCD_HEIGHT/10}, + {7*LCD_WIDTH/8, LCD_HEIGHT/2}, + {LCD_WIDTH/2, 7*LCD_HEIGHT/8} + }; + struct touchscreen_calibration cal; + int i, action; + + touchscreen_disable_mapping(); + for(i=0; i<3; i++) + { + lcd_clear_display(); + lcd_putsxy(LCD_WIDTH/2, 0, "Calibration mode"); + + get_sample(&cal, points[i][0], points[i][1]); + + /* Make sure pen is up */ + do + action = get_action(CONTEXT_STD, HZ/8); + while(action == ACTION_TOUCHSCREEN); + } + touchscreen_calibrate(&cal); + + return 0; +} + +int reset_mapping(void) +{ + touchscreen_reset_mapping(); + return 0; +} Property changes on: apps/touchscreen.c ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Index: apps/SOURCES =================================================================== --- apps/SOURCES (revision 21213) +++ apps/SOURCES (working copy) @@ -167,6 +167,7 @@ tagcache.c #endif #ifdef HAVE_TOUCHSCREEN +touchscreen.c keymaps/keymap-touchscreen.c #endif #if (CONFIG_KEYPAD == IRIVER_H100_PAD) \ Index: apps/menus/settings_menu.c =================================================================== --- apps/menus/settings_menu.c (revision 21213) +++ apps/menus/settings_menu.c (working copy) @@ -278,8 +278,20 @@ return action; } MENUITEM_SETTING(touch_mode, &global_settings.touch_mode, touch_mode_callback); + +extern int calibrate(void); +extern int reset_mapping(void); + +MENUITEM_FUNCTION(touchscreen_menu_calibrate, 0, "Calibrate", calibrate, + NULL, NULL, Icon_NOICON); +MENUITEM_FUNCTION(touchscreen_menu_reset_calibration, 0, "Reset calibration", reset_mapping, + NULL, NULL, Icon_NOICON); + +MAKE_MENU(touchscreen_menu, "Touchscreen Settings", NULL, Icon_NOICON, &touch_mode, + &touchscreen_menu_calibrate, &touchscreen_menu_reset_calibration); #endif + MAKE_MENU(system_menu, ID2P(LANG_SYSTEM), 0, Icon_System_menu, &start_screen, @@ -316,7 +328,7 @@ &touchpad_sensitivity, #endif #ifdef HAVE_TOUCHSCREEN - &touch_mode, + &touchscreen_menu, #endif );