local dev = GetSelf()

local data = get_base_data()

local rate = 0.01
make_default_activity(rate)

function post_initialize()

	sndhost 		= create_sound_host("MODSOUND","2D",0,0,0)
	timerclick		= sndhost:create_sound("Aircrafts/F-16C/Cockpit/click")  -- refers to sdef file, and sdef file content refers to sound file, see DCSWorld/Sounds/sdef/_example.sdef
	timertick		= sndhost:create_sound("Aircrafts/F-16C/Cockpit/ticking")

	--print_message_to_user("YO")
	
	tmr = false
	state = 0
	second = 0
	minute = 0
end

dev:listen_command(7001) -- start stop reset
dev:listen_command(7002) -- reset play auto

function SetCommand(command,value)
	if(command==7001) then
	timerclick:play_once()
	state = state + 1
	
		if state == 0 then
			tmr = false
			timertick:stop()
			elseif
				state == 1 then
				tmr = true
				timertick:play_continue()
			elseif
				state == 2 then
				tmr = false
				timertick:stop()
			elseif
				state >= 3 then
				tmr = false
				state = 0
				second = 0
		end
		
		--print_message_to_user(state)
		--print_message_to_user("timer: "..tostring(tmr))
	
	end
	
	if (command==7002) then
	timerclick:play_once()
		second = 0
		state = 1
		tmr = true
		
		--print_message_to_user(state)
		--print_message_to_user("timer: "..tostring(tmr))

	end
end

Needle = get_param_handle("OPACITY")
NeedleRot = get_param_handle("ROT")
NeedleRotSmall = get_param_handle("ROTSMALL")

function update()
station = dev:get_station_info(12)

	if station.CLSID == "{MARATHON}" then
		
		Needle:set(1)
		else
		Needle:set(0)
	
	end
	
	if tmr then
		second = second - 0.001047
	end
	
	minute = second / 60
	
NeedleRot:set(second)
NeedleRotSmall:set(minute)
--print_message_to_user(second)
end

need_to_be_closed = false
