forked from Arduino-IRremote/Arduino-IRremote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ir_Panasonic.cpp
78 lines (64 loc) · 2.71 KB
/
ir_Panasonic.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
#include "IRremote.h"
#include "IRremoteInt.h"
//==============================================================================
// PPPP AAA N N AAA SSSS OOO N N IIIII CCCC
// P P A A NN N A A S O O NN N I C
// PPPP AAAAA N N N AAAAA SSS O O N N N I C
// P A A N NN A A S O O N NN I C
// P A A N N A A SSSS OOO N N IIIII CCCC
//==============================================================================
#define PANASONIC_BITS 48
#define PANASONIC_HDR_MARK 3502
#define PANASONIC_HDR_SPACE 1750
#define PANASONIC_BIT_MARK 502
#define PANASONIC_ONE_SPACE 1244
#define PANASONIC_ZERO_SPACE 400
//+=============================================================================
#if SEND_PANASONIC
void IRsend::sendPanasonic (unsigned int address, unsigned long data)
{
// Set IR carrier frequency
enableIROut(35);
// Header
mark(PANASONIC_HDR_MARK);
space(PANASONIC_HDR_SPACE);
// Address
for (unsigned long mask = 1UL << (16 - 1); mask; mask >>= 1) {
mark(PANASONIC_BIT_MARK);
if (address & mask) space(PANASONIC_ONE_SPACE) ;
else space(PANASONIC_ZERO_SPACE) ;
}
// Data
for (unsigned long mask = 1UL << (32 - 1); mask; mask >>= 1) {
mark(PANASONIC_BIT_MARK);
if (data & mask) space(PANASONIC_ONE_SPACE) ;
else space(PANASONIC_ZERO_SPACE) ;
}
// Footer
mark(PANASONIC_BIT_MARK);
space(0); // Always end with the LED off
}
#endif
//+=============================================================================
#if DECODE_PANASONIC
bool IRrecv::decodePanasonic (decode_results *results)
{
unsigned long long data = 0;
int offset = 1;
if (!MATCH_MARK(results->rawbuf[offset++], PANASONIC_HDR_MARK )) return false ;
if (!MATCH_MARK(results->rawbuf[offset++], PANASONIC_HDR_SPACE)) return false ;
// decode address
for (int i = 0; i < PANASONIC_BITS; i++) {
if (!MATCH_MARK(results->rawbuf[offset++], PANASONIC_BIT_MARK)) return false ;
if (MATCH_SPACE(results->rawbuf[offset],PANASONIC_ONE_SPACE )) data = (data << 1) | 1 ;
else if (MATCH_SPACE(results->rawbuf[offset],PANASONIC_ZERO_SPACE)) data = (data << 1) | 0 ;
else return false ;
offset++;
}
results->value = (unsigned long)data;
results->address = (unsigned int)(data >> 32);
results->decode_type = PANASONIC;
results->bits = PANASONIC_BITS;
return true;
}
#endif