基于双向链表的窗口消息管理框架

9 篇文章 1 订阅
7 篇文章 0 订阅

基于双向链表的窗口消息管理框架

Manager.c

#include "Manager/rtdef.h"
#include "Manager/rtservice.h"
#include "Manager/Manager.h"


/**
 * @brief Manager System scheduling management function
 * @see   InitManager() Called in Initialize function interface
 * 	 	  TimeTickInc() Called in SysTick_Handler exception
 *
 */

/* Private variables --------------------------------------------------------*/
static vu32 		__uwTick = 0;									// SysTick 
static vu32 		__uwTime = 0;									// SysTime
static rt_list_t 	WindowHeader[MAX_TASK];							// Window header
static TIMERWINDOW	TimerPoolWindow[MAX_TASK][MAX_TIMER_WIN];      	// Timer window pool
static TIMER		TimerPool[MAX_TIMER];							// Timer pool

/*--------------------------- Window Manager ------------------------------*/


/**
 * @brief  Register window
 * @param  Task index
 * @param  Window pointer 
 * @retval Result of register action
 */
u8 RegisterWindow(u8 hTask,WINDOW* Window)
{
	RT_ASSERT(hTask < MAX_TASK);
	/* insert a node before a sentry node */
	rt_list_insert_before(&WindowHeader[hTask], &(Window->list));

	return (TRUE);
}


/**
 * @brief  Logout window
 * @param  Task index
 * @retval Result of logout action
 */
u8 LogoutWindow(u8 hTask)
{
	WINDOW* CurrentWindow;
	RT_ASSERT(hTask < MAX_TASK);

	/* check window list is empty */
	if (rt_list_isempty(&WindowHeader[hTask])) {
		return (FALSE);
	}

	/* check window list is one */
	if (rt_list_isone(&WindowHeader[hTask])) {
		return (FALSE);/*< The first window cant close */
	}

	/* according to the first window fix up the current window entry pointer */
	CurrentWindow = rt_list_last_entry(&WindowHeader[hTask], WINDOW, list);
	CurrentWindow->Active = FALSE;			/*< current window is no actived */
	KillWindowTimer(hTask, CurrentWindow);	/*< kill all timer of current window */
	rt_list_remove(&CurrentWindow->list);	/*< remove the current window list  */

	return (TRUE);
}


/**
 * @brief  Get current task window
 * @param  Task index
 * @retval Current window of task
 */
WINDOW* GetCurrentWindow(u8 hTask)
{
	WINDOW *CurrentWindow;

	RT_ASSERT(hTask < MAX_TASK);

	/* check window list is empty */
	if (rt_list_isempty(&WindowHeader[hTask])) {
		return NULL;
	}

	/* fix up the entry pointer */
	CurrentWindow = rt_list_last_entry(&WindowHeader[hTask], WINDOW, list);

	return CurrentWindow;
}

/**
 * @brief  Get task first window
 * @param  Task index
 * @retval Task first window
 */
WINDOW* Task_FirstWindow(u8 hTask)
{
	WINDOW *FirstWindow;

	RT_ASSERT(hTask < MAX_TASK);
	/* check window list is empty */
	if (rt_list_isempty(&WindowHeader[hTask])) {
		return NULL;
	}
	
	/* fix up the entry pointer */
	FirstWindow = rt_list_first_entry(&WindowHeader[hTask], WINDOW, list);
	
	return FirstWindow;
}

/**
 * @brief  Open window 
 * @param  Task index
 * @param  Window pointer 
 * @retval None
 */ 
void OpenWindow(u8 hTask,WINDOW *Window)
{
	DrawObject(Window);
	/* active current window  */
	Window->Active = TRUE;
	
	/* assign to current window  */
	Task_CurrentWindow[hTask] = Window;
	
	/* record window switch */
	RecordWindowSwitchProcess(hTask,Window);
}

/**
 * @brief Close window
 * @param Task index
 * @note  Close current window, redraw the previous window, 
 *        and active previous window in function of OpenWindow as current window.
 */
void CloseWindow(u8 hTask)
{
	if (LogoutWindow(hTask)){ /*< The active window handle points to the previous window */
		(*ActiveWindowProc(hTask))(WM_REDRAW,0,0,0,0);	/*< Call the window function to redraw the previous window */
	}
}


/**
 * @brief  Return current window WindowProc entry address
 * @param  Task index
 * @remark must check the function address is illegal, if address is abnormal ,the function will trigger HardFault_Handler exception
 */
WINPROCPTR ActiveWindowProc(u8 hTask)
{
	WINDOW *CurrentWindow = GetCurrentWindow(hTask);
	RT_ASSERT(CurrentWindow != NULL);

	return (CurrentWindow->WindowProc);
}

/**
 * @brief  Return first window WindowProc entry address
 * @param  Task index
 * @remark must check the function address is illegal, if address is abnormal ,the function will trigger HardFault_Handler exception
 */
WINPROCPTR ActiveFirstWindowProc(const u8 hTask)
{
	WINDOW *FirstWindow = Task_FirstWindow(hTask);
	
	/* parameter check */
	RT_ASSERT(FirstWindow != NULL);

	return (FirstWindow->WindowProc);
}

/**
 * @brief 向当前窗口的后续所有子窗口发送消息
 * @param hTask 任务索引
 * @param window 窗口实例
 * @param windowMsg 向窗口发送的消息
 * @note 在已打开的窗口双向链表里遍历后面的窗口实例并发送消息,此时需要注意的是当前的窗口不一定为当前任务活动窗口,
 *       在子窗口处理消息分支时需要注意,非当前活动窗口时避免禁止新开或关闭窗口等流程,以免打乱流程,可以暂存消息,待当前窗口激活时在WM_REFRESH分支处理
 */
void ActiveSubWindowProc(const u8 hTask, const WINDOW* window, const WINDOW_MSG* windowMsg)
{
	//当前窗口已被close不向子窗口发送消息
	if( rt_list_isempty(&window->list) || !window->Active) return;
	//遍历当前窗口的子窗口,寻找当前窗口后续所有的窗口
	rt_list_t* pos;
	WINDOW* win;
	for( pos = window->list.next; pos != &WindowHead[hTask]; pos = pos->next )
	{
		win = rt_list_entry(pos, WINDOW, list);
		(*win->WindowProc)(windowMsg->Type,windowMsg->Parameter,windowMsg->Info,windowMsg->hSrcWin,windowMsg->hTagWin);
	}
}


