Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of RemoteIR by
Revision 12:b6a25dc72156, committed 2014-10-30
- Comitter:
- altex
- Date:
- Thu Oct 30 09:20:06 2014 +0000
- Parent:
- 11:268cc2ab63bd
- Commit message:
- Fixed SONY protocol
Changed in this revision
ReceiverIR.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/ReceiverIR.cpp Mon Sep 20 00:54:59 2010 +0000 +++ b/ReceiverIR.cpp Thu Oct 30 09:20:06 2014 +0000 @@ -228,44 +228,6 @@ timeout.attach_us(this, &ReceiverIR::isr_timeout, RemoteIR::TUS_AEHA * 5); #endif } else if (RemoteIR::SONY == data.format) { - work.d1 = timer.read_us(); - } - break; - case Received: - break; - default: - break; - } - UNLOCK(); -} - -void ReceiverIR::isr_rise(void) { - LOCK(); - switch (work.state) { - case Idle: - if (0 <= work.c1) { - work.c2 = timer.read_us(); - int a = work.c2 - work.c1; - if (InRange(a, RemoteIR::TUS_SONY * 4)) { - data.format = RemoteIR::SONY; - work.state = Receiving; - data.bitcount = 0; - } else { - static const int MINIMUM_LEADER_WIDTH = 150; - if (a < MINIMUM_LEADER_WIDTH) { - init_state(); - } - } - } else { - init_state(); - } - break; - case Receiving: - if (RemoteIR::NEC == data.format) { - work.d1 = timer.read_us(); - } else if (RemoteIR::AEHA == data.format) { - work.d1 = timer.read_us(); - } else if (RemoteIR::SONY == data.format) { work.d2 = timer.read_us(); int a = work.d2 - work.d1; if (InRange(a, RemoteIR::TUS_SONY * 2)) { @@ -305,6 +267,45 @@ UNLOCK(); } +void ReceiverIR::isr_rise(void) { + LOCK(); + switch (work.state) { + case Idle: + if (0 <= work.c1) { + work.c2 = timer.read_us(); + int a = work.c2 - work.c1; + if (InRange(a, RemoteIR::TUS_SONY * 4)) { + data.format = RemoteIR::SONY; + work.state = Receiving; + data.bitcount = 0; + work.d1 = timer.read_us(); + } else { + static const int MINIMUM_LEADER_WIDTH = 150; + if (a < MINIMUM_LEADER_WIDTH) { + init_state(); + } + } + } else { + init_state(); + } + break; + case Receiving: + if (RemoteIR::NEC == data.format) { + work.d1 = timer.read_us(); + } else if (RemoteIR::AEHA == data.format) { + work.d1 = timer.read_us(); + } else if (RemoteIR::SONY == data.format) { + work.d1 = timer.read_us(); + } + break; + case Received: + break; + default: + break; + } + UNLOCK(); +} + void ReceiverIR::isr_timeout(void) { LOCK(); #if 0 @@ -325,6 +326,18 @@ work.c3 = -1; work.d1 = -1; work.d2 = -1; + + if (RemoteIR::SONY == data.format) { + // Fix for SONY empty bits, for example if 31 bits was sended, we need to fill 32nd bit with "1". + // We need to append unreceived bits with "1"s. + int bitsCount = data.bitcount % 8; + if (bitsCount != 0) { + int bytesCount = data.bitcount / 8; + for (int i = bitsCount; i < 8; i++) { + data.buffer[bytesCount] |= (1 << i); + } + } + } } UNLOCK(); }