From af@kilomonkey.com  Tue Jun 26 17:44:50 2001
Received: from spare12.tanj.com (root@spare12.tanj.com [192.168.2.12])
	by joey.tanj.com (8.9.3/8.9.1) with ESMTP id RAA01183
	for <dbs@joey.tanj.com>; Tue, 26 Jun 2001 17:44:46 -0700
Received: from mail.master.net (adsl-64-171-147-2.dsl.scrm01.pacbell.net [64.171.147.2])
	by spare12.tanj.com (8.11.4/8.11.4) with SMTP id f5R0gwa01868
	for <dbs@tanj.com>; Tue, 26 Jun 2001 17:43:02 -0700
Received: (qmail 3204 invoked from network); 27 Jun 2001 00:44:23 -0000
Received: from dal.flin.org (HELO kilomonkey.com) (aaron@64.171.147.5)
  by gate.flin.org with SMTP; 27 Jun 2001 00:44:23 -0000
Sender: aaron@tanj.com
Message-ID: <3B392C66.5504BCE5@kilomonkey.com>
Date: Tue, 26 Jun 2001 17:44:22 -0700
From: Aaron Flin <af@kilomonkey.com>
X-Mailer: Mozilla 4.76 [en] (X11; U; Linux 2.4.2 i686)
X-Accept-Language: en
MIME-Version: 1.0
To: dbs@tanj.com
Subject: Heyu User
Content-Type: multipart/mixed;
 boundary="------------50DD688524EC5CEAC5929F38"
Status: RO

This is a multi-part message in MIME format.
--------------50DD688524EC5CEAC5929F38
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

About your HEYU software...

Here is a patch, if your are interested, which allows extended dimming
control (for my Leviton light switches).  Its just a simple modification
of the preset.c code.  Its only been tested on one house code ('o') and
I'm not a C programmer so here's hoping it works!

Thanks for the software,

Aaron
--------------50DD688524EC5CEAC5929F38
Content-Type: text/plain; charset=us-ascii;
 name="patch.heyu"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="patch.heyu"

diff -u heyu.dir.org/Makefile.in heyu.dir/Makefile.in
--- heyu.dir.org/Makefile.in	Sat Feb 10 11:52:21 2001
+++ heyu.dir/Makefile.in	Tue Jun 26 15:26:47 2001
@@ -5,12 +5,12 @@
 SRCS =	date.c erase.c info.c  message.c relay.c \
 	monitor.c reset.c setclock.c stop.c \
 	tty.c turn.c x10.c xread.c xwrite.c status.c cm11a.c \
-	eeprom.c preset.c parse_sched.c
+	eeprom.c preset.c extpreset.c parse_sched.c
 
 OBJS =	date.o erase.o info.o message.o relay.o \
 	monitor.o reset.o setclock.o stop.o \
 	tty.o turn.o x10.o xread.o xwrite.o status.o cm11a.o \
-	eeprom.o preset.o parse_sched.o
+	eeprom.o preset.o extpreset.o parse_sched.o
 
 OTHERSRC = README Makefile x10config protocol.txt eeprom.h \
 	x10sched.conf.sample  monit x10biff heyu.1 x10.h x10config.5 \