/**
 * @brief  Refresh task of current window
 * @remark check the first window is null and current window is actived 
 * @note   Called in main loop
 */
void RefreshWindow(void)
{
	u16 i;
	WINDOW *CurrentWindow;
	
	for (i=0;i<MAX_TASK;i++){
		CurrentWindow = GetCurrentWindow(i); /*<get current task window */
		if (CurrentWindow != NULL && CurrentWindow->Active){
			(*ActiveWindowProc(i))(WM_REFRESH,0,0,0,0); /*<refresh the current window */
		}
	}
}



/*--------------------------- Timer Manager ------------------------------*/
/**
 * @brief  Set window timer
 * @param  Task index
 * @param  Window pointer
 * @param  Timer interval
 * @param  Timer property, 
 *         0:timer tick increase in all window, 1:timer tick increase only in register window, tick is freezed in other window 
 * @param  TimerProc callback pointer
 * @retval return index when set window timer success
 *         return -1 if timer pool window is full
 */
s16 Set_Timer_Window(u8 hTask,WINDOW* Window,WORD Interval,BYTE Property,TIMERPROCPTR TimerProc)
{
	u16 i;
	for (i=0; i<MAX_TIMER_WIN; i++){
		if (TimerPoolWindow[hTask][i].Interval == 0){
			TimerPoolWindow[hTask][i].TickCounter = 0;
			TimerPoolWindow[hTask][i].Window = Window;
			TimerPoolWindow[hTask][i].Interval = Interval;
			TimerPoolWindow[hTask][i].Property = Property;
			TimerPoolWindow[hTask][i].TimerProc = TimerProc; 
			return (i);
		}
	}
	return (-1);
}

/**
 * @brief  Kill all timer of this window
 * @param  Task index
 * @param  Window pointer
 */
void KillWindowTimer(u8 hTask, WINDOW* Window)
{
	u16 i;
	for (i = 0; i < MAX_TIMER_WIN; i++) {
		if (TimerPoolWindow[hTask][i].Interval && TimerPoolWindow[hTask][i].Window == Window) {
			TimerPoolWindow[hTask][i].Interval = 0;
		}
	}
}

/**
 * @brief  Kill special timer according to TimerProc
 * @param  Task index
 * @param  TimerProc pointer
 */
void KillWindow_SpecialTimer(u8 hTask, TIMERPROCPTR TimerProc)
{
	u16 i;
	for (i = 0; i < MAX_TIMER_WIN; i++) {
		if (TimerPoolWindow[hTask][i].Interval && TimerPoolWindow[hTask][i].TimerProc == TimerProc) {
			TimerPoolWindow[hTask][i].Interval = 0;
		}
	}
}


/**
 * @brief  Reset all timer of this window
 * @param  Task index
 * @param  Window pointer
 */
void ResetWindowTimer(u8 hTask, WINDOW* Window)
{
	u16 i;
	for (i = 0; i < MAX_TIMER_WIN; i++) {
		if (TimerPoolWindow[hTask][i].Interval && TimerPoolWindow[hTask][i].Window == Window) {
			TimerPoolWindow[hTask][i].TickCounter = 0;
		}
	}
}

/**
 * @brief  Reset the timer of this TimerProc
 * @param  Task index
 * @param  TimerProc pointer
 */
void ResetWindow_SpecialTimer(u8 hTask, TIMERPROCPTR TimerProc)
{
	u16 i;
	for (i = 0; i < MAX_TIMER_WIN; i++) {
		if (TimerPoolWindow[hTask][i].Interval && TimerPoolWindow[hTask][i].TimerProc == TimerProc) {
			TimerPoolWindow[hTask][i].TickCounter = 0;
		}
	}
}

/**
 * @brief  Judge the timer of this TimerProc is active
 * @param  Task index
 * @param  TimerProc pointer
 * @retval 0 NoActive 1 Active
 */
int WindowTimerIsActive(u8 hTask,TIMERPROCPTR TimerProc)
{
	int i;
	for (i = 0; i < sizeof(TimerPoolWindow[0])/sizeof(TimerPoolWindow[0][0]); i++) {
		if (TimerPoolWindow[hTask][i].Interval && TimerPoolWindow[hTask][i].TimerProc == TimerProc) {
			return 1;
		}
	}
	return 0;
}

/**
 * @brief TimerServerWindow
 * @note  Called in main loop
 */
void TimerServerWindow(void)
{
	static u32 LastTickCounter[MAX_TASK] = {0};
	u16 i;
	u8 hTask;
	u32	tmpTickCounter,TimePass;
	WINDOW* CurrentWindow;
	
	for (hTask=0;hTask<MAX_TASK;hTask++)
	{
		/* calculate the time pass */
		tmpTickCounter =  __uwTick;
		if(tmpTickCounter < LastTickCounter[hTask]) TimePass = (u32)( tmpTickCounter + (0x100000000 - LastTickCounter[hTask] )); 
		else                                        TimePass = tmpTickCounter - LastTickCounter[hTask];
  	
		if (TimePass!=0) {
			LastTickCounter[hTask] = tmpTickCounter;
			CurrentWindow = GetCurrentWindow(hTask);
			
			for (i=0; i<MAX_TIMER_WIN; i++) {
				if (TimerPoolWindow[hTask][i].Interval != 0) {
					/* if timer tick is freezed in other window, continue  */
					if (TimerPoolWindow[hTask][i].Property && CurrentWindow != TimerPoolWindow[hTask][i].Window )continue;
					TimerPoolWindow[hTask][i].TickCounter += TimePass;
					if (TimerPoolWindow[hTask][i].TickCounter >= TimerPoolWindow[hTask][i].Interval){
						TimerPoolWindow[hTask][i].TickCounter = 0;
						if (TimerPoolWindow[hTask][i].TimerProc != NULL){/*< timerproc is not null */
							(*TimerPoolWindow[hTask][i].TimerProc)(i);
						}
					}
				}
			}
		}
	}
}


/**
 * @brief  Set timer
 * @param  Timer interval
 * @param  Timer property, 
 * @param  TimerProc callback pointer
 * @retval return index when set window timer success
 *         return -1 if timer pool window is full
 */
s16 Set_Timer(WORD Interval,BYTE Property,TIMERPROCPTR TimerProc)
{
	u16 i;
	for (i=0; i<MAX_TIMER; i++){
		if (TimerPool[i].Interval == 0){
			TimerPool[i].TickCounter = 0;
			TimerPool[i].Interval = Interval;
			TimerPool[i].Property = Property;
			TimerPool[i].TimerProc = TimerProc; 
			return (i);
		}
	}
	return (-1);
}


/**
 * @brief  Kill special timer according to TimerProc
 * @param  Task index
 * @param  TimerProc pointer
 */
void Kill_SpecialTimer(TIMERPROCPTR TimerProc)
{
	u16 i;
	for (i = 0; i < MAX_TIMER; i++) {
		if (TimerPool[i].Interval && TimerPool[i].TimerProc == TimerProc) {
			TimerPool[i].Interval = 0;
		}
	}
}


/**
 * @brief TimerServer
 * @note  Called in main loop
 */
void TimerServer(void)
{
	static u32 LastTickCounter=0;
	u32	tmpTickCounter,TimePass;
	u16 i;
    
	tmpTickCounter = __uwTick;
	/* calculate the time pass */
	if(tmpTickCounter<LastTickCounter)TimePass = (u32)( tmpTickCounter+(0x100000000-LastTickCounter) ); 
	else							  TimePass = tmpTickCounter - LastTickCounter;

	if( TimePass!=0 ){
		LastTickCounter = tmpTickCounter;
		for(i=0; i<MAX_TIMER; i++){
			if(TimerPool[i].Interval != 0){
				TimerPool[i].TickCounter += TimePass;
				if( TimerPool[i].TickCounter >= TimerPool[i].Interval ){
					TimerPool[i].TickCounter = 0;
                    if( TimerPool[i].TimerProc != NULL ){/*< timerproc is not null */
                        (*TimerPool[i].TimerProc)(i);
                    }
				}
			}
		}
	}
}

/*--------------------------- Manager Interface ------------------------------*/

/**
 * @brief InitManager
 * @note  Called in Initialize function
 */
void InitManager(void)
{
	int i,ii;
	
	__uwTick = 0;
	__uwTime = 0;
	
	for (i = 0; i < sizeof(WindowHead)/sizeof(WindowHead[0]); i++)
	{
		rt_list_init(WindowHead +i);
	}

	for (i = 0; i < sizeof(TimerPool)/sizeof(TimerPool[0]); i++) {
        TimerPool[i].Interval = 0;
    }
	
    for (i = 0; i < sizeof(TimerPoolWindow)/sizeof(TimerPoolWindow[0]); i++) {
        for (ii = 0; ii < sizeof(TimerPoolWindow[0])/sizeof(TimerPoolWindow[0][0]); ii++) {
            TimerPoolWindow[i][ii].Interval = 0;
        }
    }
}

/**
 * @brief TickCounter increase
 * @reference Called in SysTick_Handler
 */
void TimeTickInc(void)
{
	__uwTick++;
	if (__uwTick%100 == 0){//100ms
		__uwTime++;
	}
}	



/**
 * @brief Get System Time
 * @retval System time
 */
u32 HAL_GetTime(void)
{
    return __uwTime;
}

/*--------------------------- Draw Manager ------------------------------*/

/**
 * @brief 画窗口构件 
 * @param Window 任务窗口函数
 */ 
void DrawObject(WINDOW * Window)
{
	
}

/**
 * @brief 将键盘输入发送到可编辑控件中
 * @param Key 按键输入信息
 */ 
BYTE AcceptKey(WORD Key)
{
	return 0;
}


void TimerProc_Cursor(u16 hTimer)
{
	
}

void OpenCursor_Timer(void)
{
	
}

/**
 * @brief 更新窗口中可变控件的显示内容
 * @param 指定刷新的窗口
 */
void RefreshObjectMessage(WINDOW * Window)
{
	
}

/**
 * @brief 绘制单个对象
 * @param 绘制的对象
 */
void DrowSingleObject(OBJECT * Object)
{
	
}

/**
 * @brief 寻找指定对象的索引
 * @param 对象
 */
BYTE FindObjectIndex(OBJECT * Object)
{
	
	return(0);
}

/**
 * @brief 向上寻找可接受焦点的控件对象
 */
BYTE FindUpEnableObject(void)
{
	
	return(0);
}

/**
 * @brief 向下寻找可接受焦点的控件对象
 */
BYTE FindDownEnableObject(void)
{
	
	return(0);
}

/**
 * @brief 设置对象焦点
 */
void SetFocus(OBJECT * Object,u8 uCursorOffset)
{
	
}

Manager.h

#ifndef __MANAGER_H
#define __MANAGER_H

#include "Manager/rtdef.h"

//Manager所需的参数
#ifdef MAIN
#define VAR_RANGE
#else
#define VAR_RANGE extern	
#endif




#define configUSE_OPENWINDOW_LOG		0	//0 打开窗口不打印日志 1打开窗口打印日志
#define configUSE_CLOSEWINDOW_LOG		0	//0 关闭窗口不打印日志 1关闭窗口打印日志

/* Private define ------------------------------------------------------------*/
#ifndef BYTE
	#define BYTE 	unsigned char
#endif
#ifndef CHAR
	#define CHAR	char
#endif
#ifndef WORD
	#define WORD 	unsigned short int
#endif
#ifndef INT16
	#define INT16	short int
#endif
#ifndef DWORD
	#define	DWORD	unsigned int
#endif
#ifndef INT32
	#define INT32	int
#endif
#ifndef DOUBLE
	#define DOUBLE	double
#endif
#ifndef __IO
	#define __IO    volatile
#endif
	
#ifndef NULL
	#define NULL 0
#endif
	 

