Bugfixes
[rtl-433.git] / src / devices / cardin.c
1 #include "rtl_433.h"
2
3 /*
4  * Cardin S466-TX2 generic garage door remote control on 27.195 Mhz
5  * Remember to set de freq right with -f 27195000
6  * May be usefull for other Cardin product too
7  *
8  * Copyright (C) 2015 Denis Bodor
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13
14 static int cardin_callback(bitbuffer_t *bitbuffer) {
15         bitrow_t *bb = bitbuffer->bb;
16         int i, j, k;
17         unsigned char dip[10] = {'-','-','-','-','-','-','-','-','-', '\0'};
18
19         // validate message as we can
20         if((bb[0][2] & 48) == 0 && bitbuffer->bits_per_row[0] == 24 && (
21                                 (bb[0][2] & 3) == 3 ||
22                                 (bb[0][2] & 9) == 9 ||
23                                 (bb[0][2] & 12) == 12 ||
24                                 (bb[0][2] & 6) == 6) ) {
25
26                 fprintf(stdout, "------------------------------\n");
27                 fprintf(stdout, "protocol       = Cardin S466\n");
28                 fprintf(stdout, "message        = ");
29                 for (i=0 ; i<3 ; i++) {
30                         for (k = 7; k >= 0; k--) {
31                                 if (bb[0][i] & 1 << k)
32                                         fprintf(stdout, "1");
33                                 else
34                                         fprintf(stdout, "0");
35                         }
36                         fprintf(stdout, " ");
37                 }
38                 fprintf(stdout, "\n\n");
39
40                 // Dip 1
41                 if(bb[0][0] & 8) {
42                         dip[0]='o';
43                         if(bb[0][1] & 8)
44                                 dip[0]='+';
45                 }
46                 // Dip 2
47                 if(bb[0][0] & 16) {
48                         dip[1]='o';
49                         if(bb[0][1] & 16)
50                                 dip[1]='+';
51                 }
52                 // Dip 3
53                 if(bb[0][0] & 32) {
54                         dip[2]='o';
55                         if(bb[0][1] & 32)
56                                 dip[2]='+';
57                 }
58                 // Dip 4
59                 if(bb[0][0] & 64) {
60                         dip[3]='o';
61                         if(bb[0][1] & 64)
62                                 dip[3]='+';
63                 }
64                 // Dip 5
65                 if(bb[0][0] & 128) {
66                         dip[4]='o';
67                         if(bb[0][1] & 128)
68                                 dip[4]='+';
69                 }
70                 // Dip 6
71                 if(bb[0][2] & 128) {
72                         dip[5]='o';
73                         if(bb[0][2] & 64)
74                                 dip[5]='+';
75                 }
76                 // Dip 7
77                 if(bb[0][0] & 1) {
78                         dip[6]='o';
79                         if(bb[0][1] & 1)
80                                 dip[6]='+';
81                 }
82                 // Dip 8
83                 if(bb[0][0] & 2) {
84                         dip[7]='o';
85                         if(bb[0][1] & 2)
86                                 dip[7]='+';
87                 }
88                 // Dip 9
89                 if(bb[0][0] & 4) {
90                         dip[8]='o';
91                         if(bb[0][1] & 4)
92                                 dip[8]='+';
93                 }
94
95                 fprintf(stdout, "                 123456789\n");
96                 fprintf(stdout, "dipswitch      = %s\n\n",dip);
97
98                 fprintf(stdout, "                 -->ON\n");
99                 fprintf(stdout, "right button   = ");
100                 if((bb[0][2] & 3) == 3) {
101                         fprintf(stdout,                  "2 --o (this is right button)\n");
102                         fprintf(stdout, "                 1 --o\n");
103                 }
104                 if((bb[0][2] & 9) == 9) {
105                         fprintf(stdout,                  "2 --o (this is right button)\n");
106                         fprintf(stdout, "                 1 o--\n");
107                 }
108                 if((bb[0][2] & 12) == 12) {
109                         fprintf(stdout,                  "2 o-- (this is left button or two buttons on same channel)\n");
110                         fprintf(stdout, "                 1 o--\n");
111                 }
112                 if((bb[0][2] & 6) == 6) {
113                         fprintf(stdout,                  "2 o-- (this is right button)\n");
114                         fprintf(stdout, "                 1 --o\n");
115                 }
116
117                 return 1;
118         }
119         return 0;
120 }
121
122 r_device cardin = {
123     .name           = "Cardin S466-TX2",
124     .modulation     = OOK_PULSE_PPM_RAW,
125     .short_limit    = 1212,
126     .long_limit     = 1600,
127     .reset_limit    = 32000,
128     .json_callback  = &cardin_callback,
129     .disabled       = 1,
130     .demod_arg      = 0,
131 };