int input_do (game_t * g) { static SDL_Event ev; if (SDL_PollEvent (&ev) != 0) switch (ev.type) { case SDL_KEYDOWN: if (ev.key.keysym.sym == 27) return 0; else if (ev.key.keysym.sym == SDLK_F10) video_screenshot (); else state[ev.key.keysym.sym] = 1; break; case SDL_KEYUP: state[ev.key.keysym.sym] = 0; break; } if (state[SDLK_RIGHT]) g->player[PLAYER].X += 4.0 * timer_delta (); if (state[SDLK_LEFT]) g->player[PLAYER].X -= 4.0 * timer_delta (); return 1; }
void spinner_step (void) { static int value; static int step; static const unsigned char rgch[] = { '|', '/', '-', '\\', '|', '/', '-', '\\' } ; unsigned v = timer_delta (0, timer_read ()); if (hook_spinner) hook_spinner (v); v = v/128; if (v == value) return; value = v; putchar ('\r'); putchar (rgch[step]); step = (step + 1)%8; }
void pulse_control_update(void) // Update the servo seek position and velocity based on any received servo pulses. { int16_t pulse_position; // Did we get a pulse? if (pulse_flag) { // Ignore unusual pulse durations as a sanity check. if ((pulse_duration > 500) && (pulse_duration < 2500)) { // Convert the pulse duration to a pulse time. pulse_position = pulse_duration - 998; // Limit the pulse position. if (pulse_position < MIN_POSITION) pulse_position = MIN_POSITION; if (pulse_position > MAX_POSITION) pulse_position = MAX_POSITION; // Apply a low pass filter to the pulse position. pulse_position = filter_update(pulse_position, &filter_reg_pulse); // Are we reversing the seek sense? if (registers_read_byte(REG_REVERSE_SEEK) != 0) { // Yes. Update the seek position using reverse sense. registers_write_word(REG_SEEK_POSITION_HI, REG_SEEK_POSITION_LO, (MAX_POSITION - pulse_position)); } else { // No. Update the seek position using normal sense. registers_write_word(REG_SEEK_POSITION_HI, REG_SEEK_POSITION_LO, pulse_position); } // The seek velocity will always be zero. registers_write_word(REG_SEEK_VELOCITY_HI, REG_SEEK_VELOCITY_LO, 0); // Make sure pwm is enabled. pwm_enable(); // Update the pulse time used as a time stamp. pulse_time = timer_get(); } // Reset the pulse time flag. pulse_flag = 0; } else { // If we haven't seen a pulse in .5 seconds disable pwm. if (timer_delta(pulse_time) > 50) { // Disable pwm. pwm_disable(); // Update the pulse time used as a time stamp. pulse_time = timer_get(); } } return; }