Esempio n. 1
0
// Print to the console when buttons are pressed
int on_pause_press(){
	printf("pressed Pause\n");
	if(get_mode_button_state() == 1){
		//both buttons pressed exit cleanly
		set_state(EXITING);
	}
	return 0;
}
/******************************************************************
*	void* mode_unpressed_handler(void* ptr) 
*	wait on rising edge of mode button
*******************************************************************/
void* mode_unpressed_handler(void* ptr){
	struct pollfd fdset[1];
	char buf[MAX_BUF];
	int gpio_fd = gpio_fd_open(MODE_BTN);
	fdset[0].fd = gpio_fd;
	fdset[0].events = POLLPRI; // high-priority interrupt
	// keep running until the program closes
	while(get_state() != EXITING) {
		// system hangs here until FIFO interrupt
		poll(fdset, 1, POLL_TIMEOUT);        
		if (fdset[0].revents & POLLPRI) {
			lseek(fdset[0].fd, 0, SEEK_SET);  
			read(fdset[0].fd, buf, MAX_BUF);
			if(get_mode_button_state()==UNPRESSED){
				mode_unpressed_func(); 
			}
		}
	}
	gpio_fd_close(gpio_fd);
	return 0;
}