var_mode = 1
var_modes = 10

var_alarm = 7
var_showalarm = true

var_metric = true
var_dimT = "°C"
var_dimS = "km/h"

var_night = false
var_n = 3

wm_action('sw_reset')

var_days = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}


function var_tween(A,B,C,D)
wm_schedule {action='tween',tween=D,from=A,to=B,duration=C,easing=linear}
end

tweens.moveH=1
tweens.moveM=1
tweens.moveS=1
q=180

function var_rotateH(r)
if r<90 then r=90 end
wm_schedule {action='tween',tween='moveH',from=0,to=1,duration=r/q,easing=inOutCubic}
end

function var_parkH(r)
if r<90 then r=90 end
wm_schedule {action='tween',tween='moveH',from=1,to=0,duration=r/q,easing=inOutCubic}
end

function var_rotateM(r)
if r<90 then r=90 end
wm_schedule {action='tween',tween='moveM',from=0,to=1,duration=r/q,easing=inOutCubic}
end

function var_parkM(r)
if r<90 then r=90 end
wm_schedule {action='tween',tween='moveM',from=1,to=0,duration=r/q,easing=inOutCubic}
end

function var_rotateS(r)
if r<90 then r=90 end
wm_schedule {action='tween',tween='moveS',from=0,to=1,duration=r/q,easing=inOutCubic}
end

function var_parkS(r)
if r<90 then r=90 end
wm_schedule {action='tween',tween='moveS',from=1,to=0,duration=r/q,easing=inOutCubic}
end

function on_second()
if not {abright} then
   tweens.moveH=1
   tweens.moveM=1
   tweens.moveS=1
end
if {pbl}>var_alarm then var_showalarm=true end
end


function var_logo(i)
if i==1 then return("") end
if i==2 then return("Battery levels") end
if i==3 then return("Date") end
if i==4 then return("Temperature") end
if i==5 then return("Forecast") end
if i==6 then return("Weather") end
if i==7 then return("Sensors") end
if i==8 then return("Stopwatch") end
if i==9 then return("Telemeter") end
if i==10 then return("Tachymeter") end
end


function var_leftdial(i)
if i==1 then return({swm}*6) end
if i==2 then return({br}) end
if i==3 then return(({dy}-15)*36) end
if i==4 then
   if var_metric then
      return(math.abs({wth}*9))
    else
      return({wth}*4.5+180)
   end
end
if i==5 then
   if var_metric then
      return(math.abs({wf1dth}*9))
    else
      return({wf1dt}*4.5+180)
   end
end
if i==6 then return({wh}*3.6) end
if i==7 then return({shr}*1.8) end
if i==8 then return({swm}*6) end
if i==9 then return({swm}*6) end
if i==10 then return(0) end
end


function var_rightdial(i)
if i==1 then return({drh24}) end
if i==2 then return({pbr}) end
if i==3 then return({dn}*30) end
if i==4 then
   if var_metric then
      return(math.abs({wtl}*9))
    else
      return({wtl}*4.5+180)
   end
end
if i==5 then
   if var_metric then
      return(math.abs({wf2dth}*9))
    else
      return({wf2dt}*4.5+180)
   end
end
if i==6 then
   if var_metric then
      return({wws}*1.609*1.8)
    else
      return({wws}*1.8)
   end
end
if i==7 then return({ssc}*36/100) end
if i==8 then return({swh}*15) end
if i==9 then return({swh}*15) end
if i==10 then return({drh24}) end
end


function var_bottomdial(i)
if {pbl}<=var_alarm and var_showalarm==0 then var_showalarm=1 end
if i==1 then return({drs}) end
if i==2 then
   if var_metric then
      return(({pbtc}-20)*9)
    else
      return({pbtf}-70)*4.5
   end
end
if i==3 then return({ddw0}*360/7) end
if i==4 then
   if var_metric then
      return(math.abs({wt}*9))
    else
      return({wt}*4.5+180)
   end
end
if i==5 then
   if var_metric then
      return(math.abs({wf3dth}*9))
    else
      return({wf3dt}*4.5+180)
   end
end
if i==6 then return({wwd}) end
if i==7 then return({sctd}) end
if i>7 then return({drs}) end
end


function var_textleft(i)
if i==1 then return("") end
if i==2 then return("Watch") end
if i==3 then return("Year") end
if i==4 then return("Highest " .. var_dimT) end
if i==5 then return(var_days[({ddw0}+1)%7+1]) end
if i==6 then return("Humidity") end
if i==7 then return("Heart rate") end
if i>7 then return("RESET") end
end


function var_textright(i)
if i==1 then return("") end
if i==2 then return("Phone") end
if i==3 then return("Month") end
if i==4 then return("Lowest " .. var_dimT) end
if i==5 then return(var_days[({ddw0}+2)%7+1]) end
if i==6 then return("Wind " .. var_dimS) end
if i==7 then return({ssc} .. " steps") end
end


function var_textbottom(i)
if i==1 then return("") end
if i==2 then return("Phone " .. var_dimT) end
if i==3 then return("Day") end
if i==4 then return("Current " .. var_dimT) end
if i==5 then return(var_days[({ddw0}+3)%7+1]) end
if i==6 then return("Wind") end
if i==7 then return("Compass") end
if i>7 then return("") end
end


function var_dimension(i)
if i==1 then return("") end
if i==2 then return("%") end
if i>2 and i<8 then return("") end
if i==8 then return("SEC") end
if i==9 then
   if var_metric then return("KM") else return("M") end
end
if i==10 then return(var_dimS) end
end


function var_distance(t)
if var_metric then
   dist = (math.floor(t/300))/10
   return("Distance is " .. dist .. " km")
 else
   dist = (math.floor(t*.6214/300))/10
   return("Distance is " .. dist .. " miles")
end
end


function var_speed(t)
speed = math.floor(3600000/t)
return("Speed is " .. speed .. " " .. var_dimS)
end