1. 程式人生 > >圖片播放器(十):事件處理函式

圖片播放器(十):事件處理函式

 

因為從觸控式螢幕傳過來的事件需要另外處理,因此需要分離出一個事件處理層。

系統核心函式:

int main()
{
	int ret = 0;
	char event;
	DEBUG("hello world\n");

	ret = fb_open();
	if(ret < 0){
		DERROR("open fb fail\n");
	}

	fb_draw_back(BLACK);/* 畫黑色的背景板 */

	im_manage_init();/* 初始化連結串列 */

	while(1)
	{	
		event = tu_core();/* 讀取事件 */
		st_event_handle(event);/* 處理事件 */
		DEBUG("處理結束\n");
	}
	
	fb_close();
	im_manage_destroy(); /* 銷燬連結串列 */

	DEBUG("finish \n");
	return 0;
}

 

處理觸控式螢幕傳過來的事件:

/* 處理觸控式螢幕傳過來的事件 */
int st_event_handle(int to_operating_mode)
{
	tail_node = im_read_fail();
	if(to_operating_mode == up_switchover){
		st_hand_up();//向上翻頁
		return 0;
	}else if(to_operating_mode == down_switchover){
		st_hand_down();//向下翻頁
		return 0;
	}else if(to_operating_mode == left_switchover){
		st_hand_left();//向左翻頁
		return 0;
	}else if(to_operating_mode == right_switchover){
		st_hand_right();//向右翻頁
		return 0;
	}else if(to_operating_mode == 0){
		DEBUG("未定義事件");
	}

	return -1;
}

 

各個事件對應的處理函式:

int st_hand_up(void)
{
	DEBUG("處理上翻事件\n");

	p_fb_set.w = 0;
	p_fb_set.h = 0;
	p_fb_set.rotate = ROTATE_FRONT;

	if(file_head.next == NULL){
		DEBUG("現在沒有圖片\n");
		return -1;
	}
	fb_draw_back(BLACK);

	if(now_file_head == NULL){
		now_file_head = file_head.next;
		memset(p_fb_set.path, 0, PATH_NAME_MAX);
		memcpy(p_fb_set.path, (const char *)now_file_head->iamge_file_data.path_name, strlen((const char *)now_file_head->iamge_file_data.path_name) + 1);		
		_fb_show(&p_fb_set);
		return 0;
	}

	now_file_head = now_file_head->prior;
	if(now_file_head == &file_head){
		now_file_head = tail_node;
		DEBUG("aaaaaaaaaa\n");
		memset(p_fb_set.path, 0, PATH_NAME_MAX);
		memcpy(p_fb_set.path, (const char *)now_file_head->iamge_file_data.path_name, strlen((const char *)now_file_head->iamge_file_data.path_name) + 1);
		_fb_show(&p_fb_set);
		return 0;
	}else{
		memset(p_fb_set.path, 0, PATH_NAME_MAX);
		memcpy(p_fb_set.path, (const char *)now_file_head->iamge_file_data.path_name, strlen((const char *)now_file_head->iamge_file_data.path_name) + 1);
		_fb_show(&p_fb_set);
		return 0;
	}

}

int st_hand_down(void)
{
	DEBUG("處理下翻事件\n");

	p_fb_set.w = 0;
	p_fb_set.h = 0;
	p_fb_set.rotate = ROTATE_FRONT;

	if(file_head.next == NULL){
		DEBUG("現在沒有圖片\n");
		return -1;
	}
	fb_draw_back(BLACK);

	if(now_file_head == NULL){
		now_file_head = file_head.next;
		memset(p_fb_set.path, 0, PATH_NAME_MAX);
		memcpy(p_fb_set.path, (const char *)now_file_head->iamge_file_data.path_name, strlen((const char *)now_file_head->iamge_file_data.path_name) + 1);
		_fb_show(&p_fb_set);
		return 0;
	}

	now_file_head = now_file_head->next;
	if(now_file_head == NULL){
		now_file_head = file_head.next;
		memset(p_fb_set.path, 0, PATH_NAME_MAX);
		memcpy(p_fb_set.path, (const char *)now_file_head->iamge_file_data.path_name, strlen((const char *)now_file_head->iamge_file_data.path_name) + 1);
		_fb_show(&p_fb_set);
		return 0;
	}else{
		memset(p_fb_set.path, 0, PATH_NAME_MAX);
		memcpy(p_fb_set.path, (const char *)now_file_head->iamge_file_data.path_name, strlen((const char *)now_file_head->iamge_file_data.path_name) + 1);
		_fb_show(&p_fb_set);
		return 0;
	}

	return 0;

}


int st_hand_left(void)
{
	DEBUG("處理左翻事件\n");

	p_fb_set.w = 0;
	p_fb_set.h = 0;
	p_fb_set.rotate = ROTATE_FRONT;

	if(file_head.next == NULL){
		DEBUG("現在沒有圖片\n");
		return -1;
	}
	fb_draw_back(BLACK);

	if(now_file_head == NULL){
		now_file_head = file_head.next;
		memset(p_fb_set.path, 0, PATH_NAME_MAX);
		memcpy(p_fb_set.path, (const char *)now_file_head->iamge_file_data.path_name, strlen((const char *)now_file_head->iamge_file_data.path_name) + 1);
		_fb_show(&p_fb_set);
		return 0;
	}

	now_file_head = now_file_head->prior;
	if(now_file_head == &file_head){
		now_file_head = tail_node;
		DEBUG("aaaaaaaaaa\n");
		memset(p_fb_set.path, 0, PATH_NAME_MAX);
		memcpy(p_fb_set.path, (const char *)now_file_head->iamge_file_data.path_name, strlen((const char *)now_file_head->iamge_file_data.path_name) + 1);
		_fb_show(&p_fb_set);
		return 0;
	}else{
		memset(p_fb_set.path, 0, PATH_NAME_MAX);
		memcpy(p_fb_set.path, (const char *)now_file_head->iamge_file_data.path_name, strlen((const char *)now_file_head->iamge_file_data.path_name) + 1);
		_fb_show(&p_fb_set);
		return 0;
	}

}

int st_hand_right(void)
{
	DEBUG("處理右翻事件\n");

	p_fb_set.w = 0;
	p_fb_set.h = 0;
	p_fb_set.rotate = ROTATE_FRONT;

	if(file_head.next == NULL){
		DEBUG("現在沒有圖片\n");
		return -1;
	}
	fb_draw_back(BLACK);

	if(now_file_head == NULL){
		now_file_head = file_head.next;
		memset(p_fb_set.path, 0, PATH_NAME_MAX);
		memcpy(p_fb_set.path, (const char *)now_file_head->iamge_file_data.path_name, strlen((const char *)now_file_head->iamge_file_data.path_name) + 1);
		_fb_show(&p_fb_set);
		return 0;
	}

	now_file_head = now_file_head->next;
	if(now_file_head == NULL){
		now_file_head = file_head.next;
		memset(p_fb_set.path, 0, PATH_NAME_MAX);
		memcpy(p_fb_set.path, (const char *)now_file_head->iamge_file_data.path_name, strlen((const char *)now_file_head->iamge_file_data.path_name) + 1);
		_fb_show(&p_fb_set);
		return 0;
	}else{
		memset(p_fb_set.path, 0, PATH_NAME_MAX);
		memcpy(p_fb_set.path, (const char *)now_file_head->iamge_file_data.path_name, strlen((const char *)now_file_head->iamge_file_data.path_name) + 1);
		_fb_show(&p_fb_set);
		return 0;
	}

	return 0;
}