10 'XHOME.BA House control using X10 11 'Revised: 5/7/03 12 '(C) 05/01/2003 R. H. Pigford 14 'Read X-10 command data file (1 file 15 'in RAM for each day of the week). 16 'Data file format ex: X-WED.DO 17 'Compare to day and time. 18 'Send Command strings to FireCracker 19 CLEAR500 25 POWER CONT 30 DIM D$(10),N$(10),AD$(10),D1$(10),T1$(10),D2$(10),T2$(10) 35 Z=1 40 N=0 'allows header in X-DAY.DO files 50 GOSUB2000 :'reset FireCracker 100 CLS:PRINT"XHOME.BA (c) R.H.Pigford ":PRINT@308,"ESC to Quit"; 110 GOSUB 500 115 PRINT@40,"____Name_____ Adr ___On____ ___Off___"; 200 '====Begin main XHOME.BA loop ===== 210 IFLEFT$(TIME$,5)="00:00"THENN=0:GOSUB500:' switch to next day's file & data 220 PRINT@27,DAY$+" "+TIME$; 222 A$=INKEY$:IFA$<>""THEN224ELSEGOTO225 224 IFA$=CHR$(27)THENMENU 225 IF D1$(Z)=DAY$ THEN 230 ELSE 300 230 IF T1$(Z)=LEFT$(TIME$,5) THEN 250 ELSE 300 250 SELECT$=AD$(Z)+"N":GOSUB1000:GOTO 400:'turn it on 300 IF D2$(Z)=DAY$ THEN 330 ELSE 400 330 IF T2$(Z)=LEFT$(TIME$,5) THEN 350 ELSE 400 350 SELECT$=AD$(Z)+"F":GOSUB1000:GOTO400:'turn it off 400 '==== screen riffle ====== 410 D1$=N$(Z)+" "+AD$(Z)+" "+D1$(Z)+" "+T1$(Z)+" "+D2$(Z)+" "+T2$(Z) 420 'Q=Q+1:IFQ=5THENQ=1 430 PRINT@80,D1$ 435 PRINT@120,D2$ 440 PRINT@160,D3$ 450 PRINT@200,D4$ 455 PRINT@240,D5$ 460 D5$=D4$:D4$=D3$:D3$=D2$:D2$=D1$ 480 Z=Z+1:IFZ=N+1 THEN Z=1 490 GOTO 200 :'loop over and over again 500 '===== get data from XDATA.DO ===== 505 FN$="X-"+DAY$+".DO" 520 OPEN FN$ FOR INPUT AS #1 530 INPUT #1,N$(N),AD$(N),D1$(N),T1$(N),D2$(N),T2$(N) :'data set counter 540 IF EOF(1) THEN GOTO 590 550 N=N+1:GOTO530 590 CLOSE 1:RETURN 996 '======================= 997 ' The following code is by Ken Pettit 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