From: Rusty Russell Date: Sat, 2 Feb 2008 00:40:14 +0000 (+1100) Subject: Calibration images: now usable! X-Git-Url: https://git.ozlabs.org/?p=ponghero.git;a=commitdiff_plain;h=c8bec7224a7fa4403a570e0f690f09496e815f97 Calibration images: now usable! --- diff --git a/prpong.c b/prpong.c index ddf4afb..da584f9 100644 --- a/prpong.c +++ b/prpong.c @@ -701,12 +701,20 @@ static uint16_t *find_valid_point(struct cwiid_state *state) } static void calibrate(SDL_Surface *screen, + const char *filename, cwiid_wiimote_t *wiimote, struct coord *calib, unsigned x, unsigned y) { + SDL_Surface *img = IMG_Load(filename); uint16_t *pos; struct cwiid_state state; - unsigned int last_x = MAX_X, last_y = MAX_Y, count = 0; + int last_x = MAX_X, last_y = MAX_Y, count = 0; + SDL_Rect rect = { .x = screen->w/2 - img->w/2, + .y = screen->h/2 - img->h/2 }; + + SDL_BlitSurface(img, NULL, screen, &rect); + SDL_UpdateRect(screen, 0, 0, 0, 0); + SDL_FreeSurface(img); /* Must see it for a full half second. */ while (count < 20) { @@ -716,13 +724,15 @@ static void calibrate(SDL_Surface *screen, errx(1, "No wii state"); pos = find_valid_point(&state); - if (!pos || pos[0] != last_x || pos[1] != last_y) - count = 0; - - if (pos) { + if (!pos) { + if (count) + count--; + } else { + /* Allow some jitter */ + if (abs(pos[0]-last_x) < 3 && abs(pos[1]-last_y) < 3) + count++; last_x = pos[0]; last_y = pos[1]; - count++; } SDL_Delay(25); @@ -737,6 +747,7 @@ static void calibrate(SDL_Surface *screen, calib->x = last_x; calib->y = last_y; + SDL_Delay(500); printf("Calibration point: %u,%u\n", last_x, last_y); } @@ -1084,10 +1095,14 @@ int main(int argc, char *argv[]) if (needs_calibration) { /* Calibration */ - calibrate(screen, wiimote, &calib[0], 0, 0); - calibrate(screen, wiimote, &calib[1], MAX_X - 1, 0); - calibrate(screen, wiimote, &calib[2], MAX_X - 1, MAX_Y - 1); - calibrate(screen, wiimote, &calib[3], 0, MAX_Y - 1); + calibrate(screen, "images/top-left.png", + wiimote, &calib[0], 0, 0); + calibrate(screen, "images/top-right.png", + wiimote, &calib[1], MAX_X - 1, 0); + calibrate(screen, "images/bottom-right.png", + wiimote, &calib[2], MAX_X - 1, MAX_Y - 1); + calibrate(screen, "images/bottom-left.png", + wiimote, &calib[3], 0, MAX_Y - 1); } /* Create borders, put them in list. */ @@ -1191,7 +1206,7 @@ int main(int argc, char *argv[]) SDL_UpdateRect(screen, rect.x, rect.y, rect.w, rect.h); - SDL_Delay(3000); + SDL_Delay(5000); exit(0); } }