添加delay.c模块,封装了sleep、usleep函数

This commit is contained in:
Liu Chao
2013-02-19 15:09:08 +08:00
parent c17a843657
commit 8edb07b3fe
18 changed files with 103 additions and 133 deletions
+7 -3
View File
@@ -54,12 +54,16 @@
#include LC_CONFIG_H
#ifdef WIN32
#if defined(WIN32) || defined(_WIN32)
#define LCUI_BUILD_IN_WIN32
#define LCUI_THREAD_WIN32
#define LCUI_VIDEO_DRIVER_WIN32
#undef LCUI_THREAD_PTHREAD
#undef LCUI_VIDEO_DRIVER_FRAMEBUFFER
#else
#define LCUI_BUILD_IN_LINUX
#define LCUI_KEYBOARD_DRIVER_LINUX
#define LCUI_MOUSE_DRIVER_LINUX
#endif
@@ -367,8 +371,8 @@ typedef enum {
} ALIGN_TYPE;
/*---------------------------------------------*/
#define MAX_APP_IDLE_TIME 50000
#define MAX_LCUI_IDLE_TIME 50000
#define MAX_APP_IDLE_TIME 50
#define MAX_LCUI_IDLE_TIME 50
#define nobuff_printf(format, ...) \
{ \
+2 -7
View File
@@ -149,13 +149,8 @@ BOOL LCUIKeyboard_Hit( void );
/* 功能:获取被按下的按键的键值 */
int LCUIKeyboard_Get( void );
int Find_Pressed_Key(int key);
/*
* 功能:检测指定键值的按键是否处于按下状态
* 返回值:
* 1 存在
* 0 不存在
**/
/* 检测指定键值的按键是否处于按下状态 */
BOOL KeyHit( int key_code );
/* 初始化键盘输入模块 */
void LCUIModule_Keyboard_Init( void );
+6
View File
@@ -44,6 +44,12 @@
LCUI_BEGIN_HEADER
/* 秒级延时 */
void LCUI_Sleep( unsigned int s );
/* 毫秒级延时 */
void LCUI_MSleep( unsigned int ms );
/******************************** Misc *********************************/
int Check_Option(int result, int option);
/* 功能:检测result是否包含option */
-1
View File
@@ -66,7 +66,6 @@
#include LC_GRAPH_H
#include LC_WIDGET_H
#include LC_ERROR_H
#include <unistd.h>
/************************ LCUI_Queue **********************************/
/* 为队列设定互斥锁,使之只能被一个线程使用 */
+1 -2
View File
@@ -50,7 +50,6 @@
#include LC_CURSOR_H
#include LC_INPUT_H
#include <unistd.h>
#include <math.h>
#include <limits.h>
@@ -2211,7 +2210,7 @@ void Move_Widget_To_Pos(LCUI_Widget *widget, LCUI_Pos des_pos, int speed)
x += w;
y += h;
Widget_Move(widget, Pos(x, y));
usleep(10000);/* 停顿0.01秒 */
LCUI_MSleep(10);/* 停顿0.01秒 */
}
}
+23 -23
View File
@@ -41,15 +41,20 @@
#include <LCUI_Build.h>
#include LC_LCUI_H
#ifdef LCUI_KEYBOARD_DRIVER_LINUX
#define __NEED_CATCHSCREEN__
#ifdef __NEED_CATCHSCREEN__
#include LC_GRAPH_H
#include LC_DRAW_H
#include LC_DISPLAY_H
#endif
#include <termios.h>
#include <unistd.h>
#include <sys/fcntl.h>
static struct termios tm;//, tm_old;
static int fd = STDIN_FILENO;
@@ -131,38 +136,25 @@ int LCUIKeyboard_Get( void )
return c;
}
int Find_Pressed_Key(int key)
/*
* 功能:检测指定键值的按键是否处于按下状态
* 返回值:
* 1 存在
* 0 不存在
**/
/* 检测指定键值的按键是否处于按下状态 */
BOOL KeyHit( int key_code )
{
int t;
int *t;
int i, total;
total = Queue_Get_Total(&LCUI_Sys.press_key);
for(i=0; i<total; ++i) {
t = *(int*)Queue_Get(&LCUI_Sys.press_key, i);
if(t == key) {
return 1;
t = Queue_Get(&LCUI_Sys.press_key, i);
if( t && *t == key_code ) {
return TRUE;
}
}
return 0;
return FALSE;
}
static BOOL proc_keyboard()
{
LCUI_Event event;
LCUI_Rect area;
LCUI_Graph graph;
Graph_Init(&graph);
area.width = 320;
area.height = 240;
area.x = (Get_Screen_Width()-area.width)/2;
area.y = (Get_Screen_Height()-area.height)/2;
/* 如果没有按键输入 */
if ( !LCUIKeyboard_Hit() ) {
return FALSE;
@@ -171,13 +163,20 @@ static BOOL proc_keyboard()
event.type = LCUI_KEYDOWN;
event.key.key_code = LCUIKeyboard_Get();
#define __NEED_CATCHSCREEN__
#ifdef __NEED_CATCHSCREEN__
LCUI_Rect area;
area.width = 320;
area.height = 240;
area.x = (Get_Screen_Width()-area.width)/2;
area.y = (Get_Screen_Height()-area.height)/2;
//当按下c键后,可以进行截图,只截取指定区域的图形
if(event.key.key_code == 'c') {
time_t rawtime;
struct tm * timeinfo;
char filename[100];
LCUI_Graph graph;
Graph_Init(&graph);
time ( &rawtime );
timeinfo = localtime ( &rawtime ); /* 获取系统当前时间 */
sprintf(filename, "%4d-%02d-%02d-%02d-%02d-%02d.png",
@@ -187,6 +186,7 @@ static BOOL proc_keyboard()
);
Catch_Screen_Graph_By_FB( area, &graph );
write_png(filename, &graph);
Graph_Free(&graph);
}
else if(event.key.key_code == 'r') {
/* 如果按下r键,就录制指定区域的图像 */
@@ -194,7 +194,6 @@ static BOOL proc_keyboard()
}
#endif
LCUI_PushEvent( &event );
Graph_Free(&graph);
return TRUE;
}
@@ -218,3 +217,4 @@ void LCUIModule_Keyboard_Init( void )
LCUI_Dev_Add( Enable_Keyboard_Input, proc_keyboard, Disable_Keyboard_Input );
}
#endif
+1 -1
View File
@@ -107,7 +107,7 @@ int Click_LeftButton (LCUI_MouseButtonEvent *event)
{
/* 如果按下的是鼠标左键,并且之前没有按住它 */
if (Mouse_LeftButton(event) == PRESSED
&& !Find_Pressed_Key(event->button)) {
&& !KeyHit(event->button)) {
return 1;
}
return 0;
+5 -7
View File
@@ -1,9 +1,7 @@
#include <LCUI_Build.h>
#include LC_LCUI_H
#include <unistd.h>
/*----------------------------- Device -------------------------------*/
/* 设备列表初始化 */
static void
dev_list_init( LCUI_Queue *dev_list )
@@ -39,7 +37,7 @@ proc_dev_list ( void *arg )
{
LCUI_Queue *dev_list;
dev_func_data *data_ptr;
int total, i, result, sleep_time = 1000;
int total, i, result, sleep_time = 1;
dev_list = (LCUI_Queue *)arg;
while( LCUI_Active() ) {
@@ -53,11 +51,11 @@ proc_dev_list ( void *arg )
result += data_ptr->proc_func();
}
if( result > 0 ) {
sleep_time = 1000;
sleep_time = 1;
} else {
usleep( sleep_time );
if( sleep_time < 100000 ) {
sleep_time += 1000;
LCUI_MSleep( sleep_time );
if( sleep_time < 100 ) {
sleep_time += 1;
}
}
}
+5 -5
View File
@@ -110,11 +110,11 @@ LCUI_DispatchUserEvent( LCUI_Event *event )
static void LCUI_EventLoop( void *unused )
{
LCUI_Event event;
int delay_time = 1500;
int delay_time = 1;
while( active ) {
if( LCUI_PollEvent( &event ) ) {
delay_time = 1500;
delay_time = 1;
switch( event.type ) {
case LCUI_KEYDOWN:
case LCUI_KEYUP:
@@ -128,10 +128,10 @@ static void LCUI_EventLoop( void *unused )
break;
}
} else {
if( delay_time <= 15000 ) {
delay_time += 1500;
if( delay_time <= 15 ) {
delay_time += 1;
}
usleep( delay_time );
LCUI_MSleep( delay_time );
}
}
_LCUIThread_Exit( NULL );
+4 -18
View File
@@ -10,22 +10,8 @@
#include LC_FONT_H
#include LC_WIDGET_H
#include <unistd.h>
#include <signal.h>
LCUI_System LCUI_Sys;
static clock_t start_time;
void count_time()
{
start_time = clock();
}
void end_count_time()
{
printf("%ldms\n",clock()-start_time);
}
/************************* App Management *****************************/
/* 根据程序的ID,获取指向程序数据结构的指针 */
LCUI_App *LCUIApp_Find( LCUI_ID id )
@@ -311,7 +297,7 @@ LCUIApp_RunTask( LCUI_App *app )
int LCUI_MainLoop_Run( LCUI_MainLoop *loop )
{
LCUI_App *app;
int idle_time = 1500;
int idle_time = 1;
app = LCUIApp_GetSelf();
if( !app ) {
@@ -322,12 +308,12 @@ int LCUI_MainLoop_Run( LCUI_MainLoop *loop )
loop->running = TRUE;
while( !loop->quit ) {
if( LCUIApp_HaveTask(app) ) {
idle_time = 1500;
idle_time = 1;
LCUIApp_RunTask( app );
} else {
usleep (idle_time);
LCUI_MSleep (idle_time);
if (idle_time < MAX_APP_IDLE_TIME) {
idle_time += 1500;
idle_time += 1;
}
}
}
+7 -8
View File
@@ -1,6 +1,5 @@
#include <LCUI_Build.h>
#include LC_LCUI_H
#include <unistd.h>
/*----------------------------- Timer --------------------------------*/
/*----------------------------- Private ------------------------------*/
@@ -87,7 +86,7 @@ timer_list_update( LCUI_Queue *timer_list )
return NULL;
}
if(timer->cur_ms > 0) {
usleep( timer->cur_ms*1000 );
LCUI_MSleep( timer->cur_ms );
}
/* 减少列表中所有定时器的剩余等待时间 */
timer_list_sub( timer_list, timer->cur_ms );
@@ -102,7 +101,7 @@ static BOOL timer_thread_active = TRUE;
static void
timer_list_process( void *arg )
{
int sleep_time = 1000;
int sleep_time = 1;
LCUI_Func func_data;
LCUI_Queue *timer_list;
timer_data *timer;
@@ -112,18 +111,18 @@ timer_list_process( void *arg )
func_data.arg[1] = NULL;
while( !LCUI_Active() ) {
usleep(10000);
LCUI_MSleep(10);
}
while( LCUI_Active() || timer_thread_active ) {
timer = timer_list_update( timer_list );
if( !timer ) {
usleep( sleep_time );
if(sleep_time < 500000) {
sleep_time += 1000;
LCUI_MSleep( sleep_time );
if(sleep_time < 500) {
sleep_time += 1;
}
continue;
}
sleep_time = 1000;
sleep_time = 1;
func_data.id = timer->app_id;
func_data.func = timer->callback_func;
/* 添加该任务至指定程序的任务队列,添加模式是覆盖 */
+1 -1
View File
@@ -1,5 +1,5 @@
AUTOMAKE_OPTIONS=foreign
INCLUDES = -I$(abs_top_srcdir)/include
noinst_LTLIBRARIES = libmisc.la
libmisc_la_SOURCES = catch_screen.c rect.c string.c misc.c
libmisc_la_SOURCES = catch_screen.c rect.c string.c misc.c delay.c
+4 -2
View File
@@ -47,7 +47,8 @@ CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
libmisc_la_LIBADD =
am_libmisc_la_OBJECTS = catch_screen.lo rect.lo string.lo misc.lo
am_libmisc_la_OBJECTS = catch_screen.lo rect.lo string.lo misc.lo \
delay.lo
libmisc_la_OBJECTS = $(am_libmisc_la_OBJECTS)
AM_V_lt = $(am__v_lt_$(V))
am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY))
@@ -210,7 +211,7 @@ top_srcdir = @top_srcdir@
AUTOMAKE_OPTIONS = foreign
INCLUDES = -I$(abs_top_srcdir)/include
noinst_LTLIBRARIES = libmisc.la
libmisc_la_SOURCES = catch_screen.c rect.c string.c misc.c
libmisc_la_SOURCES = catch_screen.c rect.c string.c misc.c delay.c
all: all-am
.SUFFIXES:
@@ -264,6 +265,7 @@ distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/catch_screen.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/delay.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rect.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/string.Plo@am__quote@
+1 -3
View File
@@ -46,8 +46,6 @@
#include LC_DRAW_H
#include LC_DISPLAY_H
#include <unistd.h>
void Catch_Screen_Graph_By_Cache(LCUI_Rect area, LCUI_Graph *out)
/*
* 功能:通过内存中的图像数据,捕获将在屏幕上显示的图像
@@ -131,7 +129,7 @@ static void catch()
Catch_Screen_Graph_By_FB( area, &graph );
write_png( filename, &graph );
usleep(35000);
LCUI_MSleep(35);
}
LCUIThread_Exit(NULL);
}
+27
View File
@@ -0,0 +1,27 @@
#include <LCUI_Build.h>
#include LC_LCUI_H
#ifdef LCUI_BUILD_IN_WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
/* 秒级延时 */
void LCUI_Sleep( unsigned int s )
{
#ifdef LCUI_BUILD_IN_WIN32
Sleep(s*1000);
#else
sleep(s);
#endif
}
/* 毫秒级延时 */
void LCUI_MSleep( unsigned int ms )
{
#ifdef LCUI_BUILD_IN_WIN32
Sleep(ms);
#else
usleep(ms*1000);
#endif
}
+5 -45
View File
@@ -48,8 +48,6 @@
#include LC_WIDGET_H
#include LC_CURSOR_H
#include <unistd.h>
int Get_Screen_Width ()
/*
* 功能:获取屏幕宽度
@@ -80,7 +78,6 @@ LCUI_Size Get_Screen_Size( void )
return LCUI_Sys.screen.size;
}
//static int debug_count = 0;
int Add_Screen_Refresh_Area (LCUI_Rect rect)
/* 功能:在整个屏幕内添加需要刷新的区域 */
{
@@ -88,14 +85,7 @@ int Add_Screen_Refresh_Area (LCUI_Rect rect)
if (rect.width <= 0 || rect.height <= 0) {
return -1;
}
rect = Get_Valid_Area(Get_Screen_Size(), rect);
//if( rect.width == 320 && rect.height == 240 ) {
//++debug_count;
//}
//if( debug_count >= 20 ) {
// abort();
//}
rect = Get_Valid_Area(Get_Screen_Size(), rect);
Queue_Lock( &LCUI_Sys.invalid_area );
ret = RectQueue_Add ( &LCUI_Sys.invalid_area, rect );
/* 队列使用结束,解开锁 */
@@ -166,27 +156,6 @@ Handle_Screen_Update()
Graph_Free(&graph);
}
//#define need_autoquit
#ifdef need_autoquit
static int auto_flag = 0;
static void *autoquit()
/* 在超时后,会自动终止程序,用于调试 */
{
LCUI_ID time = 0;
while(time <5000000) {
if(auto_flag == 0) {
usleep(10000);
time += 10000;
} else {
auto_flag = 0;
time = 0;
}
}
exit(-1);
}
#endif
static void
Handle_Refresh_Area( void )
/*
@@ -218,28 +187,19 @@ static void
Handle_Area_Update ()
/* 功能:进行屏幕内容更新 */
{
#ifdef need_autoquit
LCUI_Thread t;
LCUIThread_Create(&t, NULL, autoquit, NULL);
#endif
int timer_id;
/* 添加个定时器,每隔1秒刷新FPS计数 */
timer_id = set_timer( 1000, refresh_fps_count, TRUE );
//_DEBUG_MSG("enter\n");
while(LCUI_Active()) {
Handle_AllWidgetUpdate();/* 处理所有部件更新 */
usleep(5000);/* 停顿一段时间,让程序主循环处理任务 */
Handle_AllWidgetUpdate(); /* 处理所有部件更新 */
LCUI_MSleep(5); /* 停顿一段时间,让程序主循环处理任务 */
Handle_Refresh_Area(); /* 处理需要刷新的区域 */
Handle_Screen_Update();/* 处理屏幕更新 */
#ifdef need_autoquit
auto_flag = 1;
#endif
/* 累计当前更新的帧数 */
++fps_count;
Handle_Screen_Update(); /* 处理屏幕更新 */
++fps_count; /* 累计当前更新的帧数 */
}
/* 释放定时器 */
free_timer( timer_id );
//_DEBUG_MSG("exit\n");
LCUIThread_Exit(NULL);
}
+1 -2
View File
@@ -40,7 +40,6 @@
* ****************************************************************************/
//#define DEBUG
#include <LCUI_Build.h>
#include <unistd.h>
#include LC_LCUI_H
#include LC_WIDGET_H
#include LC_MISC_H
@@ -410,7 +409,7 @@ Process_Frames()
LCUI_Frames *frames;
while(!LCUI_Active()) {
usleep(10000);
LCUI_MSleep(10);
}
frames = FramesStream_Update( &sleep_time );
reset_timer( __timer_id, sleep_time );
+3 -5
View File
@@ -47,8 +47,6 @@
#include LC_PICBOX_H
#include LC_RES_H
#include <unistd.h>
/* 功能:获取进度条上闪光图形所在的PictureBox部件 */
static LCUI_Widget *
ProgressBar_GetMoveingLight(LCUI_Widget *widget)
@@ -79,7 +77,7 @@ ProgressBar_Init(LCUI_Widget *widget)
Graph_Init(&pb->fore_graph);
Graph_Init(&pb->flash_image);
pb->img_move_speed = 200;
pb->sleep_time = 100000;
pb->sleep_time = 100;
pb->max_value = 1;
pb->value = 0;
@@ -204,9 +202,9 @@ ProgressBar_ProcMoveingLight(void *arg)
x<=flash->parent->size.w;
x+=(pb->img_move_speed/20.0+0.5)) {
Widget_Move(flash, Pos(x , flash->pos.y));
usleep(50000);
LCUI_MSleep(50);
}
usleep(pb->sleep_time);
LCUI_MSleep(pb->sleep_time);
}
LCUIThread_Exit(NULL);
}