Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Initial variables to set before anything
- var_display="0000000000000"
- var_delay=.5
- var_lock=0
- -- Simple lock routine to prevent double presses etc.
- function lock()
- if var_lock == 0 then
- var_lock = 1 else
- var_lock = 0
- end
- end
- -- Individual functions named according to our table funso below. Not all need to be in the table.
- function check_data()
- wm_action('m_task:WMCheck')
- var_display={twmdigit}
- end
- function clear_data()
- wm_action('m_task:WMClear')
- end
- function confirm_data()
- wm_action('m_task:WMConfirm')
- end
- function zero()
- wm_action('m_task:WMDigit0')
- var_digit=0
- end
- function one()
- wm_action('m_task:WMDigit1')
- var_digit=1
- end
- function two()
- wm_action('m_task:WMDigit2')
- var_digit=2
- end
- function three()
- wm_action('m_task:WMDigit3')
- var_digit=3
- end
- function four()
- wm_action('m_task:WMDigit4')
- var_digit=4
- end
- function five()
- wm_action('m_task:WMDigit5')
- var_digit=5
- end
- function six()
- wm_action('m_task:WMDigit6')
- var_digit=6
- end
- function seven()
- wm_action('m_task:WMDigit7')
- var_digit=7
- end
- function eight()
- wm_action('m_task:WMDigit8')
- var_digit=8
- end
- function nine()
- wm_action('m_task:WMDigit9')
- var_digit=9
- end
- function star()
- wm_action('m_task:WMDigitStar')
- var_digit="*"
- end
- function hash()
- wm_action('m_task:WMDigitHash')
- var_digit="#"
- end
- -- Delay routine used in conjunction with lock
- function delay()
- wm_schedule {
- { action='run_function',run_function=lock },
- { action='sleep',sleep=0.25 },
- { action='run_function',run_function=check_data },
- { action='sleep',sleep=0.05 },
- { action='run_function',run_function=lock }
- }
- end
- -- Used to update Tasker variable data for Watchmaker
- function update_value()
- var_display=wm_tag('{twmdigit}')
- end
- -- The reset Tasker variable routine
- function reset_display()
- wm_schedule {
- { action='run_function',run_function=clear_data },
- { action='sleep',sleep=var_delay },
- { action='run_function',run_function=check_data },
- }
- end
- -- This is where the funk happens!
- var_run = 1
- -- 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.
- funso = {[0] = zero, one, two, three, four, five, six, seven, eight, nine}
- -- Update the tags prior to sending them to phone. These are changed in the function below.
- var_s_steps=0
- var_measure=0
- function measurements()
- if var_measure == 0 then
- measurement=tonumber(wm_tag({ssc}))
- elseif var_measure == 1 then
- measurement=tonumber(wm_tag({bl}))
- elseif var_measure == 2 then
- measurement=tonumber(wm_tag({shr}))
- end
- end
- -- Change the tag used for recording. Can use any tag, string or number providing it contains just numerals.
- function chg_measurement()
- if var_measure < 2 then
- var_measure=var_measure+1 else
- var_measure=0
- end
- end
- -- 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.
- function loopy()
- measurements()
- key=nil
- a=tonumber(string.len(measurement))
- s=1
- for i=1,s do
- if var_s_steps == a then
- break
- end
- var_s_steps = var_s_steps + s
- key = funso[tonumber(string.sub(measurement,var_s_steps,var_s_steps))]
- wm_schedule {
- { action='run_function',run_function=key },
- }
- end
- end
- -- Reset everything for next send.
- function reset()
- key = nil
- var_s_steps = 0
- var_run = 1
- s = 1
- a = 1
- check_data()
- end
- -- Toggle the on_second running. As to stop the loop from ever running when not needed.
- function toggle()
- var_run=var_run%3+1
- end
- -- The ontap Action to easily reset every (C button).
- function run()
- wm_schedule {
- { action='run_function',run_function=toggle },
- { action='sleep',sleep=5 },
- { action='run_function',run_function=reset }
- }
- end
- -- On second function to permit the funk happening.
- function on_second()
- if var_run == 2 then
- loopy()
- end
- end
Add Comment
Please, Sign In to add comment