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.
Dependents: mbed-os-example-FinalReal mbed-os-example-FinalReal
ir_NEC.cpp
00001 #include "IRremote.h" 00002 #include "IRremoteInt.h" 00003 00004 //============================================================================== 00005 // N N EEEEE CCCC 00006 // NN N E C 00007 // N N N EEE C 00008 // N NN E C 00009 // N N EEEEE CCCC 00010 //============================================================================== 00011 00012 #define NEC_BITS 32 00013 #define NEC_HDR_MARK 9000 00014 #define NEC_HDR_SPACE 4500 00015 #define NEC_BIT_MARK 560 00016 #define NEC_ONE_SPACE 1690 00017 #define NEC_ZERO_SPACE 560 00018 #define NEC_RPT_SPACE 2250 00019 00020 //+============================================================================= 00021 #if SEND_NEC 00022 void IRsend::sendNEC (unsigned long data, int nbits) 00023 { 00024 // Set IR carrier frequency 00025 enableIROut(38); 00026 00027 // Header 00028 mark(NEC_HDR_MARK); 00029 space(NEC_HDR_SPACE); 00030 00031 // Data 00032 for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { 00033 if (data & mask) { 00034 mark(NEC_BIT_MARK); 00035 space(NEC_ONE_SPACE); 00036 } else { 00037 mark(NEC_BIT_MARK); 00038 space(NEC_ZERO_SPACE); 00039 } 00040 } 00041 00042 // Footer 00043 mark(NEC_BIT_MARK); 00044 space(0); // Always end with the LED off 00045 } 00046 #endif 00047 00048 //+============================================================================= 00049 // NECs have a repeat only 4 items long 00050 // 00051 #if DECODE_NEC 00052 bool IRrecv::decodeNEC (decode_results *results) 00053 { 00054 long data = 0; // We decode in to here; Start with nothing 00055 int offset = 1; // Index in to results; Skip first entry!? 00056 00057 // Check header "mark" 00058 if (!MATCH_MARK(results->rawbuf[offset], NEC_HDR_MARK)) return false ; 00059 offset++; 00060 00061 // Check for repeat 00062 /*if ( (irparams.rawlen == 4) 00063 && MATCH_SPACE(results->rawbuf[offset ], NEC_RPT_SPACE) 00064 && MATCH_MARK (results->rawbuf[offset+1], NEC_BIT_MARK ) 00065 ) { 00066 results->bits = 0; 00067 results->value = REPEAT; 00068 results->decode_type = NEC; 00069 return true; 00070 } 00071 */ 00072 00073 // Check we have enough data 00074 if (irparams.rawlen < (2 * NEC_BITS) + 4) return false ; 00075 00076 // Check header "space" 00077 if (!MATCH_SPACE(results->rawbuf[offset], NEC_HDR_SPACE)) return false ; 00078 offset++; 00079 00080 int forInverse[32] = {0}; 00081 int j = 31; 00082 // Build the data 00083 for (int i = 0; i < NEC_BITS; i++) { 00084 // Check data "mark" 00085 if (!MATCH_MARK(results->rawbuf[offset], NEC_BIT_MARK)) return false ; 00086 offset++; 00087 // Suppend this bit 00088 if (MATCH_SPACE(results->rawbuf[offset], NEC_ONE_SPACE )) 00089 forInverse[i] = 1; 00090 else if (MATCH_SPACE(results->rawbuf[offset], NEC_ZERO_SPACE)) 00091 forInverse[i] = 0; 00092 else return false ; 00093 offset++; 00094 00095 } 00096 00097 00098 for(int j = 0; j < 8; j++){ // 00099 data = (data << 1) | forInverse[j]; 00100 } 00101 for(int j = 8; j < 16; j++){ // 00102 data = (data << 1) | forInverse[j]; 00103 } 00104 for(int j = 23; j > 15; j--){ // 00105 data = (data << 1) | forInverse[j]; 00106 } 00107 for(int j = 31; j > 23; j--){ // 00108 data = (data << 1) | forInverse[j]; 00109 } 00110 00111 00112 00113 00114 // Success 00115 results->bits = NEC_BITS; 00116 results->value = data; 00117 results->decode_type = NEC; 00118 00119 return true; 00120 } 00121 #endif
Generated on Tue Jul 12 2022 22:48:11 by
1.7.2