'>Hxtr1-7.BSx '============================================================== 'Milford Instruments http://www.milinst.com 'Hextor Design, Bug Commander - Behavioural Operating System 'and the Behavioural Controller programs by David Buckley '================================================================ '{$stamp BS2Sx} debug "prog7" '============================================================== 'Hxtr1-0.BSx - main 'Hxtr1-1.BSx - Activity sequencer 'Hxtr1-2.BSx - US Behaviour 'Hxtr1-3.BSx - Direct Control 'Hxtr1-4.BSx - Prog4 'Hxtr1-5.BSx - Prog5 'Hxtr1-6.BSx - Prog6 'Hxtr1-7.BSx - Utils- LCD menu and IR remote 'Hxtr1-Doc.BSx - Meta Commands and Program Headers '============================================================== 'New '--- 'LCD display for KirCon now displays:- ' IR code, BOScmnd, cmndpge, options. 'flags, FwarmIR 'If KirCon is Default action at poweron then IR chip is cold ' and spurious codes are put out for first few seconds ' so FwarmIR is tested and if 0='a cold chip' then program ' waits 5secs. ' This also results in an unavoidable delay on reset. ' 'CommonRam: #2,#6 'Variables: Prog,flags,irwatch made part of flags, FwarmIR 'Routines: Uname incremented by 1, RUN0 replaced some RUNX ' #2 cleared in RUN0 and RUNX '============================================================== 'History '------- '15Aug05 FokLEDs,Fokfeelers,Fokus renamed FuseLEDs,Fusefeelers,FuseUS '============================================================== '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 cmndpge=0 'pages are indicated by the two LEDs, red,green = 00,01,10,11 ' ' cmnd cmndpge=0 cmndpge=1 cmndpge=2 cmndpge=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 cmndpge=0 'key6 01 cmndpge=1 'key7 10 cmndpge=2 'key8 11 cmndpge=3 '============================================================== ' 'Ultrasonic-behaviour name-table program2 '---------------------------------------- US_null con 0 US_sitcorner con 1 US_beg con 2 US_hello con 3 US_wander con 4 US_user1 con 5 US_user2 con 6 US_user3 con 7 US_user4 con 8 US_last con 8 'last routine ' 'Utilities name-table '--------------------- U_KlcdCon con 1 U_KirCon con 2 U_last con 2 'last routine ' '-------------------------------------------------------------- '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 12,4,"IR=",16,86,"Cd=",16,80,"back",16,92,"Pg=",0 dmIR0 data 16,72,"FBRL ",0 dmIR1 data 16,72,"SUMK ",0 dmIR2 data 16,72,"PDOC ",0 dmIR3 data 16,72,"0 Wndr",0 dmIRw data 12,"Leting IR settlewait 5 secs",0 '-------------------------------------------------------------- 'common RAM '0 program to return to - all '1 Program option - Activity to do, USrules to do, Options '2 current Utility routine '3 usyawn0 - US-behaviour '4 usyawn1 - US-behaviour '5 irin - current IR value on change of pgm '6 oldbtn - current button on change of pgm '7 menc - last menu code '8 mopt - menu option OAUIP '9 flags - various flag bits ' bit0=irwatch - 0=>ignore IR signal, 1=>act on it ' bit1=useLEDs - 0=>ignore LED cmnds, 1=>enable LEDs ' (for if pins remapped) ' bit2=useFeelers - 0=>ignore feelers ' bit3=useUS - 0=>don't run US routines ' bit4=warmIR - 1=>IR chip needs no warmup time ' bit7=flagsvalid - 0 after download, 1->ok 'Note there is no test for the stack being too big, beware of 'the stack growing down through 9! '60 down sequence stack '61 sequence stack pointer '62 letterbox for push and pop '63 active program number used by BS2Sx '-------------------------------------------------------------- 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 Prog var name 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 'button states are in lower nibble btn1state var lcdbtns.bit0 btn2state var lcdbtns.bit1 btn3state var lcdbtns.bit2 btn4state var lcdbtns.bit3 btn var lcdbtns.highnib '0 - 4 current button state oldbtn var nib cmnd var nib 'Kir command cmndpge var nib 'Kir command page menc var byte 'current menu Choice lcdmsg var word 'pointer to current char in text lcdchar var byte 'character to send to LCD flags var byte 'various flags Firwatch var flags.bit0 '1=>watch for IR FwarmIR var flags.bit4 '1 if IR chip warmed up init: high epower 'keep electronics on get 1,Uname put 1,0 'so we don't do it again and ... get 9,flags 'IRwatch,warmIR if Uname<>0 then brnch 'something to do get 2,Uname if Uname<>0 then brnch 'we have unfinished busines goto RUN0 'nothing else to do brnch:if Uname>U_last then RUNX 'back to calling pgm branch Uname,[RUN0,KlcdCon,KirCon] 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 100 '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] 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 'set irwatch to on in case Kircon is default DO Firwatch =1 put 9,flags if FwarmIR=1 then ncmnd lcdmsg =dmIRw :gosub lcd pause 5000 'wait for IR chip to settle FwarmIR =1 put 9,flags ncmnd:cmnd=nocmnd BOScmnd ="z" 'otherwise we inherit "V" lcdmsg =dmIR :gosub lcd 'write IR screen cmndpge =0 'FBRL goto Kirpagecmnd 'make sure LEDs are correct Kir: oldirin =irin gosub btns if btn=1 then RUN0 '"back" button pause 20 'IR gives wrong results if asked too often Kirops:gosub irget 'look at IR stream serout lcdtx,i96n,[16,67,dec2 irin,16,89,BOScmnd,16,95,dec1 cmndpge] lookup cmndpge,[dmIR0,dmIR1,dmIR2,dmIR3],lcdmsg :gosub LCD 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 cmndpge =irin -5 'cmndpge 0,1,2,3 goto Kirpagecmnd 'act on page cmnd Kircmnd:cmnd =irin -1 'new cmnd =0,1,2,3 'process cmnd and cmndpge into instructions for BOS branch cmndpge,[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 RUN0 if cmnd=3 then Kiruswander goto Kir Kirpagecmnd: outRled =cmndpge.bit1 'cmndpge to LEDS p8,p9 outLled =cmndpge.bit0 BOScmnd ="z" 'new page, so old cmnd is invalid goto Kir '------------- RUN leaves ---------------------- Kiruswander: put 1,US_wander get 63,Prog 'put this Prog in arg.lownib(3) put 0,Prog put 5,irin run 2 '-------------- RUN0: get 63,Prog 'put this Prog in arg.lownib(3) put 0,Prog put 2,0 'clear Uname in CommonRam put 6,oldbtn run 0 '-------------- RUNX: get 0,retprog get 63,Prog 'put this Prog in arg.lownib(3) put 0,Prog put 1,0 'no info on what to do put 2,0 'clear Uname in CommonRam 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 Firwatch=0 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 -------------------------