ChipMaster's bwBASIC This also includes history going back to v2.10. *WARN* some binary files might have been corrupted by CRLF.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

251 lines
6.8 KiB

  1. 2 rem Relays control program in bwbasic 3.2 4-18-2020 ken.at.github@gmail.com
  2. 3 rem 4-18-2020 Added hardware check. Error traps and help.
  3. 4 rem As of 4-13-2020 Debian apt get install bwbasic installs an old 2.2.
  4. 5 rem Assumes bwbasic 3.2. bwbasic 2.2 has issues see changelog.
  5. 6 rem Download bwbasic-3.2a.tar file. Untar then cd bwbasic-3.2a then
  6. 7 rem make then sudo make install to uninstall sudo make remove
  7. 8 rem Set terminal to ANSI mode. Linux and Windows. Only 3.2 or newer
  8. 10 option terminal ANSI
  9. 11 call cls
  10. : rem Clear screen on initial startup. Only 3.2 or newer
  11. 12 call close
  12. : rem Close any open files. Again 3.2 or newer.
  13. 13 rem Trap errors
  14. 14 on error gosub 10000
  15. 15 gosub 9000
  16. : rem Get Dogtag & Model & see if it's allowable hardware.
  17. 16 print
  18. : print "=== Relay games on ";DATE$;" at ";TIME$;" ==="
  19. : print " ";d$
  20. 17 print " ";o$
  21. 18 print
  22. 24 rem b$ = Base address as of Beaglebone Black Debian 10.3 3-26-2020
  23. 25 let b$="/sys/class/gpio/gpio"
  24. 50 print "0 Off, 1 On, s State, sa State All,";
  25. 52 print " ao All Off, l Label, h for Help or x Exit ";
  26. : input m$
  27. 60 IF m$ = "0" or m$ = "1" or m$ = "l" or m$ = "s" then
  28. : goto 70
  29. : END IF
  30. 63 IF m$ = "x" or m$ = "e" then
  31. : system
  32. : END IF
  33. : rem Stop program. Exit to system.
  34. 64 IF m$ = "sa" then
  35. : print
  36. : print "Currently:"
  37. : gosub 500
  38. : goto 16
  39. : END IF
  40. : rem State all
  41. 65 IF m$ = "ao" then
  42. : print
  43. : print "Was:"
  44. : gosub 500
  45. : print "Now:"
  46. : gosub 600
  47. : goto 16
  48. : END IF
  49. 66 IF m$ = "q" then
  50. : print "Bye"
  51. : stop
  52. : END IF
  53. : rem Stop program
  54. 67 IF m$ = "h" then
  55. : gosub 1000
  56. : goto 16
  57. : END IF
  58. 68 print "Mode error. Only 0, 1, s, l, ao All Off, sa State All ";
  59. 69 print "h Help or x allowed"
  60. : goto 50
  61. 70 print "Relay # = gpio: 1 = 20, 2 = 7, 3 = 112, 4 = 115 or r to Return. ";
  62. 71 input "Enter gpio # ";s$
  63. 75 IF s$ = "20" or s$ = "7" or s$ = "112" or s$ = "115" then
  64. : goto 80
  65. : END IF
  66. 76 IF s$ = "r" then
  67. : goto 16
  68. : END IF
  69. : rem Start over
  70. 78 print "Relay gpio number error. Only 20, 7, 112, 115 or r"
  71. : goto 70
  72. 80 print
  73. 82 IF m$ = "l" then
  74. : gosub 400
  75. : goto 16
  76. : END IF
  77. : rem l = Label
  78. 84 IF m$ = "s" then
  79. : gosub 300
  80. : print
  81. : goto 16
  82. : END IF
  83. : rem s = State
  84. 86 IF m$ = "0" or m$ = "1" then
  85. : gosub 100
  86. : goto 16
  87. : END IF
  88. : rem Change Relay state
  89. 90 print
  90. : print "Error. Code fall through at line 90"
  91. : print
  92. : stop
  93. 100 rem Change state of a Relay.
  94. 101 rem p$ = Complete address to gpio. b$ is the Base + gpio# + end of string
  95. 102 let p$=b$ + s$ + "/value"
  96. 110 call open("O",#1,p$)
  97. : rem Open for Output and write m$
  98. 150 print #1,m$
  99. : rem Print to gpio string m$
  100. 160 call close(#1)
  101. 210 call open("I",#1,p$)
  102. : rem Open for Input
  103. 250 read #1,x
  104. : rem Read numeric result
  105. 255 call close(#1)
  106. 256 IF s$ = "20" then
  107. : print "#1 ";
  108. : END IF
  109. 257 IF s$ = "7" then
  110. : print "#2 ";
  111. : END IF
  112. 258 IF s$ = "112" then
  113. : print "#3 ";
  114. : END IF
  115. 259 IF s$ = "115" then
  116. : print "#4 ";
  117. : END IF
  118. 260 gosub 700
  119. 299 return
  120. 300 rem p$ = Complete address to gpio. b$ is the Base + gpio# + end of string
  121. 304 let p$=b$ + s$ + "/value"
  122. 310 call open("I",#1,p$)
  123. : rem Open for Input
  124. 350 read #1,x
  125. : rem Read numeric result
  126. 355 call close(#1)
  127. 360 gosub 700
  128. 396 return
  129. : rem Start over
  130. 400 rem p$ = Complete address to gpio. b$ is the Base + gpio# + end of string
  131. 404 let p$=b$ + s$ + "/label"
  132. 410 call open("I",#1,p$)
  133. 420 read #1,l$
  134. 425 call close(#1)
  135. 430 print "Label for gpio ";s$;" is ";l$
  136. 440 return
  137. 500 rem Display the state of all Relays 'sa'
  138. 510 let s$ = "20"
  139. : print "#1 ";
  140. : gosub 300
  141. 520 let s$ = "7"
  142. : print "#2 ";
  143. : gosub 300
  144. 530 let s$ = "112"
  145. : print "#3 ";
  146. : gosub 300
  147. 540 let s$ = "115"
  148. : print "#4 ";
  149. : gosub 300
  150. 550 return
  151. 600 rem Turn all Relays off 'ao'
  152. 612 let m$ = "0"
  153. : rem Set mode to '0' off
  154. 620 let s$ = "20"
  155. : gosub 100
  156. 624 let s$ = "7"
  157. : gosub 100
  158. 626 let s$ = "112"
  159. : gosub 100
  160. 628 let s$ = "115"
  161. : gosub 100
  162. 630 return
  163. 700 rem Print relay state gathered from 'read'
  164. 704 print "Relay gpio ";s$," state is now = ";x;
  165. 770 IF x = 0 then
  166. : print " Off"
  167. : END IF
  168. 780 IF x = 1 then
  169. : print " On"
  170. : END IF
  171. 790 IF x > 1 or x < 0 then
  172. : print " Error"
  173. : END IF
  174. 799 return
  175. 1000 rem Give them some help
  176. 1010 print
  177. : print "Information"
  178. : print
  179. 1020 print "To change the state of a relay use 0 for Off or 1 for On"
  180. 1022 print " Then enter the gpio number 20, 7, 112 or 115"
  181. : print
  182. 1024 print "To check the state of a single relay use s"
  183. 1026 print " Then enter the gpio number"
  184. : print
  185. 1028 print "To get the associated label (header pin) use l"
  186. 1030 print " Then enter the gpio number"
  187. : print
  188. 1032 print "To get the state of all relays use sa"
  189. : print
  190. 1034 print "To turn all relays off use ao"
  191. : print
  192. 1035 print "For the latest updates goto:"
  193. 1036 print "https://github.com/kenmartin-unix/Bwbasic-3.2a-for-BeagleBone"
  194. 1038 print "ken.at.github@gmail.com"
  195. 1040 print
  196. : input "Press enter ? ",h
  197. 1099 return
  198. 9000 rem Get Model & Dogtag d$ = Dogtag 0$ = MOdel. Check for Beaglebone 'Black'
  199. 9002 rem If we fail here we should not. This only runs once at startup.
  200. 9004 call open("I",#1,"/etc/dogtag")
  201. : rem Open dogtag file
  202. 9008 read #1,d$
  203. : call close(#1)
  204. 9014 call open("I",#1,"/proc/device-tree/model")
  205. : rem Open model info
  206. 9018 read #1,o$
  207. : call close(#1)
  208. 9020 rem Lets see if it's a 'Black'
  209. 9025 IF (instr(1,o$,"Black") > 0) then
  210. : return
  211. : END IF
  212. 9055 print
  213. : print "Warning: It appears this is not a BeagleBone 'Black'"
  214. : print
  215. 9056 print "It appears to be : ";o$
  216. 9057 print "Running : ";d$
  217. 9058 system
  218. 10000 rem Trap errors here. Hopefuly you will not get here.
  219. 10020 print
  220. : print "Error code ";err;" Error line ";erl
  221. 10040 print
  222. 10041 IF (err = 2) then
  223. : print "A program syntax error."
  224. : print
  225. : system
  226. : END IF
  227. 10042 IF (err = 5) then
  228. : print "Trouble working with files."
  229. : print
  230. : system
  231. : END IF
  232. 10043 IF (erl > 9000) then
  233. : print "Trouble during initial setup."
  234. : print
  235. : system
  236. : END IF
  237. 10044 IF (err = 62) then
  238. : print "Reading past the end of file attempted."
  239. : print
  240. : END IF
  241. 10048 IF (err = 64) then
  242. : print "Invalid path. Verify open paths."
  243. : system
  244. : END IF
  245. 10060 rem CLOSE will fail on 2.2 and loop but not 3.2+
  246. 10070 call close
  247. : rem Just in case something is open.
  248. 11100 system
  249. : rem Stop program