/* Export typedef ------------------------------------------------------------*/
typedef unsigned          char u8;
typedef unsigned short     int u16;
typedef unsigned           int u32;
typedef   signed          char s8;
typedef   signed short     int s16;
typedef   signed           int s32;

typedef volatile unsigned          char vu8;
typedef volatile unsigned short     int vu16;
typedef volatile unsigned           int vu32;
typedef volatile   signed          char vs8;
typedef volatile   signed short     int vs16;
typedef volatile   signed           int vs32;


typedef DWORD  OBJECTPTR;													   
typedef void ( * WINPROCPTR      )(WORD, WORD, BYTE*, WORD, WORD);
typedef void ( * TIMERPROCPTR    )(WORD);



/* Export types --------------------------------------------------------------*/
/****************************************************************************************/
/*  				长方形区域结构														*/
/****************************************************************************************/
typedef struct tagRECT{	
									BYTE left;		//左边界
									BYTE right;		//右边界
									BYTE top;		//上边界
									BYTE bottom;	//下边界	
								}RECT;
/****************************************************************************************/
/*					声明点坐标结构														*/
/****************************************************************************************/
typedef struct tagPOINT{	
									WORD x;			//横坐标
									WORD y;			//纵坐标
								}POINT;
/****************************************************************************************/
/*					光标资源结构	  		 											*/
/****************************************************************************************/
typedef struct tagCURSOR{	
									vu8 x;			//坐标x
									vu8 y;			//坐标y
									vu8 Font;		//字体
									vu8 Enable;		//使能
									vu8 Reverse;	//正常显示/反转显示	
								}CURSOR;
/****************************************************************************************/
/*					对象信息结构														*/
/****************************************************************************************/
typedef struct tagOBJECT{	
									RECT Region;	//窗口范围
									BYTE X_Offset;	//窗口x偏移
									BYTE Y_Offset;	//窗口y偏移
									BYTE Property;	//窗口属性
									BYTE Font; 		//字体0  16*8  1 32*32
									BYTE * Message;	//信息
								}OBJECT;
/****************************************************************************************/
/*					窗口信息结构														*/
/****************************************************************************************/
typedef struct tagWINDOW{	
									WINPROCPTR const 	WindowProc;		//窗口函数	
									OBJECTPTR* const 	Objects;		//对象指针集合的首地址
									u32*  const			Address;		//窗口加载函数首地址
									const char* 		Name;			//窗口名
									BYTE				Property;		//窗口属性
									BYTE				Size;			//尺寸
									BYTE				Active;			//窗口活动标志
									BYTE				Focus;			//焦点
									CURSOR				Cursor;			//显示相关:光标
									rt_list_t  			list;          	/**< the object list */
								} WINDOW;

#define INIT_WIN(fun)   {WindowProc,0,(unsigned int*)&fun,#fun,ODS_VISIBLE,0,FALSE,0}
/****************************************************************************************/
/*					任务信息结构														*/
/****************************************************************************************/
typedef struct tagTASKINFO{
									u32 Time;			
									vu8 Status;
									vu8 ConfigStatus;
								} TASKINFO;
/****************************************************************************************/
/*					定时器结构	     													*/
/****************************************************************************************/
typedef struct tagTIMER{	
									vu32			TickCounter;	//计数器时记录计数器的运行值
									vu32			Interval;		//计数器时设为非零值
									vu8 			Property;		//0 单次定时器 1循环定时器
									vu8  			Style;			//0 定时器 1计数器
									vu32  			TickCounterFreq;//定时器频率
									vu32  			TickCounterToal;//
									TIMERPROCPTR	TimerProc;		//定时事件
								} TIMER;
/****************************************************************************************/
/*					窗口定时器结构	     												*/
/****************************************************************************************/
typedef struct tagTIMERWINDOW{	
									WINDOW*			Window;			//活动窗口
									vu32			TickCounter;	//计数器时记录计数器的运行值
									vu32			Interval;		//计数器时设为非零值
									vu8           	Property;     	//属性  0正常计时(无窗口限制)  1只允许在当前窗口计时非当前窗口计数值锁定
									TIMERPROCPTR	TimerProc;		//定时事件
								}TIMERWINDOW;
//窗口消息类型            
typedef struct tagWINDOW_MSG{
									WORD Type;
									WORD Parameter;
									BYTE *Info;
									WORD hSrcWin;
									WORD hTagWin;
								}WINDOW_MSG;

/* Export macro -------------------------------------------------------------*/
//****************************窗口和定时器常量定义*******************************
#define MAX_TASK					(POWER_TASK+1)
				#define MAIN_TASK		0  	//主任务
				#define MOTOR_TASK		1  	//电机任务
						#define KINCO_TASK		MOTOR_TASK
				#define MDX_TASK	    2
				#define CANOPEN_TASK	3  	//CANOpen PDO管理任务					
				#define POWER_TASK		4  	//电源管理任务


#define MAX_TIMER_WIN	32
#define MAX_TIMER		16
//*******************************************************************************                        
//************************( Window Message )********************/
#ifndef WM_CLOSE
	#define WM_CLOSE	1
#endif
#ifndef WM_REDRAW
	#define WM_REDRAW	2
#endif
#ifndef WM_REFRESH
	#define WM_REFRESH	3
#endif
	
#ifndef TRUE
	#define TRUE 		0xFF
#endif
#ifndef FALSE
	#define FALSE 		0
#endif

#define RT_ASSERT(EX) 

//****************************** 任务状态	******************************


/* Export variables ---------------------------------------------------------*/

VAR_RANGE WINDOW* 		Task_CurrentWindow[MAX_TASK];					//当前任务活动窗口

/* Export function prototypes -----------------------------------------------*/

/*--------------------------- Window Manager ------------------------------*/
WINDOW* Task_FirstWindow(const u8 hTask);
u8 RegisterWindow(const u8 hTask, WINDOW* Window);
u8 LogoutWindow(const u8 hTask);
WINDOW* GetCurrentWindow(const u8 hTask);
void OpenWindow(const u8 hTask, WINDOW * Window);

void CloseWindow(const u8 hTask);
WINPROCPTR ActiveWindowProc(const u8 hTask);
WINPROCPTR ActiveFirstWindowProc(const u8 hTask);
void ActiveSubWindowProc(const u8 hTask, const WINDOW* window, const WINDOW_MSG* windowMsg);
void RefreshWindow(void);

