Fwd: [Elua-svn] r132 - trunk/romfs

classic Classic list List threaded Threaded
1 message Options
Dado Sutter Dado Sutter
Reply | Threaded
Open this post in threaded view
|

Fwd: [Elua-svn] r132 - trunk/romfs

:-O
   The commit was done ~4 days ago, on the Sun-Monday night but the
notification has just arrived :-o
   Was BerliOS in vacations or what ? :-o :)

Best
Dado


---------- Forwarded message ----------
From: dadosutter at BerliOS <dadosutter at mail.berlios.de>
Date: Mon, Dec 8, 2008 at 17:39
Subject: [Elua-svn] r132 - trunk/romfs
To: elua-svn at lists.berlios.de


Author: dadosutter
Date: 2008-12-08 20:39:47 +0100 (Mon, 08 Dec 2008)
New Revision: 132

Added:
  trunk/romfs/LM3S.lua
Modified:
  trunk/romfs/pong.lua
Log:
Pong example remorphed for a require() / module () scheme.
It now illustrates how to create and use a module in Lua for eLua.
An LM3S platform-dependend module is created, exposing it's buttons, leds
and offering some utility functions.




Added: trunk/romfs/LM3S.lua
===================================================================
--- trunk/romfs/LM3S.lua        2008-12-01 23:04:05 UTC (rev 131)
+++ trunk/romfs/LM3S.lua        2008-12-08 19:39:47 UTC (rev 132)
@@ -0,0 +1,20 @@
+local pio = pio
+
+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
+btnpressed = function( button )
+  return ( pio.get ( button ) == 0 )
+end
+
+LED_1 = pio.PF_0
+
+pio.input( BTN_UP, BTN_DOWN, BTN_LEFT, BTN_RIGHT, BTN_SELECT )
+pio.pullup( BTN_UP, BTN_DOWN, BTN_LEFT, BTN_RIGHT, BTN_SELECT )
+pio.output ( LED_1 )
+
+

Modified: trunk/romfs/pong.lua
===================================================================
--- trunk/romfs/pong.lua        2008-12-01 23:04:05 UTC (rev 131)
+++ trunk/romfs/pong.lua        2008-12-08 19:39:47 UTC (rev 132)
@@ -3,26 +3,8 @@
  Function lm3s_init will become a separate module, require()d here
 --]]

-function lm3s_init()
-  btn = {}
-  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.LED1 = pio.PF_0
-  pio.input( btn.UP, btn.DOWN, btn.LEFT, btn.RIGHT, btn.SELECT )
-  pio.pullup( btn.UP, btn.DOWN, btn.LEFT, btn.RIGHT, btn.SELECT )
-  pio.output ( btn.LED1 )
-  btn.pressed = function( btn )
-    return ( pio.get ( btn ) == 0 )
-  end
-end
+require("LM3S")

-function term.keypressed()
-  return( uart.recv (0, 0, 0) >= 0 )
-end
-
 function drawPaddle( y, color )
  disp.stringdraw("|", 0, y,   color)
  disp.stringdraw("|", 0, y+4, color)
@@ -43,13 +25,13 @@
 end

 function updatePaddlePos()
-  if btn.pressed( btn.UP ) then
+  if LM3S.btnpressed( LM3S.BTN_UP ) then
    if ( py > 0 ) then
      drawPaddle( py, 0 )
      py = py - 1
      drawPaddle( py, 11 )
    end
-  elseif btn.pressed( btn.DOWN ) then
+  elseif LM3S.btnpressed( LM3S.BTN_DOWN ) then
    if ( py < 80 ) then
      drawPaddle( py, 0 )
      py = py + 1
@@ -61,12 +43,11 @@
 end

 ------------ MAIN ------------
-lm3s_init()
 disp.init(1000000)

 term.clrscr()
---term.gotoxy( 5, 1 )
---print( "Welcome to eLua Tenis on a RIT display" )
+term.gotoxy( 5, 1 )
+print( "Welcome to eLua Pong on a RIT display" )
 disp.stringdraw( "eLua Pong", 30, 40, 11 )
 tmr.delay ( 0, 2000000 )

@@ -104,14 +85,14 @@
    end

    if change == 0 then
-      if btn.pressed( btn.RIGHT ) and time > 0 then
+      if LM3S.btnpressed( LM3S.BTN_RIGHT ) and time > 0 then
        change = 1
-      elseif btn.pressed( btn.LEFT ) and dscore > 1 then
+      elseif LM3S.btnpressed( LM3S.BTN_LEFT ) and dscore > 1 then
        change = -1
      end
    end

-    if ( btn.pressed( btn.RIGHT ) ) == false and ( btn.pressed( btn.LEFT )
) == false then
+    if ( LM3S.btnpressed( LM3S.BTN_RIGHT ) ) == false and (
LM3S.btnpressed( LM3S.BTN_LEFT ) ) == false then
      if change == 1 then
        time = time - 2000
        dscore = dscore + 1
@@ -136,7 +117,7 @@
  disp.stringdraw( "High score: " .. tostring( highscore ), 15, 50, 11 )
  disp.stringdraw( "SELECT to restart", 6, 70, 11 )
  for i=0, 500000 do
-    if btn.pressed( btn.SELECT ) then
+    if LM3S.btnpressed( LM3S.BTN_SELECT ) then
      play = true
      break
    end

_______________________________________________
Elua-svn mailing list
Elua-svn at lists.berlios.de
https://lists.berlios.de/mailman/listinfo/elua-svn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.berlios.de/pipermail/elua-dev/attachments/20081210/06ac6245/attachment.html