--下面列出了常用的回调函数
--更多功能请阅读<<LUA脚本API.pdf>>

--初始化函数
--function on_init()
--end

--定时回调函数，系统每隔1秒钟自动调用。
--function on_systick()
--end

--用户通过触摸修改控件后，执行此回调函数。
--点击按钮控件，修改文本控件、修改滑动条都会触发此事件。
--function on_control_notify(screen,control,value)
--end

--当画面切换时，执行此回调函数，screen为目标画面。
--function on_screen_change(screen)
--end
local progress = 0
local meter_value = 0
local meter_flag = 0
local Progress_screenid = 5
local Meter_screenid = 6
local Slider_screendid = 7
local Seltor_screenid = 12
local Languagescreen_id = 15
local Bootanimation_id = 36

function on_init()
	set_button_notify_release()
	start_timer(0,1000,0,0)
	start_timer(18,1000,0,1)
	local language_id = get_language()
	if language_id == 0 then
		set_value(Languagescreen_id,1,1)
		set_value(Languagescreen_id,2,0)
	end
	if language_id == 1 then
		set_value(Languagescreen_id,2,1)
		set_value(Languagescreen_id,1,0)
	end
end

function on_timer(timer_id)
 if timer_id==18 then
	print("uart_set_baudrate(921600)")
	-- uart_set_baudrate(460800)
 end
 if timer_id==1
  then
    if meter_value <=0                                                       --小于0时，数值加
  	then
  		meter_flag = 0
    end
    if meter_value >=270                                                     --大于0时，数值减
  	then
  		meter_flag = 1
    end
    if meter_flag  ==0
    then
    set_value(Meter_screenid,1,meter_value)
	set_value(Meter_screenid,5,meter_value)                                               --指针转动
	meter_value = meter_value+2                                              --数值增加
	end
	if meter_flag ==1
	then
	set_value(Meter_screenid,1,meter_value)
	set_value(Meter_screenid,5,meter_value)                                               --指针转动
	meter_value = meter_value-2                                              --数值增加
	end  
  end
end




function on_control_notify(screen,control,value)
	if screen == Meter_screenid then
		if control == 4 and value == 1 then
			start_timer(1,15,0,0)
		end
		if control == 4 and value == 0 then
			stop_timer(1)
		end
	end
	
	if screen == Seltor_screenid then
		if control == 1 then
			if value >= 0 and value <= 6 then
				set_value(screen,3,0)
			end
			if value > 6 and value <= 12 then
				set_value(screen,3,1)
			end
			if value > 12 and value <= 18 then
				set_value(screen,3,2)
			end
			if value > 18 and value <= 21 then
				set_value(screen,3,3)
			end
			if value > 21 and value <= 23 then
				set_value(screen,3,4)
			end
		end
	end

	if screen == Progress_screenid then
		if control == 3
		then
			if value == 0 or value == 2
			then
				progress = progress - 1
				if progress <= 0
				then
					progress = 0
				end
				set_value(screen,1,progress)
				set_value(screen,2,progress)
			end
		elseif control == 1
		then
			set_value(screen, 2, value)
			progress = value
		elseif control == 4
		then
			if value == 0 or value == 2
			then
				progress = progress + 1
				if progress >= 100
				then
					progress = 100
				end
				set_value(screen,1,progress)
				set_value(screen,2,progress)
			end
		end
	end
	if screen == Slider_screendid then
		if control == 2 then
			set_value(screen,3,value)
			set_backlight(value)
		end
		if control == 5 then
			set_value(screen,6,value)
		end
	end
end
