#include "tw523.c" main(int argc, char *argv[]) { char c, *ptr; int i, temp, house, unit; if(argc != 4) /* must be exactly 4 arguments */ { helpmsg(); exit(1); } c = *argv[1]; /* get com or lpt port # */ if((c < '1')||(c > '7')) { printf("\nInvalid Port Number\n\n"); exit(1); } if(tw523ok(c - '1')) /* check for working TW523 */ { printf("\nCannot communicate with TW523\n\n"); exit(1); } ptr = argv[2]; /* point to house/unit */ c = toupper(*ptr++); /* get house # */ if((c < 'A')||(c > 'P')) { printf("\nInvalid House Code\n\n"); exit(1); } house = tbltx[c - 'A']; temp = atoi(ptr); /* get unit # */ if((temp < 1)||(temp > 16)) { printf("\nInvalid Unit Code\n\n"); exit(1); } unit = tbltx[temp - 1]; ptr = argv[3]; /* point to function */ switch(*ptr++) { case '0': /* off */ sendx10(house, unit); /* select device */ sendx10(house, 0x1c); /* perform funtion */ break; case '1': /* on */ sendx10(house, unit); /* select device */ sendx10(house, 0x14); /* perform funtion */ break; case 'i': /* intensity */ case 'I': temp = atoi(ptr); /* get brightness */ if((temp < 1)||(temp > 16)) { printf("\nInvalid Intensity Level\n\n"); exit(1); } sendx10(house, unit); /* select device */ for(i = 0; i < 16; i++) /* go bright */ sendx10(house, 0x1a); for(i = 16; i > temp; i--) /* then dim */ sendx10(house, 0x12); break; default: printf("\nInvalid Function\n\n"); exit(1); } printf("\nX10 Command Sent\n\n"); exit(0); } helpmsg() { printf("\n"); printf("Usage: CMD523 p a f\n\n"); printf(" p - COM(1-4) Enter (1-4)\n"); printf(" - LPT(1-3) Enter (5-7)\n"); printf(" a - House/Unit Address (A1 - P16)\n"); printf(" f - Function: 0 - off\n"); printf(" 1 - on\n"); printf(" i# - intensity (i1 - i16)\n"); printf("\n"); }