Advertisement
MattRMiller

rfidReader v0.1

Oct 19th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.20 KB | None | 0 0
  1. --[[
  2.     rfidReader by:MRMiller
  3.     Outputs based on RFID card input
  4. --]]
  5. local version = "0.5" --Change as needed
  6. local paste = "sSgdMsNN" --Change to your pastebin
  7. local programName = "rfidReader " -- change to your proram name
  8. local isDebug = true --Toggle Debug mode
  9.  
  10. local card = {}
  11. local rfidReader = ""
  12. local rsSide = "top"
  13. local event = ""
  14. local data = ""
  15.  
  16.  
  17. local function update()
  18.     term.clear()
  19.     print("Checking for updates...")
  20.     local response = http.get("http://pastebin.com/raw.php?i="..paste)
  21.  
  22.     local reply = response.readAll()
  23.  
  24.     local a, b, c, onlineVersion = string.find(reply, "([\"'])(.-)%1") --trash a,b,c http://www.lua.org/pil/20.3.html
  25.     print("My Version: " .. version)
  26.     print("Online Version: " .. onlineVersion)
  27.     if(version~=onlineVersion) then
  28.  
  29.         fs.delete(programName)
  30.         local file = fs.open(programName,"w")
  31.         file.write(reply)
  32.         file.close()
  33.  
  34.         print("New "..programName.." file succesfully downloaded and installed")
  35.  
  36.         if(isDebug) then
  37.             print("Please Reboot (CTRL+R)")
  38.         else
  39.             shell.run("reboot")
  40.         end
  41.     else
  42.         print("No update found")
  43.     end
  44. end
  45.  
  46.  
  47.  
  48. local function getPeripheral() -- finds a peripheral and wraps it
  49.     for a,b in pairs(peripheral.getNames()) do
  50.         if peripheral.getType(b) == "rfid reader" then
  51.             rfidReader = peripheral.wrap(b)
  52.             break
  53.         end
  54.     end
  55. end
  56.  
  57. local function capture() -- captures events from the rfid reader and gets info from the card
  58.     repeat
  59.         rfidReader.scan() -- Defualt 5m (Blocks)
  60.         --local event, data, distance, side = os.pullEvent()
  61.         local event, data = os.pullEvent()
  62.         sleep(1)
  63.     until event == "rfid_detected"
  64.    
  65.     card = textutils.unserialize(data)
  66.  
  67.     if isDebug then
  68.         print("event pulled ('rfid_data')")
  69.         print(data)
  70.     end
  71. end
  72.  
  73. local function main()
  74.     update()
  75.     getPeripheral()
  76.     capture()
  77.    -- if card["name"] == "MRMiller" then
  78.    print(card)
  79.     if toString(card.name) == "MRMiller" then
  80.         rs.setOutput(rsSide, true)
  81.         sleep(5)
  82.         rs.setOutput(rsSide, false)
  83.     end
  84. end
  85.  
  86. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement