// Buzz open the gate, but not too much. int buzz_open_gate(void) { // if opened less than BUZZER_SOLENOID_REST_TIME, or buzzer_state == 1, return 1 // otherwise, open the gate and return 0 int result; struct timeval now; gettimeofday(&now, NULL); int time_delta = (int)now.tv_sec - (int)last_buzzer_firing.tv_sec; if (buzzer_state == 1 || time_delta < BUZZER_SOLENOID_REST_TIME) { return(1); } else { result = enable_buzzer_solenoid(); buzzer_state = 1; last_buzzer_firing = now; return(result); } }
// Buzz open the gate, but not too much. int buzz_open_gate(void) { // if opened less than BUZZER_SOLENOID_REST_TIME ago, or buzzer_state == 1 already, return 1 (already opened) // otherwise, open the gate and return 0 (success) // This may also return -1 from the underlying calls to ioctl(2) in enable_buzzer_solenoid int result; struct timeval now; gettimeofday(&now, NULL); int time_delta = (int)now.tv_sec - (int)last_buzzer_firing.tv_sec; if (buzzer_state == 1 || time_delta < BUZZER_SOLENOID_REST_TIME) { #ifdef DEBUG fprintf(stderr, "buzz_open_gate(): The buzzer has already been engaged. Returning 1\n"); #endif return(1); } else { #ifdef DEBUG fprintf(stderr, "buzz_open_gate(): enabling the buzzer solenoid\n"); #endif result = enable_buzzer_solenoid(); buzzer_state = 1; last_buzzer_firing = now; return(result); } }