/*--------------------------- Timer Manager ------------------------------*/
void TimerServerWindow(void);
int Set_Timer_Window(u8 hTask,WINDOW* Window,unsigned int Interval,BYTE Property,TIMERPROCPTR TimerProc);
void KillWindowTimer(u8 hTask, WINDOW* Window);
void KillWindow_SpecialTimer(u8 hTask,TIMERPROCPTR TimerProc);
void ResetWindowTimer(u8 hTask,WINDOW* Window);
void ResetWindow_SpecialTimer(u8 hTask, TIMERPROCPTR TimerProc);
int WindowTimerIsActive(u8 hTask,TIMERPROCPTR TimerProc);

void TimerServer(void);
int Set_Timer(unsigned int Interval,BYTE Property,TIMERPROCPTR TimerProc);
void Kill_SpecialTimer(TIMERPROCPTR TimerProc);
/*--------------------------- Manager Interface ------------------------------*/

void InitManager(void);
void TimeTickInc(void);
u32 HAL_GetTime(void);

void DrawObject(WINDOW *Window);
BYTE AcceptKey(WORD Key);
void TimerProc_Cursor(u16 hTimer);
void OpenCursor_Timer(void);
void RefreshObjectMessage(WINDOW * Window);
void DrowSingleObject(OBJECT * Object);
BYTE FindObjectIndex(OBJECT * Object);
BYTE FindUpEnableObject(void);
BYTE FindDownEnableObject(void);
void SetFocus(OBJECT *Object,u8 uCursorOffset);

/*--------------------------- Orher Interface ------------------------------*/
void RecordWindowSwitchProcess(u8 hTask,WINDOW * Window);

#endif

rtdef.h

#ifndef __RT_DEF_H__
#define __RT_DEF_H__


/* RT-Thread basic data type definitions */
#ifndef RT_USING_ARCH_DATA_TYPE
typedef signed   char                   rt_int8_t;      /**<  8bit integer type */
typedef signed   short                  rt_int16_t;     /**< 16bit integer type */
typedef signed   int                    rt_int32_t;     /**< 32bit integer type */
typedef unsigned char                   rt_uint8_t;     /**<  8bit unsigned integer type */
typedef unsigned short                  rt_uint16_t;    /**< 16bit unsigned integer type */
typedef unsigned int                    rt_uint32_t;    /**< 32bit unsigned integer type */

#ifdef ARCH_CPU_64BIT
typedef signed long                     rt_int64_t;     /**< 64bit integer type */
typedef unsigned long                   rt_uint64_t;    /**< 64bit unsigned integer type */
#else
typedef signed long long                rt_int64_t;     /**< 64bit integer type */
typedef unsigned long long              rt_uint64_t;    /**< 64bit unsigned integer type */
#endif
#endif

typedef int                             rt_bool_t;      /**< boolean type */
typedef long                            rt_base_t;      /**< Nbit CPU related date type */
typedef unsigned long                   rt_ubase_t;     /**< Nbit unsigned CPU related data type */

typedef rt_base_t                       rt_err_t;       /**< Type for error number */
typedef rt_uint32_t                     rt_time_t;      /**< Type for time stamp */
typedef rt_uint32_t                     rt_tick_t;      /**< Type for tick count */
typedef rt_base_t                       rt_flag_t;      /**< Type for flags */
typedef rt_ubase_t                      rt_size_t;      /**< Type for size number */
typedef rt_ubase_t                      rt_dev_t;       /**< Type for device */
typedef rt_base_t                       rt_off_t;       /**< Type for offset */

/* boolean type definitions */
#define RT_TRUE                         1               /**< boolean true  */
#define RT_FALSE                        0               /**< boolean fails */

/**@}*/

/* maximum value of base type */
#define RT_UINT8_MAX                    0xff            /**< Maxium number of UINT8 */
#define RT_UINT16_MAX                   0xffff          /**< Maxium number of UINT16 */
#define RT_UINT32_MAX                   0xffffffff      /**< Maxium number of UINT32 */
#define RT_TICK_MAX                     RT_UINT32_MAX   /**< Maxium number of tick */


#if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#define __CLANG_ARM
#endif

/* Compiler Related Definitions */
#if defined(__CC_ARM) || defined(__CLANG_ARM)           /* ARM Compiler */
    #include <stdarg.h>
    #define SECTION(x)                  __attribute__((section(x)))
    #define RT_UNUSED                   __attribute__((unused))
    #define RT_USED                     __attribute__((used))
    #define ALIGN(n)                    __attribute__((aligned(n)))

    #define RT_WEAK                     __attribute__((weak))
    #define rt_inline                   static __inline
    /* module compiling */
    #ifdef RT_USING_MODULE
        #define RTT_API                 __declspec(dllimport)
    #else
        #define RTT_API                 __declspec(dllexport)
    #endif

#elif defined (__IAR_SYSTEMS_ICC__)     /* for IAR Compiler */
    #include <stdarg.h>
    #define SECTION(x)                  @ x
    #define RT_UNUSED
    #define RT_USED                     __root
    #define PRAGMA(x)                   _Pragma(#x)
    #define ALIGN(n)                    PRAGMA(data_alignment=n)
    #define RT_WEAK                     __weak
    #define rt_inline                   static inline
    #define RTT_API

#elif defined (__GNUC__)                /* GNU GCC Compiler */
    #ifdef RT_USING_NEWLIB
        #include <stdarg.h>
    #else
        /* the version of GNU GCC must be greater than 4.x */
        typedef __builtin_va_list       __gnuc_va_list;
        typedef __gnuc_va_list          va_list;
        #define va_start(v,l)           __builtin_va_start(v,l)
        #define va_end(v)               __builtin_va_end(v)
        #define va_arg(v,l)             __builtin_va_arg(v,l)
    #endif

    #define SECTION(x)                  __attribute__((section(x)))
    #define RT_UNUSED                   __attribute__((unused))
    #define RT_USED                     __attribute__((used))
    #define ALIGN(n)                    __attribute__((aligned(n)))
    #define RT_WEAK                     __attribute__((weak))
    #define rt_inline                   static __inline
    #define RTT_API
