Ledger Nano X - The secure hardware wallet
SHARE
TWEET

redtest

kssr3951 May 1st, 2018 (edited) 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- ========================
  2. -- == redtest
  3. -- ========================
  4. -- -------------------
  5. -- getIOAll
  6. -- -------------------
  7. function dumpIOAll()
  8.     sides = {"front", "back", "top", "bottom", "left", "right"}
  9.     i_rslt = ""
  10.     o_rslt = ""
  11.     for i, s in ipairs(sides) do
  12.         i_rslt = i_rslt .. string.format("%2d", rs.getAnalogInput(s))
  13.         o_rslt = o_rslt .. string.format("%2d", rs.getAnalogOutput(s))
  14.     end
  15.     print("[fbudlr]/in[" .. i_rslt .. "]/out[" .. o_rslt .. "]")
  16. end
  17. -- -------------------
  18. -- setOffAll
  19. -- -------------------
  20. function setOffAll()
  21.     sides = {"front", "back", "top", "bottom", "left", "right"}
  22.     for i, s in ipairs(sides) do
  23.         rs.setOutput(s, false)
  24.         rs.setAnalogOutput(s, 0)
  25.     end
  26. end
  27. -- -------------------
  28. -- setOnAll
  29. -- -------------------
  30. function setOnAll()
  31.     sides = {"front", "back", "top", "bottom", "left", "right"}
  32.     for i, s in ipairs(sides) do
  33.         rs.setOutput(s, true)
  34.         rs.setAnalogOutput(s, 15)
  35.     end
  36. end
  37. -- -------------------
  38. -- key_tbl
  39. -- -------------------
  40. key_tbl = {}
  41. key_tbl[keys.f] = { dir="front"       , side="front"  }
  42. key_tbl[keys.b] = { dir="back"        , side="back"   }
  43. key_tbl[keys.u] = { dir="top(up)"     , side="top"    }
  44. key_tbl[keys.d] = { dir="bottom(down)", side="bottom" }
  45. key_tbl[keys.l] = { dir="left"        , side="left"   }
  46. key_tbl[keys.r] = { dir="right"       , side="right"  }
  47. -- -------------------
  48. -- output_tbl
  49. -- -------------------
  50. tmp_tbl = {
  51.     "zero","one","two","three","four","five","six","seven","eight","nine",
  52.     "a","b","c","d","e","f" }
  53. output_tbl = {}
  54. for i, v in ipairs(tmp_tbl) do
  55.     output_tbl[v] = { digital=false, analog= i-1 }
  56. end
  57. output_tbl.f.digital = true
  58. -- -------------------
  59. -- main
  60. -- -------------------
  61. dumpIOAll()
  62. while true do
  63.   local event, p1 = os.pullEvent()
  64.     if "redstone" == event then
  65.         dumpIOAll()
  66.     elseif "key" == event then
  67.         if nil ~= key_tbl[p1] then
  68.             print("output for " .. key_tbl[p1].dir)
  69.             term.write("(0-9 a-f (x->all[0] z->all[15] other->cancel)>")
  70.             _, key = os.pullEvent("key")
  71.             key_char = keys.getName(key)
  72.             if "x" == key_char then
  73.                 setOffAll()
  74.                 dumpIOAll()
  75.             elseif "z" == key_char then
  76.                 setOnAll()
  77.                 dumpIOAll()
  78.             elseif nil ~= output_tbl[key_char] then
  79.                 pressed_key = output_tbl[key_char]
  80.                 rs.setOutput      (key_tbl[p1].side, pressed_key.digital)
  81.                 rs.setAnalogOutput(key_tbl[p1].side, pressed_key.analog )
  82.                 dumpIOAll()
  83.             else
  84.                 print("cancelled")
  85.             end
  86.         end
  87.     end
  88. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top