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

Committer:
eunmango
Date:
Sun Jun 16 04:49:45 2019 +0000
Revision:
8:9d9b1e1f9b1b
Parent:
0:70c8e56bac45
s

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yuhki50 0:70c8e56bac45 1 #include "IRremote.h"
yuhki50 0:70c8e56bac45 2 #include "IRremoteInt.h"
yuhki50 0:70c8e56bac45 3
yuhki50 0:70c8e56bac45 4 //==============================================================================
yuhki50 0:70c8e56bac45 5 // L GGGG
yuhki50 0:70c8e56bac45 6 // L G
yuhki50 0:70c8e56bac45 7 // L G GG
yuhki50 0:70c8e56bac45 8 // L G G
yuhki50 0:70c8e56bac45 9 // LLLLL GGG
yuhki50 0:70c8e56bac45 10 //==============================================================================
yuhki50 0:70c8e56bac45 11
yuhki50 0:70c8e56bac45 12 #define LG_BITS 28
yuhki50 0:70c8e56bac45 13
yuhki50 0:70c8e56bac45 14 #define LG_HDR_MARK 8000
yuhki50 0:70c8e56bac45 15 #define LG_HDR_SPACE 4000
yuhki50 0:70c8e56bac45 16 #define LG_BIT_MARK 600
yuhki50 0:70c8e56bac45 17 #define LG_ONE_SPACE 1600
yuhki50 0:70c8e56bac45 18 #define LG_ZERO_SPACE 550
yuhki50 0:70c8e56bac45 19 #define LG_RPT_LENGTH 60000
yuhki50 0:70c8e56bac45 20
yuhki50 0:70c8e56bac45 21 //+=============================================================================
yuhki50 0:70c8e56bac45 22 #if DECODE_LG
yuhki50 0:70c8e56bac45 23 bool IRrecv::decodeLG (decode_results *results)
yuhki50 0:70c8e56bac45 24 {
yuhki50 0:70c8e56bac45 25 long data = 0;
yuhki50 0:70c8e56bac45 26 int offset = 1; // Skip first space
yuhki50 0:70c8e56bac45 27
yuhki50 0:70c8e56bac45 28 // Check we have the right amount of data
yuhki50 0:70c8e56bac45 29 if (irparams.rawlen < (2 * LG_BITS) + 1 ) return false ;
yuhki50 0:70c8e56bac45 30
yuhki50 0:70c8e56bac45 31 // Initial mark/space
yuhki50 0:70c8e56bac45 32 if (!MATCH_MARK(results->rawbuf[offset++], LG_HDR_MARK)) return false ;
yuhki50 0:70c8e56bac45 33 if (!MATCH_SPACE(results->rawbuf[offset++], LG_HDR_SPACE)) return false ;
yuhki50 0:70c8e56bac45 34
yuhki50 0:70c8e56bac45 35 for (int i = 0; i < LG_BITS; i++) {
yuhki50 0:70c8e56bac45 36 if (!MATCH_MARK(results->rawbuf[offset++], LG_BIT_MARK)) return false ;
yuhki50 0:70c8e56bac45 37
yuhki50 0:70c8e56bac45 38 if (MATCH_SPACE(results->rawbuf[offset], LG_ONE_SPACE)) data = (data << 1) | 1 ;
yuhki50 0:70c8e56bac45 39 else if (MATCH_SPACE(results->rawbuf[offset], LG_ZERO_SPACE)) data = (data << 1) | 0 ;
yuhki50 0:70c8e56bac45 40 else return false ;
yuhki50 0:70c8e56bac45 41 offset++;
yuhki50 0:70c8e56bac45 42 }
yuhki50 0:70c8e56bac45 43
yuhki50 0:70c8e56bac45 44 // Stop bit
yuhki50 0:70c8e56bac45 45 if (!MATCH_MARK(results->rawbuf[offset], LG_BIT_MARK)) return false ;
yuhki50 0:70c8e56bac45 46
yuhki50 0:70c8e56bac45 47 // Success
yuhki50 0:70c8e56bac45 48 results->bits = LG_BITS;
yuhki50 0:70c8e56bac45 49 results->value = data;
yuhki50 0:70c8e56bac45 50 results->decode_type = LG;
yuhki50 0:70c8e56bac45 51 return true;
yuhki50 0:70c8e56bac45 52 }
yuhki50 0:70c8e56bac45 53 #endif
yuhki50 0:70c8e56bac45 54
yuhki50 0:70c8e56bac45 55 //+=============================================================================
yuhki50 0:70c8e56bac45 56 #if SEND_LG
yuhki50 0:70c8e56bac45 57 void IRsend::sendLG (unsigned long data, int nbits)
yuhki50 0:70c8e56bac45 58 {
yuhki50 0:70c8e56bac45 59 // Set IR carrier frequency
yuhki50 0:70c8e56bac45 60 enableIROut(38);
yuhki50 0:70c8e56bac45 61
yuhki50 0:70c8e56bac45 62 // Header
yuhki50 0:70c8e56bac45 63 mark(LG_HDR_MARK);
yuhki50 0:70c8e56bac45 64 space(LG_HDR_SPACE);
yuhki50 0:70c8e56bac45 65 mark(LG_BIT_MARK);
yuhki50 0:70c8e56bac45 66
yuhki50 0:70c8e56bac45 67 // Data
yuhki50 0:70c8e56bac45 68 for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) {
yuhki50 0:70c8e56bac45 69 if (data & mask) {
yuhki50 0:70c8e56bac45 70 space(LG_ONE_SPACE);
yuhki50 0:70c8e56bac45 71 mark(LG_BIT_MARK);
yuhki50 0:70c8e56bac45 72 } else {
yuhki50 0:70c8e56bac45 73 space(LG_ZERO_SPACE);
yuhki50 0:70c8e56bac45 74 mark(LG_BIT_MARK);
yuhki50 0:70c8e56bac45 75 }
yuhki50 0:70c8e56bac45 76 }
yuhki50 0:70c8e56bac45 77 space(0); // Always end with the LED off
yuhki50 0:70c8e56bac45 78 }
yuhki50 0:70c8e56bac45 79 #endif
yuhki50 0:70c8e56bac45 80