예제 #1
0
파일: blink.c 프로젝트: jselfridge/BBB
int on_mode_press(){
	printf("pressed mode\n");
	if(get_pause_button_state() == 1){
		//both buttons pressed exit cleanly
		set_state(EXITING);
	}
	return 0;
}
/******************************************************************
*	void* pause_unpressed_handler(void* ptr) 
*
*	wait on rising edge of pause button
*******************************************************************/
void* pause_unpressed_handler(void* ptr){
	struct pollfd fdset[1];
	char buf[MAX_BUF];
	int gpio_fd = gpio_fd_open(PAUSE_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_pause_button_state()==UNPRESSED){
				pause_unpressed_func(); 
			}
		}
	}
	gpio_fd_close(gpio_fd);
	return 0;
}
예제 #3
0
/************************************************************************
*	on_pause_press
*	If the user holds the pause button for a second, exit cleanly
*	disarm on momentary press
************************************************************************/
int on_pause_press(){
	int i=0;
	const int samples = 100;	// check for release 100 times in this period
	const int us_wait = 2000000; // 2 seconds
	
	switch(get_state()){
	// pause if running
	case EXITING:
		return 0;
	case RUNNING:
		set_state(PAUSED);
		disarm_controller();
		setRED(HIGH);
		setGRN(LOW);
		break;
	case PAUSED:
		set_state(RUNNING);
		disarm_controller();
		setGRN(HIGH);
		setRED(LOW);
		break;
	default:
		break;
	}
	
	// now wait to see if the user wants to shut down the program
	while(i<samples){
		usleep(us_wait/samples);
		if(get_pause_button_state() == UNPRESSED){
			return 0; //user let go before time-out
		}
		i++;
	}
	printf("long press detected, shutting down\n");
	//user held the button down long enough, blink and exit cleanly
	blink_red();
	set_state(EXITING);
	return 0;
}