/** * \brief Starts the calibration routines and displays user instructions on screen. * * \return 0 if calibration is successful, else 1. */ uint32_t rtouch_calibrate(void) { uint32_t i; uint32_t x, y; /* Print user instructions */ lcd_fill(UNI_COLOR_WHITE); lcd_set_foreground_color(UNI_COLOR_BLACK); lcd_draw_string(30, 60, (uint8_t *)"LCD calibration"); lcd_draw_string(1, 190, (uint8_t *)"Touch the dots to\ncalibrate the screen"); /* Calibration points */ for (i = 0; i < 5; i++) { draw_calibration_point(&gs_calibration_points[i].panel); /* Wait for touch & end of conversion */ rtouch_wait_pressed(); rtouch_get_raw_point(&x, &y); gs_calibration_points[i].raw.x = x; gs_calibration_points[i].raw.y = y; clear_calibration_point(&gs_calibration_points[i].panel); /* Wait for contact loss */ rtouch_wait_released(); } if (rtouch_compute_calibration((rtouch_calibration_point_t *) &gs_calibration_points) == 0) { lcd_fill(UNI_COLOR_WHITE); lcd_set_foreground_color(UNI_COLOR_BLACK); lcd_draw_string(20, 130, (uint8_t *)"Calibration done."); return 0; } else { lcd_fill(UNI_COLOR_WHITE); lcd_set_foreground_color(UNI_COLOR_BLACK); lcd_draw_string(10, 100, (uint8_t *)"Calibration failed!"); lcd_draw_string(10, 190, (uint8_t *)"Please try again..."); /* Wait for contact loss */ rtouch_wait_released(); return 1; } }
void rtouch_process(void) { static rtouch_point_t old_position; uint32_t timeKeep; int32_t xDiff, yDiff; uint32_t x, y; if (g_ul_is_rtouch_enabled == 0) { return; } g_ul_timestamp++; /** * Get the current position of the pen if penIRQ has * low value (pen pressed) */ if (rtouch_is_pressed()) { /** Get the current position of the pressed pen */ if (rtouch_is_calibrated()) { rtouch_get_raw_point(&x, &y); event.raw.x = x; event.raw.y = y; old_position.x = event.panel.x; old_position.y = event.panel.y; rtouch_get_calibrated_point(&event.raw, &event.panel); } /** call the callback function */ if (pen_state == STATE_PEN_PRESSED) { if (rtouch_is_calibrated()) { /** Filter move event if the move is too low */ xDiff = old_position.x - event.panel.x; yDiff = old_position.y - event.panel.y; if (!((xDiff >= -POINTS_MAX_ERROR) && (xDiff <= POINTS_MAX_ERROR) && (yDiff >= -POINTS_MAX_ERROR) && (yDiff <= POINTS_MAX_ERROR))) { event.type = RTOUCH_MOVE; if (event_handler) { event_handler(&event); } } } } } /** Determine the pen state */ if (rtouch_is_pressed()) { /** Touch pressed: reinit the last time when release */ g_ul_timerelease = g_ul_timestamp; if (pen_state == STATE_PEN_DEBOUNCE) { timeKeep = g_ul_timestamp; timeKeep -= g_ul_timepress; if (timeKeep > DEBOUNCE_TIME) { /** pen is pressed during an enough time : the state change */ pen_state = STATE_PEN_PRESSED; event.type = RTOUCH_PRESS; /** call the callback function */ if (rtouch_is_calibrated() && event_handler) { event_handler(&event); } } } } else { /** Touch released: reinit the last time when release */ g_ul_timepress = g_ul_timestamp; if (pen_state == STATE_PEN_DEBOUNCE) { timeKeep = g_ul_timestamp; timeKeep -= g_ul_timerelease; if (timeKeep > DEBOUNCE_TIME) { /** pen is pressed during an enough time : the state change */ pen_state = STATE_PEN_RELEASED; event.type = RTOUCH_RELEASE; /** call the callback function */ if (rtouch_is_calibrated() && event_handler) { event_handler(&event); } } } } }
/** * \brief Starts the calibration routines and displays user instructions on screen. * * \return 0 if calibration is successful, else 1. */ uint32_t rtouch_calibrate(void) { uint32_t i; uint32_t x, y; /* Fill the whole screen with the background color */ gfx_draw_filled_rect(0, 0, gfx_get_width(), gfx_get_height(), BGCOLOR); /* Print user instructions */ /* Write center-aligned text string to the top of the display */ gfx_draw_string_aligned(string_calib_name, gfx_get_width() / 2, 60, &sysfont, GFX_COLOR_WHITE, TXTCOLOR, TEXT_POS_CENTER, TEXT_ALIGN_LEFT); gfx_draw_string_aligned(string_calib_instruction, gfx_get_width() / 2, 190, &sysfont, GFX_COLOR_WHITE, TXTCOLOR, TEXT_POS_CENTER, TEXT_ALIGN_LEFT); /* Calibration points */ for (i = 0; i < NUM_TOUCH_POINTS; i++) { draw_calibration_point(&gs_calibration_points[i].panel); /* Wait for touch & end of conversion */ rtouch_wait_pressed(); rtouch_get_raw_point(&x, &y); gs_calibration_points[i].raw.x = x; gs_calibration_points[i].raw.y = y; clear_calibration_point(&gs_calibration_points[i].panel); /* Wait for contact loss */ rtouch_wait_released(); } /* Check if the points acceptable */ if (rtouch_compute_calibration((rtouch_calibration_point_t *) &gs_calibration_points) == 0) { for (i=0;i<NUM_TOUCH_POINTS;i++) { g_demo_parameters.calib_points[i].raw.x = gs_calibration_points[i].raw.x; g_demo_parameters.calib_points[i].raw.y = gs_calibration_points[i].raw.y; } /* Commit changes to the parameter area */ demo_parameters_commit_changes(); /* Display calibration done string */ gfx_draw_string_aligned(string_calib_done, gfx_get_width() / 2, 130, &sysfont, GFX_COLOR_WHITE, TXTCOLOR, TEXT_POS_CENTER, TEXT_ALIGN_LEFT); return 0; } else { /* Clear instruction string first */ gfx_draw_string_aligned(string_calib_instruction, gfx_get_width() / 2, 190, &sysfont, GFX_COLOR_WHITE, GFX_COLOR_WHITE, TEXT_POS_CENTER, TEXT_ALIGN_LEFT); /* Show up failed string */ gfx_draw_string_aligned(string_calib_failed, gfx_get_width() / 2, 100, &sysfont, GFX_COLOR_WHITE, TXTCOLOR, TEXT_POS_CENTER, TEXT_ALIGN_LEFT); /* Display retry string */ gfx_draw_string_aligned(string_calib_retry, gfx_get_width() / 2, 190, &sysfont, GFX_COLOR_WHITE, TXTCOLOR, TEXT_POS_CENTER, TEXT_ALIGN_LEFT); /* Wait for contact loss */ rtouch_wait_released(); return 1; } }