-
Notifications
You must be signed in to change notification settings - Fork 0
/
xPosSw.lua
67 lines (50 loc) · 1.83 KB
/
xPosSw.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
-- TNS|n-POSITION-SWITCH|TNE
---- ########################################################
---- # #
---- # Copyright (C) arminRC #
---- # YouTube channel: https://www.youtube.com/@arminrc #
---- # !!! Please like and subscribe !!! #
---- # #
---- ########################################################
TRIG1_IDX = 0 -- index of the 1st logical switch that trigger the script (up)
TRIG2_IDX = 1 -- index of the 2nd logical switch that trigger the script (down)
START_IDX = 4 -- index of the 1st logical switch in the multi-position-switch
current_idx = START_IDX -- index of the currently active switch-position
-- Called once when the script is loaded
local function init()
setStickySwitch(START_IDX, true)
end
-- Called periodically while the Special Function switch is on
local function run()
trig1_val = getLogicalSwitchValue(TRIG1_IDX)
trig2_val = getLogicalSwitchValue(TRIG2_IDX)
if trig1_val == true then
incrementSticky()
elseif trig2_val == true then
decrementSticky()
end
end
function incrementSticky()
sw_val = model.getLogicalSwitch(current_idx + 1)
if sw_val == nil then
return
end
if sw_val["func"] ~= LS_FUNC_STICKY then
return
end
setStickySwitch(current_idx, false)
setStickySwitch(current_idx + 1, true)
current_idx = current_idx + 1
end
function decrementSticky()
if current_idx == START_IDX then
return
end
setStickySwitch(current_idx, false)
setStickySwitch(current_idx - 1, true)
current_idx = current_idx - 1
end
-- Called periodically while the Special Function switch is off
local function background()
end
return { run=run, background=background, init=init }