From f60f17056a53a7d283270d9bf894e49bcba85003 Mon Sep 17 00:00:00 2001 From: Dado Sutter Date: Sun, 9 Jan 2011 23:31:57 +0000 Subject: [PATCH] - Removing eLua exemples from the official distro's ROMFS --- romfs/EK-LM3S1968.lua | 34 ---- romfs/EK-LM3S6965.lua | 37 ---- romfs/EK-LM3S8962.lua | 37 ---- romfs/MBED.lua | 23 --- romfs/adcpoll.lua | 53 ------ romfs/adcscope.lua | 66 ------- romfs/bisect.lua | 27 --- romfs/codes.bin | Bin 7780 -> 0 bytes romfs/dataflash.lua | 34 ---- romfs/dualpwm.lua | 39 ----- romfs/hangman.lua | 136 --------------- romfs/hello.lua | 1 - romfs/index.pht | 50 ------ romfs/info.lua | 3 - romfs/inttest.lua | 45 ----- romfs/led.lua | 64 ------- romfs/lhttpd.lua | 122 ------------- romfs/life.lua | 108 ------------ romfs/logo.bin | Bin 2048 -> 0 bytes romfs/logo.lua | 81 --------- romfs/morse.lua | 136 --------------- romfs/piano.lua | 108 ------------ romfs/pong.lua | 339 ------------------------------------ romfs/pwmled.lua | 35 ---- romfs/snake.lua | 219 ----------------------- romfs/spaceship.lua | 274 ----------------------------- romfs/test.lua | 5 - romfs/tetrives.lua | 392 ------------------------------------------ romfs/tvbgone.lua | 70 -------- 29 files changed, 2538 deletions(-) delete mode 100644 romfs/EK-LM3S1968.lua delete mode 100644 romfs/EK-LM3S6965.lua delete mode 100644 romfs/EK-LM3S8962.lua delete mode 100644 romfs/MBED.lua delete mode 100755 romfs/adcpoll.lua delete mode 100644 romfs/adcscope.lua delete mode 100644 romfs/bisect.lua delete mode 100644 romfs/codes.bin delete mode 100644 romfs/dataflash.lua delete mode 100644 romfs/dualpwm.lua delete mode 100644 romfs/hangman.lua delete mode 100644 romfs/hello.lua delete mode 100644 romfs/index.pht delete mode 100644 romfs/info.lua delete mode 100644 romfs/inttest.lua delete mode 100644 romfs/led.lua delete mode 100644 romfs/lhttpd.lua delete mode 100644 romfs/life.lua delete mode 100644 romfs/logo.bin delete mode 100644 romfs/logo.lua delete mode 100644 romfs/morse.lua delete mode 100644 romfs/piano.lua delete mode 100644 romfs/pong.lua delete mode 100644 romfs/pwmled.lua delete mode 100644 romfs/snake.lua delete mode 100644 romfs/spaceship.lua delete mode 100644 romfs/test.lua delete mode 100644 romfs/tetrives.lua delete mode 100644 romfs/tvbgone.lua diff --git a/romfs/EK-LM3S1968.lua b/romfs/EK-LM3S1968.lua deleted file mode 100644 index dbe4fd89..00000000 --- a/romfs/EK-LM3S1968.lua +++ /dev/null @@ -1,34 +0,0 @@ --- This auxiliar platform dependent module defines some hardware devices --- available in the specific development kit. --- It will be automatically require()d when eLua detects it is running on the --- respective platform, exposing auxiliar constants and functions to facilitate --- and keep portable the access to the underlying hardware. --- The code configures the MCU to interface with the platform devices and --- exposes the following objects, constants and fuctions: --- Onboard Buttons: --- BTN_UP, BTN_DOWN, BTN_LEFT, BTN_RIGHT, BTN_SELECT --- Onboard LED: --- Auxiliar Function: --- btn_pressed( button ) --- returns true if the arg button is pressed, false otherwise - -local pio = pio - -module(...) - -BTN_UP = pio.PG_3 -BTN_DOWN = pio.PG_4 -BTN_LEFT = pio.PG_5 -BTN_RIGHT = pio.PG_6 -BTN_SELECT = pio.PG_7 - -btn_pressed = function( button ) - return pio.pin.getval( button ) == 0 -end - -LED_1 = pio.PG_2 - -pio.pin.setdir( pio.INPUT, BTN_UP, BTN_DOWN, BTN_LEFT, BTN_RIGHT, BTN_SELECT ) -pio.pin.setpull( pio.PULLUP, BTN_UP, BTN_DOWN, BTN_LEFT, BTN_RIGHT, BTN_SELECT ) -pio.pin.setdir( pio.OUTPUT, LED_1 ) - diff --git a/romfs/EK-LM3S6965.lua b/romfs/EK-LM3S6965.lua deleted file mode 100644 index 0e84e1f5..00000000 --- a/romfs/EK-LM3S6965.lua +++ /dev/null @@ -1,37 +0,0 @@ --- This auxiliary platform dependent module defines some hardware devices --- available in the specific development kit. --- It will be automatically require()d when eLua detects it is running on the --- respective platform, exposing auxiliary constants and functions to facilitate --- and keep portable the access to the underlying hardware. --- The code configures the MCU to interface with the platform devices and --- exposes the following objects, constants and functions: --- On-board buttons: --- BTN_UP, BTN_DOWN, BTN_LEFT, BTN_RIGHT, BTN_SELECT --- On-board LED: --- LED_1 --- On-board LED: --- Auxiliary Function: --- btn_pressed( button ) --- returns true if the arg button is pressed, false otherwise - -local pio = pio -local lm3s = lm3s - -module(...) - -BTN_UP = pio.PE_0 -BTN_DOWN = pio.PE_1 -BTN_LEFT = pio.PE_2 -BTN_RIGHT = pio.PE_3 -BTN_SELECT = pio.PF_1 - -btn_pressed = function( button ) - return pio.pin.getval( button ) == 0 -end - -LED_1 = pio.PF_0 - -pio.pin.setdir( pio.INPUT, BTN_UP, BTN_DOWN, BTN_LEFT, BTN_RIGHT, BTN_SELECT ) -pio.pin.setpull( pio.PULLUP, BTN_UP, BTN_DOWN, BTN_LEFT, BTN_RIGHT, BTN_SELECT ) -pio.pin.setdir( pio.OUTPUT, LED_1 ) - diff --git a/romfs/EK-LM3S8962.lua b/romfs/EK-LM3S8962.lua deleted file mode 100644 index 9d8b8fac..00000000 --- a/romfs/EK-LM3S8962.lua +++ /dev/null @@ -1,37 +0,0 @@ --- This auxiliary platform dependent module defines some hardware devices --- available in the specific development kit. --- It will be automatically require()d when eLua detects it is running on the --- respective platform, exposing auxiliary constants and functions to facilitate --- and keep portable the access to the underlying hardware. --- The code configures the MCU to interface with the platform devices and --- exposes the following objects, constants and functions: --- On-board buttons: --- BTN_UP, BTN_DOWN, BTN_LEFT, BTN_RIGHT, BTN_SELECT --- On-board LED: --- LED_1 --- On-board LED: --- Auxiliary Function: --- btn_pressed( button ) --- returns true if the arg button is pressed, false otherwise - -local pio = pio -local lm3s = lm3s - -module(...) - -BTN_UP = pio.PE_0 -BTN_DOWN = pio.PE_1 -BTN_LEFT = pio.PE_2 -BTN_RIGHT = pio.PE_3 -BTN_SELECT = pio.PF_1 - -btn_pressed = function( button ) - return pio.pin.getval( button ) == 0 -end - -LED_1 = pio.PF_0 - -pio.pin.setdir( pio.INPUT, BTN_UP, BTN_DOWN, BTN_LEFT, BTN_RIGHT, BTN_SELECT ) -pio.pin.setpull( pio.PULLUP, BTN_UP, BTN_DOWN, BTN_LEFT, BTN_RIGHT, BTN_SELECT ) -pio.pin.setdir( pio.OUTPUT, LED_1 ) - diff --git a/romfs/MBED.lua b/romfs/MBED.lua deleted file mode 100644 index c5f0b71b..00000000 --- a/romfs/MBED.lua +++ /dev/null @@ -1,23 +0,0 @@ --- This auxiliary platform dependent module defines some hardware devices --- available in the specific development kit. --- It will be automatically require()d when eLua detects it is running on the --- respective platform, exposing auxiliary constants and functions to facilitate --- and keep portable the access to the underlying hardware. --- The code configures the MCU to interface with the platform devices and --- exposes the following objects, constants and functions: --- On-board LEDs: --- Led1, Led2, Led3 and Led4 - -local pio = pio - -module(...) - -LED_1 = mbed.pio.LED1 -LED_2 = mbed.pio.LED2 -LED_3 = mbed.pio.LED3 -LED_4 = mbed.pio.LED4 - -pio.pin.setdir( pio.OUTPUT, LED_1 ) -pio.pin.setdir( pio.OUTPUT, LED_2 ) -pio.pin.setdir( pio.OUTPUT, LED_3 ) -pio.pin.setdir( pio.OUTPUT, LED_4 ) diff --git a/romfs/adcpoll.lua b/romfs/adcpoll.lua deleted file mode 100755 index 247406eb..00000000 --- a/romfs/adcpoll.lua +++ /dev/null @@ -1,53 +0,0 @@ --- Acquire ADC samples using a timer with polling for available samples - -if pd.board() == "ET-STM32" then - timer = 2 - adcchannels = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15} - adcsmoothing = {4, 4, 4, 4, 16, 16, 16, 16, 32, 32, 32, 32, 64, 128, 64, 128} -elseif pd.board() == "MBED" or pd.board() == "ELUA-PUC" then - timer = 1 - adcchannels = {0,1,2,3,4,5} - adcsmoothing = {4, 4, 16, 16, 32, 32} -else - timer = 0 - adcchannels = {0,1,2,3} - adcsmoothing = {4, 64, 32, 16} -end - --- Setup ADC and start sampling -for i, v in ipairs(adcchannels) do - adc.setblocking(v,0) -- no blocking on any channels - adc.setsmoothing(v,adcsmoothing[i]) -- set smoothing from adcsmoothing table - adc.setclock(v, 4 ,timer) -- get 4 samples per second, per channel -end - --- Draw static text on terminal -term.clrscr() -term.print(1,1,"ADC Status:") -term.print(1,3," CH SLEN RES") -term.print(1,#adcchannels+5,"Press ESC to exit.") - --- start sampling on all channels at the same time -adc.sample(adcchannels,128) - -while true do - for i, v in ipairs(adcchannels) do - -- If samples are not being collected, start - if adc.isdone(v) == 1 then adc.sample(v,128) end - - -- Try and get a sample - tsample = adc.getsample(v) - - -- If we have a new sample, then update display - if not (tsample == nil) then - term.print(1,i+3,string.format("ADC%02d (%03d): %04d\n", v, adcsmoothing[i], tsample)) - end - end - - -- Exit if user hits Escape - key = term.getchar( term.NOWAIT ) - if key == term.KC_ESC then break end -end - -term.clrscr() -term.moveto(1, 1) diff --git a/romfs/adcscope.lua b/romfs/adcscope.lua deleted file mode 100644 index b260ce98..00000000 --- a/romfs/adcscope.lua +++ /dev/null @@ -1,66 +0,0 @@ --- Acquire ADC samples as quickly as possible, without the use of a timer --- provides statistics on time and memory usage while running - -if pd.board() == "ET-STM32" then - adcchannels = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15} - adcsmoothing = {4, 4, 4, 4, 16, 16, 16, 16, 32, 32, 32, 32, 64, 128, 64, 128} - numiter = 50 -elseif pd.board() == "MBED" or pd.board() == "ELUA-PUC" then - adcchannels = {0,1,2,3,4,5} - adcsmoothing = {4, 4, 16, 16, 32, 32} - numiter = 2 -else - adcchannels = {0,1,2,3} - adcsmoothing = {4, 16, 64, 128} - numiter = 200 -end - --- Setup ADC -for i, v in ipairs(adcchannels) do - adc.setblocking(v,1) -- block, waiting for samples when an adc.get* function is used - adc.setclock(v,0) -- set clock to zero: no timer, acquire samples as fast as possible - adc.setsmoothing(v,adcsmoothing[i]) -- apply moving average filter using lengths from adcsmoothing -end - --- Draw static text on terminal -term.clrscr() -term.print(1,1,"ADC Status:") -term.print(1,3," CH SLEN RES") -term.print(1,#adcchannels+7,"Press ESC to exit.") - --- Use some locals for speed -local adcvals = {} -local key, stime, etime, dtime, i, v -local sample = adc.sample -local insertsamples = adc.insertsamples -local tread = tmr.read -local tstart = tmr.start - -while true do - stime = tstart(0) -- start timer - for j=1,numiter do -- acuire numiter samples - sample(adcchannels, 1) - for i, v in ipairs(adcchannels) do - insertsamples(v,adcvals,i,1) -- for each iteration j, get samples and put them in adcvals - end - end - etime = tread(0) -- get cycle end time - dtime = tmr.gettimediff(0,etime,stime)/numiter -- compute average acquisition time per cycle - - -- draw last acquired samples on the console - term.moveto(1,4) - for i, v in ipairs(adcchannels) do - term.print(string.format("ADC%02d (%03d): %04d\n", v, adcsmoothing[i],adcvals[i])) - term.moveto(1,i+4) - end - - -- draw acquisition statistics - term.print(string.format("Tcyc: %06d (us)\n",dtime)) - term.print(1,#adcchannels+5,string.format("Mem: %03.2f (kB)\n",collectgarbage("count"))) - - key = term.getchar( term.NOWAIT ) - if key == term.KC_ESC then break end -- exit if user hits Escape -end - -term.clrscr() -term.moveto( 1 , 1 ) diff --git a/romfs/bisect.lua b/romfs/bisect.lua deleted file mode 100644 index 6f389a09..00000000 --- a/romfs/bisect.lua +++ /dev/null @@ -1,27 +0,0 @@ --- bisection method for solving non-linear equations - -delta=1e-6 -- tolerance - -function bisect(f,a,b,fa,fb) - local c=(a+b)/2 - io.write(n," c=",c," a=",a," b=",b,"\n") - if c==a or c==b or math.abs(a-b)*k!_s-4udm?|!s7$EsjiBY=dplF^yhddEFCrhg58d6eAS*?d@};ZDiza);WX6yX=KqWU5_YJk>w9PRSR-P+%9U#7=REo)c9qWU5_YJk>w z4DIsBiHz$#eY1Qkx5&d01J4|hI>uwYnT9za^VSDPBcE5#Jo^yAGY8D8w|e?O8hiL_ zFqNEhyJeTeZ8qhBF+-izun)N~W)IdeKEH7~`CWTW4tf;%>yXIf`k8P3g%|tytp6)p zI@CAsfwS&6H!O3K*_isFt(J!#ny`*BbGDE5hkMVhi{lWfejvIw-lcY2*Whv~^JARN z!)N^N_N6-dvGONF*PxQ9{+nHm`Q$wVF zTi5#N;qSr2$!T39ck23NZ7z*1!lyx7BxiflkJatyc{^Fup05l5dA;|!{q8Z@ptfH; zT0i6v(?T7!HV+MKu(Hq9*5G?Y-qHK}i2l~9dab>kRHTsug0nHXkY_D<8(WUO$b~WM z?Dv2h?V3z}(Bpl7z$4eKyyq&PdEqnA@?nn8(L7{rh^^06y!T|!eCWfTTurWPV|A(N zv$VLydM#BNYw|rsXHq+7#{8Fd#OF^tlg8@o9BlU|xvyyV8OgOno zr$yV`_wh5dooC^5K8|6G3+ux;HbYykb%yr)UUl8=s_Qv=gul|hGI^)_UY+Ru8gcc` zpVuWk_wah!^QPZ={+Lf{?qhwI;pgSlBU-))M|~cKJ)k2OB72Z$9K*4`x;u8|ELwZA z2ED?5F^>8?40}LFE=2Yq&p3v>Ut;sDoe}L^$XSmZk$i~Z+!)5xpWk>a-6!^#cWl(# zKIDMpV;pi;lc%+{@LT8EH>O1n$hffq=i?Be`L0r2E3*8S{!Zl4QcW%^(jG};APqSY z97}KMGo4Nv&akb zw45&eTK4FV7rwUzMW4%Jk#Dv*S=P7k7u7~1XgT=alJ3rHc>U(|9eP%uE3o?_M&2Uz zqWNCifnSvB%9o& NYrMf{OhgX8$Uly9>m2|9 diff --git a/romfs/dataflash.lua b/romfs/dataflash.lua deleted file mode 100644 index 2d56eefc..00000000 --- a/romfs/dataflash.lua +++ /dev/null @@ -1,34 +0,0 @@ --- eLua test - -local cspin, id - -if pd.board() == "ATEVK1101" then - cspin = pio.PA_16 - id = 0 -elseif pd.board() == "ATEVK1100" then - cspin = pio.PA_14 - id = 4 -else - print( "\nError: Unknown board " .. pd.board() .. " !" ) - return -end - -function select() - pio.pin.setlow( cspin ) -end - -function unselect() - pio.pin.sethigh( cspin ) -end - - -pio.pin.setdir( pio.OUTPUT, cspin ) -spi.setup( id, spi.MASTER, 1000000, 0, 0, 8 ) - -print( "" ) - -select() -spi.write( id, 0x9F ) -print( "JEDEC Manufacturer ID : ", spi.readwrite( id, 0 )[1] ) -unselect() - diff --git a/romfs/dualpwm.lua b/romfs/dualpwm.lua deleted file mode 100644 index 612fc353..00000000 --- a/romfs/dualpwm.lua +++ /dev/null @@ -1,39 +0,0 @@ --- Control LED intensity with PWM on two channels - -local pwmid1, pwmid2, tmrid - -if pd.board() == 'MOD711' or pd.board() == 'ET-STM32' then - pwmid1, pwmid2, tmrid = 0, 1, 3 -elseif pd.board() == 'MBED' then - pwmid1, pwmid2, tmrid = 1, 2, 0 - mbed.pio.configpin(mbed.pio.LED1, 2, 0, 0) - mbed.pio.configpin(mbed.pio.LED2, 2, 0, 0) -else - print( pd.board() .. " not supported by this example" ) - return -end - -print "Control LED with PWM (fade up/down)" -print "Press any key to exit" -local crtduty, incr = 10, 5 -tmr.start( tmrid ) - -pwm.setup( pwmid1, 50000, crtduty ) -pwm.setup( pwmid2, 50000, 100 - crtduty ) - -pwm.start( pwmid1 ) -pwm.start( pwmid2 ) - -while uart.getchar( 1, 0 ) == "" do - if crtduty == 95 or crtduty == 5 then - incr = -incr - end - crtduty = crtduty + incr - pwm.setup( pwmid1, 50000, crtduty ) - pwm.setup( pwmid2, 50000, 100 - crtduty ) - tmr.delay( tmrid, 50000 ) -end - -pwm.stop( pwmid1 ) -pwm.stop( pwmid2 ) - diff --git a/romfs/hangman.lua b/romfs/hangman.lua deleted file mode 100644 index 02cd0747..00000000 --- a/romfs/hangman.lua +++ /dev/null @@ -1,136 +0,0 @@ --- Hangman in eLua using the 'term' module --- Inspired by the original 'hangman' from the bsdgames package - --- we need a random function --- using math.random for now, which implies target=lua, not lualong -if not math then - print "\nError: Hangman needs the math module (disabled when target=lualong) !" - return -end - -local h, w = term.getlines(), term.getcols() -local tries = 0 - --- "Database" with our words -local words = { "simple", "hangman", "guess", "elua", "inane", "serial", - "stupenduous", "software" } - --- Build our hanging site :) -function hang() - if tries == 0 then - -- Build the basic structure - term.print( 5, 1, string.rep( '_', 6 ) ) - term.print( 5, 2, '| |') - for i = 3, 6 do - term.print( 5, i, '|' ) - end - term.print( 3, 7, '__|_____') - term.print( 3, 8, '| |___') - term.print( 3, 9, '|__________|') - - elseif tries == 1 then - -- Draw the head - term.print( 10, 3, "O" ) - - elseif tries == 2 or tries == 3 then - -- First or second part of body - term.print( 10, tries + 2, "|" ) - - elseif tries == 4 or tries == 5 then - -- First leg / first hand - term.print( 9, tries == 4 and 6 or 4, "/" ) - - elseif tries == 6 or tries == 7 then - -- Second hand / second leg - term.print( 11, tries == 7 and 6 or 4, "\\" ) - end -end - -local total, guessed = 0, 0 - --- Show the game statistics -function stats() - term.print( w - 20, 5, "Total words: ", tostring( total ) ) - term.print( w - 20, 6, "Guessed words: ", tostring( guessed ) ) -end - -while true do - term.clrscr() - term.print( 3, 12, "eLua hangman" ) - term.print( 3, 13, "ESC to exit" ) - stats() - - -- Draw the hanging site - tries = 0 - hang() - - -- Then write the "Guess" line - term.print( 2, h - 3, "Word: " ) - local lword = words[ math.random( #words ) ]:lower() - term.print( string.rep( "-", #lword ) ) - term.print( 2, h - 2, "Guess: " ) - - local nguess = 0 - local tried = {} - local key - while tries < 7 and nguess < #lword do - key = term.getchar() - if key == term.KC_ESC then break end - if key > 0 and key < 255 then - key = string.char( key ):lower() - term.moveto( 2, h - 1 ) - term.clreol() - if not key:find( '%l' ) then - term.print( "Invalid character" ) - else - key = key:byte() - if tried[ key ] ~= nil then - term.print( "Already tried this key" ) - else - tried[ key ] = true - local i - local ok = false - for i = 1, #lword do - if key == lword:byte( i ) then - ok = true - term.print( 7 + i, h - 3, string.char( key ) ) - nguess = nguess + 1 - end - end - if not ok then - tries = tries + 1 - hang() - end - end - end - term.moveto( 9, h - 2 ) - end - end - if key == term.KC_ESC then break end - - term.moveto( 2, h - 1 ) - total = total + 1 - if nguess == #lword then - term.print( "Congratulations! Another game? (y/n)" ) - guessed = guessed + 1 - else - term.print( 8, h - 3, lword ) - term.print( 2, h - 1, "Game over. Another game? (y/n)" ) - end - - -- Show statistics again - stats() - - repeat - key = string.char( term.getchar() ):lower() - until key == 'y' or key == 'n' - - if key == 'n' then - break - end - -end - -term.clrscr() -term.moveto( 1 , 1 ) - diff --git a/romfs/hello.lua b/romfs/hello.lua deleted file mode 100644 index 7df869a1..00000000 --- a/romfs/hello.lua +++ /dev/null @@ -1 +0,0 @@ -print("Hello, World!") diff --git a/romfs/index.pht b/romfs/index.pht deleted file mode 100644 index 7dbd656e..00000000 --- a/romfs/index.pht +++ /dev/null @@ -1,50 +0,0 @@ - -eLua webserver test - -

