1 /** @file
2     Generic remote Blyss DC5-UK-WH as sold by B&Q.
3 
4     Copyright (C) 2016 John Jore
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 Generic remote Blyss DC5-UK-WH as sold by B&Q.
13 
14 DC5-UK-WH pair with receivers, the codes used may be specific to a receiver - use with caution
15 
16 warmup pulse 5552 us, 2072 gap
17 short is 512 us pulse, 1484 us gap
18 long is 1508 us pulse, 488 us gap
19 packet gap is 6964 us
20 
21 */
22 #include "decoder.h"
23 
blyss_callback(r_device * decoder,bitbuffer_t * bitbuffer)24 static int blyss_callback(r_device *decoder, bitbuffer_t *bitbuffer)
25 {
26     data_t *data;
27     uint8_t *b;
28     char id_str[16];
29 
30     for (int i = 0; i < bitbuffer->num_rows; ++i) {
31         if (bitbuffer->bits_per_row[i] != 33) // last row is 32
32             continue; // DECODE_ABORT_LENGTH
33 
34         b = bitbuffer->bb[i];
35 
36         //This needs additional validation, but works on mine. Suspect each DC5-UK-WH uses different codes as the transmitter
37         //is paired to the receivers to avoid being triggered by the neighbours transmitter ?!?
38         // TODO: cleaner implementation with 2 preamble arrays
39         if (((b[0] != 0xce) || (b[1] != 0x8e) || (b[2] != 0x2a) || (b[3] != 0x6c) || (b[4] != 0x80)) &&
40                 ((b[0] != 0xe7) || (b[1] != 0x37) || (b[2] != 0x7a) || (b[3] != 0x2c) || (b[4] != 0x80)))
41             continue; // DECODE_ABORT_EARLY
42 
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, "Blyss-DC5ukwh",
47                 "id",       "", DATA_STRING, id_str,
48                 NULL);
49         decoder_output_data(decoder, data);
50 
51         return 1;
52     }
53 
54     return DECODE_FAIL_SANITY;
55 }
56 
57 static char *output_fields[] = {
58     "model",
59     "id",
60     NULL
61 };
62 
63 r_device blyss = {
64     .name           = "Blyss DC5-UK-WH",
65     .modulation     = OOK_PULSE_PWM,
66     .short_width    = 500,
67     .long_width     = 1500,
68     .gap_limit      = 2500,
69     .reset_limit    = 8000,
70     .decode_fn      = &blyss_callback,
71     .disabled       = 0,
72     .fields         = output_fields,
73 };
74