![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
This is a very simple guide, reviewing the steps required to get Blinky working on an Mbed OS platform.
Dependencies: mbed Adafruit_GFX
ReceiverIR.cpp@96:7465ab270e7a, 2019-06-13 (annotated)
- Committer:
- ParkChunMyong
- Date:
- Thu Jun 13 03:26:42 2019 +0000
- Revision:
- 96:7465ab270e7a
- Parent:
- 95:250afd53b710
first init
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ParkChunMyong | 95:250afd53b710 | 1 | /** |
ParkChunMyong | 95:250afd53b710 | 2 | * IR receiver (Version 0.0.4) |
ParkChunMyong | 95:250afd53b710 | 3 | * |
ParkChunMyong | 95:250afd53b710 | 4 | * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems) |
ParkChunMyong | 95:250afd53b710 | 5 | * http://shinta.main.jp/ |
ParkChunMyong | 95:250afd53b710 | 6 | */ |
ParkChunMyong | 95:250afd53b710 | 7 | |
ParkChunMyong | 95:250afd53b710 | 8 | #include "ReceiverIR.h" |
ParkChunMyong | 95:250afd53b710 | 9 | |
ParkChunMyong | 95:250afd53b710 | 10 | #define LOCK() |
ParkChunMyong | 95:250afd53b710 | 11 | #define UNLOCK() |
ParkChunMyong | 95:250afd53b710 | 12 | |
ParkChunMyong | 95:250afd53b710 | 13 | #define InRange(x,y) ((((y) * 0.7) < (x)) && ((x) < ((y) * 1.3))) |
ParkChunMyong | 95:250afd53b710 | 14 | |
ParkChunMyong | 95:250afd53b710 | 15 | /** |
ParkChunMyong | 95:250afd53b710 | 16 | * Constructor. |
ParkChunMyong | 95:250afd53b710 | 17 | * |
ParkChunMyong | 95:250afd53b710 | 18 | * @param rxpin Pin for receive IR signal. |
ParkChunMyong | 95:250afd53b710 | 19 | */ |
ParkChunMyong | 95:250afd53b710 | 20 | ReceiverIR::ReceiverIR(PinName rxpin) : evt(rxpin) { |
ParkChunMyong | 95:250afd53b710 | 21 | init_state(); |
ParkChunMyong | 95:250afd53b710 | 22 | evt.fall(this, &ReceiverIR::isr_fall); |
ParkChunMyong | 95:250afd53b710 | 23 | evt.rise(this, &ReceiverIR::isr_rise); |
ParkChunMyong | 95:250afd53b710 | 24 | evt.mode(PullUp); |
ParkChunMyong | 95:250afd53b710 | 25 | ticker.attach_us(this, &ReceiverIR::isr_wdt, 10 * 1000); |
ParkChunMyong | 95:250afd53b710 | 26 | } |
ParkChunMyong | 95:250afd53b710 | 27 | |
ParkChunMyong | 95:250afd53b710 | 28 | /** |
ParkChunMyong | 95:250afd53b710 | 29 | * Destructor. |
ParkChunMyong | 95:250afd53b710 | 30 | */ |
ParkChunMyong | 95:250afd53b710 | 31 | ReceiverIR::~ReceiverIR() { |
ParkChunMyong | 95:250afd53b710 | 32 | } |
ParkChunMyong | 95:250afd53b710 | 33 | |
ParkChunMyong | 95:250afd53b710 | 34 | /** |
ParkChunMyong | 95:250afd53b710 | 35 | * Get state. |
ParkChunMyong | 95:250afd53b710 | 36 | * |
ParkChunMyong | 95:250afd53b710 | 37 | * @return Current state. |
ParkChunMyong | 95:250afd53b710 | 38 | */ |
ParkChunMyong | 95:250afd53b710 | 39 | ReceiverIR::State ReceiverIR::getState() { |
ParkChunMyong | 95:250afd53b710 | 40 | LOCK(); |
ParkChunMyong | 95:250afd53b710 | 41 | State s = work.state; |
ParkChunMyong | 95:250afd53b710 | 42 | UNLOCK(); |
ParkChunMyong | 95:250afd53b710 | 43 | return s; |
ParkChunMyong | 95:250afd53b710 | 44 | } |
ParkChunMyong | 95:250afd53b710 | 45 | |
ParkChunMyong | 95:250afd53b710 | 46 | /** |
ParkChunMyong | 95:250afd53b710 | 47 | * Get data. |
ParkChunMyong | 95:250afd53b710 | 48 | * |
ParkChunMyong | 95:250afd53b710 | 49 | * @param format Pointer to format. |
ParkChunMyong | 95:250afd53b710 | 50 | * @param buf Buffer of a data. |
ParkChunMyong | 95:250afd53b710 | 51 | * @param bitlength Bit length of the buffer. |
ParkChunMyong | 95:250afd53b710 | 52 | * |
ParkChunMyong | 95:250afd53b710 | 53 | * @return Data bit length. |
ParkChunMyong | 95:250afd53b710 | 54 | */ |
ParkChunMyong | 95:250afd53b710 | 55 | int ReceiverIR::getData(RemoteIR::Format *format, uint8_t *buf, int bitlength) { |
ParkChunMyong | 95:250afd53b710 | 56 | LOCK(); |
ParkChunMyong | 95:250afd53b710 | 57 | |
ParkChunMyong | 95:250afd53b710 | 58 | if (bitlength < data.bitcount) { |
ParkChunMyong | 95:250afd53b710 | 59 | UNLOCK(); |
ParkChunMyong | 95:250afd53b710 | 60 | return -1; |
ParkChunMyong | 95:250afd53b710 | 61 | } |
ParkChunMyong | 95:250afd53b710 | 62 | |
ParkChunMyong | 95:250afd53b710 | 63 | const int nbits = data.bitcount; |
ParkChunMyong | 95:250afd53b710 | 64 | const int nbytes = data.bitcount / 8 + (((data.bitcount % 8) != 0) ? 1 : 0); |
ParkChunMyong | 95:250afd53b710 | 65 | *format = data.format; |
ParkChunMyong | 95:250afd53b710 | 66 | for (int i = 0; i < nbytes; i++) { |
ParkChunMyong | 95:250afd53b710 | 67 | buf[i] = data.buffer[i]; |
ParkChunMyong | 95:250afd53b710 | 68 | } |
ParkChunMyong | 95:250afd53b710 | 69 | |
ParkChunMyong | 95:250afd53b710 | 70 | init_state(); |
ParkChunMyong | 95:250afd53b710 | 71 | |
ParkChunMyong | 95:250afd53b710 | 72 | UNLOCK(); |
ParkChunMyong | 95:250afd53b710 | 73 | return nbits; |
ParkChunMyong | 95:250afd53b710 | 74 | } |
ParkChunMyong | 95:250afd53b710 | 75 | |
ParkChunMyong | 95:250afd53b710 | 76 | void ReceiverIR::init_state(void) { |
ParkChunMyong | 95:250afd53b710 | 77 | work.c1 = -1; |
ParkChunMyong | 95:250afd53b710 | 78 | work.c2 = -1; |
ParkChunMyong | 95:250afd53b710 | 79 | work.c3 = -1; |
ParkChunMyong | 95:250afd53b710 | 80 | work.d1 = -1; |
ParkChunMyong | 95:250afd53b710 | 81 | work.d2 = -1; |
ParkChunMyong | 95:250afd53b710 | 82 | work.state = Idle; |
ParkChunMyong | 95:250afd53b710 | 83 | data.format = RemoteIR::UNKNOWN; |
ParkChunMyong | 95:250afd53b710 | 84 | data.bitcount = 0; |
ParkChunMyong | 95:250afd53b710 | 85 | timer.stop(); |
ParkChunMyong | 95:250afd53b710 | 86 | timer.reset(); |
ParkChunMyong | 95:250afd53b710 | 87 | for (int i = 0; i < sizeof(data.buffer); i++) { |
ParkChunMyong | 95:250afd53b710 | 88 | data.buffer[i] = 0; |
ParkChunMyong | 95:250afd53b710 | 89 | } |
ParkChunMyong | 95:250afd53b710 | 90 | } |
ParkChunMyong | 95:250afd53b710 | 91 | |
ParkChunMyong | 95:250afd53b710 | 92 | void ReceiverIR::isr_wdt(void) { |
ParkChunMyong | 95:250afd53b710 | 93 | LOCK(); |
ParkChunMyong | 95:250afd53b710 | 94 | static int cnt = 0; |
ParkChunMyong | 95:250afd53b710 | 95 | if ((Idle != work.state) || ((0 <= work.c1) || (0 <= work.c2) || (0 <= work.c3) || (0 <= work.d1) || (0 <= work.d2))) { |
ParkChunMyong | 95:250afd53b710 | 96 | cnt++; |
ParkChunMyong | 95:250afd53b710 | 97 | if (cnt > 50) { |
ParkChunMyong | 95:250afd53b710 | 98 | #if 0 |
ParkChunMyong | 95:250afd53b710 | 99 | printf("# WDT [c1=%d, c2=%d, c3=%d, d1=%d, d2=%d, state=%d, format=%d, bitcount=%d]\n", |
ParkChunMyong | 95:250afd53b710 | 100 | work.c1, |
ParkChunMyong | 95:250afd53b710 | 101 | work.c2, |
ParkChunMyong | 95:250afd53b710 | 102 | work.c3, |
ParkChunMyong | 95:250afd53b710 | 103 | work.d1, |
ParkChunMyong | 95:250afd53b710 | 104 | work.d2, |
ParkChunMyong | 95:250afd53b710 | 105 | work.state, |
ParkChunMyong | 95:250afd53b710 | 106 | data.format, |
ParkChunMyong | 95:250afd53b710 | 107 | data.bitcount); |
ParkChunMyong | 95:250afd53b710 | 108 | #endif |
ParkChunMyong | 95:250afd53b710 | 109 | init_state(); |
ParkChunMyong | 95:250afd53b710 | 110 | cnt = 0; |
ParkChunMyong | 95:250afd53b710 | 111 | } |
ParkChunMyong | 95:250afd53b710 | 112 | } else { |
ParkChunMyong | 95:250afd53b710 | 113 | cnt = 0; |
ParkChunMyong | 95:250afd53b710 | 114 | } |
ParkChunMyong | 95:250afd53b710 | 115 | UNLOCK(); |
ParkChunMyong | 95:250afd53b710 | 116 | } |
ParkChunMyong | 95:250afd53b710 | 117 | |
ParkChunMyong | 95:250afd53b710 | 118 | void ReceiverIR::isr_fall(void) { |
ParkChunMyong | 95:250afd53b710 | 119 | LOCK(); |
ParkChunMyong | 95:250afd53b710 | 120 | switch (work.state) { |
ParkChunMyong | 95:250afd53b710 | 121 | case Idle: |
ParkChunMyong | 95:250afd53b710 | 122 | if (work.c1 < 0) { |
ParkChunMyong | 95:250afd53b710 | 123 | timer.start(); |
ParkChunMyong | 95:250afd53b710 | 124 | work.c1 = timer.read_us(); |
ParkChunMyong | 95:250afd53b710 | 125 | } else { |
ParkChunMyong | 95:250afd53b710 | 126 | work.c3 = timer.read_us(); |
ParkChunMyong | 95:250afd53b710 | 127 | int a = work.c2 - work.c1; |
ParkChunMyong | 95:250afd53b710 | 128 | int b = work.c3 - work.c2; |
ParkChunMyong | 95:250afd53b710 | 129 | if (InRange(a, RemoteIR::TUS_NEC * 16) && InRange(b, RemoteIR::TUS_NEC * 8)) { |
ParkChunMyong | 95:250afd53b710 | 130 | /* |
ParkChunMyong | 95:250afd53b710 | 131 | * NEC. |
ParkChunMyong | 95:250afd53b710 | 132 | */ |
ParkChunMyong | 95:250afd53b710 | 133 | data.format = RemoteIR::NEC; |
ParkChunMyong | 95:250afd53b710 | 134 | work.state = Receiving; |
ParkChunMyong | 95:250afd53b710 | 135 | data.bitcount = 0; |
ParkChunMyong | 95:250afd53b710 | 136 | } else if (InRange(a, RemoteIR::TUS_NEC * 16) && InRange(b, RemoteIR::TUS_NEC * 4)) { |
ParkChunMyong | 95:250afd53b710 | 137 | /* |
ParkChunMyong | 95:250afd53b710 | 138 | * NEC Repeat. |
ParkChunMyong | 95:250afd53b710 | 139 | */ |
ParkChunMyong | 95:250afd53b710 | 140 | data.format = RemoteIR::NEC_REPEAT; |
ParkChunMyong | 95:250afd53b710 | 141 | work.state = Received; |
ParkChunMyong | 95:250afd53b710 | 142 | data.bitcount = 0; |
ParkChunMyong | 95:250afd53b710 | 143 | work.c1 = -1; |
ParkChunMyong | 95:250afd53b710 | 144 | work.c2 = -1; |
ParkChunMyong | 95:250afd53b710 | 145 | work.c3 = -1; |
ParkChunMyong | 95:250afd53b710 | 146 | work.d1 = -1; |
ParkChunMyong | 95:250afd53b710 | 147 | work.d2 = -1; |
ParkChunMyong | 95:250afd53b710 | 148 | } else if (InRange(a, RemoteIR::TUS_AEHA * 8) && InRange(b, RemoteIR::TUS_AEHA * 4)) { |
ParkChunMyong | 95:250afd53b710 | 149 | /* |
ParkChunMyong | 95:250afd53b710 | 150 | * AEHA. |
ParkChunMyong | 95:250afd53b710 | 151 | */ |
ParkChunMyong | 95:250afd53b710 | 152 | data.format = RemoteIR::AEHA; |
ParkChunMyong | 95:250afd53b710 | 153 | work.state = Receiving; |
ParkChunMyong | 95:250afd53b710 | 154 | data.bitcount = 0; |
ParkChunMyong | 95:250afd53b710 | 155 | } else if (InRange(a, RemoteIR::TUS_AEHA * 8) && InRange(b, RemoteIR::TUS_AEHA * 8)) { |
ParkChunMyong | 95:250afd53b710 | 156 | /* |
ParkChunMyong | 95:250afd53b710 | 157 | * AEHA Repeat. |
ParkChunMyong | 95:250afd53b710 | 158 | */ |
ParkChunMyong | 95:250afd53b710 | 159 | data.format = RemoteIR::AEHA_REPEAT; |
ParkChunMyong | 95:250afd53b710 | 160 | work.state = Received; |
ParkChunMyong | 95:250afd53b710 | 161 | data.bitcount = 0; |
ParkChunMyong | 95:250afd53b710 | 162 | work.c1 = -1; |
ParkChunMyong | 95:250afd53b710 | 163 | work.c2 = -1; |
ParkChunMyong | 95:250afd53b710 | 164 | work.c3 = -1; |
ParkChunMyong | 95:250afd53b710 | 165 | work.d1 = -1; |
ParkChunMyong | 95:250afd53b710 | 166 | work.d2 = -1; |
ParkChunMyong | 95:250afd53b710 | 167 | } else { |
ParkChunMyong | 95:250afd53b710 | 168 | init_state(); |
ParkChunMyong | 95:250afd53b710 | 169 | } |
ParkChunMyong | 95:250afd53b710 | 170 | } |
ParkChunMyong | 95:250afd53b710 | 171 | break; |
ParkChunMyong | 95:250afd53b710 | 172 | case Receiving: |
ParkChunMyong | 95:250afd53b710 | 173 | if (RemoteIR::NEC == data.format) { |
ParkChunMyong | 95:250afd53b710 | 174 | work.d2 = timer.read_us(); |
ParkChunMyong | 95:250afd53b710 | 175 | int a = work.d2 - work.d1; |
ParkChunMyong | 95:250afd53b710 | 176 | if (InRange(a, RemoteIR::TUS_NEC * 3)) { |
ParkChunMyong | 95:250afd53b710 | 177 | data.buffer[data.bitcount / 8] |= (1 << (data.bitcount % 8)); |
ParkChunMyong | 95:250afd53b710 | 178 | } else if (InRange(a, RemoteIR::TUS_NEC * 1)) { |
ParkChunMyong | 95:250afd53b710 | 179 | data.buffer[data.bitcount / 8] &= ~(1 << (data.bitcount % 8)); |
ParkChunMyong | 95:250afd53b710 | 180 | } |
ParkChunMyong | 95:250afd53b710 | 181 | data.bitcount++; |
ParkChunMyong | 95:250afd53b710 | 182 | #if 0 |
ParkChunMyong | 95:250afd53b710 | 183 | /* |
ParkChunMyong | 95:250afd53b710 | 184 | * Length of NEC is always 32 bits. |
ParkChunMyong | 95:250afd53b710 | 185 | */ |
ParkChunMyong | 95:250afd53b710 | 186 | if (32 <= data.bitcount) { |
ParkChunMyong | 95:250afd53b710 | 187 | data.state = Received; |
ParkChunMyong | 95:250afd53b710 | 188 | work.c1 = -1; |
ParkChunMyong | 95:250afd53b710 | 189 | work.c2 = -1; |
ParkChunMyong | 95:250afd53b710 | 190 | work.c3 = -1; |
ParkChunMyong | 95:250afd53b710 | 191 | work.d1 = -1; |
ParkChunMyong | 95:250afd53b710 | 192 | work.d2 = -1; |
ParkChunMyong | 95:250afd53b710 | 193 | } |
ParkChunMyong | 95:250afd53b710 | 194 | #else |
ParkChunMyong | 95:250afd53b710 | 195 | /* |
ParkChunMyong | 95:250afd53b710 | 196 | * Set timeout for tail detection automatically. |
ParkChunMyong | 95:250afd53b710 | 197 | */ |
ParkChunMyong | 95:250afd53b710 | 198 | timeout.detach(); |
ParkChunMyong | 95:250afd53b710 | 199 | timeout.attach_us(this, &ReceiverIR::isr_timeout, RemoteIR::TUS_NEC * 5); |
ParkChunMyong | 95:250afd53b710 | 200 | #endif |
ParkChunMyong | 95:250afd53b710 | 201 | } else if (RemoteIR::AEHA == data.format) { |
ParkChunMyong | 95:250afd53b710 | 202 | work.d2 = timer.read_us(); |
ParkChunMyong | 95:250afd53b710 | 203 | int a = work.d2 - work.d1; |
ParkChunMyong | 95:250afd53b710 | 204 | if (InRange(a, RemoteIR::TUS_AEHA * 3)) { |
ParkChunMyong | 95:250afd53b710 | 205 | data.buffer[data.bitcount / 8] |= (1 << (data.bitcount % 8)); |
ParkChunMyong | 95:250afd53b710 | 206 | } else if (InRange(a, RemoteIR::TUS_AEHA * 1)) { |
ParkChunMyong | 95:250afd53b710 | 207 | data.buffer[data.bitcount / 8] &= ~(1 << (data.bitcount % 8)); |
ParkChunMyong | 95:250afd53b710 | 208 | } |
ParkChunMyong | 95:250afd53b710 | 209 | data.bitcount++; |
ParkChunMyong | 95:250afd53b710 | 210 | #if 0 |
ParkChunMyong | 95:250afd53b710 | 211 | /* |
ParkChunMyong | 95:250afd53b710 | 212 | * Typical length of AEHA is 48 bits. |
ParkChunMyong | 95:250afd53b710 | 213 | * Please check a specification of your remote controller if you find a problem. |
ParkChunMyong | 95:250afd53b710 | 214 | */ |
ParkChunMyong | 95:250afd53b710 | 215 | if (48 <= data.bitcount) { |
ParkChunMyong | 95:250afd53b710 | 216 | data.state = Received; |
ParkChunMyong | 95:250afd53b710 | 217 | work.c1 = -1; |
ParkChunMyong | 95:250afd53b710 | 218 | work.c2 = -1; |
ParkChunMyong | 95:250afd53b710 | 219 | work.c3 = -1; |
ParkChunMyong | 95:250afd53b710 | 220 | work.d1 = -1; |
ParkChunMyong | 95:250afd53b710 | 221 | work.d2 = -1; |
ParkChunMyong | 95:250afd53b710 | 222 | } |
ParkChunMyong | 95:250afd53b710 | 223 | #else |
ParkChunMyong | 95:250afd53b710 | 224 | /* |
ParkChunMyong | 95:250afd53b710 | 225 | * Set timeout for tail detection automatically. |
ParkChunMyong | 95:250afd53b710 | 226 | */ |
ParkChunMyong | 95:250afd53b710 | 227 | timeout.detach(); |
ParkChunMyong | 95:250afd53b710 | 228 | timeout.attach_us(this, &ReceiverIR::isr_timeout, RemoteIR::TUS_AEHA * 5); |
ParkChunMyong | 95:250afd53b710 | 229 | #endif |
ParkChunMyong | 95:250afd53b710 | 230 | } else if (RemoteIR::SONY == data.format) { |
ParkChunMyong | 95:250afd53b710 | 231 | work.d1 = timer.read_us(); |
ParkChunMyong | 95:250afd53b710 | 232 | } |
ParkChunMyong | 95:250afd53b710 | 233 | break; |
ParkChunMyong | 95:250afd53b710 | 234 | case Received: |
ParkChunMyong | 95:250afd53b710 | 235 | break; |
ParkChunMyong | 95:250afd53b710 | 236 | default: |
ParkChunMyong | 95:250afd53b710 | 237 | break; |
ParkChunMyong | 95:250afd53b710 | 238 | } |
ParkChunMyong | 95:250afd53b710 | 239 | UNLOCK(); |
ParkChunMyong | 95:250afd53b710 | 240 | } |
ParkChunMyong | 95:250afd53b710 | 241 | |
ParkChunMyong | 95:250afd53b710 | 242 | void ReceiverIR::isr_rise(void) { |
ParkChunMyong | 95:250afd53b710 | 243 | LOCK(); |
ParkChunMyong | 95:250afd53b710 | 244 | switch (work.state) { |
ParkChunMyong | 95:250afd53b710 | 245 | case Idle: |
ParkChunMyong | 95:250afd53b710 | 246 | if (0 <= work.c1) { |
ParkChunMyong | 95:250afd53b710 | 247 | work.c2 = timer.read_us(); |
ParkChunMyong | 95:250afd53b710 | 248 | int a = work.c2 - work.c1; |
ParkChunMyong | 95:250afd53b710 | 249 | if (InRange(a, RemoteIR::TUS_SONY * 4)) { |
ParkChunMyong | 95:250afd53b710 | 250 | data.format = RemoteIR::SONY; |
ParkChunMyong | 95:250afd53b710 | 251 | work.state = Receiving; |
ParkChunMyong | 95:250afd53b710 | 252 | data.bitcount = 0; |
ParkChunMyong | 95:250afd53b710 | 253 | } else { |
ParkChunMyong | 95:250afd53b710 | 254 | static const int MINIMUM_LEADER_WIDTH = 150; |
ParkChunMyong | 95:250afd53b710 | 255 | if (a < MINIMUM_LEADER_WIDTH) { |
ParkChunMyong | 95:250afd53b710 | 256 | init_state(); |
ParkChunMyong | 95:250afd53b710 | 257 | } |
ParkChunMyong | 95:250afd53b710 | 258 | } |
ParkChunMyong | 95:250afd53b710 | 259 | } else { |
ParkChunMyong | 95:250afd53b710 | 260 | init_state(); |
ParkChunMyong | 95:250afd53b710 | 261 | } |
ParkChunMyong | 95:250afd53b710 | 262 | break; |
ParkChunMyong | 95:250afd53b710 | 263 | case Receiving: |
ParkChunMyong | 95:250afd53b710 | 264 | if (RemoteIR::NEC == data.format) { |
ParkChunMyong | 95:250afd53b710 | 265 | work.d1 = timer.read_us(); |
ParkChunMyong | 95:250afd53b710 | 266 | } else if (RemoteIR::AEHA == data.format) { |
ParkChunMyong | 95:250afd53b710 | 267 | work.d1 = timer.read_us(); |
ParkChunMyong | 95:250afd53b710 | 268 | } else if (RemoteIR::SONY == data.format) { |
ParkChunMyong | 95:250afd53b710 | 269 | work.d2 = timer.read_us(); |
ParkChunMyong | 95:250afd53b710 | 270 | int a = work.d2 - work.d1; |
ParkChunMyong | 95:250afd53b710 | 271 | if (InRange(a, RemoteIR::TUS_SONY * 2)) { |
ParkChunMyong | 95:250afd53b710 | 272 | data.buffer[data.bitcount / 8] |= (1 << (data.bitcount % 8)); |
ParkChunMyong | 95:250afd53b710 | 273 | } else if (InRange(a, RemoteIR::TUS_SONY * 1)) { |
ParkChunMyong | 95:250afd53b710 | 274 | data.buffer[data.bitcount / 8] &= ~(1 << (data.bitcount % 8)); |
ParkChunMyong | 95:250afd53b710 | 275 | } |
ParkChunMyong | 95:250afd53b710 | 276 | data.bitcount++; |
ParkChunMyong | 95:250afd53b710 | 277 | #if 0 |
ParkChunMyong | 95:250afd53b710 | 278 | /* |
ParkChunMyong | 95:250afd53b710 | 279 | * How do I know the correct length? (6bits, 12bits, 15bits, 20bits...) |
ParkChunMyong | 95:250afd53b710 | 280 | * By a model only? |
ParkChunMyong | 95:250afd53b710 | 281 | * Please check a specification of your remote controller if you find a problem. |
ParkChunMyong | 95:250afd53b710 | 282 | */ |
ParkChunMyong | 95:250afd53b710 | 283 | if (12 <= data.bitcount) { |
ParkChunMyong | 95:250afd53b710 | 284 | data.state = Received; |
ParkChunMyong | 95:250afd53b710 | 285 | work.c1 = -1; |
ParkChunMyong | 95:250afd53b710 | 286 | work.c2 = -1; |
ParkChunMyong | 95:250afd53b710 | 287 | work.c3 = -1; |
ParkChunMyong | 95:250afd53b710 | 288 | work.d1 = -1; |
ParkChunMyong | 95:250afd53b710 | 289 | work.d2 = -1; |
ParkChunMyong | 95:250afd53b710 | 290 | } |
ParkChunMyong | 95:250afd53b710 | 291 | #else |
ParkChunMyong | 95:250afd53b710 | 292 | /* |
ParkChunMyong | 95:250afd53b710 | 293 | * Set timeout for tail detection automatically. |
ParkChunMyong | 95:250afd53b710 | 294 | */ |
ParkChunMyong | 95:250afd53b710 | 295 | timeout.detach(); |
ParkChunMyong | 95:250afd53b710 | 296 | timeout.attach_us(this, &ReceiverIR::isr_timeout, RemoteIR::TUS_SONY * 4); |
ParkChunMyong | 95:250afd53b710 | 297 | #endif |
ParkChunMyong | 95:250afd53b710 | 298 | } |
ParkChunMyong | 95:250afd53b710 | 299 | break; |
ParkChunMyong | 95:250afd53b710 | 300 | case Received: |
ParkChunMyong | 95:250afd53b710 | 301 | break; |
ParkChunMyong | 95:250afd53b710 | 302 | default: |
ParkChunMyong | 95:250afd53b710 | 303 | break; |
ParkChunMyong | 95:250afd53b710 | 304 | } |
ParkChunMyong | 95:250afd53b710 | 305 | UNLOCK(); |
ParkChunMyong | 95:250afd53b710 | 306 | } |
ParkChunMyong | 95:250afd53b710 | 307 | |
ParkChunMyong | 95:250afd53b710 | 308 | void ReceiverIR::isr_timeout(void) { |
ParkChunMyong | 95:250afd53b710 | 309 | LOCK(); |
ParkChunMyong | 95:250afd53b710 | 310 | #if 0 |
ParkChunMyong | 95:250afd53b710 | 311 | printf("# TIMEOUT [c1=%d, c2=%d, c3=%d, d1=%d, d2=%d, state=%d, format=%d, bitcount=%d]\n", |
ParkChunMyong | 95:250afd53b710 | 312 | work.c1, |
ParkChunMyong | 95:250afd53b710 | 313 | work.c2, |
ParkChunMyong | 95:250afd53b710 | 314 | work.c3, |
ParkChunMyong | 95:250afd53b710 | 315 | work.d1, |
ParkChunMyong | 95:250afd53b710 | 316 | work.d2, |
ParkChunMyong | 95:250afd53b710 | 317 | work.state, |
ParkChunMyong | 95:250afd53b710 | 318 | data.format, |
ParkChunMyong | 95:250afd53b710 | 319 | data.bitcount); |
ParkChunMyong | 95:250afd53b710 | 320 | #endif |
ParkChunMyong | 95:250afd53b710 | 321 | if (work.state == Receiving) { |
ParkChunMyong | 95:250afd53b710 | 322 | work.state = Received; |
ParkChunMyong | 95:250afd53b710 | 323 | work.c1 = -1; |
ParkChunMyong | 95:250afd53b710 | 324 | work.c2 = -1; |
ParkChunMyong | 95:250afd53b710 | 325 | work.c3 = -1; |
ParkChunMyong | 95:250afd53b710 | 326 | work.d1 = -1; |
ParkChunMyong | 95:250afd53b710 | 327 | work.d2 = -1; |
ParkChunMyong | 95:250afd53b710 | 328 | } |
ParkChunMyong | 95:250afd53b710 | 329 | UNLOCK(); |
ParkChunMyong | 95:250afd53b710 | 330 | } |
ParkChunMyong | 95:250afd53b710 | 331 |