Advertisement
Guest User

BadgeMonitor_v1_0.spin

a guest
Mar 9th, 2016
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. {{
  2. ─────────────────────────────────────────────────
  3. File: BadgeMonitor_v1_0.spin
  4. Version: 1.0
  5. Copyright (c) 2016 Tymkrs
  6. See end of file for terms of use.
  7.  
  8. Author: Whisker
  9. ─────────────────────────────────────────────────
  10. }}
  11.  
  12. {
  13. HISTORY:
  14. This driver is made as an example for using the Badge Bug to monitor a Cyphercon2016 badge over a serial port
  15.  
  16. USAGE:
  17. • Install Badge Bug
  18. • Flash this firmware to the Badge Bug (via Propeller Tool & Prop Plug, etc.)
  19. • Use a serial terminal emulator and a usb ttl serial cable to talk to Badge Bug at 115200 baud
  20. • Parse the incoming data to use the badge as a controller?
  21.  
  22. }
  23.  
  24. Con
  25. _clkmode = xtal1 + pll16x
  26. _xinfreq = 5_000_000
  27.  
  28. OBJ
  29. fds : "FullDuplexSerial"
  30.  
  31. VAR
  32. long PreviousStates, PinName, PinNameEnd
  33.  
  34. Pub Main | Index
  35. Init
  36. repeat
  37. ScanEvents
  38.  
  39. Pub ScanEvents | Index
  40. dirb := ina ^ PreviousStates
  41. PreviousStates := ina
  42. repeat Index from 0 to 31
  43. case Index
  44. 0..12, 16..23:
  45. if dirb[Index] == 1
  46. SetPinName(Index)
  47. fds.Str(@PinName)
  48. if ina[Index] == 0
  49. fds.Str(String("0"))
  50. elseif ina[Index] == 1
  51. fds.Str(String("1"))
  52.  
  53. Pub SetPinName(PinOffset) | Index
  54. repeat Index from 0 to 3
  55. BYTE[@PinName][Index] := BYTE[@PinKey][(Pinoffset * 4) + Index]
  56. PinNameEnd := 0
  57.  
  58. Pub Init
  59. fds.Start(31, 30, 0, 115_200)
  60. waitcnt((clkfreq / 1000) + cnt)
  61.  
  62. DAT
  63. PinKey byte "SR_0SR_1SR_2SR_3SR_4SR_5SR_6SR_7STEPDATAIN_0IN_1IN_2 KEY0KEY1KEY2XOR0XOR1XOR2TAPATAPB "
  64.  
  65. {{
  66. ┌──────────────────────────────────────────────────────────────────────────────────────┐
  67. │ TERMS OF USE: MIT License │
  68. ├──────────────────────────────────────────────────────────────────────────────────────┤
  69. │Permission is hereby granted, free of charge, to any person obtaining a copy of this │
  70. │software and associated documentation files (the "Software"), to deal in the Software │
  71. │without restriction, including without limitation the rights to use, copy, modify, │
  72. │merge, publish, distribute, sublicense, and/or sell copies of the Software, and to │
  73. │permit persons to whom the Software is furnished to do so, subject to the following │
  74. │conditions: │
  75. │ │
  76. │The above copyright notice and this permission notice shall be included in all copies │
  77. │or substantial portions of the Software. │
  78. │ │
  79. │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, │
  80. │INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A │
  81. │PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT │
  82. │HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION │
  83. │OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
  84. │SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
  85. └──────────────────────────────────────────────────────────────────────────────────────┘
  86. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement