- Merged with upstream version
[rtl-433.git] / src / devices / waveman.c
diff --git a/src/devices/waveman.c b/src/devices/waveman.c
new file mode 100644 (file)
index 0000000..6ac2dca
--- /dev/null
@@ -0,0 +1,39 @@
+#include "rtl_433.h"
+
+static int waveman_callback(uint8_t bb[BITBUF_ROWS][BITBUF_COLS],int16_t bits_per_row[BITBUF_ROWS]) {
+    /* Two bits map to 2 states, 0 1 -> 0 and 1 1 -> 1 */
+    int i;
+    uint8_t nb[3] = {0};
+
+    if (((bb[0][0]&0x55)==0x55) && ((bb[0][1]&0x55)==0x55) && ((bb[0][2]&0x55)==0x55) && ((bb[0][3]&0x55)==0x00)) {
+        for (i=0 ; i<3 ; i++) {
+            nb[i] |= ((bb[0][i]&0xC0)==0xC0) ? 0x00 : 0x01;
+            nb[i] |= ((bb[0][i]&0x30)==0x30) ? 0x00 : 0x02;
+            nb[i] |= ((bb[0][i]&0x0C)==0x0C) ? 0x00 : 0x04;
+            nb[i] |= ((bb[0][i]&0x03)==0x03) ? 0x00 : 0x08;
+        }
+
+        fprintf(stdout, "BUTTON:TYPE=WAVEMAN,");
+        fprintf(stdout, "ID= %c,", 'A'+nb[0]);
+        fprintf(stdout, "CHANNEL=%d,", (nb[1]>>2)+1);
+        fprintf(stdout, "PRESSED=%d,", (nb[1]&3)+1);
+        fprintf(stdout, "STATE=%s\n", (nb[2]==0xe) ? "on" : "off");
+        fprintf(stderr, "%02x %02x %02x\n",nb[0],nb[1],nb[2]);
+
+        if (debug_output)
+            debug_callback(bb, bits_per_row);
+
+        return 1;
+    }
+    return 0;
+}
+
+r_device waveman = {
+    /* .id             = */ 6,
+    /* .name           = */ "Waveman Switch Transmitter",
+    /* .modulation     = */ OOK_PWM_P,
+    /* .short_limit    = */ 1000/4,
+    /* .long_limit     = */ 8000/4,
+    /* .reset_limit    = */ 30000/4,
+    /* .json_callback  = */ &waveman_callback,
+};