1
0
mirror of https://github.com/elua/elua.git synced 2025-01-25 01:02:54 +08:00
elua/romfs/tvbgone.lua
Bogdan Marinescu 45285ea064 - LTR: even if we (obviously) can't set new keys/values in a rotable, we still respect the __newindex metamethod. This allows for interesting tricks, like the one shown below :)
- complete rewrite of the PIO module. New usage:

pio.PA = 10 -- set the value of PA to 10
pio.PB_1 = 1 -- set the value of pin 1 of PB to 1

local value = pio.PB -- get the value of PB
local value = pio.PB_3 -- get the value of pin 3 of PB

pio.PA_DIR = pio.OUTPUT/pio.INPUT - set the direction of PA
pio.dir[ pio.PA ] = pio.OUTPUT/pio.INPUT - same as above

pio.PA_2_DIR = pio.OUTPUT/pio.INPUT - set the direction of pin 2 of PA
pio.dir[ pio.PA_2 ] = pio.OUTPUT/pio.INPUT - same as above

pio.PA_PULL = pio.PULLUP/pio.PULLDOWN/pio.NOPULL - set pulls on PA
pio.pull[ pio.PA ] = pio.PULLUP/pio.PULLDOWN/pio.NOPULL - same as above

pio.P0_3_PULL = pio.PULLUP/pio.PULLDOWN/pio.NOPULL - set pulls on pin 3 of P0
pio.pull[ pio.P0_3 ] = pio.PULLUP/pio.PULLDOWN/pio.NOPULL - same as above

- samples modified to use the new PIO syntax
- bugfix in AT91SAM7X256 UART int handler
- fixed yet another bug in AVR32's libc (actually replaced strcmp (which is broken on AVR32) with a custom version).
2009-02-10 17:54:01 +00:00

71 lines
1.7 KiB
Lua

-- 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 = "PF_0", "PF_1", "PE_1"
else
print( pd.board() .. " not supported with this example" )
return
end
-- Setup PIO
pio.dir[ led ] = pio.OUTPUT
pio.dir[ startpin ], pio.dir[ exitpin ] = pio.INPUT, pio.INPUT
pio.pull[ startpin ], pio.pull[ exitpin ] = pio.PULLUP, pio.PULLUP
-- 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[ startpin ] == 1 do
if pio[ exitpin ] == 0 then
runme = false
break
end
end
if not runme then break end
pio[ led ] = 1
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[ exitpin ] == 0 then
runme = false
break
end
end
if not runme then break end
tmr.delay( tmrid, 250000 )
end
pio[ led ] = 0
if not runme then break end
tmr.delay( tmrid, 500000 )
end
codes:close()