Bugfixes
[rtl-433.git] / src / devices / lelux.c
1 /* Lelux alarm sensors
2  *
3  * Tested devices:
4  * 616PR
5  * EV1527
6  *
7  * Copyright (C) 2015 Tommy Vestermark
8  * Copyright (C) 2015 nebman
9  * COpyringt (C) 2016 Roman Bazalevskiy
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  */
15 #include "rtl_433.h"
16 #include "pulse_demod.h"
17 #include "data.h"
18 #include "util.h"
19
20 static int lelux_callback(bitbuffer_t *bitbuffer) {
21         bitrow_t *bb = bitbuffer->bb;
22         uint8_t *b = bb[0];
23         data_t *data;
24         char time_str[LOCAL_TIME_BUFLEN];
25
26         if (bitbuffer->num_rows != 1) return 0;
27
28         unsigned bits = bitbuffer->bits_per_row[0];
29
30         // Validate package
31         if (bits == 32) {
32
33                 uint32_t FULL = b[0] << 24 | b[1] << 16 | b[2] << 8 | b[3];
34                 char id_buf[16];
35                 snprintf(id_buf,15,"%08x",FULL);
36
37                 local_time_str(0, time_str);
38
39                 data = data_make(
40                         "time",         "",             DATA_STRING, time_str,
41                         "model",        "",             DATA_STRING, "Lelux PIR",
42                         "id",           "House Code",   DATA_STRING, id_buf,
43                         "command",      "",             DATA_STRING, "PIR",
44                       NULL);
45
46                 data_acquired_handler(data);
47
48                 return 1;
49         }
50         return 0;
51 }
52
53
54 r_device lelux = {
55         .name           = "Lelux PIR sensor",
56         .modulation    = OOK_PULSE_PPM_RAW,
57         .short_limit   = 1000,
58         .long_limit    = 1600,
59         .reset_limit   = 4000,
60         .json_callback  = &lelux_callback,
61         .disabled       = 0,
62         .demod_arg      = 0
63 };