
unit Light
{
	public const uint16 ID = 0;
	
	//[i] linkinterface_led led;
	link unit led {}
	
	//[i] interface_analog analog;
	unit analog
	{
		public link void SetValue( int32 v ) {}
		public link void Stop() {}
	}
	analog.SetValue = SetValue;
	analog.Stop = Stop;
	
	int8 value;
	int8 tick;
	bool Open;
	
	//[i] var_int32_w data;
	public myVT int32 data;
	memory myVT {}
	void set_uint32( uint32 v )
	{
		int32 vv = (int)v;
		if( vv > 100 ) vv = 100;
		if( vv < 0 ) vv = 0;
		value = (int8)(int16)vv;
	}
	uint32 get_uint32()
	{
		return (uint)value;
	}
	
	//---------------------------------------------------
	//[i] function_void OS_init;
	public void OS_init()
	{
		value = 0;
		tick = 0;
		Open = false;
	}
	//---------------------------------------------------
	//[i] function_void OS_run100us;
	public void OS_run100us()
	{
		tick + 1;
		if( tick == 100 ) {
			tick = 0;
		}
		if( tick < value ) {
			Open = true;
		}
		if( tick >= value ) {
			Open = false;
		}
		if( Open ) {
			led.Open();
		}
		else {
			led.Close();
		}
	}
	void SetValue( int32 v )
	{
		if( v < 0 ) {
			value = 0;
		}
		else if( v > 100 ) {
			value = 100;
		}
		else {
			value = (int8)(int16)v;
		}
	}
	void Stop()
	{
		value = 0;
	}
}



