]> the.earth.li Git - energenie-attiny.git/commitdiff
Add a wait before sending via the 433MHz transmitter
authorJonathan McDowell <noodles@earth.li>
Tue, 29 May 2018 06:32:09 +0000 (07:32 +0100)
committerJonathan McDowell <noodles@earth.li>
Tue, 29 May 2018 06:32:09 +0000 (07:32 +0100)
Rather than immediately entering the lengthy (24ms+) loop to send a
command allow a number of calls to usbPoll() to complete first. This
allows the usbrelay control program to successfully receive a response
to its hid_write() call before we stop responding to USB for a bit.

main.c

diff --git a/main.c b/main.c
index d6a5095cc45f1a9e295d62f22f4a3d43cedb7215..d5bf590ee49d42f92bc2c35bcfe9b9a0ccfdc5e7 100644 (file)
--- a/main.c
+++ b/main.c
@@ -40,7 +40,7 @@
 uchar serno_read = 0;
 uchar serno[6];
 unsigned long cmd = 0;
-int repeat = 0;
+int repeat = 0, wait = 0;
 
 PROGMEM const char usbHidReportDescriptor[22] = {
        0x06, 0x00, 0xff,               /* USAGE PAGE (Generic Desktop) */
@@ -126,11 +126,14 @@ uchar usbFunctionWrite(uchar *data, uchar len)
 {
        if (data[0] == CMD_ALL_ON) {
                cmd = ENER_ADDR | 0xd;
+               wait = 200;
                repeat = 5;
        } else if (data[0] == CMD_ALL_OFF) {
                cmd = ENER_ADDR | 0xc;
+               wait = 10;
                repeat = 5;
        } else if (data[0] == CMD_ON) {
+               wait = 200;
                switch (data[1]) {
                case 1:
                        cmd = ENER_ADDR | 0xf;
@@ -152,6 +155,7 @@ uchar usbFunctionWrite(uchar *data, uchar len)
                        break;
                }
        } else if (data[0] == CMD_OFF) {
+               wait = 200;
                switch (data[1]) {
                case 1:
                        cmd = ENER_ADDR | 0xe;
@@ -241,9 +245,13 @@ int __attribute__((noreturn)) main(void)
                wdt_reset();
                usbPoll();
                if (cmd) {
-                       t433_send(cmd, 24);
-                       if (--repeat == 0)
-                               cmd = 0;
+                       if (wait) {
+                               wait--;
+                       } else {
+                               t433_send(cmd, 24);
+                               if (--repeat == 0)
+                                       cmd = 0;
+                       }
                }
        }
 }