_ENCRYPT_=0    --LUA脚本加密

--数据类型定义
--VTYPE

--系统加载LUA脚本文件之后,立即调用此回调函数,通常用于执行初始化操作
function on_init()
	--numvar = 0
	volume = 0x20
	dataRecordId = 0
	meterNum = 0
	meterBackNum = 0
	sTimerNum = 0
	mTimerNum = 0
	hTimerNum = 0
	set_text(4, 3, "0")
	meterPlayerFlag = 0
	timerPlayerFlag = 0
	--set_text(7, 13, 32)
	--顺时针驱动仪表指令
	--meterClockwiseCmd = {0xAA, 0xB1, 0x1C, 0x00, 0x05, 0x00, 0x02, 0x20, 0xCC, 0x33, 0xC3, 0x3C}
	meterClockwiseCmd = {0xAA, 0xB1, 0x1C, 0x00, 0x04, 0x00, 0x02, 0x17, 0xCC, 0x33, 0xC3, 0x3C}
	--逆时针驱动仪表指令
	--meterAnticlockwiseCmd = {0xAA, 0xB1, 0x1D, 0x00, 0x05, 0x00, 0x02, 0x10, 0xCC, 0x33, 0xC3, 0x3C}
	meterAnticlockwiseCmd = {0xAA, 0xB1, 0x1D, 0x00, 0x04, 0x00, 0x02, 0x17, 0xCC, 0x33, 0xC3, 0x3C}


	--秒针
	sTimerClockInitCmd = {0xAA, 0xB1, 0x10, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0A, 0xCC, 0x33, 0xC3, 0x3C}
	sTimerClockCmd = {0xAA, 0xB1, 0x1C, 0x00, 0x02, 0x00, 0x02, 0x0A, 0xCC, 0x33, 0xC3, 0x3C}

	--分针
	mTimerClockInitCmd = {0xAA, 0xB1, 0x10, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0A, 0xCC, 0x33, 0xC3, 0x3C}
	mTimerClockCmd = {0xAA, 0xB1, 0x1C, 0x00, 0x02, 0x00, 0x03, 0x0A, 0xCC, 0x33, 0xC3, 0x3C}
	
	--时针
	hTimerClockInitCmd = {0xAA, 0xB1, 0x10, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0A, 0xCC, 0x33, 0xC3, 0x3C}
	hTimerClockCmd = {0xAA, 0xB1, 0x1C, 0x00, 0x02, 0x00, 0x04, 0x0A, 0xCC, 0x33, 0xC3, 0x3C}
end

--系统每隔1秒钟自动调用此回调函数
function on_systick()

end

--当画面需要切换时,执行此回调函数,screen为目标画面.
function on_screen_change(screen)
	if screen == 2 then
		if (timerPlayerFlag == 1 ) then
			--start_timer(1, 1000, 0, 0)
			--start_timer(2, 60*1000, 0, 0)
			--start_timer(3,  60*60*1000, 0, 0)
			
			start_timer(1, 1000, 0, 0)
			start_timer(2, 25000, 0, 0)
			start_timer(3, 60000, 0, 0)

			timerPlayerFlag = 0
		end
	end
end

--函数功能：用户触摸修改控件后,执行此回调函数.
function on_control_notify(screen, control, value)
	
	--时钟
	if (screen == 0) and (control == 1) then
		if (value == 1) then
			timerPlayerFlag = 1
		end
	end
	--仪表
	if (screen == 4) and (control == 5) then
		if (value == 0) then
			meterPlayerFlag = 0
			stop_timer(0)
		else
			meterPlayerFlag = 1
			start_timer(0, 100, 0, 0)
		end
	end
	--进度条
	if (screen == 5) and (control == 3) then
		local progressValue = get_value(5, 3)
		set_text(5, 5, progressValue)
	end
	



end

--定时器方面的几个函数使用
--LUA定时器中断函数,timer_id值范围为0-31
function on_timer(timer_id)
	if (timer_id == 0) then
		if (meterPlayerFlag == 1) then
			if (meterNum >= 0) and (meterNum <= 16) and (meterBackNum == 0) then
				run_HexCmd(meterClockwiseCmd)
				meterNum = (meterNum + 1)
				set_text(4, 3, meterNum * 10)
				
				if (meterNum == 17) then
					meterBackNum = 32
				end
			end
			
			if (meterBackNum > 0) and (meterBackNum <= 32) then
				--meterNum = (meterNum + 1)
				if (meterBackNum - meterNum) >= 0 then
					set_text(4, 3, (meterBackNum - meterNum) * 10)
					meterBackNum = meterBackNum - 1
				else
					meterNum = 0
					meterBackNum = 0
				end
				run_HexCmd(meterAnticlockwiseCmd)
			end 
		end
	end
	
	if (timer_id == 1) then
		if (sTimerNum >= 0) and (sTimerNum <= 59) then
			run_HexCmd(sTimerClockCmd)
			sTimerNum = (sTimerNum + 1)
			if (sTimerNum == 59) then
				run_HexCmd(sTimerClockInitCmd)
				sTimerNum = 0
			end
		end
	end
	

	if (timer_id == 2) then
		if (mTimerNum >= 0) and (mTimerNum <= 59) then
			run_HexCmd(mTimerClockCmd)
			mTimerNum = (mTimerNum + 1)
			if (mTimerNum == 59) then
				run_HexCmd(mTimerClockInitCmd)
				mTimerNum = 0
			end
		end
	end
	
	if (timer_id == 3) then
		if (hTimerNum >= 0) and (hTimerNum <= 59) then
			run_HexCmd(hTimerClockCmd)
			hTimerNum = (hTimerNum + 1)
			if (hTimerNum == 59) then
				run_HexCmd(hTimerClockInitCmd)
				hTimerNum = 0
			end
		end
	end
	
end


function on_run(screen)
end

function on_update(slave, vtype, addr)
end

function on_draw(screen_id, control_id)
end