#elif defined (__ADSPBLACKFIN__)        /* for VisualDSP++ Compiler */
    #include <stdarg.h>
    #define SECTION(x)                  __attribute__((section(x)))
    #define RT_UNUSED                   __attribute__((unused))
    #define RT_USED                     __attribute__((used))
    #define ALIGN(n)                    __attribute__((aligned(n)))
    #define RT_WEAK                     __attribute__((weak))
    #define rt_inline                   static inline
    #define RTT_API
#elif defined (_MSC_VER)
    #include <stdarg.h>
    #define SECTION(x)
    #define RT_UNUSED
    #define RT_USED
    #define ALIGN(n)                    __declspec(align(n))
    #define RT_WEAK
    #define rt_inline                   static __inline
    #define RTT_API
#elif defined (__TI_COMPILER_VERSION__)
    #include <stdarg.h>
    /* The way that TI compiler set section is different from other(at least
     * GCC and MDK) compilers. See ARM Optimizing C/C++ Compiler 5.9.3 for more
     * details. */
    #define SECTION(x)
    #define RT_UNUSED
    #define RT_USED
    #define PRAGMA(x)                   _Pragma(#x)
    #define ALIGN(n)
    #define RT_WEAK
    #define rt_inline                   static inline
    #define RTT_API
#else
    #error not supported tool chain
#endif


/**@}*/

/**
 * @ingroup BasicDef
 *
 * @def RT_ALIGN(size, align)
 * Return the most contiguous size aligned at specified width. RT_ALIGN(13, 4)
 * would return 16.
 */
#define RT_ALIGN(size, align)           (((size) + (align) - 1) & ~((align) - 1))

/**
 * @ingroup BasicDef
 *
 * @def RT_ALIGN_DOWN(size, align)
 * Return the down number of aligned at specified width. RT_ALIGN_DOWN(13, 4)
 * would return 12.
 */
#define RT_ALIGN_DOWN(size, align)      ((size) & ~((align) - 1))

/**
 * @ingroup BasicDef
 *
 * @def RT_NULL
 * Similar as the \c NULL in C library.
 */
#define RT_NULL                         (0)

/**
 * Double List structure
 */
struct rt_list_node
{
    struct rt_list_node *next;                          /**< point to next node. */
    struct rt_list_node *prev;                          /**< point to prev node. */
};
typedef struct rt_list_node rt_list_t;                  /**< Type for lists. */

/**
 * Single List structure
 */
struct rt_slist_node
{
    struct rt_slist_node *next;                         /**< point to next node. */
};
typedef struct rt_slist_node rt_slist_t;                /**< Type for single list. */


#endif

rt_service.h

#ifndef __RT_SERVICE_H__
#define __RT_SERVICE_H__

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @addtogroup KernelService
 */

/**@{*/

/**
 * rt_container_of - return the member address of ptr, if the type of ptr is the
 * struct type.
 */
#define rt_container_of(ptr, type, member) \
    ((type *)((char *)(ptr) - (unsigned long)(&((type *)0)->member)))


/**
 * @brief initialize a list object
 */
#define RT_LIST_OBJECT_INIT(object) { &(object), &(object) }

/**
 * @brief initialize a list
 *
 * @param l list to be initialized
 */
rt_inline void rt_list_init(rt_list_t *l)
{
    l->next = l->prev = l;
}

/**
 * @brief insert a node after a list
 *
 * @param l list to insert it
 * @param n new node to be inserted
 */
rt_inline void rt_list_insert_after(rt_list_t *l, rt_list_t *n)
{
    l->next->prev = n;
    n->next = l->next;

    l->next = n;
    n->prev = l;
}

/**
 * @brief insert a node before a list
 *
 * @param n new node to be inserted
 * @param l list to insert it
 */
rt_inline void rt_list_insert_before(rt_list_t *l, rt_list_t *n)
{
    l->prev->next = n;
    n->prev = l->prev;

    l->prev = n;
    n->next = l;
}

/**
 * @brief remove node from list.
 * @param n the node to remove from the list.
 */
rt_inline void rt_list_remove(rt_list_t *n)
{
    n->next->prev = n->prev;
    n->prev->next = n->next;

    n->next = n->prev = n;
}

/**
 * @brief tests whether a list is empty
 * @param l the list to test.
 */
rt_inline int rt_list_isempty(const rt_list_t *l)
{
    return l->next == l;
}


/**
 * @brief tests whether a list is one
 * @param l the list to test.
 */
rt_inline int rt_list_isone(const rt_list_t* l)
{
	return (l->next != l) && (l->next->next == l);
}
	
/**
 * @brief get the list length
 * @param l the list to get.
 */
rt_inline unsigned int rt_list_len(const rt_list_t *l)
{
    unsigned int len = 0;
    const rt_list_t *p = l;
    while (p->next != l)
    {
        p = p->next;
        len ++;
    }

    return len;
}

/**
 * @brief get the struct for this entry
 * @param node the entry point
 * @param type the type of structure
 * @param member the name of list in structure
 */
#define rt_list_entry(node, type, member) \
    rt_container_of(node, type, member)

/**
 * rt_list_for_each - iterate over a list
 * @pos:    the rt_list_t * to use as a loop cursor.
 * @head:   the head for your list.
 */
#define rt_list_for_each(pos, head) \
    for (pos = (head)->next; pos != (head); pos = pos->next)

/**
 * rt_list_for_each_safe - iterate over a list safe against removal of list entry
 * @pos:    the rt_list_t * to use as a loop cursor.
 * @n:      another rt_list_t * to use as temporary storage
 * @head:   the head for your list.
 */
#define rt_list_for_each_safe(pos, n, head) \
    for (pos = (head)->next, n = pos->next; pos != (head); \
        pos = n, n = pos->next)

/**
 * rt_list_for_each_entry  -   iterate over list of given type
 * @pos:    the type * to use as a loop cursor.
 * @head:   the head for your list.
 * @member: the name of the list_struct within the struct.
 */
