-
Notifications
You must be signed in to change notification settings - Fork 0
/
tvbgone.lua
70 lines (63 loc) · 1.72 KB
/
tvbgone.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
-- TVBGone in eLua
-- Adapted from LadyAda's TVBGone project
-- Check codes file
local codes = io.open( "/rom/codes.bin", "rb" )
if codes == nil then
print "Unable to open TVBGone codes file"
return
end
local pwmid, tmrid
if pd.board() == 'EK-LM3S8962' or pd.board() == 'EK-LM3S6965' then
pwmid, tmrid = 2, 1
pwm.setclock( pwmid, 25000000 )
led, startpin, exitpin = pio.PF_0, pio.PF_1, pio.PE_1
else
print( pd.board() .. " not supported with this example" )
return
end
-- Setup PIO
pio.pin.setdir( pio.OUTPUT, led )
pio.pin.setdir( pio.INPUT, startpin, exitpin )
pio.pin.setpull( pio.PULLUP, startpin, exitpin )
-- Local variables
local _, fstr, freq, timesstr, ontime, offtime, runme
-- Send all the codes in an infinite loop
collectgarbage( "stop" )
runme = true
while runme do
while pio.pin.getval( startpin ) == 1 do
if pio.pin.getval( exitpin ) == 0 then
runme = false
break
end
end
if not runme then break end
pio.pin.sethigh( led )
codes:seek( "set", 0 )
while true do
fstr = codes:read( 4 )
if fstr == nil then break end
_, freq = pack.unpack( fstr, "<L" )
pwm.setup( pwmid, freq, 50 )
while true do
timesstr = codes:read( 4 )
_, ontime = pack.unpack( timesstr, "<H" )
_, offtime = pack.unpack( timesstr, "<H", 3 )
pwm.start( pwmid )
tmr.delay( tmrid, ontime * 10 )
pwm.stop( pwmid )
if offtime == 0 then break end
tmr.delay( tmrid, offtime * 10 )
if pio.pin.getval( exitpin ) == 0 then
runme = false
break
end
end
if not runme then break end
tmr.delay( tmrid, 250000 )
end
pio.pin.setlow( led )
if not runme then break end
tmr.delay( tmrid, 500000 )
end
codes:close()