版权声明:转载请声明 https://blog.csdn.net/qq_40732350/article/details/84327910
因为从触摸屏传过来的事件需要另外处理,因此需要分离出一个事件处理层。
系统核心函数:
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;
}
扫描二维码关注公众号,回复:
4216348 查看本文章