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.

123 lines
5.9 KiB

  1. 2 rem Relays control program in bwbasic 3.2 4-18-2020 Ken.
  2. 3 rem 4-18-2020 Added hardware check. Error traps and help.
  3. 5 rem As of 4-13-2020 Debian apt get install bwbasic installs an old 2.2.
  4. 6 rem Assumes bwbasic 3.2. bwbasic 2.2 has issues see changelog.
  5. 7 rem Download bwbasic-3.2a.tar file. Untar then cd bwbasic-3.2a then sh compile
  6. 8 rem Set terminal to ANSI mode. Linux and Windows. Only 3.2 or newer
  7. 9 rem option terminal ANSI
  8. 11 call cls : rem Clear screen on initial startup. Only 3.2 or newer
  9. 12 call close : rem Close any open files. Again 3.2 or newer.
  10. 13 rem Trap errors
  11. 14 on error gosub 10000
  12. 15 gosub 9000 : rem Get Dogtag & Model & see if it's allowable hardware.
  13. 16 print : print "=== Relay games on ";DATE$;" at ";TIME$;" ===" : print " ";d$
  14. 17 print " ";o$
  15. 18 print
  16. 24 rem b$ = Base address as of Beaglebone Black Debian 10.3 3-26-2020
  17. 25 let b$="/sys/class/gpio/gpio"
  18. 50 print "0 Off, 1 On, s State, sa State All,";
  19. 52 print " ao All Off, l Label, h for Help or x Exit "; : input m$
  20. 60 IF m$ = "0" or m$ = "1" or m$ = "l" or m$ = "s" then goto 70
  21. 63 IF m$ = "x" or m$ = "e" then system : rem Stop program. Exit to system.
  22. 64 IF m$ = "sa" then print:print "Currently:":gosub 500:goto 16 : rem State all
  23. 65 IF m$ = "ao" then print:print "Was:":gosub 500:print "Now:":gosub 600:goto 16
  24. 66 IF m$ = "q" then print "Bye" : stop : rem Stop program
  25. 67 IF m$ = "h" then gosub 1000 : goto 16
  26. 68 print "Mode error. Only 0, 1, s, l, ao All Off, sa State All ";
  27. 69 print "h Help or x allowed" : goto 50
  28. 70 print "Relay # = gpio: 1 = 20, 2 = 7, 3 = 112, 4 = 115 or r to Return. ";
  29. 71 input "Enter gpio # ";s$
  30. 75 IF s$ = "20" or s$ = "7" or s$ = "112" or s$ = "115" then goto 80
  31. 76 IF s$ = "r" then goto 16 : rem Start over
  32. 78 print "Relay gpio number error. Only 20, 7, 112, 115 or r" : goto 70
  33. 80 print
  34. 82 IF m$ = "l" then gosub 400 : goto 16 : rem l = Label
  35. 84 IF m$ = "s" then gosub 300 : print : goto 16 : rem s = State
  36. 86 IF m$ = "0" or m$ = "1" then gosub 100 : goto 16 : rem Change Relay state
  37. 90 print : print "Error. Code fall through at line 90" : print : stop
  38. 100 rem Change state of a Relay.
  39. 101 rem p$ = Complete address to gpio. b$ is the Base + gpio# + end of string
  40. 102 let p$=b$ + s$ + "/value"
  41. 110 call open("O",#1,p$) : rem Open for Output and write m$
  42. 150 print #1,m$ : rem Print to gpio string m$
  43. 160 call close(#1)
  44. 210 call open("I",#1,p$) : rem Open for Input
  45. 250 read #1,x : rem Read numeric result
  46. 255 call close(#1)
  47. 256 IF s$ = "20" then print "#1 ";
  48. 257 IF s$ = "7" then print "#2 ";
  49. 258 IF s$ = "112" then print "#3 ";
  50. 259 IF s$ = "115" then print "#4 ";
  51. 260 gosub 700
  52. 299 return
  53. 300 rem p$ = Complete address to gpio. b$ is the Base + gpio# + end of string
  54. 304 let p$=b$ + s$ + "/value"
  55. 310 call open("I",#1,p$) : rem Open for Input
  56. 350 read #1,x : rem Read numeric result
  57. 355 call close(#1)
  58. 360 gosub 700
  59. 396 return : rem Start over
  60. 400 rem p$ = Complete address to gpio. b$ is the Base + gpio# + end of string
  61. 404 let p$=b$ + s$ + "/label"
  62. 410 call open("I",#1,p$)
  63. 420 read #1,l$
  64. 425 call close(#1)
  65. 430 print "Label for gpio ";s$;" is ";l$
  66. 440 return
  67. 500 rem Display the state of all Relays 'sa'
  68. 510 let s$ = "20" : print "#1 "; : gosub 300
  69. 520 let s$ = "7" : print "#2 "; : gosub 300
  70. 530 let s$ = "112" : print "#3 "; : gosub 300
  71. 540 let s$ = "115" : print "#4 "; : gosub 300
  72. 550 return
  73. 600 rem Turn all Relays off 'ao'
  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. 1000 rem Give them some help
  87. 1010 print:print "Information" : print
  88. 1020 print "To change the state of a relay use 0 for Off or 1 for On"
  89. 1022 print " Then enter the gpio number 20, 7, 112 or 115":print
  90. 1024 print "To check the state of a single relay use s"
  91. 1026 print " Then enter the gpio number":print
  92. 1028 print "To get the associated label (header pin) use l"
  93. 1030 print " Then enter the gpio number":print
  94. 1032 print "To get the state of all relays use sa": print
  95. 1034 print "To turn all relays off use ao":print
  96. 1035 print "For the latest updates goto:"
  97. 1036 print "https://github.com/kenmartin-unix/Bwbasic-3.2a-for-BeagleBone"
  98. 1040 print : input "Press enter ? ",h
  99. 1099 return
  100. 9000 rem Get Model & Dogtag d$ = Dogtag 0$ = MOdel. Check for Beaglebone 'Black'
  101. 9002 rem If we fail here we should not. This only runs once at startup.
  102. 9004 call open("I",#1,"/etc/dogtag") : rem Open dogtag file
  103. 9008 read #1,d$ : call close(#1)
  104. 9014 call open("I",#1,"/proc/device-tree/model") : rem Open model info
  105. 9018 read #1,o$ : call close(#1)
  106. 9020 rem Lets see if it's a 'Black'
  107. 9025 IF (instr(1,o$,"Black") > 0) then return
  108. 9055 print : print "Warning: It appears this is not a BeagleBone 'Black'" : print
  109. 9056 print "It appears to be : ";o$
  110. 9057 print "Running : ";d$
  111. 9058 system
  112. 10000 rem Trap errors here. Hopefuly you will not get here.
  113. 10020 print : print "Error code ";err;" Error line ";erl
  114. 10040 print
  115. 10041 IF (err = 2) then print "A program syntax error." : print : system
  116. 10042 IF (err = 5) then print "Trouble working with files." : print :system
  117. 10043 IF (erl > 9000) then print "Trouble during initial setup." : print : system:
  118. 10044 IF (err = 62) then print "Reading past the end of file attempted." : print
  119. 10048 IF (err = 64) then print "Invalid path. Verify open paths." : system
  120. 10060 rem CLOSE will fail on 2.2 and loop but not 3.2+
  121. 10070 call close : rem Just in case something is open.
  122. 11100 system : rem Stop program