/** 处理列表中的设备的数据 */ static void proc_dev_list( void *arg ) { LCUI_Queue *dev_list; dev_func_data *data_ptr; int total, i, timeout_count = 0; dev_list = (LCUI_Queue *)arg; while( LCUI_Active() ) { Queue_Lock( dev_list ); total = Queue_GetTotal( dev_list ); for(i=0; i<total; ++i) { data_ptr = (dev_func_data*)Queue_Get( dev_list, i ); if( !data_ptr || !data_ptr->proc_func ) { continue; } if( data_ptr->proc_func() ) { ++timeout_count; } } Queue_Unlock( dev_list ); if( timeout_count > 20 ) { LCUI_MSleep( 10 ); timeout_count = 0; } LCUI_MSleep( 5 ); } LCUIThread_Exit(NULL); }
static void Process_Frames( void ) /* 功能:处理动画的每一帧的更新 */ { int sleep_time = 10; LCUI_Frames *frames; while(!LCUI_Active()) { LCUI_MSleep(10); } frames = FramesStream_Update( &sleep_time ); reset_timer( __timer_id, sleep_time ); if( frames ) { Frames_CallFunc( frames ); } }
static void thread(void *arg) { LCUI_Widget *widget, *label; widget = (LCUI_Widget*)arg; label = Widget_New( "label" ); Widget_Container_Add( widget, label ); Widget_SetAlign( label, ALIGN_MIDDLE_CENTER, Pos(0,0) ); Widget_Show( label ); while(LCUI_Active()) { Label_Text( label, "DOCK_TYPE_TOP" ); Widget_SetDock( widget, DOCK_TYPE_TOP ); Widget_SetSize( widget, "120px", "120px" ); /* 还原尺寸 */ LCUI_Sleep(1); Label_Text( label, "DOCK_TYPE_LEFT" ); Widget_SetDock( widget, DOCK_TYPE_LEFT ); Widget_SetSize( widget, "120px", "120px" ); LCUI_Sleep(1); Label_Text( label, "DOCK_TYPE_RIGHT" ); Widget_SetDock( widget, DOCK_TYPE_RIGHT ); Widget_SetSize( widget, "120px", "120px" ); LCUI_Sleep(1); Label_Text( label, "DOCK_TYPE_BOTTOM" ); Widget_SetDock( widget, DOCK_TYPE_BOTTOM ); Widget_SetSize( widget, "120px", "120px" ); LCUI_Sleep(1); Label_Text( label, "DOCK_TYPE_FILL" ); Widget_SetDock( widget, DOCK_TYPE_FILL ); Widget_SetSize( widget, "120px", "120px" ); LCUI_Sleep(1); Label_Text( label, "DOCK_TYPE_NONE" ); Widget_SetDock( widget, DOCK_TYPE_NONE ); Widget_SetSize( widget, "120px", "120px" ); LCUI_Sleep(1); } LCUIThread_Exit(NULL); }
/** 定时器线程,用于处理列表中各个定时器 */ static void TimerThread( void *arg ) { int i, n; long int n_ms; LCUI_Func func_data; LCUI_Queue *timer_list; timer_data *timer = NULL; int64_t lost_ms; timer_list = (LCUI_Queue*)arg; func_data.arg[0] = NULL; func_data.arg[1] = NULL; while( !LCUI_Active() ) { LCUI_MSleep(10); } while( timer_thread_active ) { Queue_Lock( timer_list ); n = Queue_GetTotal( timer_list ); for(i=0; i<n; ++i) { timer = (timer_data*)Queue_Get( timer_list , i); if( !timer ) { continue; } if( timer->state == STATE_RUN ) { break; } } Queue_Unlock( timer_list ); /* 没有要处理的定时器,停留一段时间再进行下次循环 */ if(i >= n || !timer ) { LCUI_MSleep(10); continue; } lost_ms = LCUI_GetTicks( timer->start_time ); /* 减去处于暂停状态的时长 */ lost_ms -= timer->pause_ms; /* 若流失的时间未达到总定时时长 */ if( lost_ms < timer->total_ms ) { Queue_Lock( timer_list ); n_ms = timer->total_ms - lost_ms; /* 开始睡眠 */ LCUISleeper_StartSleep( &timer_sleeper, n_ms ); Queue_Unlock( timer_list ); lost_ms = LCUI_GetTicks( timer->start_time ); lost_ms -= timer->pause_ms; if( lost_ms < timer->total_ms ) { continue; } } DEBUG_MSG("timer: %d, start_time: %I64dms, cur_time: %I64dms, cur_ms: %I64d, total_ms: %ld\n", timer->id, timer->start_time, LCUI_GetTickCount(), timer->total_ms-lost_ms, timer->total_ms); /* 准备任务数据 */ func_data.id = timer->app_id; func_data.func = (CallBackFunc)timer->callback_func; func_data.arg[0] = timer->arg; func_data.destroy_arg[0] = FALSE; /* 添加该任务至指定程序的任务队列,添加模式是覆盖 */ AppTasks_CustomAdd( ADD_MODE_REPLACE | AND_ARG_F, &func_data ); Queue_Lock( timer_list ); /* 若需要重复使用,则重置剩余等待时间 */ if( timer->reuse ) { timer->start_time = LCUI_GetTickCount(); timer->pause_ms = 0; TimerList_UpdateTimerPos( timer_list, timer ); } else { /* 否则,释放该定时器 */ LCUITimer_Free( timer->id ); } Queue_Unlock( timer_list ); } LCUIThread_Exit(NULL); }
static void * Handle_TouchScreen_Input () /* 功能:处理触屏输入 */ { char *tsdevice; struct ts_sample samp; int button, x, y, ret; LCUI_MouseEvent event; char str[100]; while (LCUI_Active()) { if (LCUI_Sys.ts.status != INSIDE) { tsdevice = getenv("TSLIB_TSDEVICE"); if( tsdevice != NULL ) { LCUI_Sys.ts.td = ts_open(tsdevice, 0); } else { tsdevice = TS_DEV; } LCUI_Sys.ts.td = ts_open (tsdevice, 0); if (!LCUI_Sys.ts.td) { sprintf (str, "ts_open: %s", tsdevice); perror (str); LCUI_Sys.ts.status = REMOVE; break; } if (ts_config (LCUI_Sys.ts.td)) { perror ("ts_config"); LCUI_Sys.ts.status = REMOVE; break; } LCUI_Sys.ts.status = INSIDE; } /* 开始获取触屏点击处的坐标 */ ret = ts_read (LCUI_Sys.ts.td, &samp, 1); if (ret < 0) { perror ("ts_read"); continue; } if (ret != 1) { continue; } x = samp.x; y = samp.y; if (x > Get_Screen_Width ()) { x = Get_Screen_Width (); } if (y > Get_Screen_Height ()) { y = Get_Screen_Height (); } if (x < 0) { x = 0; } if (y < 0) { y = 0; } /* 设定游标位置 */ Set_Cursor_Pos (Pos(x, y)); event.global_pos.x = x; event.global_pos.y = y; /* 获取当前鼠标指针覆盖到的部件的指针 */ event.widget = Get_Cursor_Overlay_Widget(); /* 如果有覆盖到的部件,就需要计算鼠标指针与部件的相对坐标 */ if(event.widget != NULL) { event.pos.x = x - Get_Widget_Global_Pos(event.widget).x; event.pos.y = y - Get_Widget_Global_Pos(event.widget).y; } else {/* 否则,和全局坐标一样 */ event.pos.x = x; event.pos.y = y; } if (samp.pressure > 0) { button = 1; } else { button = 0; } /* 处理鼠标事件 */ Handle_Mouse_Event(button, &event); //printf("%ld.%06ld: %6d %6d %6d\n", samp.tv.tv_sec, samp.tv.tv_usec, samp.x, samp.y, samp.pressure); } if(LCUI_Sys.ts.status == INSIDE) { ts_close(LCUI_Sys.ts.td); } LCUI_Sys.ts.status = REMOVE; thread_exit (NULL); }