1 /* Doorbell implementation for Elro DB286A devices
 
   3  * Note that each device seems to have two codes, which alternate
 
   4  * for every other button press.
 
   6  * Example code: 37f62a6c80
 
   8  * Copyright (C) 2016 Fabian Zaremba <fabian@youremail.eu>
 
   9  * This program is free software; you can redistribute it and/or modify
 
  10  * it under the terms of the GNU General Public License as published by
 
  11  * the Free Software Foundation; either version 2 of the License, or
 
  12  * (at your option) any later version.
 
  16 #include "pulse_demod.h"
 
  20 //33 pulses per data pattern
 
  21 #define DB286A_PULSECOUNT               33
 
  22 //5*8 = 40 bits, 7 trailing zero bits are encoded, too
 
  23 #define DB286A_CODEBYTES                5
 
  24 //Hex character count for code:
 
  25 //(DB286A_CODEBYTES*8)/4 (8 bits per byte, 4 bits per hex character)
 
  26 #define DB286A_CODECHARS                DB286A_CODEBYTES*2
 
  27 //Minimum data pattern repetitions (14 is maximum)
 
  28 #define DB286A_MINPATTERN               5
 
  30 static int doorbell_db286a_callback(bitbuffer_t *bitbuffer) {
 
  32         char time_str[LOCAL_TIME_BUFLEN];
 
  34         bitrow_t *bb = bitbuffer->bb;
 
  36         unsigned bits = bitbuffer->bits_per_row[1];
 
  38         char id_string[DB286A_CODECHARS+1];
 
  39         char *idsp = id_string;
 
  43         if (bits != DB286A_PULSECOUNT) {
 
  47         if (count_repeats(bitbuffer, 1) < DB286A_MINPATTERN) {
 
  51         //Get hex string representation of code pattern
 
  52         for (i = 0; i <= DB286A_CODEBYTES; i++) {
 
  53             idsp += sprintf(idsp, "%02x", b[i]);        
 
  55         id_string[DB286A_CODECHARS] = '\0';
 
  57         local_time_str(0, time_str);
 
  60                                 "time",                 "",             DATA_STRING, time_str,
 
  61                                 "model",                "",             DATA_STRING, "Elro DB286A",
 
  62                                 "code",                 "Code", DATA_STRING, id_string,
 
  65         data_acquired_handler(data);
 
  71 static char *output_fields[] = {
 
  78 r_device elro_db286a = {
 
  79         .name                   = "Elro DB286A Doorbell",
 
  80         .modulation     = OOK_PULSE_PWM_RAW,
 
  83         .reset_limit    = 2000*4,
 
  84         .json_callback  = &doorbell_db286a_callback,
 
  86     .fields         = output_fields