RemoteIR.
Dependents: RemoteIR_TestProgram SerialGPS_TestProgram StarBoardOrangeExpansion1 Door_Slamming_Device ... more
Revision 11:268cc2ab63bd, committed 2010-09-20
- Comitter:
- shintamainjp
- Date:
- Mon Sep 20 00:54:59 2010 +0000
- Parent:
- 10:c54fb1204d1e
- Commit message:
Changed in this revision
diff -r c54fb1204d1e -r 268cc2ab63bd ReceiverIR.cpp --- a/ReceiverIR.cpp Fri Sep 17 21:44:01 2010 +0000 +++ b/ReceiverIR.cpp Mon Sep 20 00:54:59 2010 +0000 @@ -95,7 +95,7 @@ if ((Idle != work.state) || ((0 <= work.c1) || (0 <= work.c2) || (0 <= work.c3) || (0 <= work.d1) || (0 <= work.d2))) { cnt++; if (cnt > 50) { -#if 1 +#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, @@ -126,14 +126,14 @@ work.c3 = timer.read_us(); int a = work.c2 - work.c1; int b = work.c3 - work.c2; - if (InRange(a, TUS_NEC * 16) && InRange(b, TUS_NEC * 8)) { + if (InRange(a, RemoteIR::TUS_NEC * 16) && InRange(b, RemoteIR::TUS_NEC * 8)) { /* * NEC. */ data.format = RemoteIR::NEC; work.state = Receiving; data.bitcount = 0; - } else if (InRange(a, TUS_NEC * 16) && InRange(b, TUS_NEC * 4)) { + } else if (InRange(a, RemoteIR::TUS_NEC * 16) && InRange(b, RemoteIR::TUS_NEC * 4)) { /* * NEC Repeat. */ @@ -145,14 +145,14 @@ work.c3 = -1; work.d1 = -1; work.d2 = -1; - } else if (InRange(a, TUS_AEHA * 8) && InRange(b, TUS_AEHA * 4)) { + } else if (InRange(a, RemoteIR::TUS_AEHA * 8) && InRange(b, RemoteIR::TUS_AEHA * 4)) { /* * AEHA. */ data.format = RemoteIR::AEHA; work.state = Receiving; data.bitcount = 0; - } else if (InRange(a, TUS_AEHA * 8) && InRange(b, TUS_AEHA * 8)) { + } else if (InRange(a, RemoteIR::TUS_AEHA * 8) && InRange(b, RemoteIR::TUS_AEHA * 8)) { /* * AEHA Repeat. */ @@ -173,9 +173,9 @@ if (RemoteIR::NEC == data.format) { work.d2 = timer.read_us(); int a = work.d2 - work.d1; - if (InRange(a, TUS_NEC * 3)) { + if (InRange(a, RemoteIR::TUS_NEC * 3)) { data.buffer[data.bitcount / 8] |= (1 << (data.bitcount % 8)); - } else if (InRange(a, TUS_NEC * 1)) { + } else if (InRange(a, RemoteIR::TUS_NEC * 1)) { data.buffer[data.bitcount / 8] &= ~(1 << (data.bitcount % 8)); } data.bitcount++; @@ -196,14 +196,14 @@ * Set timeout for tail detection automatically. */ timeout.detach(); - timeout.attach_us(this, &ReceiverIR::isr_timeout, TUS_NEC * 5); + timeout.attach_us(this, &ReceiverIR::isr_timeout, RemoteIR::TUS_NEC * 5); #endif } else if (RemoteIR::AEHA == data.format) { work.d2 = timer.read_us(); int a = work.d2 - work.d1; - if (InRange(a, TUS_AEHA * 3)) { + if (InRange(a, RemoteIR::TUS_AEHA * 3)) { data.buffer[data.bitcount / 8] |= (1 << (data.bitcount % 8)); - } else if (InRange(a, TUS_AEHA * 1)) { + } else if (InRange(a, RemoteIR::TUS_AEHA * 1)) { data.buffer[data.bitcount / 8] &= ~(1 << (data.bitcount % 8)); } data.bitcount++; @@ -225,7 +225,7 @@ * Set timeout for tail detection automatically. */ timeout.detach(); - timeout.attach_us(this, &ReceiverIR::isr_timeout, TUS_AEHA * 5); + timeout.attach_us(this, &ReceiverIR::isr_timeout, RemoteIR::TUS_AEHA * 5); #endif } else if (RemoteIR::SONY == data.format) { work.d1 = timer.read_us(); @@ -246,7 +246,7 @@ if (0 <= work.c1) { work.c2 = timer.read_us(); int a = work.c2 - work.c1; - if (InRange(a, TUS_SONY * 4)) { + if (InRange(a, RemoteIR::TUS_SONY * 4)) { data.format = RemoteIR::SONY; work.state = Receiving; data.bitcount = 0; @@ -268,9 +268,9 @@ } else if (RemoteIR::SONY == data.format) { work.d2 = timer.read_us(); int a = work.d2 - work.d1; - if (InRange(a, TUS_SONY * 2)) { + if (InRange(a, RemoteIR::TUS_SONY * 2)) { data.buffer[data.bitcount / 8] |= (1 << (data.bitcount % 8)); - } else if (InRange(a, TUS_SONY * 1)) { + } else if (InRange(a, RemoteIR::TUS_SONY * 1)) { data.buffer[data.bitcount / 8] &= ~(1 << (data.bitcount % 8)); } data.bitcount++; @@ -293,7 +293,7 @@ * Set timeout for tail detection automatically. */ timeout.detach(); - timeout.attach_us(this, &ReceiverIR::isr_timeout, TUS_SONY * 4); + timeout.attach_us(this, &ReceiverIR::isr_timeout, RemoteIR::TUS_SONY * 4); #endif } break;
diff -r c54fb1204d1e -r 268cc2ab63bd ReceiverIR.h --- a/ReceiverIR.h Fri Sep 17 21:44:01 2010 +0000 +++ b/ReceiverIR.h Mon Sep 20 00:54:59 2010 +0000 @@ -74,10 +74,6 @@ int d2; } work_t; - static const int TUS_NEC = 562; - static const int TUS_AEHA = 425; - static const int TUS_SONY = 600; - InterruptIn evt; /**< Interrupt based input for input. */ Timer timer; /**< Timer for WDT. */ Ticker ticker; /**< Tciker for tick. */
diff -r c54fb1204d1e -r 268cc2ab63bd RemoteIR.h --- a/RemoteIR.h Fri Sep 17 21:44:01 2010 +0000 +++ b/RemoteIR.h Mon Sep 20 00:54:59 2010 +0000 @@ -20,6 +20,10 @@ SONY } Format; + static const int TUS_NEC = 562; + static const int TUS_AEHA = 425; + static const int TUS_SONY = 600; + private: RemoteIR(); };
diff -r c54fb1204d1e -r 268cc2ab63bd TransmitterIR.cpp --- a/TransmitterIR.cpp Fri Sep 17 21:44:01 2010 +0000 +++ b/TransmitterIR.cpp Mon Sep 20 00:54:59 2010 +0000 @@ -10,6 +10,11 @@ #define LOCK() #define UNLOCK() +/** + * Constructor. + * + * @param txpin Pin for transmit IR signal. + */ TransmitterIR::TransmitterIR(PinName txpin) : tx(txpin) { tx.write(0.0); tx.period_us(26.3); @@ -24,9 +29,17 @@ data.bitlength = 0; } +/** + * Destructor. + */ TransmitterIR::~TransmitterIR() { } +/** + * Get state. + * + * @return Current state. + */ TransmitterIR::State TransmitterIR::getState(void) { LOCK(); State s = work.state; @@ -34,6 +47,15 @@ return s; } +/** + * Set data. + * + * @param format Format. + * @param buf Buffer of a data. + * @param bitlength Bit length of the data. + * + * @return Data bit length. + */ int TransmitterIR::setData(RemoteIR::Format format, uint8_t *buf, int bitlength) { LOCK(); if (work.state != Idle) { @@ -57,15 +79,15 @@ switch (format) { case RemoteIR::NEC: ticker.detach(); - ticker.attach_us(this, &TransmitterIR::tick, TUS_NEC); + ticker.attach_us(this, &TransmitterIR::tick, RemoteIR::TUS_NEC); break; case RemoteIR::AEHA: ticker.detach(); - ticker.attach_us(this, &TransmitterIR::tick, TUS_AEHA); + ticker.attach_us(this, &TransmitterIR::tick, RemoteIR::TUS_AEHA); break; case RemoteIR::SONY: ticker.detach(); - ticker.attach_us(this, &TransmitterIR::tick, TUS_SONY); + ticker.attach_us(this, &TransmitterIR::tick, RemoteIR::TUS_SONY); break; } @@ -241,7 +263,7 @@ * AEHA. */ static const int TRAILER_AEHA_HEAD = 1; - static const int TRAILER_AEHA_TAIL = 8000 / TUS_AEHA; + static const int TRAILER_AEHA_TAIL = 8000 / RemoteIR::TUS_AEHA; if (work.trailer < TRAILER_AEHA_HEAD) { tx.write(0.5); } else {
diff -r c54fb1204d1e -r 268cc2ab63bd TransmitterIR.h --- a/TransmitterIR.h Fri Sep 17 21:44:01 2010 +0000 +++ b/TransmitterIR.h Mon Sep 20 00:54:59 2010 +0000 @@ -75,10 +75,6 @@ Ticker ticker; data_t data; work_t work; - - static const int TUS_NEC = 562; - static const int TUS_AEHA = 425; - static const int TUS_SONY = 600; void tick();