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(stderr, "NewKaku event:\n");
80 fprintf(stderr, "Model = NewKaKu on/off/dimmer switch\n");
81 fprintf(stderr, "KakuId = %d (H%.2X)\n", kakuid, kakuid);
82 fprintf(stderr, "Unit = %d (H%.2X)\n", unit, unit);
83 fprintf(stderr, "Group Call = %s\n", (((bb[0][6] & (0x04)) == 0x04)&((bb[0][6] & (0x02)) == 0)) ? "Yes" : "No");
84 fprintf(stderr, "Command = %s\n", (((bb[0][6] & (0x01)) == 0x01)&((bb[0][7] & (0x80)) == 0)) ? "On" : "Off");
85 if (((bb[0][6] & (0x01)) == 0x01)&((bb[0][7] & (0x80)) == 0x80)) {//11 indicates DIM command, 4 extra bits indicate DIM value
86 fprintf(stderr, "Dim = Yes\n");
87 tmp = bb[0][8] << 1; // get packet, loose first bit
89 if ((bb[0][9]&(1 << 7)) != 0) {// if bit is set Add to current packet
91 for (bitcount = 0; bitcount < 8; bitcount += 2) {//process last bit outside
92 if (((tmp << bitcount & (0x80)) == 0x80)&((tmp << bitcount & (0x40)) == 0)) {
97 if (((tmp << bitcount & (0x80)) == 0)&((tmp << bitcount & (0x40)) == 0x40)) {
101 return 0; //00 and 11 indicates packet error. Do exit, no valid packet
105 fprintf(stderr, "Dim Value = %d\n", dv);
107 fprintf(stderr, "Dim = No\n");
108 fprintf(stderr, "Dim Value = 0\n");
110 fprintf(stderr, "%02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
111 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]);
113 debug_callback(bb, bits_per_row);
121 /* .name = */ "KlikAanKlikUit Wireless Switch",
122 /* .modulation = */ OOK_PWM_D,
123 /* .short_limit = */ 200,
124 /* .long_limit = */ 800,
125 /* .reset_limit = */ 4000,
126 /* .json_callback = */ &newkaku_callback,