Bwbasic 3.2a for the BeagleBone
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.
 
 

92 lines
3.8 KiB

  1. 2 rem Relay control program in bwbasic 3.2 4-15-2020 Ken.
  2. 3 rem As of 4-13-2020 Debian apt get install bwbasic installs an old 2.2.
  3. 4 rem Assumes bwbasic 3.2. bwbasic 2.2 has issues see changelog.
  4. 5 rem Download 3.2a tar file. Untar then cd bwbasic-3.2a then sh compile
  5. 8 rem Set terminal to ANSI mode. Only 3.2 or newer
  6. 10 option terminal ANSI
  7. 12 rem Clear screen on initial startup. Only 3.2 or newer
  8. 15 cls
  9. 16 print : print "=== Relay games on ";DATE$;" at ";TIME$;" ===" : print " ";
  10. 17 shell "cat /etc/dogtag"
  11. 18 print
  12. 19 rem If an error occurs gosub to line 1000
  13. 20 on error gosub 1000
  14. 24 rem b$ = Base address Beaglebone Black Debian 10.3 3-26-2020
  15. 30 let b$="/sys/class/gpio/gpio"
  16. 40 call close
  17. 50 print "0 Off, 1 On, s State, sa State All,";
  18. 52 print " ao All Off, l Label or x Exit "; : input m$
  19. 60 IF m$ = "0" or m$ = "1" or m$ = "l" or m$ = "s" then goto 70
  20. 63 IF m$ = "x" or m$ = "e" then end : rem Stop program
  21. 64 IF m$ = "sa" then gosub 500 : goto 16 : rem State all
  22. 65 IF m$ = "ao" then gosub 600 : goto 16 : rem All Relays off
  23. 66 print "Mode error. Only 0, 1, s, l, ao All Off, sa State All ";
  24. 67 print "or x allowed" : goto 50
  25. 70 print "Relay # = gpio: 1 = 20, 2 = 7, 3 = 112, 4 = 115 or r to Return. ";
  26. 71 print "Enter gpio # ";
  27. 72 input s$
  28. 75 IF s$ = "20" or s$ = "7" or s$ = "112" or s$ = "115" then goto 80
  29. 76 IF s$ = "r" then goto 16 : rem Start over
  30. 78 print "Relay gpio number error. Only 20, 7, 112, 115 or r" : goto 70
  31. 80 print
  32. 82 IF m$ = "l" then gosub 400 : goto 16 : rem l = Label
  33. 84 IF m$ = "s" then gosub 300 : print : goto 16 : rem s = State
  34. 86 IF m$ = "0" or m$ = "1" then gosub 100 : goto 16 : rem Change Relay state
  35. 90 print : print "Error. Code fall through at line 90" : print : end
  36. 100 rem Change state of a Relay.
  37. 101 rem p$ = Complete address to gpio. b$ is the Base + gpio# + end of string
  38. 102 let p$=b$ + s$ + "/value"
  39. 110 call open("O",#1,p$) : rem Open for Output and write m$
  40. 150 print #1,m$ : rem Print to gpio string m$
  41. 160 call close(#1)
  42. 210 call open("I",#1,p$) : rem Open for Input
  43. 250 read #1,x : rem Read numeric result
  44. 255 call close(#1)
  45. 256 IF s$ = "20" then print "#1 ";
  46. 257 IF s$ = "7" then print "#2 ";
  47. 258 IF s$ = "112" then print "#3 ";
  48. 259 IF s$ = "115" then print "#4 ";
  49. 260 gosub 700
  50. 299 return
  51. 300 rem p$ = Complete address to gpio. b$ is the Base + gpio# + end of string
  52. 304 let p$=b$ + s$ + "/value"
  53. 310 call open("I",#1,p$) : rem Open for Input
  54. 350 read #1,x : rem Read numeric result
  55. 355 call close(#1)
  56. 360 gosub 700
  57. 396 return : rem Start over
  58. 400 rem p$ = Complete address to gpio. b$ is the Base + gpio# + end of string
  59. 404 let p$=b$ + s$ + "/label"
  60. 410 call open("I",#1,p$)
  61. 420 read #1,l$
  62. 425 call close(#1)
  63. 430 print "Label for gpio ";s$;" is ";l$
  64. 440 return
  65. 500 rem Display the state of all Relays 'sa'
  66. 505 print
  67. 510 let s$ = "20" : print "#1 "; : gosub 300
  68. 520 let s$ = "7" : print "#2 "; : gosub 300
  69. 530 let s$ = "112" : print "#3 "; : gosub 300
  70. 540 let s$ = "115" : print "#4 "; : gosub 300
  71. 550 return
  72. 600 rem Turn all Relays off 'ao'
  73. 610 print
  74. 612 let m$ = "0" : rem Set mode to '0' off
  75. 620 let s$ = "20" : gosub 100
  76. 624 let s$ = "7" : gosub 100
  77. 626 let s$ = "112" : gosub 100
  78. 628 let s$ = "115" : gosub 100
  79. 630 return
  80. 700 rem Print relay state gathered from 'read'
  81. 704 print "Relay gpio ";s$," state is now = ";x;
  82. 770 IF x = 0 then print " Off"
  83. 780 IF x = 1 then print " On"
  84. 790 IF x > 1 or x < 0 then print " Error"
  85. 799 return
  86. 999 rem Trap errors here. Hopefuly you will not get here.
  87. 1000 print : print "Error code ";err;" Error line ";erl
  88. 1040 print
  89. 1060 rem CLOSE will fail on 2.2 and loop but not 3.2+
  90. 1070 call close : rem Just in case something is open.
  91. 1100 end : rem Stop program