' button_control.bas uses the Blassic interpreter ' and is sent variables $name $timedate ' from the ash script pg-beeper1_pages.sh that is called by beeper1_pages.cgi ' that sets up the web page seen by the remote user. ' The top part of the web page is from beeper1_pages.html ' Sunspot 18 July 2007 - www.sunspot.co.uk DIM cut_number(60) DIM line$(80) they_are_in = 1 'first assume they are in - it will become 0 if they do not respond again = 0 ' becomes 1 if they ask for a repeat message$ = ENVIRON$ ("message") 'this came from string$ generated on the web page via export of an evironmental variable shell "echo 'led switch 1' > /dev/gpio2" ' make gpio2 an output ready to flash the white LED shell "echo 'LED ON' > /dev/gpio2" ' turn the gpio2 LED line ON - this turns the white LED off - the transistor driver inverts ' find who is calling and make the speaker give their personal beep If programarg$(1) = "A" Then sender$ = "Anne-Marie" : GOSUB AnneMarie If programarg$(1) = "S" Then sender$ = "Stephen" : GOSUB Stephen If programarg$(1) = "D" Then sender$ = "David" : GOSUB David 'save time sent message_time$ = programarg$(2) ' tell the sender what they actually sent and Sweex time/date print "",sender$," just sent this message
" print "", message$, "
" print "",programarg$(2),"
" GOSUB ParseAndDisplay 'send structured message confirmation to the remote browser GOSUB ButtonLampsOff 'start in the correct state For j = 1 to 2 GOSUB flash_white_LED GOSUB CycleTheLCDPages 'cycle the kitchen LCD pages with the parsed message GOSUB ReadTheButtonLeds IF left_button$ = "0" OR middle_button$ = "0" OR right_button$ = "0" THEN GOTO RespondToMessage IF left_button$ = "1" AND middle_button$ = "1" AND right_button$ = "1" Then print " No response yet, beeping again in 5 seconds, try ",j," of 10
" ' - no button pressed so ring the bell again using distinct chime for A or S or D if programarg$(1) = "A" Then GOSUB AnneMarie if programarg$(1) = "S" Then GOSUB Stephen if programarg$(1) = "D" Then GOSUB David PAUSE 5000 : ' do it again in 5 seconds next j they_are_in = 0 ' they seem to be out - flash the white LED and show options menu till they press a button GOTO Options '------------------------------------------------------------------------------------- LABEL RespondToMessage IF left_button$ = "0" Then response$ = "OK!



" IF middle_button$ = "0" Then response$ = "Sorry - I am busy



" IF right_button$ = "0" Then response$ = "I will do that in 10 minutes



