- Merged with upstream version
[rtl-433.git] / src / devices / leak.c
diff --git a/src/devices/leak.c b/src/devices/leak.c
new file mode 100644 (file)
index 0000000..e656be0
--- /dev/null
@@ -0,0 +1,52 @@
+#include "rtl_433.h"
+
+int leak_callback(uint8_t bb[BITBUF_ROWS][BITBUF_COLS], int16_t bits_per_row[BITBUF_ROWS]) {
+    int i,j,k;
+    int rows_used[BITBUF_ROWS];
+    int col_max = 0;
+    int row_cnt = 0;
+
+    // determine what part of bb[][] has non-zero data to avoid
+    // outputting lots of empty rows 
+    for (i=0 ; i<BITBUF_ROWS ; i++) {
+        for (j=BITBUF_COLS - 1 ; j > 0 ; j--) {
+            if (bb[i][j] != 0)
+                break;
+        }
+        if (j != 0) {
+            rows_used[i] = 1;
+            row_cnt++;
+            if (j > col_max)
+                col_max = j;
+        } else {
+            rows_used[i] = 0;
+        }
+    }
+
+    if (row_cnt != 1) {
+        return 0;
+    }
+
+    if (col_max !=3) {
+       return 0;
+    }
+
+    if ((bb[0][0] == 0x76) || (bb[0][0] == 0x77)) {
+
+       fprintf(stdout,"ALARM:TYPE=LEAK,ID=%2X%2X%2X%2X\n",bb[0][0],bb[0][1],bb[0][2],bb[0][3]);
+
+    }
+
+    return 1;
+
+}
+
+r_device leak = {
+    /* .id             = */ 20,
+    /* .name           = */ "Leak sensor",
+    /* .modulation     = */ OOK_MANCHESTER,
+    /* .short_limit    = */ 150,
+    /* .long_limit     = */ 0, 
+    /* .reset_limit    = */ 1000,
+    /* .json_callback  = */ &leak_callback,
+};