Beispiel #1
0
/*
 * Generic Input handling
 */
int handle_input() {
	int i = 0;
	SDL_Event event;

	while (picframe_get_event(&event)) {

		switch (event.type) {
		case SDL_QUIT:
			printf("Quitting\n");
			return 1;
			break;
		case SDL_KEYDOWN:
			if (event.key.keysym.sym == SDLK_LEFT) {
				leftArrow->selected = 1;
				curr_window_idx--;
				if (curr_window_idx < 0)
					curr_window_idx = 0;
				printf("Current window: %d\n", curr_window_idx);

			}

			if (event.key.keysym.sym == SDLK_RIGHT) {
				rightArrow->selected = 1;
				curr_window_idx++;
				if (curr_window_idx > NUM_WINDOWS - 1)
					curr_window_idx = NUM_WINDOWS - 1;

				printf("Current window: %d\n", curr_window_idx);
			}

			if (event.key.keysym.sym == SDLK_RETURN) {
				i = picframe_get_lightsensor();
				printf("Light sensor: %d\n", i);
			}

			break;

		case SDL_KEYUP:
			if (event.key.keysym.sym == SDLK_LEFT) {
				leftArrow->selected = 0;
			}

			if (event.key.keysym.sym == SDLK_RIGHT) {
				rightArrow->selected = 0;
			}

			break;
		default:
			break;
		}
		if (prev_window_idx != curr_window_idx) {
			prev_window_idx = curr_window_idx;
			return 2;
		}
		prev_window_idx = curr_window_idx;
	}
	return 0;
}
Beispiel #2
0
/*
 * Generic Input handling
 */
int handle_input() {
	int i=0;
	struct LList_t *tmp_window = NULL;

//	picframe_gpio_handle_events();

	while (picframe_get_event(&event)) {
		switch (event.type) {
			case SDL_QUIT:
				printf("Quitting\n");
                                return 1;
				break;
                        case SDL_KEYDOWN:
                        	if (event.key.keysym.sym == SDLK_LEFT) {
                                	left_arrow_icon.selected = 1;
                                     	curr_window_idx--;
                                        if (curr_window_idx < 1) curr_window_idx = 1;
                                        	tmp_window = picframe_get_window(curr_window_idx);
                                        if (tmp_window) curr_window = tmp_window;
                                        else curr_window_idx++;

                                        printf("Current window: %d\n", curr_window_idx);
                                }

                                if (event.key.keysym.sym == SDLK_RIGHT) {
                                	right_arrow_icon.selected = 1;
                                        curr_window_idx++;
                                        if (curr_window_idx > NUM_WINDOWS) curr_window_idx = NUM_WINDOWS;
                                        	tmp_window = picframe_get_window(curr_window_idx);
                                        if (tmp_window) curr_window = tmp_window;
                                        else curr_window_idx--;
                                        
				        printf("Current window: %d\n", curr_window_idx);
				}

                                if (event.key.keysym.sym == SDLK_RETURN) {
                                	i = picframe_get_lightsensor();
                                	printf("Light sensor: %d\n", i);
                                }
	

				if (event.key.keysym.sym == '1') {
					appls[0].selected = 1;
				}	
                                if (event.key.keysym.sym == '2') {
                                        appls[1].selected = 1;
                                }
                                if (event.key.keysym.sym == '3') {
                                        appls[2].selected = 1;
                                }
                                if (event.key.keysym.sym == '4') {
                                        appls[3].selected = 1;
                                }

                                break;

                   	case SDL_KEYUP:
                        	if (event.key.keysym.sym == SDLK_LEFT) {
                                	left_arrow_icon.selected = 0;
                                }

                                if (event.key.keysym.sym == SDLK_RIGHT) {
                               		right_arrow_icon.selected = 0;
                                }

				if (event.key.keysym.sym == '1') {
					appls[0].selected = 0;
				}
                                if (event.key.keysym.sym == '2') {
                                        appls[1].selected = 0;
                                }
                                if (event.key.keysym.sym == '3') {
                                        appls[2].selected = 0;
                                }
                                if (event.key.keysym.sym == '4') {
                                        appls[3].selected = 0;
                                }

                                break;
                       	default:
                        	break;
		}
		if (prev_window_idx != curr_window_idx) {
			prev_window_idx = curr_window_idx;
			return 2;
		}
		prev_window_idx = curr_window_idx;
	}
	return 0;
}