Welcome to the eLua web server!

-
-
The right column of the following table is generated by embedded Lua code:
-
- - - - - - - - - - - -
eLua CPU
eLua board
-
-And now let's test CGI. Use the form below to control the on-board LED.

-
- - - - - - - -
-
-The LED is now ON
' - elseif reqdata['ledoff'] then - pio.pin.setlow( pio.PF_0 ) - print '
The LED is now OFF
' - elseif next(reqdata) ~= nil then - print '
Invalid CGI request!
' - end -?> -
- -Press here to go to a test page generated completely by a Lua script.
-
-AND MOST IMPORTANTLY... remember to have fun with eLua! :)
-
- diff --git a/romfs/info.lua b/romfs/info.lua deleted file mode 100644 index 95b595a7..00000000 --- a/romfs/info.lua +++ /dev/null @@ -1,3 +0,0 @@ -print( "I'm running on platform " .. pd.platform() ) -print( "The CPU is a " .. pd.cpu() ) -print( "The board name is " .. pd.board() ) diff --git a/romfs/inttest.lua b/romfs/inttest.lua deleted file mode 100644 index 5ffacdf5..00000000 --- a/romfs/inttest.lua +++ /dev/null @@ -1,45 +0,0 @@ -local vtmrid = tmr.VIRT0 -local to = 1500000 -local uartid = 0 -local new_prev_tmr, prev_tmr, prev_gpio - -local function tmr_handler( resnum ) - print( string.format( "Timer interrupt for timer %d", resnum ) ) - if prev_tmr then prev_tmr( resnum ) end -end - -local function new_tmr_handler( resnum ) - print( string.format( "NEW HANDLER: timer interrupt for timer %d", resnum ) ) - if new_prev_tmr then new_prev_tmr( resnum ) end -end - -local function gpio_negedge_handler( resnum ) - local port, pin = pio.decode( resnum ) - print( string.format( "Port is %d, pin is %d", port, pin ) ) - if prev_gpio then prev_gpio( resnum ) end -end - -prev_tmr = cpu.set_int_handler( cpu.INT_TMR_MATCH, tmr_handler ) -prev_gpio = cpu.set_int_handler( cpu.INT_GPIO_NEGEDGE, gpio_negedge_handler ) -tmr.set_match_int( vtmrid, to, tmr.INT_CYCLIC ) -cpu.sei( cpu.INT_GPIO_NEGEDGE, pio.P0_0 ) -cpu.sei( cpu.INT_TMR_MATCH, vtmrid ) - -local tmrid, count = 0, 0 -while true do - print "Outside interrupt" - for i = 1, 1000 do tmr.delay( tmrid, 1000 ) end - if uart.getchar( uartid, 0 ) ~= "" then break end - count = count + 1 - if count == 5 then - print "Changing timer interrupt handler" - new_prev_tmr = cpu.set_int_handler( cpu.INT_TMR_MATCH, new_tmr_handler ) - end -end - -tmr.set_match_int( vtmrid, 0, tmr.INT_CYCLIC ); -cpu.cli( cpu.INT_GPIO_NEGEDGE, pio.P0_0 ) -cpu.cli( cpu.INT_TMR_MATCH, vtmrid ) -cpu.set_int_handler( cpu.INT_TMR_MATCH, nil ); -cpu.set_int_handler( cpu.INT_GPIO_NEGEDGE, nil ); - diff --git a/romfs/led.lua b/romfs/led.lua deleted file mode 100644 index f0d25367..00000000 --- a/romfs/led.lua +++ /dev/null @@ -1,64 +0,0 @@ --- eLua test - -local uartid, invert, ledpin = 0, false -if pd.board() == "SAM7-EX256" then - ledpin = pio.PB_20 -elseif pd.board() == "EK-LM3S1968" then - ledpin = pio.PG_2 -elseif pd.board() == "EK-LM3S8962" or pd.board() == "EK-LM3S6965" then - ledpin = pio.PF_0 -elseif pd.board() == "EAGLE-100" then - ledpin = pio.PE_1 -elseif pd.board() == "STR9-COMSTICK" then - ledpin = pio.P9_0 -elseif pd.board() == "LPC-H2888" then - ledpin = pio.P2_1 -elseif pd.board() == "MOD711" then - ledpin = pio.P1_7 - uartid = 1 -elseif pd.board() == "ATEVK1100" then - ledpin = pio.PB_27 - invert = true -elseif pd.board() == "ATEVK1101" then - ledpin = pio.PA_8 - invert = true - uartid = 1 -elseif pd.board() == "MIZAR32" then - ledpin = pio.PB_29 - invert = true -elseif pd.board() == "STR-E912" then - ledpin = pio.P6_4 -elseif pd.board() == "ELUA-PUC" then - ledpin = pio.P1_20 -elseif pd.board() == "MBED" then - ledpin = mbed.pio.LED1 - mbed.pio.configpin( ledpin, 0, 0, 0 ) -else - print( "\nError: Unknown board " .. pd.board() .. " !" ) - return -end - -function cycle() - if not invert then - pio.pin.sethigh( ledpin ) - else - pio.pin.setlow( ledpin ) - end - tmr.delay( 0, 500000 ) - if not invert then - pio.pin.setlow( ledpin ) - else - pio.pin.sethigh( ledpin ) - end - tmr.delay( 0, 500000 ) -end - -pio.pin.setdir( pio.OUTPUT, ledpin ) -print( "Hello from eLua on " .. pd.board() ) -print "Watch your LED blinking :)" -print "Press any key to end this demo.\n" - -while uart.getchar( uartid, 0 ) == "" do - cycle() -end - diff --git a/romfs/lhttpd.lua b/romfs/lhttpd.lua deleted file mode 100644 index 9cfa824e..00000000 --- a/romfs/lhttpd.lua +++ /dev/null @@ -1,122 +0,0 @@ --- Check platform -if pd.board() ~= 'EK-LM3S8962' and pd.board() ~= 'EK-LM3S6965' and pd.board() ~= 'EAGLE-100' and pd.board() ~= 'EK-LM3S9B92' then - print( pd.board() .. " not supported by this example" ) - return -end - --- Mapping between file extension (and request) and HTTP response -local extmap = { - txt = "text/plain", - htm = "text/html", - pht = "text/html", - gif = "image/gif", - jpg = "imge/jpeg", - png = "image/png", - lua = "text/html" -} - -local basedir = "/rom/" -reqdata = {} - --- Auxiliary function: execute the given code with a substituted "print" --- that prints everything to a string, return the code output -local function docode(thecode) - local strbuf = {} - local oldprint, newprint = print, function(...) - local total, idx = select('#', ...) - for idx = 1, total do - strbuf[#strbuf + 1] = tostring(select(idx, ...)) .. (idx == total and '\n' or '\t') - end - end - print = newprint - local f = loadstring(thecode) - if f then - f() - else - print ">>> Invalid Lua code <<<" - end - print = oldprint - collectgarbage('collect') - return table.concat(strbuf) -end - -function process(header) - -- look for first line - local s, e = header:find("[^\n]+\n") - local reqstr = header:sub(s, e) - local respheader, respdata = '', '' - - reqdata = {} - -- check if the request is valid, also keep the actual request - local i, valid, req = 0, false - for w in reqstr:gmatch("%S+") do - valid = ( i == 0 and w == "GET" ) or valid - req = ( i == 1 and w ) or req - i = i + 1 - end - - -- valid is true if the request is valid, req has the request string - if valid then - -- now look for all parameters in this request (if any) - local fname = "" - if req:find("%?") then - local rest - _, _, fname, rest = req:find("(.*)%?(.*)") - -- small trick: end "rest" with a "&" for easier processing - -- now look for "var=value" pairs in the request (GET encoding) - rest = rest .. "&" - for crtpair in rest:gmatch("[^&]+") do - local _, __, k, v = crtpair:find("(.*)=(.*)") - -- replace all "%xx" characters with their actual value - v = v:gsub("(%%%x%x)", function(s) return string.char(tonumber(s:sub(2, -1), 16)) end) - reqdata[k] = v - end - else - fname = req - end - fname = ( fname == "/" ) and "index.pht" or fname:sub(2, -1) - s, e = fname:find("%.[%a%d]+$") - local ftype = fname:sub(s+1, e):lower() - ftype = (#ftype > 0 and ftype) or "txt" - fname = basedir .. fname - - -- now "fname" has the name of the requested file, and "reqdata" the actual request data - -- also "ftype" holds the file type (actually its extension) - local tf = io.open(fname, "r") - if tf then - respheader = "HTTP/1.1 200 OK\r\nConnection: close\r\nServer: eLua-miniweb\r\nContent-Type: " .. extmap[ftype or "txt"] .. "\r\n\r\n" - -- Preprocess "lua" and "pht" files: run the Lua ones, parse the .htm ones for "" sequences - if ftype == "pht" or ftype == "lua" then - local fdata = tf:read("*a") - if ftype == "lua" then - respdata = docode(fdata) - else - -- Look for patterns and execute them accordingly - respdata = fdata:gsub("<%?lua(.-)%?>", docode) - end - else - respdata = tf:read("*a") - end - tf:close() - else - respheader = "HTTP/1.1 404 Not Found\r\nConnection: close\r\nServer: eLua-miniweb\r\nContent-Type: text/html\r\n\r\nPage not found" - end - end - return respheader .. respdata -end - -while true do - local sock, remoteip, err = net.accept( 80 ) - print( "Got connection on socket", sock ) - print( "Remote ip: " .. net.unpackip( remoteip, "*s" ) ) - local response, err2 = net.recv( sock, 1024 ) - print "Got request" - local httpdata = process( response ) - if #httpdata > 0 then - print "Sending response" - net.send( sock, httpdata ) - end - net.close( sock ) - reqdata = {} - collectgarbage('collect') -end diff --git a/romfs/life.lua b/romfs/life.lua deleted file mode 100644 index 7c88f302..00000000 --- a/romfs/life.lua +++ /dev/null @@ -1,108 +0,0 @@ --- life.lua --- original by Dave Bollinger posted to lua-l --- modified to use ANSI terminal escape sequences --- modified to use for instead of while - -local write=io.write - -ALIVE="O" DEAD="-" - -function delay() -- NOTE: SYSTEM-DEPENDENT, adjust as necessary -end - -function ARRAY2D(w,h) - local t = {w=w,h=h} - for y=1,h do - t[y] = {} - for x=1,w do - t[y][x]=0 - end - end - return t -end - -_CELLS = {} - --- give birth to a "shape" within the cell array -function _CELLS:spawn(shape,left,top) - for y=0,shape.h-1 do - for x=0,shape.w-1 do - self[top+y][left+x] = shape[y*shape.w+x+1] - end - end -end - --- run the CA and produce the next generation -function _CELLS:evolve(next) - local ym1,y,yp1,yi=self.h-1,self.h,1,self.h - while yi > 0 do - local xm1,x,xp1,xi=self.w-1,self.w,1,self.w - while xi > 0 do - local sum = self[ym1][xm1] + self[ym1][x] + self[ym1][xp1] + - self[y][xm1] + self[y][xp1] + - self[yp1][xm1] + self[yp1][x] + self[yp1][xp1] - next[y][x] = ((sum==2) and self[y][x]) or ((sum==3) and 1) or 0 - xm1,x,xp1,xi = x,xp1,xp1+1,xi-1 - end - ym1,y,yp1,yi = y,yp1,yp1+1,yi-1 - end -end - --- output the array to screen -function _CELLS:draw() - local out="" -- accumulate to reduce flicker - for y=1,self.h do - for x=1,self.w do - out=out..(((self[y][x]>0) and ALIVE) or DEAD) - end - out=out.."\n" - end - write(out) -end - --- constructor -function CELLS(w,h) - local c = ARRAY2D(w,h) - c.spawn = _CELLS.spawn - c.evolve = _CELLS.evolve - c.draw = _CELLS.draw - return c -end - --- --- shapes suitable for use with spawn() above --- -HEART = { 1,0,1,1,0,1,1,1,1; w=3,h=3 } -GLIDER = { 0,0,1,1,0,1,0,1,1; w=3,h=3 } -EXPLODE = { 0,1,0,1,1,1,1,0,1,0,1,0; w=3,h=4 } -FISH = { 0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,0,0,1,0; w=5,h=4 } -BUTTERFLY = { 1,0,0,0,1,0,1,1,1,0,1,0,0,0,1,1,0,1,0,1,1,0,0,0,1; w=5,h=5 } - --- the main routine -function LIFE(w,h) - -- create two arrays - local thisgen = CELLS(w,h) - local nextgen = CELLS(w,h) - - -- create some life - -- about 1000 generations of fun, then a glider steady-state - thisgen:spawn(GLIDER,5,4) - thisgen:spawn(EXPLODE,25,10) - thisgen:spawn(FISH,4,12) - - -- run until break - local gen=1 - write("\027[2J") -- ANSI clear screen - while 1 do - thisgen:evolve(nextgen) - thisgen,nextgen = nextgen,thisgen - write("\027[H") -- ANSI home cursor - thisgen:draw() - write("Life - generation ",gen,", mem ", string.format("%3.1f",collectgarbage('count')), " kB\n") - gen=gen+1 - if gen>2000 then break end - --delay() -- no delay - end -end - -LIFE(32,16) diff --git a/romfs/logo.bin b/romfs/logo.bin deleted file mode 100644 index fa39226fd6b462c8ffa905ff1c5e162863620c6c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2048 zcmcgt%}*0S6o0b?xlUW4;%U1zf<#IAIB?)V1r*~2ln*Z^knmxm9w@3IEjN8hr@QleAHVs{n;n3EXTh+{ z&2(l!P}eG1ga@Kp6-4kEs(4<)ijqTNl=&gRSr`J~*XfUIIv7wc#5Cc48a(Wh5I=D` z7Yubm`~YAv^wD&KRrczK`#sG&6#r*bEQ$|p_oRNLKUxjWZ_&1ANO>hD&FF?;7=z!ZC7r@!R>wQ&DA zCw|zDM`8)WNk7bg7xTAH&dd?MSs{kA7eB3;!W!c8Yyhi4{oUf>HFkIDI}yL|=JKIFsGro= z7AK7KMSf_9`*YkOt=J*l<`udx%*r77o0bbS5|Ks!|5-%KW>kG z)!#_s)boKol=FNMKh5)eVmaI&#g8>6-PI9qaQFe3UU*u{L-O`{>WBSH3TvLn;uVDsJ?XM0njxbW;p0frx%1F uLIe8bG6nfhhv|O9i;XiK@WjzI=O= -xf ) and ( xx1 <= xf ) and ( yy1 >= -yf ) and ( yy1 <= yf ) then - newdata[ w1 ] = imgdata[ floor( yy1 ) * maxx + floor( xx1 ) + ct ] - end - if ( xx2 >= -xf ) and ( xx2 <= xf ) and ( yy2 >= -yf ) and ( yy2 <= yf ) then - newdata[ w2 ] = imgdata[ floor( yy2 ) * maxx + floor( xx2 ) + ct ] - end - if ( -xx2 >= -xf ) and ( -xx2 <= xf ) and ( -yy2 >= -yf ) and ( -yy2 <= yf ) then - newdata[ w3 ] = imgdata[ floor( -yy2 ) * maxx + floor( -xx2 ) + ct ] - end - if ( -xx1 >= -xf ) and ( -xx1 <= xf ) and ( -yy1 >= -yf ) and ( -yy1 <= yf ) then - newdata[ w4 ] = imgdata[ floor( -yy1 ) * maxx + floor( -xx1 ) + ct ] - end - xx1 = xx1 + c ; yy1 = yy1 + s ; xx2 = xx2 - c ; yy2 = yy2 - s - w1 = w1 + 1 ; w2 = w2 - 1 ; w3 = w3 + 1 ; w4 = w4 - 1 - end - p1 = p1 - s ; p2 = p2 + c ; p3 = p3 - s ; p4 = p4 + c - widx1 = widx1 + maxx ; widx2 = widx2 + maxx ; widx3 = widx3 - maxx ; widx4 = widx4 - maxx - end - return bitarray.tostring( newdata, "raw" ) -end - -local origx = ( 128 - maxx ) / 2 -local origy = ( 96 - maxy ) / 2 -disp.draw( imgdata, origx, origy, maxx, maxy ) -local imgd = bitarray.new( imgdata, 4 ) -imgdata = nil -collectgarbage() - -local delta = pi / 8 -local angles = { 0, delta, pi / 4, 3 * delta, pi / 2, 5 * delta, 3 * pi / 4, 7 * delta, pi, - 9 * delta, 5 * pi / 4, 11 * delta, 3 * pi / 2, 13 * delta, 7 * pi / 4, 15 * delta } -local index = 2 - -while uart.getchar( 0, uart.NO_TIMEOUT ) == "" do - local newimg = rotate( imgd, angles[ index ] ) - disp.draw( newimg, origx, origy, maxx, maxy ) - newimg = nil - collectgarbage() - index = index + 1 - index = index > #angles and 1 or index -end - -disp.clear() - diff --git a/romfs/morse.lua b/romfs/morse.lua deleted file mode 100644 index 35077c28..00000000 --- a/romfs/morse.lua +++ /dev/null @@ -1,136 +0,0 @@ -------------------------------------------------------------------------------- --- eLua Morse Demo --- --- Dado Sutter sep 2008 -------------------------------------------------------------------------------- - -local pwmid, tmrid, ledpin -if pd.board() == "EK-LM3S1968" then - pwmid, tmrid, ledpin = 2, 1, pio.PG_2 -elseif pd.board() == "EK-LM3S8962" or pd.board() == "EK-LM3S6965" then - pwmid, tmrid, ledpin = 1, 1, pio.PF_0 -elseif pd.board() == "EAGLE-100" then - wmid, tmrid, ledpin = 1, 1, pio.PE_1 -elseif pd.board() == "SAM7-EX256" then - pwmid, tmrid, ledpin = 0, 1, pio.PB_20 - tmr.setclock( 1, 100000 ) -else - print( pd.board() .. " not supported with this example" ) - return -end - ------------- User Adjusted Variables ------------ - -local dotDelay, playFreq, playFreqSave = 90000, 880, 880 -local freqStep, dotDelayStep = 220, 10000 - --- Morse Alphabet -local Morse = { - A='.-', - B='-...', - C='-.-.', - D='-..', - E='.', - F='..-.', - G='--.', - H='....', - I='..', - J='.---', - K='-.-', - L='.-..', - M='--', - N='-.', - O='---', - P='.--.', - Q='--.-', - R='.-.', - S='...', - T='-', - U='..-', - V='...-', - W='.--', - X='-..-', - Y='-.--', - Z='--..' -} - ------------- Auxiliar Functions ------------ - -local function play(m) - term.print(m) - if m == ' ' then - tmr.delay(tmrid, 2 * dotDelay) - else - pio.pin.sethigh( ledpin ) - pwm.start(pwmid) - tmr.delay(tmrid, m == '.' and dotDelay or 3 * dotDelay) - pwm.stop(pwmid) - pio.pin.setlow( ledpin ) - tmr.delay(tmrid, dotDelay) - end -end - -local function HandleKbd(k) - if k == term.KC_ESC then - return true - elseif k == term.KC_UP then -- Speed up - dotDelay = dotDelay + dotDelayStep - elseif k == term.KC_DOWN then -- Speed down - dotDelay = dotDelay - dotDelayStep - elseif k > 0 and k < 256 then - if string.char(k) == '+' then -- Frequency up - playFreq = playFreq + freqStep - elseif string.char(k) == '-' then -- Frequency down - playFreq = playFreq - freqStep - elseif string.char(k) == 's' then -- Sound on/off - if playFreq == 0 then - playFreq = playFreqSave - else - playFreqSave = playFreq - playFreq = 0 - end - end - end - pwm.setup(pwmid, playFreq, 50) -end - ------------- Main Program ------------ -pio.pin.setdir( pio.OUTPUT, ledpin ) -pwm.setup( pwmid, playFreq, 50 ) - -while true do - term.clrscr() - term.moveto(1, 1) - print("Welcome to eLua Morse Playing on " .. pd.board()) - io.write("Enter phrase (empty phrase to exit): ") - local msg, enabled = io.read(), true - if #msg == 0 then break end - - term.print(' ') - while term.getchar(term.NOWAIT) ~= -1 do end -- flush - - while enabled do -- Main Loop - for i = 1, #msg do -- msg loop - local ch = msg:sub(i, i):upper() - term.print(ch) -- show what will be played - if ch ~= ' ' and Morse[ch] then - for j = 1, #Morse[ch] do -- Morse symbol loop - play(Morse[ch]:sub(j,j)) -- play each morse symbol - end - else - play(' ') play(' ') -- Between words - end - play(' ') -- Extra between words & lett - key = term.getchar(term.NOWAIT) -- Handle UI actions - if key ~= -1 then - if HandleKbd(key) then - enabled = false - break - end - end - end - if not enabled then break end - print() - play(' ') play(' ') play(' ') -- Between sentences - end -end diff --git a/romfs/piano.lua b/romfs/piano.lua deleted file mode 100644 index d253b9c5..00000000 --- a/romfs/piano.lua +++ /dev/null @@ -1,108 +0,0 @@ --- "Piano" in eLua, showing yet another use for the PWM module :) - -local pwmid, tmrid - -if not math then - print "This example required floating point Lua (integer Lua not supported)" - return -end - -if pd.board() == "EK-LM3S8962" or pd.board() == "EK-LM3S6965" or pd.board() == "EAGLE-100" then - pwmid, tmrid = 1, 1 -elseif pd.board() == "EK-LM3S1968" then - pwmid, tmrid = 2, 1 -elseif pd.board() == "SAM7-EX256" then - pwmid, tmrid = 0, 1 - tmr.setclock( 1, 1000000 ) -elseif pd.board() == "STR-E912" then - local g = str9.pio - g.setpin( pio.P4_6, g.OUTPUT, g.OUTPUT_PUSHPULL, false, g.ALT_OUTPUT2 ) - pwmid, tmrid = 3, 1 -else - print( pd.board() .. " not supported with this example" ) - return -end - -local oct, pause = 4, 0 - --- Mapping between keys and note offsets -local offsets = { a = 0, w = 1, s = 2, d = 3, r = 4, f = 5, t = 6, g = 7, h = 8, - u = 9, j = 10, i = 11, k = 12, o = 13, l = 14, [";"] = 15, ["["] = 16, ["'"] = 17, - ["]"] = 18, ["\\"] = 19 } - --- Write the curent octave -function show_octave() - term.print( 2, 4, "Oct: " .. tostring( oct ) .. "(+/-)" ) - term.moveto( 2, 19 ) -end - --- Write the current pause between notes -function show_pause() - term.moveto( 2, 5 ) - term.clreol() - term.print( 2, 5, "Pause between notes: " .. tostring( pause ) .. "ms ()" ) - term.moveto( 2, 19 ) -end - --- Show the main interface -function show_all() - term.print( 2, 2, "eLua piano demo" ) - show_octave() - show_pause() - term.print( 4, 7, " w r t u i o [ ] " ) - term.print( 4, 8, " | | | | | | | | " ) - term.print( 4, 9, " A# C# D# F# G# A# C# D# " ) - term.print( 4, 10, "A BC D EF G A BC D E" ) - term.print( 4, 11, "| || | || | | || | |" ) - term.print( 4, 12, "a sd f gh j k l; ' \\" ) - term.print( 2, 14, "Use above keys to play notes." ) - term.print( 2, 15, "+/- to change octave." ) - term.print( 2, 16, " to change pause between notes." ) - term.print( 2, 17, "Space to stop playing." ) - term.print( 2, 18, "ESC to exit." ) - term.moveto( 2, 19 ) -end - --- Conversion of note to frequency -function note_to_freq( index ) - return 55 * 2 ^ ( ( index + ( oct - 1 ) * 12 ) / 12 ) -end - --- Entry point -term.clrscr() -pwm.setclock( pwmid, 1000000 ) -show_all() -while true do - local key = term.getchar() - if key == term.KC_ESC then break end - local res, strkey = pcall( string.char, key ) - if res then - if offsets[ strkey ] ~= nil then - local freq = note_to_freq( offsets[ strkey ] ) - pwm.stop( pwmid ) - if pause > 0 then - tmr.delay( tmrid, pause * 1000 ) - end - pwm.setup( pwmid, freq, 50 ) - pwm.start( pwmid ) - elseif strkey == ">" then - pause = pause < 1000 and pause + 10 or pause - show_pause() - elseif strkey == "<" then - pause = pause > 0 and pause - 10 or pause - show_pause() - elseif strkey == "+" then - oct = oct < 7 and oct + 1 or oct - show_octave() - elseif strkey == "-" then - oct = oct > 1 and oct - 1 or oct - show_octave() - elseif strkey == " " then - pwm.stop( pwmid ) - end - end -end - -pwm.stop( pwmid ) -term.clrscr() -term.moveto( 1, 1 ) diff --git a/romfs/pong.lua b/romfs/pong.lua deleted file mode 100644 index b51270e8..00000000 --- a/romfs/pong.lua +++ /dev/null @@ -1,339 +0,0 @@ -------------------------------------------------------------------------------- --- --- eLua Pong Game --- --- LED Lab @ PUC-Rio - 2009 --- Dado Sutter --- Ives Negreiros --- Ricardo Rosa --- Pedro Bittencourt --- Teo Benjamin --- - --- Initial Version by Dado Sutter, Fev 2009 --- This had only the ball bouncing on walls, paddle and paddle movement --- --- Greatly enhanced by Teo Benjamin in Aug/Sep 2009, adding: --- Score, resizeable paddles, levels/speeds, items --- --- -------------------------------------------------------------------------------- - -local canvas = {} --- canvas.x -- Horizontal display size --- canvas.y -- Vertical display size - -local paddle = {} --- paddle.size -- Actual Paddle size = ( 6 * ( paddle.size + 1 ) ) + 2 --- paddle.max_size -- Max paddle.size value -> Constant --- paddle.min_size -- Min paddle.size value -> Constant --- paddle.y -- Paddle's Y position ( X position not needed, always 0 ) - -local ball = {} --- ball.x -- Ball's X position --- ball.y -- Ball's Y position -> starts at a random position --- ball.dx -- Ball's X movement ( 1 = moving right; -1 = moving left ) --- ball.dy -- Ball's Y movement ( 1 = moving down; -1 = moving up ) --- ball.char -- The char that is printed for the ball -> Constant - -local item = {} --- item.x -- Item's X position --- item.y -- Item's Y position ( fix for each item ) --- item.char -- This is the char that represents the item ( if false, there is no item ) --- item.all_chars -- A table that contains all the possibles item chars. Initialized by upload_items() function - --- Define all constants -local tmr_id = 1 -paddle.max_size = 4 -paddle.min_size = 0 -ball.char = "*" -local delay_incr = 2000 - - --- Define all "global" variables as program local ones. --- The values are initialized at the main loop. - -local score -- Player's score -local dscore -- How many points for each paddle hit -local delay_time -- This value is used for the main delay, to make the game speed faster or slower -local paddle_hits -- Counts the number of hits on paddle -local highscore -- Current Highscore - -item.all_chars = {} -local pressed = {} -- pressed[ button ] is true if the corresponding button was pressed, or nil if not - -local kit = require( pd.board() ) -- This variable is used as a pin assignments for the specific board - -local itemFunction = { -["L"] = function () - draw_paddle( paddle.y, 0, 0 ) - if paddle.size < paddle.max_size then - paddle.size = paddle.size + 1 - end - draw_paddle( paddle.y, 11, 0 ) - end, -["S"] = function () - draw_paddle( paddle.y, 0, 0 ) - if paddle.size > paddle.min_size then - paddle.size = paddle.size - 1 - end - draw_paddle( paddle.y, 11, 0 ) - end, - -["?"] = function () - item.char = item.all_chars[ math.random( #item.all_chars ) ] - use_item() - end, - -["*"] = function () - end, - -["P"] = function () - score = score + dscore - end, - -["D"] = function () - score = score * 2 - end, - -["Z"] = function () - lm3s.disp.print( tostring( score ), 111, 89, 0 ) - score = 0 - end, - -["T"] = function () - lm3s.disp.print( ball.char, ball.x, ball.y, 0 ) - ball.y = math.random( 82 ) - lm3s.disp.print( ball.char, ball.x, ball.y, 15 ) - end, -["F"] = function() - if delay_time >= 1000 then - delay_time = delay_time - 1000 - end - end, -} - --- Updates Y paddle position and draw it using the draw_paddle( ... ) function -function update_paddle_pos() - if kit.btn_pressed( kit.BTN_UP ) then - if ( paddle.y > 0 ) then - paddle.y = paddle.y - 1 - draw_paddle( paddle.y, 11, -1 ) - else - tmr.delay( 1, 1700 ) - end - elseif kit.btn_pressed( kit.BTN_DOWN ) then - if ( paddle.y + ( paddle.size*6 ) + 1 < 90 ) then - paddle.y = paddle.y + 1 - draw_paddle( paddle.y, 11, 1 ) - else - tmr.delay( 1, 1600 ) - end - else - draw_paddle( paddle.y, 11, 0 ) - tmr.delay( 1, 300 ) -- Maintain function processing time aprox the same - end -end - --- Draw the paddle in the display. This function is used by update_paddle_pos() function -function draw_paddle( y, color, movement ) - if ( movement == 0 ) then - for i = 0, paddle.size, 1 do - lm3s.disp.print( "|", 0, y + ( i * 6 ), color ) - end - elseif ( movement > 0 ) then -- Paddle moving Down - if y < 8 then - lm3s.disp.print( "|", 0, 0, 0 ) - else - lm3s.disp.print( "|", 0, y - 8 , 0 ) - end - for i = 0, paddle.size, 1 do - lm3s.disp.print( "|", 0, y + ( i * 6 ), color ) - end - elseif ( movement < 0 ) then -- Paddle moving Up - lm3s.disp.print( "|", 0, y + ( ( paddle.size + 1 ) * 6 ) + 2 , 0 ) - for i = 0, paddle.size, 1 do - lm3s.disp.print( "|", 0, y + ( i * 6 ), color ) - end - end -end - --- Updates the ( X, Y ) ball position and prints the corresponding char -function update_ball_pos() - if( ( ball.x + 5 >= canvas.x ) or ( ball.x <= 4 ) ) then - ball.dx = -ball.dx; - if ball.dx == -1 and item.char == false then - createItem() - end - end - if( ( ball.y >= 90 - ball.dy ) or ( ball.y <= 1 - ball.dy ) ) then - ball.dy = -ball.dy; - end - lm3s.disp.print( ball.char, ball.x, ball.y, 0 ) - ball.x, ball.y = ( ball.x + ball.dx ), ( ball.y + ball.dy ); - lm3s.disp.print( ball.char, ball.x, ball.y, 15 ) -end - - --- Draw the top wall and erase the last one. Used to move it -function draw_wall( x ) - for i = 0, canvas.y, 7 do -- Erase the wall - lm3s.disp.print( "|", canvas.x + 1, i, 0 ) - end - canvas.x = x - for i = 0, canvas.y, 7 do -- Draw a new wall - lm3s.disp.print( "|", canvas.x + 1, i, 6 ) - end -end - --- Item Functions -function createItem() - item.char = item.all_chars[ math.random( #item.all_chars ) ] - item.x = canvas.x - 10 - item.y = ball.y -end - --- Upload the itens from table itemFunction into the table item.all_chars --- Must be used to initialize the items -function upload_items() - for k,v in pairs( itemFunction ) do - table.insert( item.all_chars, k ) - end -end - --- Updates the item X position -function update_item_pos() - if item.char then - if ( item.x <= 4 ) then - if ( ( item.y + 8 < paddle.y ) or ( item.y > paddle.y + ( paddle.size * 6 ) + 8 ) ) == false then - use_item() - end - lm3s.disp.print( item.char, item.x, item.y, 0 ) - item.char = false - return - end - lm3s.disp.print( item.char, item.x, item.y, 0 ) - item.x = item.x - 2 - lm3s.disp.print( item.char, item.x, item.y, 10 ) - end -end - --- Uses the item's function -function use_item() - itemFunction[ item.char ]() -end - --- Checks if a button was clicked ( pressed and released ) --- Returns true or false -function button_clicked( button ) - if kit.btn_pressed( button ) then - pressed[ button ] = true - else - if pressed[ button ] then - pressed[ button ] = nil - return true - end - pressed[ button ] = nil - end - return false -end - ------------- MAIN ------------ -upload_items() -lm3s.disp.init( 1000000 ) - -tmr.start( tmr_id ) ---menu() -math.randomseed( tmr.read( tmr_id ) ) -- If you use the menu function, the time will be used as a seed to the random function ---tmr.stop( tmr_id ) - -collectgarbage( "collect" ) - - - - - ---------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------- --- -- --- GAME START -- --- -- ---------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------- - -repeat - canvas.x = 124 - canvas.y = 97 - ball.x = 5 - ball.y = math.random( ( canvas.y - 8 ) / 2 ) + ( canvas.y / 4 ) - ball.dx = 1 - ball.dy = 1 - paddle.y = ball.y - 4 - item.x = 0 - item.y = 0 - score = 0 - dscore = 1 - item.char = false - paddle.size = 2 - delay_time = 10000 - paddle_hits = 0 - - lm3s.disp.clear() - - draw_wall( canvas.x ) - draw_paddle( paddle.y, 11, 0 ) - - while ( true ) do - for i = 0, 1 do - update_paddle_pos() - end - tmr.delay ( 0, delay_time ) - update_ball_pos() - update_item_pos() - if ( ball.x <= 4 ) then - if ( ( ball.y + 8 < paddle.y ) or ( ball.y > paddle.y + ( paddle.size * 6 ) + 8 ) ) then -- If this is true, you lose - break - else -- Else, you score - score = score + dscore - paddle_hits = paddle_hits + 1 - end - end - - if button_clicked( kit.BTN_RIGHT ) and delay_time > 0 then -- If the right button is clicked, increase the level - delay_time = delay_time - delay_incr - dscore = dscore + 1 - end - if button_clicked( kit.BTN_LEFT ) and dscore > 0 then -- If the left button is clicked, decrease the level - delay_time = delay_time + delay_incr - dscore = dscore - 1 - end - - if ( paddle_hits == 5 ) and canvas.x > 80 then -- After 5 hits in a row, move the wall until canvas.x = 80 - paddle_hits = 0 - draw_wall( canvas.x - 5 ) - end - lm3s.disp.print( tostring( dscore ), 118, 0, 6 ) - lm3s.disp.print( tostring( score ), 111, 89, 6 ) - collectgarbage( "collect" ) - end -------------------------------------------- --- Game Over -------------------------------------------- - if score >= ( highscore or 0 ) then - highscore = score - end - lm3s.disp.clear() - lm3s.disp.print( "Game Over :(", 30, 20, 11 ) - lm3s.disp.print( "Your score was "..tostring( score ), 15, 40, 11 ) - lm3s.disp.print( "Highscore: "..tostring( highscore ), 15, 50, 11 ) - lm3s.disp.print( "SELECT to restart", 6, 70, 11 ) - enough = true - for i=1, 100000 do - if kit.btn_pressed( kit.BTN_SELECT ) then - enough = false - break - end - end -until ( enough ) - -lm3s.disp.off() diff --git a/romfs/pwmled.lua b/romfs/pwmled.lua deleted file mode 100644 index e7163522..00000000 --- a/romfs/pwmled.lua +++ /dev/null @@ -1,35 +0,0 @@ --- Control LED intensity with PWM - -local pwmid, tmrid, ledpin -if pd.board() == 'EK-LM3S1968' or pd.board() == 'EK-LM3S8962' or pd.board() == 'EK-LM3S6965' or pd.board() == 'ET-STM32' or pd.board() == 'EAGLE-100' then - pwmid, tmrid = 0, 1 - pwm.setclock( pwmid, 25000000 ) -elseif pd.board() == 'ELUA-PUC' then - pwmid, tmrid = 7, 0 - local psel = cpu.r32( cpu.IO_PINSEL3 ) - psel = bit.bor( bit.band( psel, 0xFFFFFCFF ), 0x00000200 ) - cpu.w32( cpu.IO_PINSEL3, psel ) -elseif pd.board() == 'MBED' then - pwmid, tmrid = 1, 0 - mbed.pio.configpin(mbed.pio.LED1, 2, 0, 0) -else - print( pd.board() .. " not supported by this example" ) - return -end - -print "Control LED with PWM (fade up/down)" -print "Press any key to exit" -local crtduty, incr = 10, 5 -tmr.start( tmrid ) -pwm.setup( pwmid, 50000, crtduty ) -pwm.start( pwmid ) -while uart.getchar( 0, 0 ) == "" do - if crtduty == 95 or crtduty == 5 then - incr = -incr - end - crtduty = crtduty + incr - pwm.setup( pwmid, 50000, crtduty ) - tmr.delay( tmrid, 50000 ) -end - -pwm.stop( pwmid ) diff --git a/romfs/snake.lua b/romfs/snake.lua deleted file mode 100644 index 14636d31..00000000 --- a/romfs/snake.lua +++ /dev/null @@ -1,219 +0,0 @@ ---------------------------------------------------------------- --- Classic snake game --- Still testing! --- --- By Ives Negreiros and Téo Benjamin ---------------------------------------------------------------- - -local xMax = math.floor( 128 / 6 ) - 1 -local yMax = math.floor( 96 / 8 ) - 1 -local game_map = {} - -local Head = {} -local Tail = {} - -local highscore = 0 -local size = 3 -Tail.x = 1 -Tail.y = 1 -Head.x = Tail.x + ( size - 1 ) -Head.y = Tail.y - -local Food = {} -Food.x = false -Food.y = false - -Head.dx = 1 -Head.dy = 0 -Tail.dx = Head.dx -Tail.dy = Head.dy -local direction = "right" -local level = 1 -local score = 0 - -lm3s.disp.init( 1000000 ) - -local kit = require( pd.board() ) -local pressed = {} - -local function create_food() --- if not food then - Food.x, Food.y = math.random( xMax - 1), math.random( yMax - 1) - while game_map[ Food.x ][ Food.y ] do - Food.x, Food.y = math.random( xMax - 1 ), math.random( yMax - 1 ) - end - game_map[ Food.x ][ Food.y ] = "food" - lm3s.disp.print( "@", Food.x * 6, Food.y * 8, 10 ) --- end -end - -local function eat_food() - lm3s.disp.print( "@", Head.x * 6, Head.y * 8, 0 ) - game_map[ Head.x ][ Head.y ] = nil - create_food() - score = score + level -end - -local function check_collision() - if Head.x <= 0 or Head.x >= xMax then - return true - elseif Head.y <= 0 or Head.y >= yMax then - return true - elseif ( ( game_map[ Head.x ][ Head.y ] ) and ( game_map[ Head.x ][ Head.y ] ~= "food" ) ) then - return true - end - return false -end - -local function move() - - if game_map[ Tail.x ][ Tail.y ] == "right" then - Tail.dx = 1 - Tail.dy = 0 - elseif game_map[ Tail.x ][ Tail.y ] == "left" then - Tail.dx = -1 - Tail.dy = 0 - elseif game_map[ Tail.x ][ Tail.y ] == "up" then - Tail.dx = 0 - Tail.dy = -1 - elseif game_map[ Tail.x ][ Tail.y ] == "down" then - Tail.dx = 0 - Tail.dy = 1 - end - game_map[ Head.x ][ Head.y ] = direction - Head.x = Head.x + Head.dx - Head.y = Head.y + Head.dy - - if game_map[ Head.x ][ Head.y ] == "food" then - eat_food() - else - lm3s.disp.print( "*", Tail.x * 6, Tail.y * 8, 0 ) - game_map[ Tail.x ][ Tail.y ] = nil - Tail.x = Tail.x + Tail.dx - Tail.y = Tail.y + Tail.dy - end - - lm3s.disp.print( "*", Head.x * 6, Head.y * 8, 10 ) - -end - - - -local function draw_walls() - for i = 0, xMax*2, 1 do - lm3s.disp.print( "_", i * 3, yMax * 8 - 6, 11 ) - lm3s.disp.print( "_", i * 3, 0, 11 ) - end - for i = 0, yMax*2, 1 do - lm3s.disp.print( "|", xMax * 6, i * 4, 11 ) - lm3s.disp.print( "|", 0, i * 4, 11 ) - end -end - -local function button_clicked( button ) - if kit.btn_pressed( button ) then - pressed[ button ] = true - else - if pressed[ button ] then - pressed[ button ] = nil - return true - end - end - return false -end - - -function init() - food = false - lm3s.disp.clear() - draw_walls() - size = 3 - score = 0 - level = 1 - Tail.x = 1 - Tail.y = 1 - Head.x = Tail.x + ( size - 1 ) - Head.y = Tail.y - Head.dx = 1 - Head.dy = 0 - Tail.dx = Head.dx - Tail.dy = Head.dy - direction = "right" - - for i = 0, xMax, 1 do - game_map[ i ] = {} - end - for i = 0, size - 1, 1 do - game_map[ Tail.x + ( i * Tail.dx ) ][ Tail.y + ( i * Tail.dy ) ] = direction - lm3s.disp.print( "*", ( Tail.x + ( i * Tail.dx ) ) * 6, ( Tail.y + ( i * Tail.dy ) ) * 8, 10 ) - end - create_food() -end - ---init() ---create_food() - -repeat - init() - while true do - local dir = direction - for i = 1, 1000 - ( 100 * level ), 1 do - - if kit.btn_pressed( kit.BTN_RIGHT ) and direction ~= "left" then - dir = "right" - Head.dx = 1 - Head.dy = 0 - end - if kit.btn_pressed( kit.BTN_LEFT ) and direction ~= "right" then - dir = "left" - Head.dx = -1 - Head.dy = 0 - end - if kit.btn_pressed( kit.BTN_UP ) and direction ~= "down" then - dir = "up" - Head.dx = 0 - Head.dy = -1 - end - if kit.btn_pressed( kit.BTN_DOWN ) and direction ~= "up" then - dir = "down" - Head.dx = 0 - Head.dy = 1 - end - if button_clicked( kit.BTN_SELECT ) and level < 10 then - level = level + 1 - end - end - direction = dir - move() - if check_collision() then print"colidiu" break end - --tmr.delay( 0, 400000 ) - --[[ - game_map[ Head.x ][ Head.y ] = nil - if Head.x < xMax then - Head.x = Head.x + 1 - end - game_map[ Head.x ][ Head.y ] = true - ]]-- - collectgarbage( "collect" ) - end - - - if score > highscore then - highscore = score - end - lm3s.disp.clear() -- This statements displays the game over screen - lm3s.disp.print( "Game Over :(", 30, 20, 11 ) - lm3s.disp.print( "Your score was "..tostring( score ), 0, 40, 11 ) - lm3s.disp.print( "Highscore: "..tostring( highscore ), 15, 50, 11 ) - lm3s.disp.print( "SELECT to restart", 6, 70, 11 ) - enough = true -- If the player presses select before the time reach 1000000ms, then restart the game - for i=1, 1000000 do - if kit.btn_pressed( kit.BTN_SELECT ) then - enough = false - break - end - end - lm3s.disp.clear() -until ( enough ) -lm3s.disp.off() - diff --git a/romfs/spaceship.lua b/romfs/spaceship.lua deleted file mode 100644 index 97ff1dfb..00000000 --- a/romfs/spaceship.lua +++ /dev/null @@ -1,274 +0,0 @@ -------------------------------------------------------------------------------- --- --- eLua SpaceShip Game --- --- LED Lab @ PUC-Rio - 2009 --- Dado Sutter --- Ives Negreiros --- Ricardo Rosa --- Pedro Bittencourt --- Teo Benjamin --- --- --- Initial Version by Téo Benjamin, Aug 2009 --- -------------------------------------------------------------------------------- - -local xcanvas = 124 -- Real screen X size -local xcanvas = xcanvas - 12 -- Canvas size with wall -local ycanvas = 96 -- Screen Y size -local pressed = {} -- This table is used to help the buttonClicked function. If the btn if pressed, - -- pressed[ btn ] = true, when it is released, pressed[ btn ] = nil -local ShipChar = ">" -- This is the char that is printed to represent the SpaceShip -local shotChar = "-" -- This char is printed to represent the shots -local enemyChar = "@" -- This char is used to represent the enemies -local sy = 16 -- Ship's Y position -local sx = 0 -- Ship's X position -local bullets = 50 -- Number of bullets left -local score = 0 -- Player's score -local numOfEnemies = 5 -- Number of simultaneous enemies -local won = false -- If the player won the game, this value is true. If not, it's false. --- Initialization -local kit = require( pd.board() ) - - -local canvasMap = {} -- canvasMap[ line ][ #shot ] --- canvasMap[ i ][ j ]: i represents the y position and j is a numeric index for each shot in that line. The value is the x position. --- canvasMap[ i ].e represents the x position of the enemy in that line, if any. --- Enemies can only appear in lines 5, 15, 25, 35, ..., 75 and 85 -for i = 1, ycanvas, 1 do - canvasMap[ i ] = {} -end -for i = 5, 85, 10 do - canvasMap[ i ].e = false -end - -function drawWall( x, y ) - for i = 0, y, 7 do - lm3s.disp.print( "|", xcanvas + 1, i, 0 ) - end - xcanvas = x - for i = 0, y, 7 do - lm3s.disp.print( "|", xcanvas + 1, i, 6 ) - end - -end - -function drawShip( x, y, color, movement ) - - if ( movement == 0 ) then - lm3s.disp.print( ShipChar, x, y, color ) - elseif ( movement > 0 ) then -- Moving Down - if y < 8 then - lm3s.disp.print( ShipChar, x, 0, 0 ) - else - lm3s.disp.print( ShipChar, x, y - 8 , 0 ) - end - lm3s.disp.print( ShipChar, x, y, color ) - elseif ( movement < 0 ) then -- Moving Up - lm3s.disp.print( ShipChar, x, y + 8, 0 ) - lm3s.disp.print( ShipChar, x, y, color ) - end -end - - -function updateShipPos() - if kit.btn_pressed( kit.BTN_UP ) then - if ( sy > 1 ) then - sy = sy - 1 - drawShip( sx, sy, 11, -1 ) - else - tmr.delay( 1, 1700 ) - end - elseif kit.btn_pressed( kit.BTN_DOWN ) then - if ( sy + 7 < ycanvas ) then - sy = sy + 1 - drawShip( sx, sy, 11, 1 ) - else - tmr.delay( 1, 1600 ) - end - else - drawShip( sx, sy, 11, 0 ) - tmr.delay( 1, 300 ) -- Maintain function processing time aprox the same - end -end - - - -function updateShots() - for i in ipairs( canvasMap ) do - for j in ipairs( canvasMap[ i ] ) do - if canvasMap[ i ][ j ] then - lm3s.disp.print( shotChar, canvasMap[ i ][ j ], i, 0 ) - canvasMap[ i ][ j ] = canvasMap[ i ][ j ] + 2 - lm3s.disp.print( shotChar, canvasMap[ i ][ j ], i, 13 ) - if canvasMap[ i ][ j ] + 4 >= xcanvas then - lm3s.disp.print( shotChar, canvasMap[ i ][ j ], i, 0 ) - table.remove( canvasMap[ i ], j ) - break - end - local en = math.floor( i / 10 ) * 10 + 5 - if canvasMap[ en ].e then - if ( canvasMap[ i ][ j ] <= canvasMap[ en ].e ) and ( canvasMap[ i ][ j ] + 4 >= canvasMap[ en ].e ) then - destroyEnemy( i, j, en ) - createEnemy() - end - end - else - tmr.delay( 1, 1200 ) - end - end - end -end - -function shot() - if bullets > 0 then - table.insert( canvasMap[ sy ], sx + 6 ) - bullets = bullets - 1 - end - sound() -end - -function buttonClicked( button ) - if kit.btn_pressed( button ) then - pressed[ button ] = true - else - if pressed[ button ] then - pressed[ button ] = false - return true - end - pressed[ button ] = false - end - return false -end - -function printBulletsNum() - lm3s.disp.print( string.format( "%2d", bullets ), xcanvas + 4, 2, 6 ) -end - -function printScore() - lm3s.disp.print( string.format( "%2d", score ), xcanvas + 4, ycanvas - 10, 6 ) -end - -function sound() - pwm.start( 1 ) - tmr.delay( 0, 20000 ) - pwm.stop( 1 ) -end - - -function updateEnemiesPos() - for i = 5, 85, 10 do - if canvasMap[ i ].e then - lm3s.disp.print( enemyChar, canvasMap[ i ].e, i, 0 ) - canvasMap[ i ].e = canvasMap[ i ].e - 1 - lm3s.disp.print( enemyChar, canvasMap[ i ].e, i, 11 ) - if canvasMap[ i ].e <= 0 then - lm3s.disp.print( enemyChar, canvasMap[ i ].e, i, 0 ) - canvasMap[ i ].e = nil - createEnemy() - end - end - end -end - -function createEnemy() - while true do - local en = ( math.random( 0, 8 ) )*10 + 5 - if not canvasMap[ en ].e then - canvasMap[ en ].e = xcanvas - 5 - break - end - end -end - -function addEnemy() - if numOfEnemies < 9 then - numOfEnemies = numOfEnemies + 1 - createEnemy() - end -end -function destroyEnemy( i, j, en ) - lm3s.disp.print( shotChar, canvasMap[ i ][ j ], i, 0 ) - table.remove( canvasMap[ i ], j ) - lm3s.disp.print( enemyChar, canvasMap[ en ].e, en, 0 ) - canvasMap[ en ].e = nil - score = score + 1 -end - -function destroyAll() - for i in ipairs( canvasMap ) do - for j in ipairs( canvasMap[ i ] ) do - lm3s.disp.print( shotChar, canvasMap[ i ][ j ], i, 0 ) - table.remove( canvasMap[ i ], j ) - end - local en = math.floor( i / 10 ) * 10 + 5 - if canvasMap[ en ].e then - lm3s.disp.print( enemyChar, canvasMap[ en ].e, en, 0 ) - canvasMap[ en ].e = nil - end - end - -end - -for i = 1, numOfEnemies, 1 do - createEnemy() -end - - -lm3s.disp.init( 1000000 ) - --- Initial information -lm3s.disp.print( "eLua SpaceShip", 10, 10, 11 ) -lm3s.disp.print( "Press SELECT -->", 10, 40, 11 ) -local seed = 0 -while not buttonClicked( kit.BTN_SELECT ) do - seed = seed + 1 -end -math.randomseed( seed ) -lm3s.disp.clear() - -------------------------------------------------------------------------------- --- --- MAIN LOOP --- -------------------------------------------------------------------------------- -pwm.setclock( 1, 25000000 ) -pwm.setup( 1, 1000, 70 ) - -drawWall( xcanvas, ycanvas ) - -while true do - updateEnemiesPos() - for i = 1, 3, 1 do - updateShipPos() - updateShots() - end - printBulletsNum() - printScore() - if buttonClicked( kit.BTN_SELECT ) then shot() end - if buttonClicked( kit.BTN_RIGHT ) then - destroyAll() - for i = 1, numOfEnemies, 1 do - createEnemy() - end - end - if score >= 50 then - won = true - break - end - if bullets <= 0 then - won = false - break - end - tmr.delay(1, 12000) - collectgarbage("collect") -end -if won then - lm3s.disp.clear() - lm3s.disp.print( "You won!", 50, 30, 11 ) - lm3s.disp.print( "Congratulations!", 70, 20, 11 ) -else - lm3s.disp.clear() - lm3s.disp.print( "Game Over! :(", 60, 20, 11 ) -end diff --git a/romfs/test.lua b/romfs/test.lua deleted file mode 100644 index b49641c9..00000000 --- a/romfs/test.lua +++ /dev/null @@ -1,5 +0,0 @@ -print "" -print "Hello from eLua!
" -print 'Press here to return to the main page.' -print "" - diff --git a/romfs/tetrives.lua b/romfs/tetrives.lua deleted file mode 100644 index f37ea56c..00000000 --- a/romfs/tetrives.lua +++ /dev/null @@ -1,392 +0,0 @@ -------------------------------------------------------------------------------- --- --- eLua Tetris Game --- --- LED Lab @ PUC-Rio - 2009 --- Dado Sutter --- Ives Negreiros --- Ricardo Rosa --- Pedro Bittencourt --- Rafael Barmak --- Teo Benjamin --- --- Initial Version by Ives Negreiros, August 2009 --- ---------------------------------------------------------------------------------- -local Vmax = 22 -- Number of pieces in vertical +1 -local Hmax = 12 -- Number of pieces horizontally + 2 -local score = 0 -- Player's score -local highscore = 0 -- Player's highscore -local next_piece = 0 -- Code for the next piece -local PieceV = 0 -- Vertical position of the piece -local PieceH = 0 -- Horizontal position of the piece -local level = 1 -- Level -local rotate_type = 0 -- Type of rotation for each piece -local total_lines = 0 -- Total number of lines made by player -local seed = 0 -- Variable used to make math.random return a diferent value each time -local game_map = {} -- Table for the game map -for i = 1, Vmax, 1 do - game_map[ i ] = {} -end - -local pwmid -if pd.board() == "EK-LM3S1968" then - pwmid = 2 -else - pwmid = 1 -end - --- Initial information -local platform = require( pd.board() ) -lm3s.disp.init( 1000000 ) - -lm3s.disp.print( "eLua Tetrives", 30, 10, 11 ) -lm3s.disp.print( "Press SELECT -->", 30, 40, 11 ) -while platform.btn_pressed( platform.BTN_SELECT ) == false do - seed = seed + 1 -end - -math.randomseed( seed ) -lm3s.disp.clear() - -function scan_piece( next_piece ) -- This function selec the next piece based on return of math.random function - if( next_piece == 1 ) then - next_piece_map = { { 1, 1 }, { 1, 1 } } - next_rotate_type = 0 - - elseif( next_piece == 2 ) then - next_piece_map = { { 1, 1, 0 }, { 0, 1, 1 }, { 0, 0, 0 } } - next_rotate_type = 1 - - elseif( next_piece == 3 ) then - next_piece_map = { { 0, 1, 1 }, { 1, 1, 0 }, { 0, 0, 0 } } - next_rotate_type = 1 - - elseif( next_piece == 4 ) then - next_piece_map = { { 0, 0, 1 }, { 1, 1, 1 }, { 0, 0, 0 } } - next_rotate_type = 2 - - elseif( next_piece == 5 ) then - next_piece_map = { { 1, 0, 0 }, { 1, 1, 1 }, { 0, 0, 0 } } - next_rotate_type = 2 - - elseif( next_piece == 6 ) then - next_piece_map = { { 0, 1, 0 }, { 1, 1, 1 }, { 0, 0, 0 } } - next_rotate_type = 2 - - elseif( next_piece == 7 ) then - next_piece_map = { {0, 0, 0, 0 }, { 1, 1, 1, 1 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } } - next_rotate_type = 4 - end -end - -function draw_walls() -- This function draws the walls and the base of game piece screen - for i = 6, 63, 3 do - lm3s.disp.print( "|", 3, i, 11 ) - end - for i = 3, 118, 4 do - lm3s.disp.print( "-", i, 2, 11 ) - lm3s.disp.print( "-", i, 65, 11 ) - end -end - -function sound() -- This function beeps - pwm.start( pwmid ) - tmr.delay( 0, 20000 ) - pwm.stop( pwmid ) -end - -function print_data() -- This function writes the score and level on screen - lm3s.disp.print( "Score:"..tostring( score ), 0, 88, 8 ) - lm3s.disp.print( "Level:"..tostring( level ), 0, 80, 8 ) -end - -function draw_piece() -- This function draws the piece on the screen - for i in ipairs( piece_map ) do - for j in ipairs( piece_map[ i ] ) do - if( piece_map[ i ][ j ] == 1 ) then - lm3s.disp.print( "*", ( PieceV + i - 1 ) * 6, ( PieceH + j - 1 ) * 6, 11 ) - end - end - end -end - -function erase_piece() -- This function erases the piece on the screen - for i in ipairs( piece_map ) do - for j in ipairs( piece_map[ i ] ) do - if( piece_map[ i ][ j ] == 1 ) then - lm3s.disp.print( "*", ( PieceV + i - 1 ) * 6, ( PieceH + j - 1 ) * 6, 0 ) - end - end - end -end - -function move_down() -- This function moves the piece down if there is no obstacle in the way, else create new piece - free = 0 -- It also test the lines (see function test_line for further explanation) - for i in ipairs( piece_map ) do - for j in ipairs( piece_map[ i ] ) do - if( piece_map[ i ][ j ] == 1 ) then - if( game_map[ PieceV + i - 1 ][ PieceH + j ] == 0 ) then - free = free + 1 - end - end - end - end - if ( free == 4 ) then - erase_piece() - PieceV = PieceV - 1 - draw_piece() - else - for i in ipairs( piece_map ) do - for j in ipairs( piece_map[ i ] ) do - if( piece_map[ i ][ j ] == 1 ) then - game_map[ PieceV + i ][ PieceH + j ] = 1 - end - end - end - test_line() - create_new_piece() - end -end - -function move_left() -- This function moves the piece left if there is no obstacle in the way - free = 0 - for i in ipairs( piece_map ) do - for j in ipairs( piece_map[ i ] ) do - if( piece_map[ i ][ j ] == 1 ) then - if( game_map[ PieceV + i ][ PieceH + j - 1 ] == 0 ) then - free = free + 1 - end - end - end - end - if ( free == 4 ) then - erase_piece() - PieceH = PieceH - 1 - draw_piece() - end -end - -function move_right() -- This function moves the piece right if there is no obstacle in the way - free = 0 - for i in ipairs( piece_map ) do - for j in ipairs( piece_map[ i ] ) do - if( piece_map[ i ][ j ] == 1 ) then - if( game_map[ PieceV + i ][ PieceH + j + 1 ] == 0 ) then - free = free + 1 - end - end - end - end - if ( free == 4 ) then - erase_piece() - PieceH = PieceH + 1 - draw_piece() - end -end - -function rotate() -- This function rotate the pieces - piecerot = {} - for i = 1, 4, 1 do - piecerot[ i ] = {} - end - free = 0 - erase_piece() - if ( rotate_type == 1 or rotate_type == 2 ) then - for i in ipairs( piece_map ) do -- this loop test if each part of piece can rotate - for j in ipairs( piece_map[ i ] ) do - if( piece_map[ i ][ j ] == 1 ) then - if( game_map[ PieceV + j ][ 4 - i + PieceH ] == 0 ) then - free = free + 1 - end - end - end - end - if( free == 4 ) then -- If all the parts of piece can rotate, then 'free' will be equals to four - if( rotate_type == 2 ) then - rotate_type = 1 - end - for i in ipairs( piece_map ) do -- This loop rotates the piece - for j in ipairs( piece_map[ i ] ) do - piecerot[ i ][ j ] = piece_map[ j ][ 4 - i ] -- This is the equation of the rotation function for this type of rotation - end - end - piece_map = piecerot - end - - elseif ( rotate_type == 3 ) then -- This part works like the upper part, but for another type of rotation - for i in ipairs( piece_map ) do - for j in ipairs( piece_map[ i ] ) do - if( piece_map[ i ][ j ] == 1 ) then - if( game_map[ 4 - j + PieceV ][ PieceH + i ] == 0 ) then - free = free + 1 - end - end - end - end - if( free == 4 ) then - rotate_type = 2 - for i in ipairs( piece_map ) do - for j in ipairs( piece_map[ i ] ) do - piecerot[ i ][ j ] = piece_map[ 4 - j ][ i ] - end - end - piece_map = piecerot - end - - elseif ( rotate_type == 4 ) then -- This part works like the upper part, but for another type of rotation - for i in ipairs( piece_map ) do - for j in ipairs( piece_map[ i ] ) do - if( piece_map[ i ][ j ] == 1 ) then - if( game_map[ PieceV + j ][ PieceH + i ] == 0 ) then - free = free + 1 - end - end - end - end - if(free == 4 ) then - for i in ipairs( piece_map ) do - for j in ipairs( piece_map [ i ] ) do - piecerot[ i ][ j ] = piece_map[ j ][ i ] - end - end - piece_map = piecerot - end - end - draw_piece() - sound() -end - -function remove_line( line ) - for i = line, Vmax - 2, 1 do - for j = 2, Hmax - 1, 1 do - lm3s.disp.print( "*", ( i - 1 ) * 6, ( j - 1 ) * 6, 0 ) - game_map[ i ][ j ] = game_map[ i + 1 ][ j ] - if( game_map[ i ][ j ] == 1 ) then - lm3s.disp.print( "*", ( i - 1 ) * 6, ( j - 1 ) * 6, 11 ) - end - end - end -end - -function test_line() -- This function tests the lines, if there is a full line, then this - lines = 0 -- function removes this line and move down everything that is upper to it - i = 2 - while ( i= 8 and level < 4 ) then - level = level + 1 - total_lines = 0 - end -end - -function create_new_piece() -- This Function creates a new piece - piece_map = next_piece_map - rotate_type = next_rotate_type - PieceV = 18 - PieceH = 4 - next_piece = math.random( 7 ) - scan_piece ( next_piece ) - for i = 1, 2, 1 do - for j = 1, 4, 1 do - lm3s.disp.print( "*", 94 + ( j * 6 ), 78 + ( i * 6 ), 0 ) - end - end - for i in ipairs( next_piece_map ) do - if( i == 3 ) then - break - end - for j in ipairs( next_piece_map[ i ] ) do - if( next_piece_map[ i ][ j ] == 1 ) then - lm3s.disp.print( "*", 94 + ( j * 6 ), 78 + ( ( 3 - i ) * 6 ), 11 ) - end - end - end - draw_piece() -end - ---------------------------------------------------------------------------------- --- -- --- MAIN LOOP -- --- -- ---------------------------------------------------------------------------------- -repeat - - for i in ipairs( game_map ) do -- This loop create the border of game's map - for j = 1, Hmax, 1 do - if( j == 1 or j == Hmax or i == 1 or i == Vmax ) then - game_map[ i ][ j ] = 1 - else - game_map[ i ][ j ] = 0 - end - end - end - level = 1 -- This statements sets the level and score from the beginning - score = 0 - pwm.setclock( pwmid, 25000000 ) -- This statements sets the PWM for the sound function - pwm.setup( pwmid, 1000, 70 ) - draw_walls() - next_piece = math.random(7) - scan_piece ( next_piece ) - create_new_piece() - collectgarbage( "collect" ) - while true do -- This loop refreshes the data and responds the player's input - print_data () - Tmax = 11 - 2 * level -- This statement raises the speed based on the level - for i = 1, Tmax, 1 do - if platform.btn_pressed( platform.BTN_UP ) then - move_left() - end - if platform.btn_pressed( platform.BTN_DOWN ) then - move_right() - end - if platform.btn_pressed( platform.BTN_RIGHT ) then - rotate() - end - if platform.btn_pressed( platform.BTN_LEFT ) then -- If the player presses "down", the piece drops instantly and a point is added to score - score = score + 1 - tmr.delay( 1, 30000 ) - break - end - tmr.delay( 1, 70000 ) - end - move_down() - if( game_map[ PieceV + 2 ][ PieceH + 2 ] == 1 ) then -- If this condition is true then game over - break - end - collectgarbage( "collect" ) - end - - if score > highscore then - highscore = score - end - lm3s.disp.clear() -- This statements displays the game over screen - lm3s.disp.print( "Game Over :(", 30, 20, 11 ) - lm3s.disp.print( "Your score was "..tostring( score ), 0, 40, 11 ) - lm3s.disp.print( "Highscore: "..tostring( highscore ), 15, 50, 11 ) - lm3s.disp.print( "SELECT to restart", 6, 70, 11 ) - enough = true -- If the player presses select before the time reach 1000000ms, then restart the game - for i=1, 1000000 do - if platform.btn_pressed( platform.BTN_SELECT ) then - enough = false - break - end - end - lm3s.disp.clear() -until ( enough ) -lm3s.disp.off() diff --git a/romfs/tvbgone.lua b/romfs/tvbgone.lua deleted file mode 100644 index 4b36fe65..00000000 --- a/romfs/tvbgone.lua +++ /dev/null @@ -1,70 +0,0 @@ --- 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, "