#define rt_list_for_each_entry(pos, head, member) \
    for (pos = rt_list_entry((head)->next, typeof(*pos), member); \
         &pos->member != (head); \
         pos = rt_list_entry(pos->member.next, typeof(*pos), member))

/**
 * rt_list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
 * @pos:    the type * to use as a loop cursor.
 * @n:      another type * to use as temporary storage
 * @head:   the head for your list.
 * @member: the name of the list_struct within the struct.
 */
#define rt_list_for_each_entry_safe(pos, n, head, member) \
    for (pos = rt_list_entry((head)->next, typeof(*pos), member), \
         n = rt_list_entry(pos->member.next, typeof(*pos), member); \
         &pos->member != (head); \
         pos = n, n = rt_list_entry(n->member.next, typeof(*n), member))

/**
 * rt_list_first_entry - get the first element from a list
 * @ptr:    the list head to take the element from.
 * @type:   the type of the struct this is embedded in.
 * @member: the name of the list_struct within the struct.
 *
 * Note, that list is expected to be not empty.
 */
#define rt_list_first_entry(ptr, type, member) \
    rt_list_entry((ptr)->next, type, member)
	
/**
 * rt_list_last_entry - get the last element from a list
 * @ptr:    the list head to take the element from.
 * @type:   the type of the struct this is embedded in.
 * @member: the name of the list_struct within the struct.
 *
 * Note, that list is expected to be not empty.
 */
#define rt_list_last_entry(ptr, type, member) \
    rt_list_entry((ptr)->prev, type, member)
	
	
#define RT_SLIST_OBJECT_INIT(object) { RT_NULL }

/**
 * @brief initialize a single list
 *
 * @param l the single list to be initialized
 */
rt_inline void rt_slist_init(rt_slist_t *l)
{
    l->next = RT_NULL;
}

rt_inline void rt_slist_append(rt_slist_t *l, rt_slist_t *n)
{
    struct rt_slist_node *node;

    node = l;
    while (node->next) node = node->next;

    /* append the node to the tail */
    node->next = n;
    n->next = RT_NULL;
}

rt_inline void rt_slist_insert(rt_slist_t *l, rt_slist_t *n)
{
    n->next = l->next;
    l->next = n;
}

rt_inline unsigned int rt_slist_len(const rt_slist_t *l)
{
    unsigned int len = 0;
    const rt_slist_t *list = l->next;
    while (list != RT_NULL)
    {
        list = list->next;
        len ++;
    }

    return len;
}

rt_inline rt_slist_t *rt_slist_remove(rt_slist_t *l, rt_slist_t *n)
{
    /* remove slist head */
    struct rt_slist_node *node = l;
    while (node->next && node->next != n) node = node->next;

    /* remove node */
    if (node->next != (rt_slist_t *)0) node->next = node->next->next;

    return l;
}

rt_inline rt_slist_t *rt_slist_first(rt_slist_t *l)
{
    return l->next;
}

rt_inline rt_slist_t *rt_slist_tail(rt_slist_t *l)
{
    while (l->next) l = l->next;

    return l;
}

rt_inline rt_slist_t *rt_slist_next(rt_slist_t *n)
{
    return n->next;
}

rt_inline int rt_slist_isempty(rt_slist_t *l)
{
    return l->next == RT_NULL;
}

/**
 * @brief get the struct for this single list node
 * @param node the entry point
 * @param type the type of structure
 * @param member the name of list in structure
 */
#define rt_slist_entry(node, type, member) \
    rt_container_of(node, type, member)

/**
 * rt_slist_for_each - iterate over a single list
 * @pos:    the rt_slist_t * to use as a loop cursor.
 * @head:   the head for your single list.
 */
#define rt_slist_for_each(pos, head) \
    for (pos = (head)->next; pos != RT_NULL; pos = pos->next)

/**
 * rt_slist_for_each_entry  -   iterate over single list of given type
 * @pos:    the type * to use as a loop cursor.
 * @head:   the head for your single list.
 * @member: the name of the list_struct within the struct.
 */
#define rt_slist_for_each_entry(pos, head, member) \
    for (pos = rt_slist_entry((head)->next, typeof(*pos), member); \
         &pos->member != (RT_NULL); \
         pos = rt_slist_entry(pos->member.next, typeof(*pos), member))

/**
 * rt_slist_first_entry - get the first element from a slist
 * @ptr:    the slist head to take the element from.
 * @type:   the type of the struct this is embedded in.
 * @member: the name of the slist_struct within the struct.
 *
 * Note, that slist is expected to be not empty.
 */
#define rt_slist_first_entry(ptr, type, member) \
    rt_slist_entry((ptr)->next, type, member)

/**
 * rt_slist_tail_entry - get the tail element from a slist
 * @ptr:    the slist head to take the element from.
 * @type:   the type of the struct this is embedded in.
 * @member: the name of the slist_struct within the struct.
 *
 * Note, that slist is expected to be not empty.
 */
#define rt_slist_tail_entry(ptr, type, member) \
    rt_slist_entry(rt_slist_tail(ptr), type, member)

/**@}*/

#ifdef __cplusplus
}
#endif

#endif

winMain.c

#include "Main.h"

/* Private macro ------------------------------------------------------------*/
/* Private variables --------------------------------------------------------*/

/* Private function prototypes ----------------------------------------------*/
static void Initialize(void);
static void TimerProc(u16 hTimer);	
static void WindowProc(WORD Type, WORD Parameter, BYTE *Info,u16 hSrcWin,u16 hTagWin);


/**
 * @brief 窗口函数结构体初始化
 */
static WINDOW Window = INIT_WIN(winMain);

/**
 * @brief 窗口初始化
 * @note  每次窗口被激活为当前窗口时调用,可以初始化每次进入窗口时需初始化的变量
 */
static void Initialize(void)
{

	/*< Initialize the variables that needs to be initialized when redraw the window  */
}
/**
 * @brief  主任务
 * @param  None
 * @retval None
 * @note   窗口加载函数,在窗口集合注册当前窗口;
 *         如果要每次打开窗口时都进行初始化,则应在此加入初始化
 */
