#include "mywin_inc.h" //清零定时器 int WIN_TimerReload (int timerId) { WIN_GetWinStruct()->softTimer[timerId-1].time_ms=0; return 0; } //设置定时器周期 int WIN_SetTimerCycle (int timerId,int cycle) { WIN_GetWinStruct()->softTimer[timerId-1].cycle_ms=cycle; return 0; } //添加定时器,成功返回id,失败返回0 int WIN_CreatTimer (WIN_WindowStruct *win,u32 ms) { for (int i=0;isoftTimer[i].win==0) { WIN_GetWinStruct()->softTimer[i].win=win; WIN_GetWinStruct()->softTimer[i].cycle_ms=ms; WIN_GetWinStruct()->softTimer[i].time_ms=0; return i+1; } } return 0; } //删除指定定时器失败返回-1,成功返回0 int WIN_DeleteTimer (int id) { if (id>=WIN_SOFTTIMER_MAXNUM) return -1; if (id<=0) return -1; WIN_GetWinStruct()->softTimer[id-1].win=0; return 0; } //删除窗口创建的所有定时器 int WIN_WinDeleteTimer (WIN_WindowStruct *win) { for (int i=0;isoftTimer[i].win==win) { WIN_GetWinStruct()->softTimer[i].win=0; } } return 0; } //定时器工作 void WIN_TimerWork (void) { WIN_MsgStruct msg={0}; u32 timePast=WIN_GetTimePast (); for (int i=0;isoftTimer[i].win) { WIN_GetWinStruct()->softTimer[i].time_ms+=timePast; if (WIN_GetWinStruct()->softTimer[i].time_ms>=WIN_GetWinStruct()->softTimer[i].cycle_ms) { WIN_GetWinStruct()->softTimer[i].time_ms=0; msg.msg=WIN_MSG_TIMER; msg.data.v=i+1; //填充定时器id WIN_SendMsg (0,WIN_GetWinStruct()->softTimer[i].win,&msg); } } } }