Infrared remote library for Arduino: send and receive infrared signals with multiple protocols Port from Arduino-IRremote https://github.com/z3t0/Arduino-IRremote
Dependents: mbed-os-example-FinalReal_copy
Revision 8:9d9b1e1f9b1b, committed 2019-06-16
- Comitter:
- eunmango
- Date:
- Sun Jun 16 04:49:45 2019 +0000
- Parent:
- 7:c82a0d54a024
- Commit message:
- s
Changed in this revision
irRecv.cpp | Show annotated file Show diff for this revision Revisions of this file |
ir_NEC.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r c82a0d54a024 -r 9d9b1e1f9b1b irRecv.cpp --- a/irRecv.cpp Thu Mar 10 15:39:34 2016 +0000 +++ b/irRecv.cpp Sun Jun 16 04:49:45 2019 +0000 @@ -102,11 +102,11 @@ void IRrecv::enableIRIn ( ) { _ticker.detach(); - _ticker.attach_us(this, &IRrecv::timer_isr, USECPERTICK); + _ticker.attach_us(this, &IRrecv::timer_isr, USECPERTICK); // 100ms마다, "timer_isr" 메소드 실행 // Initialize state machine variables - irparams.rcvstate = STATE_IDLE; - irparams.rawlen = 0; + irparams.rcvstate = STATE_IDLE; // irparams라는 구조체의 muchine state를 의미하는 변수에 STATE_IDLE 상태(아마도 초기상태) 할당 + irparams.rawlen = 0; // raw buffer의 length 0으로 초기화 } //+=============================================================================
diff -r c82a0d54a024 -r 9d9b1e1f9b1b ir_NEC.cpp --- a/ir_NEC.cpp Thu Mar 10 15:39:34 2016 +0000 +++ b/ir_NEC.cpp Sun Jun 16 04:49:45 2019 +0000 @@ -21,27 +21,27 @@ #if SEND_NEC void IRsend::sendNEC (unsigned long data, int nbits) { - // Set IR carrier frequency - enableIROut(38); + // Set IR carrier frequency + enableIROut(38); - // Header - mark(NEC_HDR_MARK); - space(NEC_HDR_SPACE); + // Header + mark(NEC_HDR_MARK); + space(NEC_HDR_SPACE); - // Data - for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { - if (data & mask) { - mark(NEC_BIT_MARK); - space(NEC_ONE_SPACE); - } else { - mark(NEC_BIT_MARK); - space(NEC_ZERO_SPACE); - } - } + // Data + for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { + if (data & mask) { + mark(NEC_BIT_MARK); + space(NEC_ONE_SPACE); + } else { + mark(NEC_BIT_MARK); + space(NEC_ZERO_SPACE); + } + } - // Footer - mark(NEC_BIT_MARK); - space(0); // Always end with the LED off + // Footer + mark(NEC_BIT_MARK); + space(0); // Always end with the LED off } #endif @@ -51,48 +51,71 @@ #if DECODE_NEC bool IRrecv::decodeNEC (decode_results *results) { - long data = 0; // We decode in to here; Start with nothing - int offset = 1; // Index in to results; Skip first entry!? + long data = 0; // We decode in to here; Start with nothing + int offset = 1; // Index in to results; Skip first entry!? - // Check header "mark" - if (!MATCH_MARK(results->rawbuf[offset], NEC_HDR_MARK)) return false ; - offset++; + // Check header "mark" + if (!MATCH_MARK(results->rawbuf[offset], NEC_HDR_MARK)) return false ; + offset++; - // Check for repeat - if ( (irparams.rawlen == 4) - && MATCH_SPACE(results->rawbuf[offset ], NEC_RPT_SPACE) - && MATCH_MARK (results->rawbuf[offset+1], NEC_BIT_MARK ) - ) { - results->bits = 0; - results->value = REPEAT; - results->decode_type = NEC; - return true; - } + // Check for repeat + /*if ( (irparams.rawlen == 4) + && MATCH_SPACE(results->rawbuf[offset ], NEC_RPT_SPACE) + && MATCH_MARK (results->rawbuf[offset+1], NEC_BIT_MARK ) + ) { + results->bits = 0; + results->value = REPEAT; + results->decode_type = NEC; + return true; + } + */ - // Check we have enough data - if (irparams.rawlen < (2 * NEC_BITS) + 4) return false ; + // Check we have enough data + if (irparams.rawlen < (2 * NEC_BITS) + 4) return false ; + + // Check header "space" + if (!MATCH_SPACE(results->rawbuf[offset], NEC_HDR_SPACE)) return false ; + offset++; - // Check header "space" - if (!MATCH_SPACE(results->rawbuf[offset], NEC_HDR_SPACE)) return false ; - offset++; - - // Build the data - for (int i = 0; i < NEC_BITS; i++) { - // Check data "mark" - if (!MATCH_MARK(results->rawbuf[offset], NEC_BIT_MARK)) return false ; - offset++; + int forInverse[32] = {0}; + int j = 31; + // Build the data + for (int i = 0; i < NEC_BITS; i++) { + // Check data "mark" + if (!MATCH_MARK(results->rawbuf[offset], NEC_BIT_MARK)) return false ; + offset++; // Suppend this bit - if (MATCH_SPACE(results->rawbuf[offset], NEC_ONE_SPACE )) data = (data << 1) | 1 ; - else if (MATCH_SPACE(results->rawbuf[offset], NEC_ZERO_SPACE)) data = (data << 1) | 0 ; - else return false ; - offset++; - } + if (MATCH_SPACE(results->rawbuf[offset], NEC_ONE_SPACE )) + forInverse[i] = 1; + else if (MATCH_SPACE(results->rawbuf[offset], NEC_ZERO_SPACE)) + forInverse[i] = 0; + else return false ; + offset++; + + } + - // Success - results->bits = NEC_BITS; - results->value = data; - results->decode_type = NEC; + for(int j = 0; j < 8; j++){ // + data = (data << 1) | forInverse[j]; + } + for(int j = 8; j < 16; j++){ // + data = (data << 1) | forInverse[j]; + } + for(int j = 23; j > 15; j--){ // + data = (data << 1) | forInverse[j]; + } + for(int j = 31; j > 23; j--){ // + data = (data << 1) | forInverse[j]; + } - return true; + + + + // Success + results->bits = NEC_BITS; + results->value = data; + results->decode_type = NEC; + + return true; } -#endif +#endif \ No newline at end of file