forked from crankyoldgit/IRremoteESP8266
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathir_Mitsubishi.cpp
56 lines (53 loc) · 2.06 KB
/
ir_Mitsubishi.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
#include "IRremote.h"
#include "IRremoteInt.h"
//==============================================================================
// MMMMM IIIII TTTTT SSSS U U BBBB IIIII SSSS H H IIIII
// M M M I T S U U B B I S H H I
// M M M I T SSS U U BBBB I SSS HHHHH I
// M M I T S U U B B I S H H I
// M M IIIII T SSSS UUU BBBBB IIIII SSSS H H IIIII
//==============================================================================
// marcosamarino nov 2016 changed to space encoding following LIRC file Mitsubishi RM 75501, not tested with real device
#define BITS 16
#define BIT_MARK 283
#define ONE_SPACE 2157
#define ZERO_SPACE 937
#define GAP 53681
#define MIN_REPEAT 2
//+=============================================================================
#if DECODE_MITSUBISHI
bool IRrecv::decodeMitsubishi (decode_results *results)
{
unsigned long data = 0;
if (irparams.rawlen < 2 * BITS + 1 + OFFSET_START) return false ;
int offset = OFFSET_START; // Skip first space
for (int i=0;i<BITS;i++ ) {
if (!MATCH_MARK(results->rawbuf[offset++], BIT_MARK)) return false ;
if (!space_decode(data,results->rawbuf[offset++],ONE_SPACE, ZERO_SPACE)) return false;
}
if (!MATCH_MARK(results->rawbuf[offset++], BIT_MARK)) return false ;
if (!MATCH_SPACE(results->rawbuf[offset++], GAP)) return false ;
// Success
results->bits = BITS;
results->value = data;
results->decode_type = MITSUBISHI;
return true;
}
#endif
#if SEND_MITSUBISHI
void IRsend::sendMitsubishi (unsigned long data, int nbits) {
// Set IR carrier frequency
enableIROut(38);
// Header
// Data
for ( int i=0 ; i< MIN_REPEAT ; i++) {
for (unsigned long mask = 1UL << (BITS - 1); mask; mask >>= 1) {
mark( BIT_MARK);
space_encode(data & mask,ONE_SPACE,ZERO_SPACE);
}
// Footer
mark( BIT_MARK);
space(GAP);
}
}
#endif