5 * Brennenstuhl RCS 2044 remote control on 433.92MHz
7 * Copyright (C) 2015 Paul Ortyl
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 3 as
10 * published by the Free Software Foundation.
14 * Receiver for the "RCS 2044 N Comfort Wireless Controller Set" sold under
15 * the "Brennenstuhl" brand.
17 * The protocol is also implemented for raspi controlled transmitter on 433.92 MHz:
18 * https://github.com/xkonni/raspberry-remote
22 static int brennenstuhl_rcs_2044_process_row(int row, const bitbuffer_t *bitbuffer)
24 const uint8_t *b = bitbuffer->bb[row];
25 const int length = bitbuffer->bits_per_row[row];
26 /* Two bits map to 2 states, 0 1 -> 0 and 1 1 -> 1 */
32 // print raw bit sequence for debug purposes (before exclusion of invalid sequenced is executed)
33 char time_str[LOCAL_TIME_BUFLEN];
34 local_time_str(0, time_str);
35 fprintf(stdout, "%s Brennenstuhl RCS 2044: received RAW bit sequence (%d bits): ", time_str, length);
36 for(int i=0; i<4; i++)
38 for(int p=7; p>=0; p--)
39 fprintf(stdout, "%d", (b[i]>>p ) & 0x1);
42 fprintf(stdout, "\n");
44 fprintf(stdout, "%s Brennenstuhl RCS 2044: received RAW bit sequence (%d bits): ", time_str, length);
45 for(int i=0; i<4; i++)
47 for(int p=7; p>=0; p--)
51 fprintf(stdout, "%d", (b[i]>>p ) & 0x1);
54 fprintf(stdout, "\n");
59 /* Test bit pattern for every second bit being 1 */
61 || (b[0]&0xaa) != 0xaa
62 || (b[1]&0xaa) != 0xaa
63 || (b[2]&0xaa) != 0xaa
65 return 0; /* something is wrong, exit now */
67 #if 0 && !defined(NDEBUG)
69 // print raw bit sequence for debug purposes (before exclusion of invalid sequenced is executed)
70 char time_str[LOCAL_TIME_BUFLEN];
71 local_time_str(0, time_str);
72 fprintf(stdout, "%s Brennenstuhl RCS 2044: received bit sequence: ", time_str);
73 for(int i=0; i<4; i++)
75 for(int p=6; p>=0; p-=2)
76 fprintf(stdout, "%d", (b[i]>>p ) & 0x1);
79 fprintf(stdout, "\n");
83 /* Only odd bits contain information, even bits are set to 1
84 * First 5 odd bits contain system code (the dip switch on the remote),
85 * following 5 odd bits code button row pressed on the remote,
86 * following 2 odd bits code button column pressed on the remote.
88 * One can press many buttons at a time and the corresponding code will be sent.
89 * In the code below only use of a single button at a time is reported,
90 * all other messages are discarded as invalid.
93 /* extract bits for system code */
103 /* extract bits for pressed key row */
106 b[1]>>4 & 1, /* Control Key A */
107 b[1]>>2 & 1, /* Control Key B */
108 b[1] & 1, /* Control Key C */
109 b[2]>>6 & 1, /* Control Key D */
110 b[2]>>4 & 1, /* Control Key E (does not exists on the remote, but can
111 be set and is accepted by receiver) */
114 /* extrat on/off bits (first or second key column on the remote */
115 int on = b[2]>>2 & 1;
119 /* Test if the message is valid. It is possible to press multiple keys on the
120 * remote at the same time. As all keys are transmitted orthogonally, this
121 * information can be transmitted. This use case is not the usual use case
122 * so we can use it for validation of the message:
123 * ONLY ONE KEY AT A TIME IS ACCEPTED.
126 for( size_t i=0; i<sizeof(control_key)/sizeof(*control_key); i++)
128 if (control_key[i]) {
130 return 0; /* at least two buttons have been pressed, reject the message */
137 return 0; /* Pressing simultaneously ON and OFF key is not useful either */
141 if (control_key[0]) key = 'A';
142 else if (control_key[1]) key = 'B';
143 else if (control_key[2]) key = 'C';
144 else if (control_key[3]) key = 'D';
145 else if (control_key[4]) key = 'E';
146 else return 0; /* None of the keys has been pressed and we still received a message.
147 Skip it. It happens sometimes as the last code repetition */
150 /* @todo: remove timestamp printing as soon as the controller takes this task */
151 char time_str[LOCAL_TIME_BUFLEN];
152 local_time_str(0, time_str);
153 fprintf(stdout, "%s Brennenstuhl RCS 2044: system code: %d%d%d%d%d. key: %c, state: %s\n",
155 system_code[0], system_code[1], system_code[2], system_code[3], system_code[4],
157 on ? "ON" : ( off ? "OFF" : "BOTH" ) /* "BOTH" is excluded above, but leave it here for debug purposes */
164 static int brennenstuhl_rcs_2044_callback(bitbuffer_t *bitbuffer)
167 for(int row=0; row<bitbuffer->num_rows; row++)
168 counter += brennenstuhl_rcs_2044_process_row(row, bitbuffer);
172 r_device brennenstuhl_rcs_2044 = {
173 .name = "Brennenstuhl RCS 2044",
174 .modulation = OOK_PULSE_PWM_RAW,
178 .json_callback = &brennenstuhl_rcs_2044_callback,