IRremote
ir_LG.cpp
Go to the documentation of this file.
1 #include "IRremote.h"
2 
3 //==============================================================================
4 // L GGGG
5 // L G
6 // L G GG
7 // L G G
8 // LLLLL GGG
9 //==============================================================================
10 
11 #define LG_BITS 28
12 
13 #define LG_HDR_MARK 8000
14 #define LG_HDR_SPACE 4000
15 #define LG_BIT_MARK 600
16 #define LG_ONE_SPACE 1600
17 #define LG_ZERO_SPACE 550
18 #define LG_RPT_LENGTH 60000
19 
20 //+=============================================================================
21 #if DECODE_LG
22 bool IRrecv::decodeLG(decode_results *results) {
23  long data = 0;
24  int offset = 1; // Skip first space
25 
26  // Check we have the right amount of data
27  if (irparams.rawlen < (2 * LG_BITS) + 1)
28  return false;
29 
30  // Initial mark/space
31  if (!MATCH_MARK(results->rawbuf[offset], LG_HDR_MARK)) {
32  return false;
33  }
34  offset++;
35 
36  if (!MATCH_SPACE(results->rawbuf[offset], LG_HDR_SPACE)) {
37  return false;
38  }
39  offset++;
40 
41  for (int i = 0; i < LG_BITS; i++) {
42  if (!MATCH_MARK(results->rawbuf[offset], LG_BIT_MARK)) {
43  return false;
44  }
45  offset++;
46 
47  if (MATCH_SPACE(results->rawbuf[offset], LG_ONE_SPACE)) {
48  data = (data << 1) | 1;
49  } else if (MATCH_SPACE(results->rawbuf[offset], LG_ZERO_SPACE)) {
50  data = (data << 1) | 0;
51  } else {
52  return false;
53  }
54  offset++;
55  }
56 
57  // Stop bit
58  if (!MATCH_MARK(results->rawbuf[offset], LG_BIT_MARK)) {
59  return false;
60  }
61 
62  // Success
63  results->bits = LG_BITS;
64  results->value = data;
65  results->decode_type = LG;
66  return true;
67 }
68 #endif
69 
70 //+=============================================================================
71 #if SEND_LG
72 void IRsend::sendLG(unsigned long data, int nbits) {
73  // Set IR carrier frequency
74  enableIROut(38);
75 
76  // Header
80 
81  // Data
82  for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) {
83  if (data & mask) {
86  } else {
89  }
90  }
91  space(0); // Always end with the LED off
92 }
93 #endif
94 
decode_results
Results returned from the decoder.
Definition: IRremote.h:174
decode_results::bits
int bits
Number of bits in decoded value.
Definition: IRremote.h:179
decode_results::rawbuf
volatile unsigned int * rawbuf
Raw intervals in 50uS ticks.
Definition: IRremote.h:180
IRsend::mark
void mark(unsigned int usec)
Definition: irSend.cpp:69
IRsend::enableIROut
void enableIROut(int khz)
Definition: irSend.cpp:127
decode_results::decode_type
decode_type_t decode_type
UNKNOWN, NEC, SONY, RC5, ...
Definition: IRremote.h:176
LG
@ LG
Definition: IRremote.h:124
MATCH_SPACE
int MATCH_SPACE(int measured_ticks, int desired_us)
Definition: IRremote.cpp:89
LG_ZERO_SPACE
#define LG_ZERO_SPACE
Definition: ir_LG.cpp:17
IRsend::sendLG
void sendLG(unsigned long data, int nbits)
Definition: ir_LG.cpp:72
irparams
volatile irparams_t irparams
Allow all parts of the code access to the ISR data NB.
LG_ONE_SPACE
#define LG_ONE_SPACE
Definition: ir_LG.cpp:16
LG_BITS
#define LG_BITS
Definition: ir_LG.cpp:11
IRremote.h
Public API to the library.
LG_BIT_MARK
#define LG_BIT_MARK
Definition: ir_LG.cpp:15
IRsend::space
void space(unsigned int usec)
Definition: irSend.cpp:103
decode_results::value
unsigned long value
Decoded value [max 32-bits].
Definition: IRremote.h:178
MATCH_MARK
int MATCH_MARK(int measured_ticks, int desired_us)
Definition: IRremote.cpp:63
LG_HDR_SPACE
#define LG_HDR_SPACE
Definition: ir_LG.cpp:14
LG_HDR_MARK
#define LG_HDR_MARK
Definition: ir_LG.cpp:13
irparams_t::rawlen
unsigned int rawlen
counter of entries in rawbuf
Definition: IRremoteInt.h:45