* Decodes also Onkyo and Apple */
| 233 | * Decodes also Onkyo and Apple |
| 234 | */ |
| 235 | bool IRrecv::decodeNEC() { |
| 236 | /* |
| 237 | * First check for right data length |
| 238 | * Next check start bit |
| 239 | * Next try the decode |
| 240 | */ |
| 241 | // Check we have the right amount of data (68). The +4 is for initial gap, start bit mark and space + stop bit mark. |
| 242 | if (!(decodedIRData.rawlen == ((2 * NEC_BITS) + 4) || (decodedIRData.rawlen == 4))) { |
| 243 | DEBUG_PRINT(F("NEC: Data length=")); |
| 244 | DEBUG_PRINT(decodedIRData.rawlen); |
| 245 | DEBUG_PRINTLN(F(" is not 68 or 4")); |
| 246 | return false; |
| 247 | } |
| 248 | |
| 249 | // Check header "mark" this must be done for repeat and data |
| 250 | if (!matchMark(irparams.rawbuf[1], NEC_HEADER_MARK)) { |
| 251 | return false; |
| 252 | } |
| 253 | |
| 254 | // Check for repeat - here we have another header space length |
| 255 | if (decodedIRData.rawlen == 4) { |
| 256 | if (matchSpace(irparams.rawbuf[2], NEC_REPEAT_HEADER_SPACE) |
| 257 | && matchMark(irparams.rawbuf[3], NEC_BIT_MARK)) { |
| 258 | decodedIRData.flags = IRDATA_FLAGS_IS_REPEAT | IRDATA_FLAGS_IS_LSB_FIRST; |
| 259 | decodedIRData.address = lastDecodedAddress; |
| 260 | decodedIRData.command = lastDecodedCommand; |
| 261 | decodedIRData.protocol = lastDecodedProtocol; // Allow recognition of repeats of NEC, APPLE, ONKYO and OPENLASIR and maybe LG |
| 262 | return true; |
| 263 | } |
| 264 | return false; |
| 265 | } |
| 266 | |
| 267 | // Check command header space |
| 268 | if (!matchSpace(irparams.rawbuf[2], NEC_HEADER_SPACE)) { |
| 269 | DEBUG_PRINTLN(F("NEC: Header space length is wrong")); |
| 270 | return false; |
| 271 | } |
| 272 | |
| 273 | // Decode as NEC protocol |
| 274 | decodePulseDistanceWidthData_P(&NECProtocolConstants, NEC_BITS); |
| 275 | |
| 276 | // Success |
| 277 | // decodedIRData.flags = IRDATA_FLAGS_IS_LSB_FIRST; // Not required, since this is the start value |
| 278 | LongUnion tValue; |
| 279 | tValue.ULong = decodedIRData.decodedRawData; |
| 280 | decodedIRData.command = tValue.UByte.MidHighByte; // 8 bit |
| 281 | |
| 282 | #if defined(DECODE_ONKYO) // Decodes NEC and Apple as Onkyo |
| 283 | // Here only Onkyo protocol is supported -> force 16 bit address and command decoding. No NEC decoding possible! |
| 284 | decodedIRData.address = tValue.UWord.LowWord; // first 16 bit |
| 285 | decodedIRData.protocol = ONKYO; |
| 286 | decodedIRData.command = tValue.UWord.HighWord; // 16 bit command |
| 287 | #else |
| 288 | // Address |
| 289 | if (tValue.UWord.LowWord == APPLE_ADDRESS) { |
| 290 | /* |
| 291 | * Apple |
| 292 | */ |
nothing calls this directly
no test coverage detected