forked RemoteIR
Fork of RemoteIR by
Revision 12:d86179332137, committed 2018-03-17
- Comitter:
- misodengaku
- Date:
- Sat Mar 17 14:42:15 2018 +0000
- Parent:
- 11:268cc2ab63bd
- Commit message:
- support level inversion
Changed in this revision
diff -r 268cc2ab63bd -r d86179332137 ReceiverIR.cpp --- a/ReceiverIR.cpp Mon Sep 20 00:54:59 2010 +0000 +++ b/ReceiverIR.cpp Sat Mar 17 14:42:15 2018 +0000 @@ -17,10 +17,17 @@ * * @param rxpin Pin for receive IR signal. */ -ReceiverIR::ReceiverIR(PinName rxpin) : evt(rxpin) { +ReceiverIR::ReceiverIR(PinName rxpin, bool rxInversion) : evt(rxpin) +{ init_state(); - evt.fall(this, &ReceiverIR::isr_fall); - evt.rise(this, &ReceiverIR::isr_rise); + if (rxInversion) { + evt.fall(this, &ReceiverIR::isr_rise); + evt.rise(this, &ReceiverIR::isr_fall); + + } else { + evt.fall(this, &ReceiverIR::isr_fall); + evt.rise(this, &ReceiverIR::isr_rise); + } evt.mode(PullUp); ticker.attach_us(this, &ReceiverIR::isr_wdt, 10 * 1000); } @@ -28,7 +35,8 @@ /** * Destructor. */ -ReceiverIR::~ReceiverIR() { +ReceiverIR::~ReceiverIR() +{ } /** @@ -36,7 +44,8 @@ * * @return Current state. */ -ReceiverIR::State ReceiverIR::getState() { +ReceiverIR::State ReceiverIR::getState() +{ LOCK(); State s = work.state; UNLOCK(); @@ -52,7 +61,8 @@ * * @return Data bit length. */ -int ReceiverIR::getData(RemoteIR::Format *format, uint8_t *buf, int bitlength) { +int ReceiverIR::getData(RemoteIR::Format *format, uint8_t *buf, int bitlength) +{ LOCK(); if (bitlength < data.bitcount) { @@ -73,7 +83,8 @@ return nbits; } -void ReceiverIR::init_state(void) { +void ReceiverIR::init_state(void) +{ work.c1 = -1; work.c2 = -1; work.c3 = -1; @@ -89,7 +100,8 @@ } } -void ReceiverIR::isr_wdt(void) { +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))) { @@ -115,7 +127,8 @@ UNLOCK(); } -void ReceiverIR::isr_fall(void) { +void ReceiverIR::isr_fall(void) +{ LOCK(); switch (work.state) { case Idle: @@ -239,7 +252,8 @@ UNLOCK(); } -void ReceiverIR::isr_rise(void) { +void ReceiverIR::isr_rise(void) +{ LOCK(); switch (work.state) { case Idle: @@ -305,7 +319,8 @@ UNLOCK(); } -void ReceiverIR::isr_timeout(void) { +void ReceiverIR::isr_timeout(void) +{ LOCK(); #if 0 printf("# TIMEOUT [c1=%d, c2=%d, c3=%d, d1=%d, d2=%d, state=%d, format=%d, bitcount=%d]\n",
diff -r 268cc2ab63bd -r d86179332137 ReceiverIR.h --- a/ReceiverIR.h Mon Sep 20 00:54:59 2010 +0000 +++ b/ReceiverIR.h Sat Mar 17 14:42:15 2018 +0000 @@ -23,7 +23,8 @@ * * @param rxpin Pin for receive IR signal. */ - explicit ReceiverIR(PinName rxpin); + explicit ReceiverIR(PinName rxpin, bool rxInversion = false); + bool RxInversion; /** * Destructor.
diff -r 268cc2ab63bd -r d86179332137 TransmitterIR.cpp --- a/TransmitterIR.cpp Mon Sep 20 00:54:59 2010 +0000 +++ b/TransmitterIR.cpp Sat Mar 17 14:42:15 2018 +0000 @@ -15,8 +15,9 @@ * * @param txpin Pin for transmit IR signal. */ -TransmitterIR::TransmitterIR(PinName txpin) : tx(txpin) { - tx.write(0.0); +TransmitterIR::TransmitterIR(PinName txpin, bool ti = false) : tx(txpin) { + txInversion = ti; + setLEDLow(); tx.period_us(26.3); work.state = Idle; @@ -112,9 +113,9 @@ static const int LEADER_NEC_HEAD = 16; static const int LEADER_NEC_TAIL = 8; if (work.leader < LEADER_NEC_HEAD) { - tx.write(0.5); + setLEDHigh(); } else { - tx.write(0.0); + setLEDLow(); } work.leader++; if ((LEADER_NEC_HEAD + LEADER_NEC_TAIL) <= work.leader) { @@ -127,9 +128,9 @@ static const int LEADER_AEHA_HEAD = 8; static const int LEADER_AEHA_TAIL = 4; if (work.leader < LEADER_AEHA_HEAD) { - tx.write(0.5); + setLEDHigh(); } else { - tx.write(0.0); + setLEDLow(); } work.leader++; if ((LEADER_AEHA_HEAD + LEADER_AEHA_TAIL) <= work.leader) { @@ -142,9 +143,9 @@ static const int LEADER_SONY_HEAD = 4; static const int LEADER_SONY_TAIL = 0; if (work.leader < LEADER_SONY_HEAD) { - tx.write(0.5); + setLEDHigh(); } else { - tx.write(0.0); + setLEDLow(); } work.leader++; if ((LEADER_SONY_HEAD + LEADER_SONY_TAIL) <= work.leader) { @@ -159,10 +160,10 @@ * NEC. */ if (work.data == 0) { - tx.write(0.5); + setLEDHigh(); work.data++; } else { - tx.write(0.0); + setLEDLow(); if (0 != (data.buffer[work.bitcount / 8] & (1 << work.bitcount % 8))) { if (3 <= work.data) { work.bitcount++; @@ -187,10 +188,10 @@ * AEHA. */ if (work.data == 0) { - tx.write(0.5); + setLEDHigh(); work.data++; } else { - tx.write(0.0); + setLEDLow(); if (0 != (data.buffer[work.bitcount / 8] & (1 << work.bitcount % 8))) { if (3 <= work.data) { work.bitcount++; @@ -215,10 +216,10 @@ * SONY. */ if (work.data == 0) { - tx.write(0.0); + setLEDLow(); work.data++; } else { - tx.write(0.5); + setLEDHigh(); if (0 != (data.buffer[work.bitcount / 8] & (1 << work.bitcount % 8))) { if (2 <= work.data) { work.bitcount++; @@ -249,9 +250,9 @@ static const int TRAILER_NEC_HEAD = 1; static const int TRAILER_NEC_TAIL = 2; if (work.trailer < TRAILER_NEC_HEAD) { - tx.write(0.5); + setLEDHigh(); } else { - tx.write(0.0); + setLEDLow(); } work.trailer++; if ((TRAILER_NEC_HEAD + TRAILER_NEC_TAIL) <= work.trailer) { @@ -265,9 +266,9 @@ static const int TRAILER_AEHA_HEAD = 1; static const int TRAILER_AEHA_TAIL = 8000 / RemoteIR::TUS_AEHA; if (work.trailer < TRAILER_AEHA_HEAD) { - tx.write(0.5); + setLEDHigh(); } else { - tx.write(0.0); + setLEDLow(); } work.trailer++; if ((TRAILER_AEHA_HEAD + TRAILER_AEHA_TAIL) <= work.trailer) { @@ -281,9 +282,9 @@ static const int TRAILER_SONY_HEAD = 0; static const int TRAILER_SONY_TAIL = 0; if (work.trailer < TRAILER_SONY_HEAD) { - tx.write(0.5); + setLEDHigh(); } else { - tx.write(0.0); + setLEDLow(); } work.trailer++; if ((TRAILER_SONY_HEAD + TRAILER_SONY_TAIL) <= work.trailer) { @@ -298,3 +299,22 @@ } UNLOCK(); } + +void TransmitterIR::setLEDHigh(void) { + if (txInversion) + { + tx.write(0.5); + } else { + tx.write(0.0); + } +} + +void TransmitterIR::setLEDLow(void) { + if (txInversion) + { + tx.write(1.0); + } else { + printf("0.5\n"); + tx.write(0.5); + } +} \ No newline at end of file
diff -r 268cc2ab63bd -r d86179332137 TransmitterIR.h --- a/TransmitterIR.h Mon Sep 20 00:54:59 2010 +0000 +++ b/TransmitterIR.h Sat Mar 17 14:42:15 2018 +0000 @@ -23,7 +23,7 @@ * * @param txpin Pin for transmit IR signal. */ - explicit TransmitterIR(PinName txpin); + explicit TransmitterIR(PinName txpin, bool txInversion); /** * Destructor. @@ -75,8 +75,11 @@ Ticker ticker; data_t data; work_t work; + bool txInversion; void tick(); + void setLEDHigh(void); + void setLEDLow(void); };