_ENCRYPT_=0    --LUA脚本加密

--数据类型定义
VT_LW = 1    --变量地址
VT_RW = 2    --FLASH存储
INVALID_POS = 0x7FFF

function on_init()
  dofile("animation.lua")
  start_timer(0,1,0,0) --播放动画的定时器
  
  set_uint16(VT_LW,0X2000,87)
  set_uint16(VT_LW,0X2001,100)
  set_uint16(VT_LW,0X2004,03)
  set_uint16(VT_LW,0X2005,27)
end

function on_run(screen)
end

function on_update(slave,vtype,addr)
end

function on_draw(screen_id,control_id)
end

press_state = 0
press_x = 0
press_y = 0

function on_slide_x(right)
  local screen = get_screen()
  if screen==0 then
    set_screen(1)
  elseif screen==1 then
    set_screen(0)
  end
end

local from_screen = 0
function on_slide_y(down)
  local screen = get_screen()
  if (screen==0 or screen== 1) then
    set_screen(3)
	from_screen = screen
  elseif screen==3 then
    set_screen(from_screen)
  end
end

function on_press(state,x,y)
  --按下
  if state==1 then
      press_state = 1
      press_x = x
	  press_y = y
  end
  
  --松开
  if state==0 and press_state==1
  then
    local dx = x-press_x
	local dy = y-press_y
	local abs_dx = math.abs(dx)
	local abs_dy = math.abs(dy)
	if abs_dx>abs_dy and abs_dx>20
	then
	  on_slide_x(dx<0)
	elseif abs_dx<abs_dy and abs_dy>20
	then
	  on_slide_y(dy<0)
	end
    press_state = 0
  end
end