" GOSUB ButtonLampsOff PRINT response$ LABEL Options GOSUB flash_white_LED shell "lcd_out_4x20 -i" shell "lcd_out_4x20 ' Please press '" shell "lcd_out_4x20 -2" shell "lcd_out_4x20 ' a button '" shell "lcd_out_4x20 -3" shell "lcd_out_4x20 '. . . . . . . . . . '" shell "lcd_out_4x20 -4" shell "lcd_out_4x20 'show again. . . quit'" PAUSE 2000 GOSUB ReadTheButtonLeds IF right_button$ = "0" THEN GOTO AllDone IF left_button$ = "0" OR middle_button$ = "0" THEN GOSUB ButtonLampsOff : again = 1 : GOSUB CycleTheLCDPages GOTO Options '------------------------------------------------------------------------------------- LABEL AnneMarie ' send a police siren for i = 1 to 6 shell "pulse_burst 0 4000 4000 350" shell "pulse_burst 0 5000 5000 300" next i RETURN '------------------------------------------------------------------------------------- LABEL Stephen ' send a down chirp for i = 1 to 2 shell "pulse_burst 0 3400 3400 100" shell "pulse_burst 0 3500 3500 100" shell "pulse_burst 0 3600 3600 100" shell "pulse_burst 0 3700 3700 100" shell "pulse_burst 0 3800 3800 100" shell "pulse_burst 0 3900 3900 100" shell "pulse_burst 0 4000 4000 100" shell "pulse_burst 0 4100 4100 100" shell "pulse_burst 0 4200 4200 100" shell "pulse_burst 0 4300 4300 100" shell "pulse_burst 0 4400 4400 100" shell "pulse_burst 0 4500 4500 100" shell "pulse_burst 0 4600 4600 100" shell "pulse_burst 0 4700 4700 100" shell "pulse_burst 0 4800 4800 100" shell "pulse_burst 0 4900 4900 100" shell "pulse_burst 0 5000 5000 100" next i RETURN '------------------------------------------------------------------------------------- LABEL David ' send Beethovens 5th for i = 1 to 2 shell "pulse_burst 0 4242 4242 160" PAUSE 40 shell "pulse_burst 0 4242 4242 160" PAUSE 40 shell "pulse_burst 0 4242 4242 160" PAUSE 40 shell "pulse_burst 0 5100 5100 1000 next i RETURN '------------------------------------------------------------------------------------- LABEL flash_white_LED If sender$ = "Stephen" Then k=1 If sender$ = "Anne-Marie" Then k=2 If sender$ = "David" Then k=3 for l=1 to k shell "echo 'LED OFF' > /dev/gpio2" PAUSE 300 shell "echo 'LED ON' > /dev/gpio2" PAUSE 300 next l RETURN '------------------------------------------------------------------------------------- LABEL ButtonLampsOff PAUSE 500 'debounce buttons shell "echo 'led on' > /dev/gpio8" shell "echo 'led off' > /dev/gpio8" 'print "
lamps turned off
" RETURN '------------------------------------------------------------------------------------- LABEL ReadTheButtonLeds open "/dev/gpio11" as #1 input #1,gpio11$ left_button$ = gpio11$ close #1 open "/dev/gpio14" as #1 input #1,gpio14$ middle_button$ = gpio14$ close #1 open "/dev/gpio17" as #1 input #1,gpio17$ right_button$ = gpio17$ close #1 RETURN '------------------------------------------------------------------------------------- LABEL ParseAndDisplay N = LEN (message$) 'PRINT "the string length is -> ";N;"
" s=0 ' we have not found a space yet char_number = 1 'start at the first character of the message n = 1: 'This is used to control which cut_number we are working on cut_number(n) = 1 'we set the first cut (start of first line) at the position of char_number 1 LABEL NextCharacter ' set the next cut_number to the character position that is 20 more ' than the last in case there are no spaces in this line and we have yet to find a space IF (s = 0) THEN cut_number(n + 1) = cut_number(n) + 20 'PRINT "character number -> " ; char_number ; "
" 'PRINT "new line - the new cut_number is" ; n ; "
" 'PRINT "cut_number (" ; n ;") is at character";cut_number(n); "
" 'PRINT "cut_number (" ; n + 1 ;") is at character";cut_number(n + 1); "
" letter$ = MID$ (message$, char_number, 1) 'PRINT "letter sampled -> " ; letter$ ; "
" ' have we reached the end of the message? IF letter$ = "" then cut_number(n + 1) = char_number :GOTO DriveDisplay ' if the letter is a space and we are not at the line end then update the next cut_number value IF (letter$ = " ") AND (char_number <> (cut_number(n) + 21)) THEN cut_number(n + 1) = char_number : s = 1 'PRINT "s -> " ; s ; "
" ' if we are 20 beyond the previous cut number then accept the last cut_number position ' which is a space or still set to the line end since there were no spaces - so start to build a new line IF char_number - cut_number(n) = 20 THEN n = n + 1 : char_number = char_number + 1 : s = 0 : GOTO NextCharacter char_number = char_number + 1 GOTO NextCharacter LABEL DriveDisplay 'feed the sender's browser display IF INT(n/4) = n/4 THEN total_pages = n/4 ELSE total_pages = INT(n/4) + 1 ' PRINT "
"; n ;"
" PRINT "
The kitchen LCD will cycle through these ";total_pages;" pages
" x = 1 'start at line number1 FOR page = 1 TO total_pages PRINT "
"; page ;"
" 'PRINT "n = ";n ;"
" IF x => (n + 1) THEN line$(x) = "......" ELSE line$(x) = MID$ (message$, cut_number(x), (cut_number(x+1) - cut_number(x))) PRINT line$(x);"
" x = x + 1 IF x => (n + 1) THEN line$(x) = "......" ELSE line$(x) = MID$ (message$, cut_number(x), (cut_number(x+1) - cut_number(x))) PRINT line$(x);"
" x = x + 1 IF x => (n + 1) THEN line$(x) = "......" ELSE line$(x) = MID$ (message$, cut_number(x), (cut_number(x+1) - cut_number(x))) PRINT line$(x);"
" x = x + 1 IF x => (n + 1) THEN line$(x) = "......" ELSE line$(x) = MID$ (message$, cut_number(x), (cut_number(x+1) - cut_number(x))) PRINT line$(x);"
" x = x + 1 NEXT page RETURN '------------------------------------------------------------------------------------- LABEL CycleTheLCDPages ' Now drive the LCD panel with delays between pages x = 1 'start at line number1 FOR page = 1 TO total_pages shell "lcd_out_4x20 -i" IF x => (n + 1) THEN line$(x) = "......" ELSE line$(x) = MID$ (message$, cut_number(x), (cut_number(x+1) - cut_number(x))) shell "lcd_out_4x20 "+CHR$(34)+line$(x)+CHR$(34) x = x + 1 IF x => (n + 1) THEN line$(x) = "......" ELSE line$(x) = MID$ (message$, cut_number(x), (cut_number(x+1) - cut_number(x))) shell "lcd_out_4x20 -2" shell "lcd_out_4x20 "+CHR$(34)+line$(x)+CHR$(34) x = x + 1 IF x => (n + 1) THEN line$(x) = "......" ELSE line$(x) = MID$ (message$, cut_number(x), (cut_number(x+1) - cut_number(x))) shell "lcd_out_4x20 -3" shell "lcd_out_4x20 "+CHR$(34)+line$(x)+CHR$(34) x = x + 1 IF x => (n + 1) THEN line$(x) = "......" ELSE line$(x) = MID$ (message$, cut_number(x), (cut_number(x+1) - cut_number(x))) shell "lcd_out_4x20 -4" shell "lcd_out_4x20 "+CHR$(34)+line$(x)+CHR$(34) x = x + 1 PAUSE 4000 NEXT page ' pages now all displayed so show date and who sent message shell "lcd_out_4x20 -i" shell "lcd_out_4x20 'Message received at:'" shell "lcd_out_4x20 -2" shell "lcd_out_4x20 ' '"+CHR$(34)+message_time$+CHR$(34) shell "lcd_out_4x20 -3" shell "lcd_out_4x20 ' '"+CHR$(34)+sender$+CHR$(34) shell "lcd_out_4x20 -4" IF (they_are_in = 1) AND (again = 0) THEN shell "lcd_out_4x20 'OK busy in10min'" IF they_are_in = 0 THEN shell "lcd_out_4x20 ' you were out '" IF again = 1 THEN shell "lcd_out_4x20 '____________________'" PAUSE 4000 RETURN '------------------------------------------------------------------------------------- LABEL AllDone shell "lcd_out_4x20 -i" shell "lcd_out_4x20 ' All done '" shell "lcd_out_4x20 -2" shell "lcd_out_4x20 ' message deleted '" shell "lcd_out_4x20 -3" shell "lcd_out_4x20 ' waiting for '" shell "lcd_out_4x20 -4" shell "lcd_out_4x20 ' next message '" GOSUB ButtonLampsOff Print "Goodbye
" system