图片播放器(十):事件处理函数

 

因为从触摸屏传过来的事件需要另外处理,因此需要分离出一个事件处理层。

系统核心函数:

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;
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值