#ifndef TIMERTASK_H_
#define TIMERTASK_H_

#include "gType.h"

//time tick task Center
class TTimerTask{
	private:
		struct{
			unsigned int OneMs;
		}RdyFlags;
		unsigned int tick_MsForSec;
		struct {
			unsigned int Count;
			void (*FunC[4])(void);
		}Task_1S;
		
	private:
	
	public:
		TTimerTask(void){
			Init();
		};
		void Init(void){
			Task_1S.Count = 0;
			Task_1S.FunC[0] = nullptr;
			Task_1S.FunC[1] = nullptr;
			Task_1S.FunC[2] = nullptr;
			Task_1S.FunC[3] = nullptr;
			
			tick_MsForSec = 0;			
		}
		void Dm_1mS(void){
			tick_MsForSec++;
			RdyFlags.OneMs = 1;
			
			if(tick_MsForSec > 999){
				tick_MsForSec = 0;
			}
			
			if( (	tick_MsForSec == 200) && (Task_1S.FunC[0] != nullptr)	)	Task_1S.FunC[0]();
			if( (	tick_MsForSec == 400) && (Task_1S.FunC[1] != nullptr)	)	Task_1S.FunC[1]();
			if( (	tick_MsForSec == 600) && (Task_1S.FunC[2] != nullptr)	)	Task_1S.FunC[2]();
			if( (	tick_MsForSec == 800) && (Task_1S.FunC[3] != nullptr)	)	Task_1S.FunC[3]();
		}
		
		int RegisteOneSecTash(void (*aFunc)(void)){
			unsigned int i;
			
			i=0;
			if(Task_1S.FunC[0] != nullptr) i++;
			if(Task_1S.FunC[1] != nullptr) i++;
			if(Task_1S.FunC[2] != nullptr) i++;
			if(Task_1S.FunC[3] != nullptr) i++;
			Task_1S.Count = i;
			
			if(Task_1S.Count < 4){
				if(Task_1S.FunC[0] != nullptr)	{Task_1S.FunC[0] = aFunc; Task_1S.Count++; return 0;}
				if(Task_1S.FunC[1] != nullptr)	{Task_1S.FunC[1] = aFunc; Task_1S.Count++; return 0;}
				if(Task_1S.FunC[2] != nullptr)	{Task_1S.FunC[2] = aFunc; Task_1S.Count++; return 0;}
				if(Task_1S.FunC[3] != nullptr)	{Task_1S.FunC[3] = aFunc; Task_1S.Count++; return 0;}
				return 1;
			}
			return 2;
		}
		
		int UnRegisteOneSecTash(void (*aFunc)(void)){
			unsigned int i;
			if(Task_1S.FunC[0] == aFunc)		Task_1S.FunC[0] = nullptr; 
			if(Task_1S.FunC[1] == aFunc)		Task_1S.FunC[1] = nullptr; 
			if(Task_1S.FunC[2] == aFunc)		Task_1S.FunC[2] = nullptr; 
			if(Task_1S.FunC[3] == aFunc)		Task_1S.FunC[3] = nullptr; 
			
			i=0;
			if(Task_1S.FunC[0] != nullptr) i++;
			if(Task_1S.FunC[1] != nullptr) i++;
			if(Task_1S.FunC[2] != nullptr) i++;
			if(Task_1S.FunC[3] != nullptr) i++;
			
			Task_1S.Count = i;
			return 0;
		}
};

















#endif




