
//2015.4.11
//开始设计闹钟程序. 设置时间的字符串格式为:
// YYYY.MM.DD HH:MM.SS
//分别对应 年.月.日 时:分:秒
//总长度为19个字符
//重要! - 加上了判断 clock0 的 isSafe 标志, 防止中断用户轮询事件的读取DS18B20时间时序

//2015.4.19
//分离出了内置的定时时间, 而是指向两个外部的时间判断相等

unit Clock
{
	//[i] linkinterface_clock clock0;
	link unit clock0 {}
	//[i] linkinterface_clock clock1;
	link unit clock1 {}
	
	//[i] var_uint8 OS_EventFlag;
	public uint8 OS_EventFlag;
	//[i] event time_event;
	
	//[i] var_uint8 OS_time;
	public uint8 OS_time;
	
	int32 temp_second;
	
	bool is_run;
	
	//---------------------------------------------------
	//[i] function_void OS_init;
	public void OS_init()
	{
		OS_time = 100;
		OS_EventFlag = 0;
		
		temp_second = 0;
		is_run = true;
	}
	//---------------------------------------------------
	//[i] function_void OS_run;
	public void OS_run()
	{
		if( !is_run ) return;
		
		if( clock0.CanChange ) {
			
			if( !clock0.isSafe ) return;
			
			if( temp_second == clock0.second ) return;
			temp_second = clock0.second;
			
			if( clock1.second != clock0.second ) return;
			if( clock1.minute != clock0.minute ) return;
			if( clock1.hour != clock0.hour ) return;
			if( clock1.day != 0 && clock1.day != clock0.day ) return;
			if( clock1.month != 0 && clock1.month != clock0.month ) return;
			if( clock1.year != 0 && clock1.year != clock0.year ) return;
		}
		if( clock1.CanChange ) {
			
			if( !clock1.isSafe ) return;
			
			if( temp_second == clock1.second ) return;
			temp_second = clock1.second;
			
			if( clock0.second != clock1.second ) return;
			if( clock0.minute != clock1.minute ) return;
			if( clock0.hour != clock1.hour ) return;
			if( clock0.day != 0 && clock0.day != clock1.day ) return;
			if( clock0.month != 0 && clock0.month != clock1.month ) return;
			if( clock0.year != 0 && clock0.year != clock1.year ) return;
		}
		OS_EventFlag.0(bit) = 1;
	}
	//---------------------------------------------------
	//[i] function_void start;
	void start()
	{
		is_run = true;
	}
	
	//---------------------------------------------------
	//[i] function_void stop;
	void stop()
	{
		is_run = false;
	}
}



