'>Hxtr0-7.BSx '============================================================== '{$stamp BS2Sx} debug "prog7" '============================================================== 'Hxtr0-0.BSx - main 'Hxtr0-1.BSx - Activity sequencer 'Hxtr0-2.BSx - US Behaviour 'Hxtr0-3.BSx - Direct Control 'Hxtr0-4.BSx - Prog4 'Hxtr0-5.BSx - Prog5 'Hxtr0-6.BSx - Prog6 'Hxtr0-7.BSx - Utils- LCD menu and IR remote 'Hxtr0-Doc.BSx - Meta Commands and Program Headers '============================================================== 'New '--- 'Introduces two routines KlcdCon and KirCon ' 'KlcdCon - allows direct control of Hextor using the Pendant 'LCD and buttons. Only the BOS commands FBRLSUMKPDOCNQT. ' 'KirCon - allows direct control of Hextor using an IR remote 'control. ' 'Both of these are called from the Menu options of Prog0 'IRremote - trained on keys 1,2,3,4,5,6,7,8 'The trained keys are numbered from 1, 'but in the program the commands and command pages are numbered 'from 0 'on powerup cmndpage=0 'pages are indicated by the two LEDs, red,green = 00,01,10,11 ' ' cmnd cmndpage=0 cmndpage=1 cmndpage=2 cmndpage=3 'key1 0 Forward Sit Grip Pick RUN0 * 'key2 1 Backward Up Grip Down 'key3 2 Rightturn Midd Grip Open 'key4 3 Leftturn Kill Grip Close uswander ' ' LEDs 'key5 00 cmndpage=0 'key6 01 cmndpage=1 'key7 10 cmndpage=2 'key8 11 cmndpage=3 '============================================================== ' 'Ultrasonic-behaviour name-table program2 '---------------------------------------- US_sitcorner con 0 US_beg con 1 US_hello con 2 US_wander con 3 ' 'Utilities name-table '--------------------- U_KirCon con 0 U_KlcdCon con 1 ' ' U_null DATA 2 'number of utility routines ' '-------------------------------------------------------------- 'LCD commands. 'For more detailed information see the ILM-216 User Manual. 'Function ASCII '-------- ----- 'Null 0 'Cursor home 1 'Hide cursor 4 'Show underline cursor 5 'Show blinking-block cursor 6 'Bell (not implemented with Hextor LCD) 7 'Backspace 8 'Horezontal tab (4 columns) 9 'Smart linefeed (cursor down one line) 10 'Vertical tab (cursor up one line) 11 'Formfeed (clear screen) 12 'Carriage return 13 'Backlight on 14 'Backlight off 15 'Accept cursor position entry 16 ' 64 is the start of the first line ' 80 is the start of the second line 'Format right aligned text 18 'Escape (ESC; start multipart instruction) 27 '--------- LCD messages - finish each message with Null ------- dbtxt data 12,4,16,80,"back < > do ",0 dmK data 1," FBRLSUMKPDOCNQT",0 dmIR data 1,"IR control ",0 '-------------------------------------------------------------- 'common RAM '0 program to return to - all '1 Activity to do - Sequencer '2 USrules to do - US-behaviour '3 usyawn0 - US-behaviour '4 usyawn1 - US-behaviour '5 irin - current IR value on change of pgm '6 incS - include level for activities prog1 '7 menc - last menu code '8 mopt - menu option OAUIP '9 irwatch - 0=>ignore IR signal, 1=>act on it 'Note there is no test for the stack being too big, beware of 'the stack growing down through 4! '61 down sequence stack '62 sequence stack pointer '-------------------------------------------------------------- BOStx con 0 'pin serial to BOS processor BOSrx con 1 'pin serial from BOS processor epower con 2 'pin high turns on power to electronics BOShalt con 3 'pin high halts current BOS move BOSbusy var in4 'pin BOS processor busy => high irrx con 5 'pin infra red comms in, i96n lcdtx con 6 'pin to send to LCD lcdrx con 7 'pin to receive from LCD outRled var out9 'pin high turns on right green led outLled var out8 'pin high turns on left red led i96n con 16624 '9600 baud, 8 bit, no parity, inverted BOScmnd var byte 'byte to send to BOS processor nocmnd con 15 'Kir - no command pending Uname var byte 'code value of Utility name lastname var byte 'last utility routine name var byte irin var byte 'infra-red command oldirin var byte 'old infra-red command retprog var byte 'program to return to irentry var byte 'irin on entry to pgm lcdbtns var byte 'return byte from Pendant btn var nib 'Pendant button code cmnd var nib 'Kir command cmndpage var nib 'Kir command page irwatch var bit 'inverted flag, 0=>watch for IR menc var byte 'current menu Choice lcdmsg var word 'pointer to current char in text lcdchar var byte 'character to send to LCD init: high epower 'keep electronics on get 1,Uname 'read doActivity read U_null,lastname if Uname>lastname then RUNX 'back to calling pgm get 9,irwatch '0=>watch branch Uname,[KirCon,KlcdCon] debug "bad branch" goto RUN0 'if invalid branch '-------------------------------------------------------- KlcdCon: 'Keys lcd Control menc =0 lcdmsg =dbtxt :gosub lcd 'cls, write keys lcdmsg =dmK :gosub lcd 'write BOScmnds Klcdit: lookup menc+1,[" FBRLSUMKPDOCNQT"],BOScmnd lookup menc,[" FBRLSUMKPDOCNQT"],lcdchar 'got to type the char before the one we want to indicate 'so the cursor ends up under the one to indicate. serout lcdtx,i96n,[5,16,(64+menc),lcdchar] if btn=1 or btn=4 then Klcdnb pause 80 'key repeat delay for < > goto Klcdb Klcdnb: gosub btns if btn<>0 then Klcdnb 'wait until finger off button Klcdb: gosub btns if btn=1 then Klcd1 if btn=2 then Klcd2 if btn=3 then Klcd3 if btn=4 then Klcd4 goto Klcdb Klcd1: serout lcdtx,i96n,[12,4] gosub btns if btn<>0 then Klcd1 'wait until finger off button goto RUN0 Klcd2: if menc>0 then K2dec menc =15 'first char so go to end K2dec: menc =menc -1 goto Klcdit Klcd3: menc =menc +1 if menc<15 then Klcdit menc =0 'last char so back to first goto Klcdit Klcd4: gosub tellBOSc if menc<5 then Klcdb 'FBRL continue goto Klcdit 'rest once only '-------------------------------------------------------- KirCon: 'Keys IR Control cmnd=nocmnd BOScmnd ="z" 'otherwise we inherit "V" cmndpage =0 'FBRL goto Kirpagecmnd 'make sure LEDs are correct Kir: oldirin =irin gosub btns if btn=1 then RUNX '"back" button pause 20 'IR gives wrong results if asked too often Kirops: gosub irget 'look at IR stream if irin > 8 then Kir 'non valid response if irin=0 then Kirdo '0 is idle value if irin=oldirin then Kirdo 'only process new IRvalues Kirnew: if irin<5 then Kircmnd cmndpage =irin -5 'cmndpage 0,1,2,3 goto Kirpagecmnd 'act on page cmnd Kircmnd:cmnd =irin -1 'new cmnd =0,1,2,3 'process cmnd and cmndpage into instructions for BOS branch cmndpage,[Kirmove,Kirpose,Kirgripper,Kirprogs] '------ Kir leaves ----- Kirdo: if BOScmnd="z" then Kir if BOSbusy=1 then Kir gosub tellBOSc if cmnd<>nocmnd then Kir BOScmnd ="z" 'so we only tell BOS once goto Kir Kirmove: 'page0 lookup cmnd,["FBRL"],BOScmnd 'since cmnd is not cleared these commands latch goto Kir Kirpose: 'page1 lookup cmnd,["SUMK"],BOScmnd cmnd =nocmnd goto Kir Kirgripper:'page2 lookup cmnd,["PDOC"],BOScmnd cmnd =nocmnd goto Kir Kirprogs:'page3 if cmnd=0 then RUNX if cmnd=3 then Kiruswander goto Kir Kirpagecmnd: outRled =cmndpage.bit1 'cmndpage to LEDS p8,p9 outLled =cmndpage.bit0 BOScmnd ="z" 'new page, so old cmnd is invalid goto Kir '------------------------------- Kiruswander: name =US_wander goto dousbehave '------------- RUN leaves ---------------------- dousbehave: put 0,7 put 2,name put 5,irin run 2 '-------------- RUN0: put 0,7 run 0 '-------------- RUNX: get 0,retprog put 0,7 run retprog 'go back to calling program '------------- subroutines --------------------- lcd: read lcdmsg,lcdchar if lcdchar=0 then lcdret 'if 0 then end of msg serout lcdtx,i96n,[lcdchar] lcdmsg =lcdmsg +1 'point to next character goto lcd lcdret: return '-------------------- btns: lcdbtns =0 'set a default value serout lcdtx,i96n,[27,"K0"] 'ask LCD for button status serin lcdrx,i96n,200,nolcd,[lcdbtns] 'get byte nolcd: btn =NCD lcdbtns.lownib '0 - 4 return '-------------------- irget:'listen to InfraRed co-processor irin =0 'set to idle value if irwatch=1 then irret serin irrx,i96n,100,irret,[irin] 'valid 0 - 8 irin =irin & $F 'mask high nibble timing data irret: return '-------------------- tellBOSc: 'used for the initialisation beeps & KeyCon pause 10 'give the BOS time to go into receive mode if BOSbusy=1 then tellBOSc 'wait until BOS not busy serout BOStx,i96n,[BOScmnd] return '------------------------ end program -------------------------