
unit module
{
	public const uint16 ID = 0;
	
	public link unit D {}
	
	//[i] var_int32_w Angle;
	public mydata int32 Angle;
	int32 st_angle;
	
	public memory mydata
	{
		
	}
	void set_uint32( uint32 d )
	{
		SetAngle( (int)d );
	}
	uint32 get_uint32()
	{
		return (uint)st_angle;
	}
	
	//---------------------------------------------------
	//[i] function_void OS_init;
	public void OS_init()
	{
		D.D0_OUT = 0;
		D.D0_DIR = 1;
		
		st_angle = 0;
		
		unit_red.v_R_data = 0;
		unit_green.v_G_data = 0;
		unit_blue.v_B_data = 0;
		Refresh_init();
	}
	//---------------------------------------------------
	//[i] function_void_old SetAngle int32;
	public void SetAngle( int32 an )
	{
		st_angle = an;
		if( an > 360 ) {
			an % 360;
		}
		else if( an < 0 ) {
			an = -an;
			an % 360;
			an = 360 - an;
		}
		
		an = an * 512 / 120;
		if( an < 256 ) {
			R_data = 256;
			G_data = an;
			B_data = 0;
			return;
		}
		if( an < 512 ) {
			R_data = 512 - an;
			G_data = 256;
			B_data = 0;
			return;
		}
		if( an < 768 ) {
			R_data = 0;
			G_data = 256;
			B_data = an - 512;
			return;
		}
		if( an < 1024 ) {
			R_data = 0;
			G_data = 1024 - an;
			B_data = 256;
			return;
		}
		if( an < 1280 ) {
			R_data = an - 1024;
			G_data = 0;
			B_data = 256;
			return;
		}
		R_data = 256;
		G_data = 0;
		B_data = 1536 - an;
	}

	//[i] interface_analog red;
	red.led = unit_red;
	unit red
	{
		link unit led {}
		
		public void SetValue( int32 v )
		{
			led.set_uint32( (uint)v );
		}
		public void Stop()
		{
			led.set_uint32( 0 );
		}
	}
	//[i] interface_analog green;
	green.led = unit_green;
	unit green
	{
		link unit led {}
		
		public void SetValue( int32 v )
		{
			led.set_uint32( (uint)v );
		}
		public void Stop()
		{
			led.set_uint32( 0 );
		}
	}
	//[i] interface_analog blue;
	blue.led = unit_blue;
	unit blue
	{
		link unit led {}
		
		public void SetValue( int32 v )
		{
			led.set_uint32( (uint)v );
		}
		public void Stop()
		{
			led.set_uint32( 0 );
		}
	}
	
	//[i] var_int32_w R_data;
	public my_red int32 R_data;
	memory my_red { target = unit_red; }
	unit_red.Refresh = Refresh;
	unit unit_red
	{
		uint8 v_R_data;
		int32 realvalue;
		public link void Refresh() {}
		
		void set_uint32( uint32 v )
		{
			int32 vv = (int)v;
			realvalue = vv;
			if( vv > 255 ) vv = 255;
			if( vv < 0 ) vv = 0;
			v_R_data = (uint)(int8)(int16)vv;
			Refresh();
		}
		uint32 get_uint32()
		{
			return (uint)realvalue;
		}
	}
	
	//[i] var_int32_w G_data;
	public my_green int32 G_data;
	int32 v_G_data;
	memory my_green { target = unit_green; }
	unit_green.Refresh = Refresh;
	unit unit_green
	{
		uint8 v_G_data;
		int32 realvalue;
		public link void Refresh() {}
		
		void set_uint32( uint32 v )
		{
			int32 vv = (int)v;
			realvalue = vv;
			if( vv > 255 ) vv = 255;
			if( vv < 0 ) vv = 0;
			v_G_data = (uint)(int8)(int16)vv;
			Refresh();
		}
		uint32 get_uint32()
		{
			return (uint)realvalue;
		}
	}
	
	//[i] var_int32_w B_data;
	public my_blue int32 B_data;
	int32 v_B_data;
	memory my_blue { target = unit_blue; }
	unit_blue.Refresh = Refresh;
	unit unit_blue
	{
		uint8 v_B_data;
		int32 realvalue;
		public link void Refresh() {}
		
		void set_uint32( uint32 v )
		{
			int32 vv = (int)v;
			realvalue = vv;
			if( vv > 255 ) vv = 255;
			if( vv < 0 ) vv = 0;
			v_B_data = (uint)(int8)(int16)vv;
			Refresh();
		}
		uint32 get_uint32()
		{
			return (uint)realvalue;
		}
	}
	
	#include "$run$.txt"
}




