forked from Arduino-IRremote/Arduino-IRremote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ir_Denon.cpp
94 lines (77 loc) · 3.17 KB
/
ir_Denon.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
#include "IRremote.h"
#include "IRremoteInt.h"
// Reverse Engineered by looking at RAW dumps generated by IRremote
// I have since discovered that Denon publish all their IR codes:
// https://www.google.co.uk/search?q=DENON+MASTER+IR+Hex+Command+Sheet
// -> http://assets.denon.com/documentmaster/us/denon%20master%20ir%20hex.xls
// Having looked at the official Denon Pronto sheet and reverse engineered
// the timing values from it, it is obvious that Denon have a range of
// different timings and protocols ...the values here work for my AVR-3801 Amp!
//==============================================================================
// DDDD EEEEE N N OOO N N
// D D E NN N O O NN N
// D D EEE N N N O O N N N
// D D E N NN O O N NN
// DDDD EEEEE N N OOO N N
//==============================================================================
#define BITS 14 // The number of bits in the command
#define HDR_MARK 300 // The length of the Header:Mark
#define HDR_SPACE 750 // The lenght of the Header:Space
#define BIT_MARK 300 // The length of a Bit:Mark
#define ONE_SPACE 1800 // The length of a Bit:Space for 1's
#define ZERO_SPACE 750 // The length of a Bit:Space for 0's
//+=============================================================================
//
#if SEND_DENON
void IRsend::sendDenon (unsigned long data, int nbits)
{
// Set IR carrier frequency
enableIROut(38);
// Header
mark (HDR_MARK);
space(HDR_SPACE);
// Data
for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) {
if (data & mask) {
mark (BIT_MARK);
space(ONE_SPACE);
} else {
mark (BIT_MARK);
space(ZERO_SPACE);
}
}
// Footer
mark(BIT_MARK);
space(0); // Always end with the LED off
}
#endif
//+=============================================================================
//
#if DECODE_DENON
bool IRrecv::decodeDenon (decode_results *results)
{
unsigned long data = 0; // Somewhere to build our code
int offset = 1; // Skip the Gap reading
// Check we have the right amount of data
if (irparams.rawlen != 1 + 2 + (2 * BITS) + 1) return false ;
// Check initial Mark+Space match
if (!MATCH_MARK (results->rawbuf[offset++], HDR_MARK )) return false ;
if (!MATCH_SPACE(results->rawbuf[offset++], HDR_SPACE)) return false ;
// Read the bits in
for (int i = 0; i < BITS; i++) {
// Each bit looks like: MARK + SPACE_1 -> 1
// or : MARK + SPACE_0 -> 0
if (!MATCH_MARK(results->rawbuf[offset++], BIT_MARK)) return false ;
// IR data is big-endian, so we shuffle it in from the right:
if (MATCH_SPACE(results->rawbuf[offset], ONE_SPACE)) data = (data << 1) | 1 ;
else if (MATCH_SPACE(results->rawbuf[offset], ZERO_SPACE)) data = (data << 1) | 0 ;
else return false ;
offset++;
}
// Success
results->bits = BITS;
results->value = data;
results->decode_type = DENON;
return true;
}
#endif