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