REM FLASH_T.BAS REM THIS IS A BRIGHTSCRIPT PROGRAM FOR THE ROKU HD600 REM THIS IS THE SCRIPT FOR OUTPUTTING 8 BITS OR FLASH BITS REM HMS ELECTRONICS ROKU_GPIO BOARD REM USE INPUTS 0-7 TO OUTPUT TO 0-7 (WITH SW8 input LOW) (SW9 input has to be high/open) REM USE INPUTS 0-7 TO SET FLASH ENABLE BITS (WITH SW9 input LOW) (SW8 input has to be high/open) REM WITH SW10 input low, IN MODE 0 (6 outputs) REM ROKU ID21 AND ID22 (LED4 AND LED5) ARE USED AS CONTROL PINS TO THE GPIO BOARD REM ROKU ID17,18,19,20 ARE THE DATA BITS TO THE GPIO BOARD REM THE ROUTINE EXITS WHEN PRESSING SW11 rem ************************************************* rem init some variables used in routines switches=0 last_switches=0 new_switches=0 REM THE VALUES FOR THE NEXT 12 VARIABLES ARE DEFINED IN ROUTINE 'GET_SWITCHES' SW0=0 SW1=0 SW2=0 SW3=0 SW4=0 SW5=0 SW6=0 SW7=7 SW8=0 SW9=0 SW10=0 SW11=0 'bits to be output OUT_0=0 '2 FOR OUTPUT 0 ON OUT_1=0 '2 FOR OUTPUT 1 ON OUT_2=0 '2 FOR OUTPUT 2 ON OUT_3=0 '2 FOR OUTPUT 3 ON OUT_4=0 '2 FOR OUTPUT 4 ON OUT_5=0 '2 FOR OUTPUT 5 ON OUT_6=0 '2 FOR OUTPUT 6 ON OUT_7=0 '2 FOR OUTPUT 7 ON 'flash enable bits to be output (the output bits will be flashed after setting these) REM THESE VARIABLES ARE SUBSTITUTED FOR THE VALUES 0 OR 2 IN ROUTINE 'SET_FLASH' FLASH_0=0 '2 FOR ENABLE FLASHING FOR OUTPUT 0 FLASH_1=0 '2 FOR ENABLE FLASHING FOR OUTPUT 1 FLASH_2=0 '2 FOR ENABLE FLASHING FOR OUTPUT 2 FLASH_3=0 '2 FOR ENABLE FLASHING FOR OUTPUT 3 FLASH_4=0 '2 FOR ENABLE FLASHING FOR OUTPUT 4 FLASH_5=0 '2 FOR ENABLE FLASHING FOR OUTPUT 5 FLASH_6=0 '2 FOR ENABLE FLASHING FOR OUTPUT 6 FLASH_7=0 '2 FOR ENABLE FLASHING FOR OUTPUT 7 rem end of init variables rem ************************************************* p=CreateObject("roMessagePort") 'p=the text returned from the message) sw=CreateObject("roGpioControlPort") 'input/ouput port? sw.SetPort(p) 'messages come from the GPIO interface rem ************************************************* gosub clear_flash gosub clear_outputs ? "Running the Flash_T (Flash Test) program" main: gosub get_switches if new_switches=0 then main if SW10>0 then goto mode0 'not latching mode (6 outputs) REM got a new switch value from reading the input port ? "Input Port=";switches new_switches=0 'now set the states of the OUTputs to match the states of the inputs 'for simplicity of codeing, setting the FLAHSn=OUT_n if SW0=0 then OUT_0=0 FLASH_0=0 ELSE OUT_0=2 FLASH_0=2 endif if SW1=0 then OUT_1=0 FLASH_1=0 ELSE OUT_1=2 FLASH_1=2 endif if SW2=0 then OUT_2=0 FLASH_2=0 ELSE OUT_2=2 FLASH_2=2 endif if SW3=0 then OUT_3=0 FLASH_3=0 ELSE OUT_3=2 FLASH_3=2 endif if SW4=0 then OUT_4=0 FLASH_4=0 ELSE OUT_4=2 FLASH_4=2 endif if SW5=0 then OUT_5=0 FLASH_5=0 ELSE OUT_5=2 FLASH_5=2 endif if SW6=0 then OUT_6=0 FLASH_6=0 ELSE OUT_6=2 FLASH_6=2 endif if SW7=0 then OUT_7=0 FLASH_7=0 ELSE OUT_7=2 FLASH_7=2 endif rem all the ouputs and flash bits have been defined rem now, if sw8>0 we are doing outputs rem if sw9>0 we are doing flash bits if sw11>0 then stop 'halt the program on switch input 11 if SW8>0 and SW9=0 then gosub set_outputs: goto main if SW9>0 and SW8=0 then gosub set_flash: goto main goto main rem ************************************************* get_switches: msg=p.GetMessage():if type(msg)<>"rotINT32" then get_switches 'this clears the message buffer! switches=sw.GetWholeState() sleep(20) 'THIS LINE IS REQUIRED OR THE GetWholeState() function returns a zero after the first read if switches=last_switches then return rem ? "Switch Input=";switches last_switches=switches new_switches=1 'we have a new switch selected or released SW0=switches and 1 SW1=switches and 2 SW2=switches and 4 SW3=switches and 8 SW4=switches and 16 SW5=switches and 32 SW6=switches and 64 SW7=switches and 128 SW8=switches and 256 SW9=switches and 512 SW10=switches and 1024 SW11=switches and 2048 return clear_flash: sw.SetWholeState(0) 'all outputs off (low) sw.SetWholeState(2^21+2^22) 'set both control pins high for record mode (HMS GPIO board) sw.SetWholeState(0^21+2^22) 'set OUT_4 low (Latch in the low order bits [Roku bits 0-3]) sw.SetWholeState(2^21+2^22) 'set OUT_4 high (stay in record mode) sw.SetWholeState(2^21+0^22) 'set OUT_5 low (Latch in the high order bits [Roku bits 0-3]) sw.SetOutputState(21,0) 'exit record mode when both OUT_4 and OUT_5 are low. return clear_outputs: sw.SetWholeState(0) 'all outputs off sw.SetOutputState(21,1) 'OUT_4 high (transparent to Outputs 0-3 while high) sw.SetOutputState(21,0) 'OUT_4 low (latch the state of the bits [Roku bits 0-3] to Outputs 0-3) sw.SetOutputState(22,1) 'OUT_5 high (transparent to Outputs 4-7 while high) sw.SetOutputState(22,0) 'OUT_5 low (latch the state of the bits [Roku bits 0-3] to Outputs 4-7) return 'the values of FLASH_0-FLASH_7 have to be 0 (zero) or 2 prior to this call set_flash: sw.SetWholeState(2^21+2^22) 'set both control pins high for record mode sleep(1) sw.SetWholeState(FLASH_0^17+FLASH_1^18+FLASH_2^19+FLASH_3^20+2^21+2^22) 'set the bits as defined by 4 lower flash definitions sleep(1) rem and keep control pins high sw.SetOutputState(21,0) 'latch in the flash bits [Roku bits 0-3] to the flash latch on GPIO board sleep(1) sw.SetOutputState(21,1) 'stay in record mode for the high order bit recording sleep(1) sw.SetWholeState(FLASH_4^17+FLASH_5^18+FLASH_6+19+FLASH_7^20+2^21+2^22) 'set the bits as defined by the 4 upper flash definitions rem and keep both control pins high sleep(1) sw.SetOutputState(22,0) 'latch in the high order flash bits [Roku bits 0-3] to the flash latch on the GPIO board. sleep(1) sw.SetOutputState(21,0) 'set OUT_4 low to exit record mode (exits record mode when both OUT_4 and OUT_5 are low. return 'this routine outputs the LEDn to the GPIO board 'prior to calling this routine, it is assumed that both ROKU_OUT4 and Roku_OUT5 are low!! 'values for OUT_0 thru OUT_7 have to be 0 (zero) or 2 for this routine to work! set_outputs: sw.SetWholeState(OUT_0^17+OUT_1^18+OUT_2^19+OUT_3^20+0^21+0^22) 'set the bits as defined by OUT_0-OUT_3 (LEAVE ID BITS 21,22 LOW) sw.SetOutputState(21,1) 'Roku_OUT_4 (low order latch control bit is high) Note: while high the output latch is 'transparent' sleep(1) 'This wait state is required by the HMS Roku_GPIO interface sw.SetOutputState(21,0) 'Roku_OUT_4 is low, the state of the ROKU bits 0-3) is latched in as the low order bits for Outputs 0-3 sleep(1) sw.SetWholeState(OUT_4^17+OUT_5^18+OUT_6^19+OUT_7^20+0^21+0^22) 'set the bits as defined by OUT_4-OUT_7, LEAVE BOTH CONTROL BITS LOW sw.SetOutputState(22,1) 'Roku OUT_5 (high order latch control bit is high) Note: while high the output latch is 'transparent' sleep(1) 'this wait state ensures that the HMS GPIO board processes the latch bit sw.SetOutputState(22,0) 'Roku OUT_5 is low, the state of the Roku Bits 0-3 are latched in as the high order bits for Outputs 4-7 return mode0: gosub get_switches if new_switches=0 then mode0 if SW10=0 then goto main new_switches=0 if sw0=0 then sw.SetOutputState(17,0) 'LED0=off else sw.SetOutputState(17,1) 'LED0=on endif if sw1=0 then sw.SetOutputState(18,0) 'LED1=off else sw.SetOutputState(18,1) 'LED1=on endif if sw2=0 then sw.SetOutputState(19,0) 'LED2=off else sw.SetOutputState(19,1) 'LED2=on endif if sw3=0 then sw.SetOutputState(20,0) 'LED3=off else sw.SetOutputState(20,1) 'LED3=on endif if sw4=0 then sw.SetOutputState(21,0) 'LED4=off else sw.SetOutputState(21,1) 'LED4=on endif if sw5=0 then sw.SetOutputState(22,0) 'LED5=off else sw.SetOutputState(22,1) 'LED5=on endif goto mode0