-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpio_commands.lua
114 lines (89 loc) · 2.71 KB
/
gpio_commands.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
local hstring = require 'hstring'
-- local hfile = require 'hfile'
local hlog = require 'hlog'
local htime = require 'htime'
local hsettings = require 'hsettings'
-- local hgps = require 'hgps'
-- local hsuntime = require 'hsuntime'
local hexecute = require 'hexecute'
local gpiocommands = {
__VERSION = '1.0',
__DESCRIPTION = 'GPIOr-related functions for lua',
}
function gpiocommands.test()
print("gpiocommands merge")
end
function gpiocommands.startGPIO()
local allowStartGPIO = gpiocommands.allowStartGPIO()
if (allowStartGPIO == false) then
hlog.logToFile('PREVENIRE PORNIRE');
return
end
hlog.logToFile('SUNTIME - PORNIRE DOUT2');
-- hexecute.tryExecute('/sbin/gpio.sh set DOUT2')
hexecute.tryExecute("/sbin/gpio.sh set DOUT2 1")
end
function gpiocommands.tryStartGPIO()
status, ret = pcall(gpiocommands.startGPIO)
if (status ~= false and ret ~= nil) then
return ret
else
return nil
end
end
function gpiocommands.allowStartGPIO()
local barrier = hsettings.getBarrier();
if (barrier == nil or barrier == '') then
return true
end
local vals = hstring.splitBy(barrier, ',');
local t1 = htime.createTimeFromHMS(vals[1]);
local t2 = htime.createTimeFromHMS(vals[2]);
local seconds1 = htime.getSeccondsUntilDate(t1)
local seconds2 = htime.getSeccondsUntilDate(t2)
print(seconds1 .. ' ' .. htime.secondsToHHMMSS(seconds1) .. ' b1')
print(seconds2 .. ' ' .. htime.secondsToHHMMSS(seconds2) .. ' b2')
if (seconds1 < 0 and seconds2 < 0) then
return true
end
if (seconds1 > 0 and seconds2 > 0) then
return true
end
return false;
end
function gpiocommands.allowStopGPIO()
local barrier = hsettings.getBarrier();
if (barrier == nil or barrier == '') then
return true
end
local vals = hstring.splitBy(barrier, ',');
local t1 = htime.createTimeFromHMS(vals[1]);
local t2 = htime.createTimeFromHMS(vals[2]);
local seconds1 = htime.getSeccondsUntilDate(t1)
local seconds2 = htime.getSeccondsUntilDate(t2)
print(seconds1 .. ' ' .. htime.secondsToHHMMSS(seconds1) .. ' b1')
print(seconds2 .. ' ' .. htime.secondsToHHMMSS(seconds2) .. ' b2')
if (seconds1 < 0 and seconds2 > 0) then
return true
end
return false;
end
function gpiocommands.stopGPIO()
local allowStopGPIO = gpiocommands.allowStopGPIO()
if (allowStopGPIO == false) then
hlog.logToFile('PREVENIRE OPRIRE');
return
end
hlog.logToFile('SUNTIME - OPRIRE DOUT2');
-- hexecute.tryExecute('/sbin/gpio.sh clear DOUT2')
hexecute.tryExecute("/sbin/gpio.sh set DOUT2 0")
end
function gpiocommands.tryStopGPIO()
status, ret = pcall(gpiocommands.stopGPIO)
if (status ~= false and ret ~= nil) then
return ret
else
return nil
end
end
return gpiocommands