-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathled_helper.lua
87 lines (70 loc) · 1.91 KB
/
led_helper.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
local led_helper = {}
local sys = require("sys")
local config = require("config")
local constants = require("constants")
local utils = require("utils")
local status_led = gpio.setup(
constants.gpio[config.board_type].LED_A,
0,
gpio.PULLUP)
local working_led = gpio.setup(
constants.gpio[config.board_type].LED_B,
0,
gpio.PULLUP
)
local function stop_and_clear_timer(timer)
sys.timerStop(timer)
timer = nil
end
local is_status_led_on = true
local status_led_blink_timer = nil
function led_helper.blink_status_led(duration)
if status_led_blink_timer then
stop_and_clear_timer(status_led_blink_timer)
end
status_led_blink_timer = sys.timerLoopStart(
function ()
status_led(is_status_led_on and 1 or 0)
is_status_led_on = not is_status_led_on
end,
duration)
end
local is_working_led_on = true
local working_led_blink_timer = nil
function led_helper.blink_working_led(duration)
if working_led_blink_timer then
stop_and_clear_timer(working_led_blink_timer)
end
working_led_blink_timer = sys.timerLoopStart(
function ()
working_led(is_working_led_on and 1 or 0)
is_working_led_on = not is_working_led_on
end,
duration
)
end
function led_helper.light_status_led()
if status_led_blink_timer then
stop_and_clear_timer(status_led_blink_timer)
end
status_led(1)
end
function led_helper.shut_status_led()
if status_led_blink_timer then
stop_and_clear_timer(status_led_blink_timer)
end
status_led(0)
end
function led_helper.light_working_led()
if working_led_blink_timer then
stop_and_clear_timer(working_led_blink_timer)
end
working_led(1)
end
function led_helper.shut_working_led()
if working_led_blink_timer then
stop_and_clear_timer(working_led_blink_timer)
end
working_led(0)
end
return led_helper