void winMain(void)
{
	if (Window.Active)return;
	if (RegisterWindow(MAIN_TASK,&Window)){
		Initialize();
		OpenWindow(MAIN_TASK,&Window);
		
		/*< Initialize the first open window all variables that you need to used */
		
		/*< Set Window Timer, you must set window timer before open another window */
		Set_Timer_Window(MAIN_TASK,&Window,100,0,TimerProc);
		
		/*< Do something */
		
	}
}

/**
 * @brief  窗口函数
 * @param  Type: 信息的类型
 * @param  Parameter: 数值型信息
 * @param  Info: 字符串型信息
 * @param  hSrcWin: 源窗口,消息的触发窗口
 * @param  hTagWin: 目标窗口,消息的目标窗口
 * @retval None
 * @note   具体处理接收到的信息(如按键输入等),每一个功能窗口都要有一个这样的函数
 *         这是一个内部函数,其他模块的窗口函数可以与它同名 
 */
static void WindowProc(WORD Type, WORD Parameter, BYTE *Info, u16 hSrcWin, u16 hTagWin)
{
	switch( Type )		// 根据信息类型,提取及处理相应的信息
	{					
	case WM_CLOSE:
			CloseWindow(MAIN_TASK);
		break;
	case WM_REDRAW:
			Initialize();
			OpenWindow(MAIN_TASK,&Window);
		break;
	case WM_REFRESH:
		break;
	case WM_ALARM_CODE:
			CloseWindow(MAIN_TASK);
			(*ActiveWindowProc(MAIN_TASK))(WM_ALARM_CODE,Parameter,Info,hSrcWin,hTagWin);
		break;
	default:
		break;
	}
}
/**
 * @brief  窗口定时器触发事件
 * @param  定时器索引
 * @retval None
 * @note   窗口定时器与窗口相关联,窗口定时器按照设定周期触发窗口定时器事件
 *         一个窗口可以有多个窗口定时器,当窗口关闭时所有的窗口定时器均被注销
 *         窗口定时器属性:0全局计时 1:当前窗口计时
 */ 
static void TimerProc(u16 hTimer)
{	
	KillWindow_SpecialTimer(MAIN_TASK,TimerProc);
	
	KillWindowTimer(MAIN_TASK, &Window);
}

/*****************************END OF FILE******************************/

win_PowerOn_SelfTest.c

#include "Main.h"

/* Private macro ------------------------------------------------------------*/
/* Private variables --------------------------------------------------------*/
static u8 sSource;
/* Private function prototypes ----------------------------------------------*/
static void Initialize(void);
static void TimerProc(u16 hTimer);	
static void WindowProc(WORD Type, WORD Parameter, BYTE *Info,u16 hSrcWin,u16 hTagWin);


/**
 * @brief 窗口函数结构体初始化
 */
static WINDOW Window = INIT_WIN(win_PowerOn_SelfTest);

/**
 * @brief 窗口初始化
 * @note  每次窗口被激活为当前窗口时调用,可以初始化每次进入窗口时需初始化的变量
 */
static void Initialize(void)
{

	/*< Initialize the variables that needs to be initialized when redraw the window  */
}
/**
 * @brief  上电自检
 * @param  None
 * @retval None
 * @note   窗口加载函数,在窗口集合注册当前窗口;
 *         如果要每次打开窗口时都进行初始化,则应在此加入初始化
 */
void win_PowerOn_SelfTest(u8 hSource)
{
	if (Window.Active)return;
	if (RegisterWindow(MAIN_TASK,&Window)){
		Initialize();
		OpenWindow(MAIN_TASK,&Window);
		
		/*< Initialize the first open window all variables that you need to used */
		sSource = hSource;
		/*< Set Window Timer, you must set window timer before open another window */
		Set_Timer_Window(MAIN_TASK,&Window,100,0,TimerProc);
		
		/*< Do something */
		CloseWindow(MAIN_TASK);
		(*ActiveWindowProc(MAIN_TASK))(WM_ALARM_CODE,NO_ALARM,0,0,0);
	}
}

/**
 * @brief  窗口函数
 * @param  Type: 信息的类型
 * @param  Parameter: 数值型信息
 * @param  Info: 字符串型信息
 * @param  hSrcWin: 源窗口,消息的触发窗口
 * @param  hTagWin: 目标窗口,消息的目标窗口
 * @retval None
 * @note   具体处理接收到的信息(如按键输入等),每一个功能窗口都要有一个这样的函数
 *         这是一个内部函数,其他模块的窗口函数可以与它同名 
 */
static void WindowProc(WORD Type, WORD Parameter, BYTE *Info, u16 hSrcWin, u16 hTagWin)
{
	switch( Type )		// 根据信息类型,提取及处理相应的信息
	{					
	case WM_CLOSE:
			CloseWindow(MAIN_TASK);
		break;
	case WM_REDRAW:
			Initialize();
			OpenWindow(MAIN_TASK,&Window);
		break;
	case WM_REFRESH:
		break;
	case WM_ALARM_CODE:
			CloseWindow(MAIN_TASK);
			(*ActiveWindowProc(MAIN_TASK))(WM_ALARM_CODE,Parameter,Info,hSrcWin,hTagWin);
		break;
	default:
		break;
	}
}
/**
 * @brief  窗口定时器触发事件
 * @param  定时器索引
 * @retval None
 * @note   窗口定时器与窗口相关联,窗口定时器按照设定周期触发窗口定时器事件
 *         一个窗口可以有多个窗口定时器,当窗口关闭时所有的窗口定时器均被注销
 *         窗口定时器属性:0全局计时 1:当前窗口计时
 */ 
static void TimerProc(u16 hTimer)
{	
	KillWindow_SpecialTimer(MAIN_TASK,TimerProc);
	
	KillWindowTimer(MAIN_TASK, &Window);
}

/*****************************END OF FILE******************************/

main.c

#define MAIN
#include "Main.h"

static void Initialize(void);

int main()
{
	Initialize();
	while (1)
	{
		TimerServer();				//软件定时器
		TimerServerWindow();		//软件窗口定时器
		RefreshWindow();			//刷新窗口
	}
}

static void Initialize(void)
{
	InitManager();

	winMain();
	win_PowerOn_SelfTest(0);
}
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值