forked from crankyoldgit/IRremoteESP8266
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathir_LG.cpp
130 lines (115 loc) · 4.39 KB
/
ir_LG.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "IRremote.h"
#include "IRremoteInt.h"
// Nov 2016 marcosamarinho included 32bits
//==============================================================================
// L GGGG
// L G
// L G GG
// L G G
// LLLLL GGG
//==============================================================================
//LIRC LGE_6711A20015N
#define LG_BITS 28
#define LG_HDR_MARK 8000
#define LG_HDR_SPACE 4000
#define LG_BIT_MARK 600
#define LG_ONE_SPACE 1600
#define LG_ZERO_SPACE 550
#define LG_RPT_LENGTH 60000
//included marcosamarinho Nov 2016
// see LIRC LGE_6711A20015N
#define LG_BITS_32 32
#define LG_HDR_MARK_32 4500
#define LG_HDR_SPACE_32 4500
#define LG_BIT_MARK_32 600
#define LG_ONE_SPACE_32 1600
#define LG_ZERO_SPACE_32 550
#define LG_RPT_LENGTH_32 44000
//+=============================================================================
#if DECODE_LG_32
bool IRrecv::decodeLG_32(decode_results *results) {
// Check we have the right amount of data
if (irparams.rawlen < 2 * LG_BITS_32 + OFFSET_START ) return false;
unsigned long data = 0;
int offset = OFFSET_START; // Skip first space
// Header
if (!MATCH_MARK( results->rawbuf[offset++], LG_HDR_MARK_32 )) return false;
if (!MATCH_SPACE(results->rawbuf[offset++], LG_HDR_SPACE_32)) return false;
// Data
for (int i = 0; i < LG_BITS_32; i++) {
if (!MATCH_MARK( results->rawbuf[offset++], LG_BIT_MARK_32 )) return false;
if (!space_decode(data,results->rawbuf[offset++],LG_ONE_SPACE_32,LG_ZERO_SPACE_32)) return false;
}
// Forced decode repetition to avoid Samsung that have same times
if (!MATCH_MARK( results->rawbuf[offset++], LG_BIT_MARK_32 )) return false;
if (!MATCH_SPACE(results->rawbuf[offset++], LG_RPT_LENGTH_32)) return false;
if (!MATCH_MARK( results->rawbuf[offset++], LG_HDR_MARK_32 )) return false;
// Success
results->bits = LG_BITS_32;
results->address = data >> 12;
results->command = data & 0xFF;
results->value = data;
results->decode_type = LG;
return true;
}
#endif
#if DECODE_LG
bool IRrecv::decodeLG(decode_results *results) {
// Check we have the right amount of data
if (irparams.rawlen < 2 * LG_BITS + OFFSET_START ) return false;
unsigned long data = 0;
int offset = OFFSET_START; // Skip first space
// Header
if (!MATCH_MARK( results->rawbuf[offset++], LG_HDR_MARK )) return false;
if (!MATCH_SPACE(results->rawbuf[offset++], LG_HDR_SPACE)) return false;
// Data
for (int i = 0; i < LG_BITS; i++) {
if (!MATCH_MARK( results->rawbuf[offset++], LG_BIT_MARK )) return false;
if (!space_decode(data,results->rawbuf[offset++],LG_ONE_SPACE,LG_ZERO_SPACE)) return false;
}
// Forced decode repetition to avoid Sanyo that have same times
if (!MATCH_MARK( results->rawbuf[offset++], LG_BIT_MARK )) return false;
if (!MATCH_SPACE(results->rawbuf[offset++], LG_RPT_LENGTH)) return false;
if (!MATCH_MARK( results->rawbuf[offset++], LG_HDR_MARK )) return false;
// Success
results->bits = LG_BITS;
results->value = data;
results->decode_type = LG;
return true;
}
#endif
//+=============================================================================
#if SEND_LG
void IRsend::sendLG (unsigned long data, int nbits) {
// Set IR carrier frequency
enableIROut(38);
// Header
if ( nbits==32 ) {
mark( LG_HDR_MARK_32 );
space(LG_HDR_SPACE_32);
// Data bits
for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) {
mark( LG_BIT_MARK_32 );
space_encode(data & mask,LG_ONE_SPACE_32,LG_ZERO_SPACE_32);
}
// forced decode footer for not take Samsung that have the same times
mark( LG_BIT_MARK_32 );
space(LG_RPT_LENGTH_32);
mark( LG_HDR_MARK_32 );
space(LG_HDR_SPACE_32 ); //force low
} else {
//28 bits
mark( LG_HDR_MARK );
space(LG_HDR_SPACE);
// Data bits
for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) {
mark( LG_BIT_MARK );
space_encode(data & mask,LG_ONE_SPACE,LG_ZERO_SPACE);
}
mark( LG_BIT_MARK );
space(LG_RPT_LENGTH);
mark( LG_HDR_MARK );
space(LG_HDR_SPACE );
}
}
#endif