IssyPutchy

Watchmaker numerics to Tasker code

Oct 21st, 2018
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.14 KB | None | 0 0
  1. -- Initial variables to set before anything
  2. var_display="0000000000000"
  3. var_delay=.5
  4. var_lock=0
  5.  
  6.  -- Simple lock routine to prevent double presses etc.
  7. function lock()
  8.  if var_lock == 0 then
  9.   var_lock = 1 else
  10.   var_lock = 0
  11.  end
  12. end
  13.  
  14. -- Individual functions named according to our table funso below. Not all need to be in the table.
  15.  
  16. function check_data()
  17.    wm_action('m_task:WMCheck')
  18.    var_display={twmdigit}
  19. end
  20. function clear_data()
  21.    wm_action('m_task:WMClear')
  22. end
  23. function confirm_data()
  24.    wm_action('m_task:WMConfirm')
  25. end
  26.  
  27. function zero()
  28.  wm_action('m_task:WMDigit0')
  29.  var_digit=0
  30. end
  31. function one()
  32.  wm_action('m_task:WMDigit1')
  33.  var_digit=1
  34. end
  35. function two()
  36.  wm_action('m_task:WMDigit2')
  37.   var_digit=2
  38. end
  39. function three()
  40.  wm_action('m_task:WMDigit3')
  41.   var_digit=3
  42. end
  43. function four()
  44.  wm_action('m_task:WMDigit4')
  45.   var_digit=4
  46. end
  47. function five()
  48.  wm_action('m_task:WMDigit5')
  49.   var_digit=5
  50. end
  51. function six()
  52.  wm_action('m_task:WMDigit6')
  53.   var_digit=6
  54. end
  55. function seven()
  56.  wm_action('m_task:WMDigit7')
  57.   var_digit=7
  58. end
  59. function eight()
  60.  wm_action('m_task:WMDigit8')
  61.   var_digit=8
  62. end
  63. function nine()
  64.  wm_action('m_task:WMDigit9')
  65.   var_digit=9
  66. end
  67. function star()
  68.  wm_action('m_task:WMDigitStar')
  69.   var_digit="*"
  70. end
  71. function hash()
  72.  wm_action('m_task:WMDigitHash')
  73.   var_digit="#"
  74. end
  75.  
  76. -- Delay routine used in conjunction with lock
  77. function delay()
  78.   wm_schedule {
  79.    { action='run_function',run_function=lock },
  80.    { action='sleep',sleep=0.25 },
  81.    { action='run_function',run_function=check_data },
  82.    { action='sleep',sleep=0.05 },
  83.    { action='run_function',run_function=lock }
  84.   }
  85. end
  86.  
  87. -- Used to update Tasker variable data for Watchmaker
  88. function update_value()
  89. var_display=wm_tag('{twmdigit}')
  90. end
  91.  
  92. -- The reset Tasker variable routine
  93. function reset_display()
  94.   wm_schedule {
  95.    { action='run_function',run_function=clear_data },
  96.    { action='sleep',sleep=var_delay },
  97.    { action='run_function',run_function=check_data },
  98.   }
  99. end
  100.  
  101. -- This is where the funk happens!
  102.  
  103. var_run = 1
  104.  
  105. -- Our table. Because of lack of quotes, we can't use these in var_vars. If we use quotes, the wm_schedule wont fire. Catch 22.
  106.  
  107. funso = {[0] = zero, one, two, three, four, five, six, seven, eight, nine}
  108.  
  109. -- Update the tags prior to sending them to phone. These are changed in the function below.
  110.  
  111. var_s_steps=0
  112. var_measure=0
  113. function measurements()
  114.  if var_measure == 0 then
  115.   measurement=tonumber(wm_tag({ssc}))
  116.  elseif var_measure == 1 then
  117.   measurement=tonumber(wm_tag({bl}))
  118.  elseif var_measure == 2 then
  119.   measurement=tonumber(wm_tag({shr}))
  120.  end
  121. end
  122.  
  123. -- Change the tag used for recording. Can use any tag, string or number providing it contains just numerals.
  124.  
  125. function chg_measurement()
  126.  if var_measure < 2 then
  127.   var_measure=var_measure+1 else
  128.   var_measure=0
  129.  end
  130. end
  131.  
  132. -- And the freaky deaky stuff! As long as "measurement" contains an integer, it'll will fire each function mapped to that number; 1 becomes one, 2 two etc. We run this function within on_second. This causes a 1 second pause between each Task fire, but 99/100 guarantees the correct sequence is made providing connection between watch and phone is good.
  133.  
  134. function loopy()
  135. measurements()
  136. key=nil
  137. a=tonumber(string.len(measurement))
  138. s=1
  139.  for i=1,s do
  140.   if var_s_steps == a then
  141.    break
  142.   end
  143.   var_s_steps = var_s_steps + s
  144.   key = funso[tonumber(string.sub(measurement,var_s_steps,var_s_steps))]
  145.   wm_schedule {
  146.    { action='run_function',run_function=key },
  147.   }
  148.  end
  149. end
  150.  
  151. -- Reset everything for next send.
  152.  
  153. function reset()
  154. key = nil
  155. var_s_steps = 0
  156. var_run = 1
  157. s = 1
  158. a = 1
  159. check_data()
  160. end
  161.  
  162. -- Toggle the on_second running. As to stop the loop from ever running when not needed.
  163.  
  164. function toggle()
  165. var_run=var_run%3+1
  166. end
  167.  
  168. -- The ontap Action to easily reset every (C button).
  169. function run()
  170.  wm_schedule {
  171.   { action='run_function',run_function=toggle },
  172.   { action='sleep',sleep=5 },
  173.   { action='run_function',run_function=reset }
  174.   }
  175. end
  176.  
  177. -- On second function to permit the funk happening.
  178. function on_second()
  179.  if var_run == 2 then
  180.   loopy()
  181.  end
  182. end
Add Comment
Please, Sign In to add comment