3 static int newkaku_callback(uint8_t bb[BITBUF_ROWS][BITBUF_COLS], int16_t bits_per_row[BITBUF_ROWS]) {
4 /* Two bits map to 2 states, 0 1 -> 0 and 1 1 -> 1 */
5 /* Status bit can be 1 1 -> 1 which indicates DIM value. 4 extra bits are present with value */
6 /*start pulse: 1T high, 10.44T low */
9 /*- 1 bit: Status bit on/off/[dim]*/
11 /*- [4 bit: dim level. Present if [dim] is used, but might be present anyway...]*/
12 /*- stop pulse: 1T high, 40T low */
20 if (bb[0][0] == 0xac) {//allways starts with ac
21 // first bit is from startbit sequence, not part of payload!
22 // check protocol if value is 10 or 01, else stop processing as it is no vallid KAKU packet!
23 //get id=24bits, remember 1st 1 bit = startbit, no payload!
24 for (packet = 0; packet < 6; packet++) {//get first part kakuid
25 tmp = bb[0][packet] << 1;
26 if ((bb[0][packet + 1]&(1 << 7)) != 0) {// if set add bit to current
30 for (bitcount = 0; bitcount < 8; bitcount += 2) {//process bitstream, check protocol!
32 if (((tmp << bitcount & (0x80)) == 0x80)&((tmp << bitcount & (0x40)) == 0)) {
37 if (((tmp << bitcount & (0x80)) == 0)&((tmp << bitcount & (0x40)) == 0x40)) {
41 return 0; //00 and 11 indicates packet error. Do exit, no valid packet
45 tmp = bb[0][6] << 1; //Get last part ID
46 for (bitcount = 0; bitcount < 4; bitcount += 2) {
47 if (((tmp << bitcount & (0x80)) == 0x80)&((tmp << bitcount & (0x40)) == 0)) {
52 if (((tmp << bitcount & (0x80)) == 0)&((tmp << bitcount & (0x40)) == 0x40)) {
57 //fprintf(stderr, " Packet error, no newkaku!!\n", tmp << bitcount);
58 return 0; //00 and 11 indicates packet error. no valid packet! do exit
63 if ((bb[0][8]&(1 << 7)) != 0) {// if set add bit to current
66 for (bitcount = 0; bitcount < 8; bitcount += 2) {//process bitstream, check protocol!
67 if (((tmp << bitcount & (0x80)) == 0x80)&((tmp << bitcount & (0x40)) == 0)) {
72 if (((tmp << bitcount & (0x80)) == 0)&((tmp << bitcount & (0x40)) == 0x40)) {
76 return 0; //00 and 11 indicates packet error. Do exit, no valid packet
79 fprintf(stdout, "BUTTON:TYPE=NEWKAKU,");
80 fprintf(stdout, "ID=%d,", kakuid);
81 fprintf(stdout, "UNIT=%d,", unit);
82 fprintf(stdout, "GROUPCALL=%s,", (((bb[0][6] & (0x04)) == 0x04)&((bb[0][6] & (0x02)) == 0)) ? "YES" : "NO");
83 fprintf(stdout, "COMMAND=%s,", (((bb[0][6] & (0x01)) == 0x01)&((bb[0][7] & (0x80)) == 0)) ? "ON" : "OFF");
84 if (((bb[0][6] & (0x01)) == 0x01)&((bb[0][7] & (0x80)) == 0x80)) {//11 indicates DIM command, 4 extra bits indicate DIM value
85 fprintf(stdout, "DIM=YES,");
86 tmp = bb[0][8] << 1; // get packet, loose first bit
88 if ((bb[0][9]&(1 << 7)) != 0) {// if bit is set Add to current packet
90 for (bitcount = 0; bitcount < 8; bitcount += 2) {//process last bit outside
91 if (((tmp << bitcount & (0x80)) == 0x80)&((tmp << bitcount & (0x40)) == 0)) {
96 if (((tmp << bitcount & (0x80)) == 0)&((tmp << bitcount & (0x40)) == 0x40)) {
100 return 0; //00 and 11 indicates packet error. Do exit, no valid packet
104 fprintf(stdout, "DIMVALUE=%d\n", dv);
106 fprintf(stdout, "DIM=NO\n");
108 fprintf(stderr, "%02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
109 bb[0][0], bb[0][1], bb[0][2], bb[0][3], bb[0][4], bb[0][5], bb[0][6], bb[0][7], bb[0][8]);
111 debug_callback(bb, bits_per_row);
119 /* .name = */ "KlikAanKlikUit Wireless Switch",
120 /* .modulation = */ OOK_PWM_D,
121 /* .short_limit = */ 200,
122 /* .long_limit = */ 800,
123 /* .reset_limit = */ 4000,
124 /* .json_callback = */ &newkaku_callback,