
unit Light
{
	public const uint16 ID = 0;

	//[i] linkinterface_digital digital0;
	link unit digital0 {}
	
	//[i] var_uint8 OS_time;
	public uint8 OS_time;
	
	//[i] linkconst_int32_0.1_秒 high_time;
	public const int32 high_time = 0;
	
	//[i] linkconst_int32_0.3_秒 all_time;
	public const int32 all_time = 0;
	
	//[i] interface_digital digital1;
	unit digital1
	{
		public link void open() {}
		public link void close() {}
	}
	digital1.open = flash;
	digital1.close = stop;
	
	//注意, 为了保证灯光及时打开的一个参数, 嘀嘀响指令中清零
	int32 tick;
	
	//---------------------------------------------------
	//[i] function_void OS_init;
	public void OS_init()
	{
		FlashOpen = false;
		FlashForever = true;
		FlashNumber = 0;
		
		OS_time = 1;
		tick = 0;
	}
	//---------------------------------------------------
	//[i] function_void OS_run;
	public void OS_run()
	{
		if( !FlashOpen ) return;
		
		if( tick == 0 ) {
			digital0.open();
		}
		if( tick == high_time ) {
			digital0.close();
		}
		
		tick + 1;
		if( tick == all_time ) {
			tick = 0;
			if( !FlashForever ) {
				FlashNumber - 1;
				if( FlashNumber == 0 ) {
					FlashOpen = false;
				}
			}
		}
	}
	//---------------------------------------------------
	//[i] function_void stop;
	public void stop()
	{
		FlashOpen = false;
		digital0.close();
	}
	//---------------------------------------------------
	//[i] function_void flash_times int32;
	public void flash_times( int32 n )
	{
		tick = 0;
		FlashNumber = n;
		FlashForever = false;
		FlashOpen = true;
	}
	//---------------------------------------------------
	//[i] function_void flash;
	public void flash()
	{
		tick = 0;
		FlashNumber = 0;
		FlashForever = true;
		FlashOpen = true;
	}
	//---------------------------------------------------
	//[i] function_bool is_ok;
	public bool is_ok()
	{
		return !FlashOpen;
	}
	//=================================================================================
	int32 FlashNumber;
	bool FlashOpen;
	bool FlashForever;
}



