10 'XONOFF.BA House control using X10 11 'Revised: 1/13/04 12 '(C) 05/01/2003 R. H. Pigford 13 'Take House Code and Unit no input 14 'Then take ON/OFF input 15 'Then execute command string strings to FireCracker 30 ' 35 ' 40 E$=CHR$(27):I$=E$+"p":J$=E$+"q" 50 GOSUB2000 :'reset FireCracker 100 CLS:PRINTI$+"===== XONOFF.BA (c) R. H. Pigford ===="+J$;:PRINT@280,I$+"X-10 with Firecracker";:PRINT@308,"ESC"+J$+" to Quit"; 115 PRINT@40,"";:INPUT"HOME Code (A-P) ";HC$ 116 IFHC$>"P" OR HC$<"A" THEN BEEP:GOTO115 118 PRINT@80,"";:INPUT"UNIT number (1-16)";HN$ 120 IF VAL(HN$)>16 OR VAL(HN$)<1 THEN BEEP:GOTO 118 124 PRINT@120,"";:INPUT"N = on, F = off ";HA$ 126 IF HA$<>"N" THEN IF HA$<>"F" THEN BEEP:GOTO124 128 AD$=HC$+HN$+HA$:PRINT@186,AD$ 130 PRINT@160,"Hit ENTER to Execute --->" 134 ' 200 A$=INKEY$:IF A$=""THEN 200 210 IF A$=CHR$(13)THEN GOTO250 224 IFA$=CHR$(27)THENMENU 250 SELECT$=AD$:GOSUB1000:AD$="":GOTO 100 996 '======================= 997 ' 1000 B1=INSTR(LOOKUP$,LEFT$(SELECT$,1)) 1010 IF B1=0 THEN PRINT "Error":RETURN 1015 ' 1016 'Get ACTion byte from end 1017 ' 1020 ACT$=RIGHT$(SELECT$,1) 1025 ' 1026 'Calculate Byte 1 (B1) 1027 ' 1030 B1=(B1-1) * 16 1040 IF ACT$="D" THEN 1200 1050 IF ACT$="B" THEN 1250 1060 NUM=VAL(RIGHT$(SELECT$,LEN(SELECT$)-1))-1 1070 IF NUM > 7 THEN B1=B1+4 1075 ' 1076 'Calculate Byte 2 (B2) 1077 ' 1080 B2=(NUM AND 1) * 16 1090 B2=B2 OR ((NUM AND 2) * 4) 1100 B2=B2 OR ((NUM AND 4) * 16) 1110 IF ACT$="F" THEN B2=B2 OR 32 1115 ' 1116 'Now go send the command 1117 ' 1120 GOTO 1300 :' Skip DIM & BRIGHT 1125 ' 1200 B2 = 152 :' DIM Command. Set B2 1210 GOTO 1300 :' Go send command 1250 B2 = 136 :' BRIGHT Command. Set B2 1290 ' 1291 'Send 5 Bytes below as follows: 1292 '2 Header, 2 Data, 1 Footer 1293 ' 1300 TX=213 :' First Header Byte 1310 GOSUB 1500 1320 TX=170 :' Second Header Byte 1330 GOSUB 1500 1340 TX=B1 :' First Data Byte 1350 GOSUB 1500 1360 TX=B2 :' Second Data Byte 1370 GOSUB 1500 1380 TX=173 :' Footer Byte 1390 GOSUB 1500 1391 ' 1392 '======================== 1393 'End of Subroutine 1 1394 '======================== 1400 RETURN 1490 ' 1491 '================================= 1492 ' Sub 2 - Write single byte (TX) 1493 ' (called by Sub 1) 1494 ' 1495 ' Write TX to FireCracker using 1496 ' RTS and DTR signals, MSB first 1497 '================================= 1498 ' 1500 IF SHOWTX$="Y" THEN 1501 ELSE 1510 1501 FOR X = 7 TO 0 STEP -1 1502 IF TX AND (2^X) THEN PRINT "1"; ELSE PRINT "0"; 1503 NEXT X 1504 PRINT " " 1506 ' 1510 P1=INP(186) :' Read PortB of 8155 1520 P1=P1 AND 247:' Clear BIT 3 1530 OUT 186, P1 :' Select RS-232 Port 1535 ' 1536 'Loop through bits starting with 1537 'the Most Significant bit 1538 ' 1540 FOR X = 7 TO 0 STEP -1 1550 IF TX AND (2^X) THEN 1600 1555 ' 1556 ' Bit is a zero - send it out 1557 ' 1560 OUT 186, P1 OR 128 :'Send a "0" 1570 OUT 186, P1 AND 127 :'Back to idle 1580 GOTO 1620 :' Skip sending a "1" 1585 ' 1586 'Bit is a one - send it out 1587 ' 1600 OUT 186, P1 OR 64 :' Send a "1" 1610 OUT 186, P1 AND 191 :' Back to idle 1615 ' 1620 NEXT X 1624 ' 1625 '========================== 1626 'End of Subroutine 2 1627 '========================== 1630 RETURN 1670 ' 1990 '================================= 1991 ' Sub 3 - FireCracker Reset 1992 ' 1993 ' Call this routine first! 1994 '================================= 1995 ' 2000 P1=INP(186) :' Read PortB of 8155 2010 P1=P1 AND 247:' Clear BIT 3 2020 OUT 186, P1 :' Select RS-232 Port 2025 ' 2026 ' Set both RTS and DTR to zero 2027 ' 2030 OUT 186, P1 OR 128 :'Set RTS low 2040 OUT 186, P1 OR 64 :'Set DTR low 2050 FOR X=1 TO 10:NEXT X:'Small Delay 2055 ' 2056 ' Set both RTS and DTR to one 2057 ' 2060 OUT 186, P1 AND 63 :'Back to idle 2065 ' 2066 ' Set LOOKUP variable for later 2067 ' 2070 LOOKUP$="MNOPCDABEFGHKLIJ" 2074 ' 2075 '========================= 2076 'End of Subroutine 3 2077 '========================= 2080 RETURN 3000 PRINT:PRINT"*** Communications Error ***" 3010 END 4000 END:MENU