-
Notifications
You must be signed in to change notification settings - Fork 0
/
aux.lua
executable file
·139 lines (121 loc) · 2.93 KB
/
aux.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
last_motor_use = 0;
motor_rest_time = 10;
porta_abrindo = false
pl = 12000;
gpio.mode(pin_pwm, gpio.OUTPUT);
servo = {min=500,max=2400}
done_page=[[<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
<body>
<title>Acesso - HackerSpace Maringá</title>
<meta name="description" content="Access page">
<meta name="author" content="HS Maringa">
<H1>HackerSpace Maringá</H1><br>]]
function listap(t)
for k,v in pairs(t) do
print(k.." : "..v)
end
end
function DBsearch(user_name,dbFile)
f = file.open(dbFile) -- check if file exists
found = false
ended = false
while ((not found)and(not ended) ) do
local result = ""
local last = ""
while(string.sub(last,#last,#last) ~= "\n" and last ~= nil) do
last = f:readline()
if (last == nil) then
f:close()
return nil --EOF and no result matched
end
result = result .. last
end
if result == nil then
ended = true
break
end
user,salt,hash = string.match(result,"(.*),(.*),(.*)\n")
if user == user_name then
f:close()
return {user=user,salt=salt,hash=hash}
end
end
f:close()
end
function shallow_copy(t)
local t2 = {}
for k,v in pairs(t) do
t2[k] = v
end
return t2
end
function serAng( x )
if (x<0) then x = 0; end;
if (x>100) then x = 100; end;
return servo.min+(servo.max-servo.min)*x/100;
end
function abre_porta()
if porta_abrindo == true then
return
end
porta_abrindo = true
local alarm_bzz=tmr.create()
local alarm_pwm=tmr.create()
local alarm_motor=tmr.create()
-- starts sending servo PWM pulses
startPWM = function()
alarm_pwm:alarm(20, 1,
function()
gpio.write(pin_pwm,gpio.LOW) tmr.delay(pl) gpio.write(pin_pwm,gpio.HIGH)
end)
end
closed_start_position = function()
pl = serAng(100) --commonly at 100% (maximum angle)
-- wait 5 seconds
alarm_bzz:alarm(500,tmr.ALARM_SINGLE,
function()
open_position()
end)
end
open_position = function()
pl = serAng( 0) --commonly at 0% (minimum angle)
alarm_motor:alarm(1000,tmr.ALARM_SINGLE,
function()
local sec, _, _ = rtctime.get()
if last_motor_use + motor_rest_time < sec then
last_motor_use = sec
gpio.write(pin_motor,gpio.HIGH)
alarm_motor:alarm(3000,tmr.ALARM_SINGLE,
function()
gpio.write(pin_motor,gpio.LOW)
end)
end
end)
-- wait 20 seconds
alarm_bzz:alarm(4000,tmr.ALARM_SINGLE,
function()
closed_end_position()
end)
end
closed_end_position = function()
pl = serAng(100) --commonly at 100% (maximum angle)
-- wait 5 seconds
alarm_bzz:alarm(500,tmr.ALARM_SINGLE,
function()
cleanup()
end)
end
cleanup = function()
alarm_bzz:unregister()
alarm_pwm:unregister()
alarm_motor:unregister()
porta_abrindo = false
end
startPWM()
closed_start_position()
end