diff -u heyu.dir.org/extpreset.c heyu.dir/extpreset.c
--- heyu.dir.org/extpreset.c	Tue Jun 26 17:02:25 2001
+++ heyu.dir/extpreset.c	Tue Jun 26 15:44:53 2001
@@ -0,0 +1,205 @@
+/*
+ * Copyright 1996, 1997, 1998, 1999 by Daniel B. Suthers,
+ * Pleasanton Ca. 94588 USA
+ * E-MAIL dbs@tanj.com
+ *
+ * You may freely copy, use, and distribute this software,
+ * in whole or in part, subject to the following restrictions:
+ *
+ *  1)  You may not charge money for it.
+ *  2)  You may not remove or alter this copyright notice.
+ *  3)  You may not claim you wrote it.
+ *  4)  If you make improvements (or other changes), you are requested
+ *      to send them to me, so there's a focal point for distributing
+ *      improved versions.
+ *
+ * Preset code donated by Gregory Gulik (greg@gagme.com)
+ * Altered for extended code presets by Aaron Flin (aaron@flin.org)
+ */
+
+#include <stdio.h>
+#include <ctype.h>
+#include "x10.h"
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+extern int tty;
+extern int sptty;
+extern int verbose;
+extern unsigned char cm11map[];
+
+extern int usage(), dimstate(), xwrite(), chksum(), exread(), check4poll();
+extern int c_turn();
+extern void parse_unit();
+extern unsigned int getunits();
+
+
+
+
+int c_extpreset(argc, argv)
+char *argv[];
+{
+    register int n;
+    unsigned int hcode, unit, unitx10, bits;
+    char *unitnums;
+    unsigned sum;
+    int timeout;
+    static int numtries = 0;
+    unsigned char buf[16], function=0;
+    unsigned int extpreset=0;
+
+    char RCSID[]= "@(#) $Id: extpreset.c,v 1.5 1999/12/13 21:12:10 dbs Exp dbs $\n";
+
+    display(RCSID);
+
+
+    timeout = 10;
+
+    if (argc != 4)
+	    usage(E_WNA);
+
+	
+    if( argc > 2)
+	parse_unit(argv[2],&hcode,&unitnums);
+
+    /* What is our extpreset value?  It should be in argv[3] */
+    extpreset = atoi(argv[3]);
+    /* if (extpreset < 1 || extpreset > 64 ) { */
+    if (extpreset < 0 || extpreset > 64 ) {
+	fprintf(stderr, "Invalid extpreset number: %s\n", argv[3]);
+	fprintf(stderr, "The extpreset value must be an integer range 1-64.\n");
+	return(-1);
+    }
+
+    bits = getunits(unitnums);
+    unit = atoi(unitnums);
+
+    /* We want to go ahead and send the address command just
+       just any other command   */
+
+    /* Header */
+    buf[0] = 0x04;	/* sync bit in header for address */
+
+    /* Address */
+    /* hcodex10 = cm11map[hcode - 1]; */
+    unitx10 = cm11map[unit - 1];
+    buf[1] = (hcode << 4 ) | unitx10 ;	/* code and unit */
+
+
+    /* Write the address header */
+
+    (void) xwrite(tty, (char *) buf, 2);
+    if( verbose )
+	fprintf(stderr, "Sending header %0x %0x\n", buf[0], buf[1]); 
+
+    /* get a check sum in reply */
+    sum=chksum(buf,2) ;
+    n = exread(sptty, buf, 1, timeout);
+    if( sum == buf[0]) 
+    {
+	    (void) xwrite(tty, "\00" , 1);	/* WRMI (we really mean it) */
+    }
+    else
+    {
+	    if( ++numtries < 3 )
+	        return(c_extpreset(argc, argv) );
+	    fprintf(stderr, "Failure sending address header\n");
+	    return(-1);
+    }
+
+    /*
+     * Now we wait for the CM11A to send us the ready code before
+     * we send the rest of the command.
+     */
+
+    buf[0] = 0;
+    n = exread(sptty, buf, 1, timeout);
+    if( n == 1 )
+        if(buf[0] != 0x55 )
+	{
+	    if(buf[0] == 0x5a )
+		if( ++numtries < 3 )
+		{
+		    sleep(1);
+		    return(c_turn(argc, argv) );
+		}
+	    fprintf(stderr, "Ack after execution = %0x, It should be 0x55)\n",
+	            buf[0]);
+	    n = 0;
+	}
+    if(n != 1)
+    {
+	if( ++numtries < 3 )
+	    return(c_turn(argc, argv) );
+	fprintf(stderr,
+	        "Interface not ready after excuting function (buf= %0x)\n",
+		buf[0]);
+	fprintf(stderr, "N = %0x)\n", n);
+        return(-1);
+    }
+
+
+    /* Now we built the extpreset dim function */
+
+    function = 07; /* extended code */
+    buf[0] = function ;	/* different */
+    buf[1] =  function | (hcode << 4) ;
+    buf[2] =  unitx10;
+    buf[3] =  extpreset;
+    buf[4]=  0x31;    /* I have no idea why this goes here */
+    if( verbose )
+	fprintf(stderr, "Sending function %0x %0x %0x %0x %0x\n", buf[0], buf[1],buf[2], buf[3], buf[4]); 
+    (void) xwrite(tty, (char *) buf, 5);
+
+    /* get a check sum in reply */
+    sum=chksum(buf,5);
+    n = exread(sptty, buf, 1, timeout);
+    if( sum == buf[0]) 
+    {
+	(void) xwrite(tty, "\00" , 1);	/* WRMI */
+    }
+    else
+    {
+	if( ++numtries < 3 )
+	{
+	    sleep(1);
+	    return(c_extpreset(argc, argv) );
+	}
+	fprintf(stderr, "failure sending function header sum = %0x,buf= %0x\n",
+	        sum , buf[0]);
+	fprintf(stderr, "N = %0x)\n", n);
+        return(-1);
+    }
+
+    /*
+     * Wait for that darned ready (0x55) command
+     */
+    buf[0] = 0;
+    n = exread(sptty, buf, 1, timeout);
+    if( n == 1 )
+        if(buf[0] != 0x55 )
+	{
+	    if(buf[0] == 0x5a )
+		if( ++numtries < 3 )
+		{
+		    sleep(1);
+		    return(c_turn(argc, argv) );
+		}
+	    fprintf(stderr, "Ack after execution = %0x, It should be 0x55)\n",
+	            buf[0]);
+	    n = 0;
+	}
+    if(n != 1)
+    {
+	if( ++numtries < 3 )
+	    return(c_turn(argc, argv) );
+	fprintf(stderr,
+	        "Interface not ready after excuting function (buf= %0x)\n",
+		buf[0]);
+	fprintf(stderr, "N = %0x)\n", n);
+        return(-1);
+    }
+return(0);
+}
diff -u heyu.dir.org/message.c heyu.dir/message.c
--- heyu.dir.org/message.c	Mon Jan 17 21:15:39 2000
+++ heyu.dir/message.c	Tue Jun 26 15:49:17 2001
@@ -51,6 +51,7 @@
  heyu info                    gets current settings\n\
  heyu monitor                 monitor X10 activity (end with <BREAK>)\n\
  heyu preset ann vv           sets unit to level vv for next dim/bright\n\
