Added a new Brand "Kamoona" to be used for other applications that are not a known brand.
Fork of RemoteIR by
Diff: ReceiverIR.cpp
- Revision:
- 13:ddc6f7c92583
- Parent:
- 11:268cc2ab63bd
--- a/ReceiverIR.cpp Sun Apr 19 19:11:32 2015 +0000 +++ b/ReceiverIR.cpp Mon Apr 27 01:47:26 2015 +0000 @@ -52,59 +52,59 @@ * * @return Data bit length. */ -int ReceiverIR::getData(RemoteIR::Format *format, uint8_t *buf, int bitlength) { +int ReceiverIR::getData(RemoteIR::Format *format) { LOCK(); - if (bitlength < data.bitcount) { + /* if (bitlength < data.bitcount) { UNLOCK(); return -1; - } + }*/ - const int nbits = data.bitcount; - const int nbytes = data.bitcount / 8 + (((data.bitcount % 8) != 0) ? 1 : 0); - *format = data.format; - for (int i = 0; i < nbytes; i++) { - buf[i] = data.buffer[i]; - } +// const int nbits = data.bitcount; +// const int nbytes = data.bitcount / 8 + (((data.bitcount % 8) != 0) ? 1 : 0); + // *format = data.format; + // for (int i = 0; i < nbytes; i++) { + // buf[i] = data.buffer[i]; + // } init_state(); UNLOCK(); - return nbits; + return 0; } void ReceiverIR::init_state(void) { work.c1 = -1; work.c2 = -1; - work.c3 = -1; - work.d1 = -1; - work.d2 = -1; + // work.c3 = -1; + // work.d1 = -1; + // work.d2 = -1; work.state = Idle; data.format = RemoteIR::UNKNOWN; - data.bitcount = 0; + // data.bitcount = 0; timer.stop(); timer.reset(); - for (int i = 0; i < sizeof(data.buffer); i++) { - data.buffer[i] = 0; - } +// for (int i = 0; i < sizeof(data.buffer); i++) { +// data.buffer[i] = 0; +// } } void ReceiverIR::isr_wdt(void) { LOCK(); static int cnt = 0; - if ((Idle != work.state) || ((0 <= work.c1) || (0 <= work.c2) || (0 <= work.c3) || (0 <= work.d1) || (0 <= work.d2))) { + if ((Idle != work.state) || ((0 <= work.c1) || (0 <= work.c2))) { cnt++; if (cnt > 50) { #if 0 printf("# WDT [c1=%d, c2=%d, c3=%d, d1=%d, d2=%d, state=%d, format=%d, bitcount=%d]\n", work.c1, work.c2, - work.c3, - work.d1, - work.d2, - work.state, + // work.c3, + // work.d1, + // work.d2, + // work.state, data.format, - data.bitcount); + // data.bitcount); #endif init_state(); cnt = 0; @@ -123,20 +123,34 @@ timer.start(); work.c1 = timer.read_us(); } else { - work.c3 = timer.read_us(); + //work.c3 = timer.read_us(); int a = work.c2 - work.c1; - int b = work.c3 - work.c2; - if (InRange(a, RemoteIR::TUS_NEC * 16) && InRange(b, RemoteIR::TUS_NEC * 8)) { + // int b = work.c3 - work.c2; + if (InRange(a, RemoteIR::TUS_Wifi * 4)) { /* - * NEC. + * Wifi Get Users. + */ + data.format = RemoteIR::WifiGetUsers; + work.state = Received; + // data.bitcount = 0; + } else if (InRange(a, RemoteIR::TUS_Wifi * 8)) { + /* + * Wifi Get Password. */ - data.format = RemoteIR::NEC; - work.state = Receiving; - data.bitcount = 0; - } else if (InRange(a, RemoteIR::TUS_NEC * 16) && InRange(b, RemoteIR::TUS_NEC * 4)) { + data.format = RemoteIR::WifiGetPassword; + work.state = Received; + // data.bitcount = 0; + } else if (InRange(a, RemoteIR::TUS_Wifi * 16)) { /* - * NEC Repeat. + * Wifi Change Password. */ + data.format = RemoteIR::WifiChangePassword; + work.state = Received; + // data.bitcount = 0; + /* } else if (InRange(a, RemoteIR::TUS_NEC * 16) && InRange(b, RemoteIR::TUS_NEC * 4)) { + + //* NEC Repeat. + data.format = RemoteIR::NEC_REPEAT; work.state = Received; data.bitcount = 0; @@ -146,16 +160,16 @@ work.d1 = -1; work.d2 = -1; } else if (InRange(a, RemoteIR::TUS_AEHA * 8) && InRange(b, RemoteIR::TUS_AEHA * 4)) { - /* - * AEHA. - */ + + // * AEHA. + data.format = RemoteIR::AEHA; work.state = Receiving; data.bitcount = 0; } else if (InRange(a, RemoteIR::TUS_AEHA * 8) && InRange(b, RemoteIR::TUS_AEHA * 8)) { - /* - * AEHA Repeat. - */ + + // * AEHA Repeat. + data.format = RemoteIR::AEHA_REPEAT; work.state = Received; data.bitcount = 0; @@ -164,12 +178,12 @@ work.c3 = -1; work.d1 = -1; work.d2 = -1; - } else { + */ } else { init_state(); } } break; - case Receiving: + /* case Receiving: if (RemoteIR::NEC == data.format) { work.d2 = timer.read_us(); int a = work.d2 - work.d1; @@ -180,9 +194,9 @@ } data.bitcount++; #if 0 - /* - * Length of NEC is always 32 bits. - */ + + // * Length of NEC is always 32 bits. + if (32 <= data.bitcount) { data.state = Received; work.c1 = -1; @@ -192,12 +206,12 @@ work.d2 = -1; } #else - /* + / * Set timeout for tail detection automatically. - */ - timeout.detach(); - timeout.attach_us(this, &ReceiverIR::isr_timeout, RemoteIR::TUS_NEC * 5); -#endif + / + // timeout.detach(); + // timeout.attach_us(this, &ReceiverIR::isr_timeout, RemoteIR::TUS_Wifi * 4); + } else if (RemoteIR::AEHA == data.format) { work.d2 = timer.read_us(); int a = work.d2 - work.d1; @@ -208,10 +222,10 @@ } data.bitcount++; #if 0 - /* + / * Typical length of AEHA is 48 bits. * Please check a specification of your remote controller if you find a problem. - */ + / if (48 <= data.bitcount) { data.state = Received; work.c1 = -1; @@ -220,17 +234,17 @@ work.d1 = -1; work.d2 = -1; } -#else - /* + + / * Set timeout for tail detection automatically. - */ + / timeout.detach(); timeout.attach_us(this, &ReceiverIR::isr_timeout, RemoteIR::TUS_AEHA * 5); -#endif + } else if (RemoteIR::SONY == data.format) { work.d1 = timer.read_us(); } - break; + break; */ case Received: break; default: @@ -246,7 +260,7 @@ if (0 <= work.c1) { work.c2 = timer.read_us(); int a = work.c2 - work.c1; - if (InRange(a, RemoteIR::TUS_SONY * 4)) { + /*if (InRange(a, RemoteIR::TUS_SONY * 4)) { data.format = RemoteIR::SONY; work.state = Receiving; data.bitcount = 0; @@ -254,13 +268,13 @@ static const int MINIMUM_LEADER_WIDTH = 150; if (a < MINIMUM_LEADER_WIDTH) { init_state(); - } - } + } + }*/ } else { init_state(); } break; - case Receiving: + /* case Receiving: if (RemoteIR::NEC == data.format) { work.d1 = timer.read_us(); } else if (RemoteIR::AEHA == data.format) { @@ -275,11 +289,11 @@ } data.bitcount++; #if 0 - /* + * How do I know the correct length? (6bits, 12bits, 15bits, 20bits...) * By a model only? * Please check a specification of your remote controller if you find a problem. - */ + if (12 <= data.bitcount) { data.state = Received; work.c1 = -1; @@ -289,14 +303,14 @@ work.d2 = -1; } #else - /* + * Set timeout for tail detection automatically. - */ + timeout.detach(); timeout.attach_us(this, &ReceiverIR::isr_timeout, RemoteIR::TUS_SONY * 4); #endif } - break; + break; */ case Received: break; default: @@ -317,14 +331,14 @@ work.state, data.format, data.bitcount); -#endif + if (work.state == Receiving) { work.state = Received; work.c1 = -1; - work.c2 = -1; - work.c3 = -1; - work.d1 = -1; - work.d2 = -1; - } +#endif work.c2 = -1; + // work.c3 = -1; + // work.d1 = -1; + // work.d2 = -1; + UNLOCK(); }