⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer.c

📁 定时器LINUX上的实现
💻 C
字号:
/***************************COPYRIGHT (C)*******************************                      PORCHESON TECH. CO.,LTD*                      http://www.porcheson.com****************************FILE INFO.**********************************	NAME	:	timer.c*	VERSION	:	V1.0*	DATE	:	2006.11.08*	AUTHOR	:	pearli*	DESP.	:	the interval timer**********************************************************************/#include "./include.h"void StartIntervalTimer(void){    static clock_t oldTick,currentTick;    static INT32U  number;    static FLOAT32 tp = 0;    static FLOAT32 timeIntervalMin = 0.1;    time_t timer;    struct tm* timeCurr;        tp = sysconf(_SC_CLK_TCK);    currentTick = oldTick = times(NULL);    number = 0;    // 修正number    do    {        timer = time(NULL);        timeCurr = localtime(&timer);        number = timeCurr->tm_sec * 10;        timer = time(NULL);        timeCurr = localtime(&timer);    }    while (number != timeCurr->tm_sec * 10);        while (1)    {        currentTick = times(NULL);                if (((FLOAT32)(currentTick - oldTick)                / tp) > timeIntervalMin)        {            oldTick = currentTick;            number++;            if (number % 8 == 0)            {                CheckUsbOnLine();                PostMessage(GetActiveWindow(),MSG_UPDATETIMER,0,0);            }            if (number % 600 == 0)            {                number = 0;                timer = time(NULL);                timeCurr = localtime(&timer);                                if (number != timeCurr->tm_sec * 10)                {                    do                    {                        timer = time(NULL);                        timeCurr = localtime(&timer);                        number = timeCurr->tm_sec * 10;                        timer = time(NULL);                        timeCurr = localtime(&timer);                    }                    while (number != timeCurr->tm_sec * 10);                }            }            if (gstruSystem.hintLen && gstruSystem.isHint)            {                pthread_mutex_lock(&gMutexHintTime);                                // 编辑框获得焦点后等待0.3秒再弹出提示                if (3 == gHintStartTime)                {                    PostMessage(GetActiveWindow(),SHOW_MHINT,0,0);                 }                                if (gHintStartTime == gstruSystem.hintLen + 3)                {                    PostMessage(GetActiveWindow(),HIDE_MHINT,0,0);                }                if (gHintStartTime <= gstruSystem.hintLen + 3)                {                    gHintStartTime++;                }                pthread_mutex_unlock(&gMutexHintTime);            }            // for show speed, MUST not be deleted            pthread_mutex_lock(&gMutexReDraw);            if (1 == gReDrawTime)            {                PostMessage(GetActiveWindow(),MSG_REDRWA,0,0);             }            if (++gReDrawTime > 2)            {                gReDrawTime = 2;            }            pthread_mutex_unlock(&gMutexReDraw);        }                // 延时0.005秒        usleep(5000);    }         }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -