/** * \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; } }
/** * \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; } }