static void os_delay(void) { double delay_time; target_clock_t start, stop; target_yield(); delay_time = adv_measure_step(os_wait, 0.0001, 0.2, 7); if (delay_time > 0) { log_std(("os: sleep granularity %g\n", delay_time)); target_usleep_granularity(delay_time * 1000000); } else { log_std(("ERROR:os: sleep granularity NOT measured\n")); target_usleep_granularity(20000 /* 20 ms */); } target_yield(); start = target_clock(); stop = target_clock(); while (stop == start) stop = target_clock(); log_std(("os: clock granularity %g\n", (stop - start) / (double)TARGET_CLOCKS_PER_SEC)); }
void run(void) { target_clock_t last; printf("Press ESC or Break to exit\n\r"); signal(SIGINT, sigint); last = target_clock(); while (!done) { if (inputb_hit()) { unsigned k; target_clock_t current = target_clock(); double period = (current - last) * 1000.0 / TARGET_CLOCKS_PER_SEC; k = inputb_get(); last = current; if (k > 32 && k < 256) printf("(%6.1f ms) %d '%c'\n\r", period, k, (char)k); else printf("(%6.1f ms) %d\n\r", period, k); if (k == 27) done = 1; } os_poll(); target_yield(); } }
void wait_button_release(void) { target_clock_t start = target_clock(); while (target_clock() - start < TARGET_CLOCKS_PER_SEC / 10) { if (button_pressed()) start = target_clock(); } }
/** * Wait a vsync using the VGA registers. */ static adv_error fb_wait_vsync_vga(void) { unsigned counter; assert(fb_is_active() && fb_mode_is_active()); counter = 0; while ((target_port_get(0x3da) & 0x8) != 0) { if (counter > VSYNC_LIMIT) { log_std(("ERROR:fb: wait timeout\n")); return -1; } ++counter; } while ((target_port_get(0x3da) & 0x8) == 0) { if (counter > VSYNC_LIMIT) { log_std(("ERROR:fb: wait timeout\n")); return -1; } ++counter; } fb_state.wait_last = target_clock(); return 0; }
adv_error joystickb_lgallegro_init(int id) { log_std(("joystickb:lgallegro: joystickb_lgallegro_init(id:%d)\n", id)); if (id == JOY_TYPE_AUTODETECT) { error_set("No auto detection"); return -1; } lgallegro_state.id = id; lgallegro_state.last = target_clock(); log_std(("joystickb:lgallegro: joystick initialization\n")); if (install_joystick(lgallegro_state.id) != 0) { log_std(("joystickb:lgallegro: joystick initialization failed\n")); return -1; } return 0; }
void joystickb_lgallegro_poll(void) { unsigned j, s, a; log_debug(("joystickb:lgallegro: joystickb_lgallegro_poll()\n")); target_clock_t now = target_clock(); if (lgallegro_option.filter == FILTER_AUTO || lgallegro_option.filter == FILTER_TIME ) { /* don't poll too frequently */ if (now - lgallegro_state.last > TARGET_CLOCKS_PER_SEC / 30) { log_debug(("joystickb:lgallegro: effective poll\n")); lgallegro_state.last = now; poll_joystick(); } else { log_debug(("joystickb:lgallegro: skipped poll\n")); } } else { lgallegro_state.last = now; poll_joystick(); } for(j=0;j<joystickb_lgallegro_count_get();++j) { for(s=0;s<joystickb_lgallegro_stick_count_get(j);++s) { for(a=0;a<joystickb_lgallegro_stick_axe_count_get(j,s);++a) { struct joystick_axe_context* c = &lgallegro_state.map[j].axe_map[s][a]; int r = joy[j].stick[s].axis[a].pos; if (lgallegro_option.filter == FILTER_VALUE) { int limit = 127; if (r <= -limit || r >= limit) { /* skip */ continue; } } /* store the new values */ c->v = r; c->d1 = joy[j].stick[s].axis[a].d1; c->d2 = joy[j].stick[s].axis[a].d2; /* update autocalibration */ if (c->l == 0 && c->h == 0) { c->l = c->v; c->h = c->v; } else { if (c->v < c->l) c->l = c->v; if (c->v > c->h) c->h = c->v; } if (lgallegro_option.calibration == CALIBRATION_AUTO) { c->a = joystickb_adjust_analog(c->v, c->l, c->h); } else if (lgallegro_option.calibration == CALIBRATION_NONE) { c->a = joystickb_adjust_analog(c->v, -128, 128); } else { c->a = 0; } log_debug(("joystickb:lgallegro: id:%d,%d,%d,v:%d[%d:%d>%d]\n", j, s, a, c->v, c->l, c->h, c->a)); } } } }
void run(void) { char msg[1024]; char new_msg[1024]; int i, j, k; target_clock_t last; printf("Press Break to exit\n"); signal(SIGINT, sigint); last = target_clock(); msg[0] = 0; while (!done) { new_msg[0] = 0; for (i = 0; i < joystickb_count_get(); ++i) { if (i != 0) sncat(new_msg, sizeof(new_msg), "\n"); snprintf(new_msg + strlen(new_msg), sizeof(new_msg) - strlen(new_msg), "joy %d, [", i); for (j = 0; j < joystickb_button_count_get(i); ++j) { if (joystickb_button_get(i, j)) sncat(new_msg, sizeof(new_msg), "_"); else sncat(new_msg, sizeof(new_msg), "-"); } sncat(new_msg, sizeof(new_msg), "], "); for (j = 0; j < joystickb_stick_count_get(i); ++j) { for (k = 0; k < joystickb_stick_axe_count_get(i, j); ++k) { char digital; if (joystickb_stick_axe_digital_get(i, j, k, 0)) digital = '\\'; else if (joystickb_stick_axe_digital_get(i, j, k, 1)) digital = '/'; else digital = '-'; sncatf(new_msg, sizeof(new_msg), " %d/%d [%6d %c]", j, k, joystickb_stick_axe_analog_get(i, j, k), digital); } } sncat(new_msg, sizeof(new_msg), " ["); for (j = 0; j < joystickb_rel_count_get(i); ++j) { if (j != 0) sncat(new_msg, sizeof(new_msg), "/"); sncatf(new_msg, sizeof(new_msg), "%d", joystickb_rel_get(i, j)); } sncat(new_msg, sizeof(new_msg), "]"); } if (strcmp(msg, new_msg) != 0) { target_clock_t current = target_clock(); double period = (current - last) * 1000.0 / TARGET_CLOCKS_PER_SEC; last = current; sncpy(msg, sizeof(msg), new_msg); printf("%s (%4.0f ms)\n", msg, period); } os_poll(); joystickb_poll(); target_yield(); } }