Bugfixes
[rtl-433.git] / src / devices / quhwa.c
1 /* Quhwa
2  *
3  * Tested devices:
4  * QH-C-CE-3V (which should be compatible with QH-832AC),
5  * also sold as "1 by One" wireless doorbell
6  *
7  * Copyright (C) 2016 Ask Jakobsen
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  */
13 #include "rtl_433.h"
14 #include "pulse_demod.h"
15 #include "data.h"
16 #include "util.h"
17
18
19 static int quhwa_callback(bitbuffer_t *bitbuffer) {
20         bitrow_t *bb = bitbuffer->bb;
21         uint8_t *b = bb[0];
22             
23         b[0] = ~b[0];
24         b[1] = ~b[1];
25         b[2] = ~b[2];
26         
27         unsigned bits = bitbuffer->bits_per_row[0];
28
29         if ((bits == 18) &&
30             ((b[1] & 0x03) == 0x03) &&
31             ((b[2] & 0xC0) == 0xC0))
32           {
33             uint32_t ID = (b[0] << 8) | b[1];
34             data_t *data;
35
36             char time_str[LOCAL_TIME_BUFLEN];
37             local_time_str(0, time_str);
38             
39             data = data_make("time", "", DATA_STRING, time_str,
40                              "model", "", DATA_STRING, "Quhwa doorbell",
41                              "id", "ID", DATA_INT, ID,
42                              NULL);
43
44             data_acquired_handler(data);
45
46             return 1;
47         }
48         return 0;
49 }
50
51 static char *output_fields[] = {
52   "time",
53   "model",
54   "id",
55   NULL
56 };
57
58
59 PWM_Precise_Parameters pwm_precise_parameters_quhwa = {
60         .pulse_tolerance        = 20,
61         .pulse_sync_width       = 0,    // No sync bit used
62 };
63
64 r_device quhwa = {
65         .name                   = "Quhwa",
66         .modulation             = OOK_PULSE_PWM_PRECISE,
67         .short_limit            = 360,  // Pulse: Short 360µs, Long 1070µs 
68         .long_limit             = 1070, // Gaps: Short 360µs, Long 1070µs 
69         .reset_limit            = 1200, // Intermessage Gap 5200µs 
70         .json_callback          = &quhwa_callback,
71         .disabled               = 0,
72         .demod_arg              = (uintptr_t)&pwm_precise_parameters_quhwa,
73 };