+ heyu extpreset ann vv        sets unit to level vv using extended presets\n\
  heyu reset  [housecode]      reset interface to 'A' or specified housecode\n\
  heyu setclock                sets X10 clock to system clock\n\
  heyu status ann[,nn...]      returns status of smart modules (rr501...)\n\
Only in heyu.dir.org: patch.heyu
diff -u heyu.dir.org/x10.c heyu.dir/x10.c
--- heyu.dir.org/x10.c	Sat Apr 21 08:38:22 2001
+++ heyu.dir/x10.c	Tue Jun 26 15:32:41 2001
@@ -116,7 +116,7 @@
 extern int
  c_data(), c_date(), c_delete(), c_diagnostic(), c_dump(), c_fdump(),
  c_finfo(), c_fload(), c_info(), c_monitor(), c_reset(), c_schedule(),
- c_setclock(), c_turn(), c_dbs(), c_stop(), c_erase(), c_preset();
+ c_setclock(), c_turn(), c_dbs(), c_stop(), c_erase(), c_preset(), c_extpreset();
 
 extern int c_load_macro(), c_qerase(), c_list();
 
@@ -135,6 +135,7 @@
     {"macro", c_load_macro,1},
     {"monitor", c_monitor,0},
     {"preset", c_preset,1},
+    {"extpreset", c_extpreset,1},
     {"reset", c_reset,1},
     {"setclock", c_setclock,1},
     {"status", c_turn,1},

--------------50DD688524EC5CEAC5929F38--

