1 /** @file
2     Generic doorbell implementation for Elro DB286A devices.
3 
4     Copyright (C) 2016 Fabian Zaremba <fabian@youremail.eu>
5 
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 
11 */
12 /**
13 Generic doorbell implementation for Elro DB286A devices.
14 
15 Note that each device seems to have two codes, which alternate
16 for every other button press.
17 
18 short is 456 us pulse, 1540 us gap
19 long is 1448 us pulse, 544 us gap
20 packet gap is 7016 us
21 
22 Example code: 37f62a6c80
23 */
24 
25 
26 #include "decoder.h"
27 
elro_db286a_callback(r_device * decoder,bitbuffer_t * bitbuffer)28 static int elro_db286a_callback(r_device *decoder, bitbuffer_t *bitbuffer)
29 {
30     data_t *data;
31     uint8_t *b;
32     char id_str[4*2+1];
33 
34     // 33 bits expected, 5 minimum packet repetitions (14 expected)
35     int row = bitbuffer_find_repeated_row(bitbuffer, 5, 33);
36 
37     if (row < 0 || bitbuffer->bits_per_row[row] != 33)
38         return DECODE_ABORT_LENGTH;
39 
40     b = bitbuffer->bb[row];
41 
42     // 32 bits, trailing bit is dropped
43     sprintf(id_str, "%02x%02x%02x%02x", b[0], b[1], b[2], b[3]);
44 
45     data = data_make(
46             "model",    "",        DATA_STRING, "Elro-DB286A",
47             "id",       "ID",      DATA_STRING, id_str,
48             NULL);
49 
50     decoder_output_data(decoder, data);
51 
52     return 1;
53 
54 }
55 
56 static char *output_fields[] = {
57     "model",
58     "id",
59     NULL
60 };
61 
62 r_device elro_db286a = {
63     .name           = "Elro DB286A Doorbell",
64     .modulation     = OOK_PULSE_PWM,
65     .short_width    = 456,
66     .long_width     = 1448,
67     .gap_limit      = 2000,
68     .reset_limit    = 8000,
69     .decode_fn      = &elro_db286a_callback,
70     .disabled       = 1,
71     .fields         = output_fields
72 };
73