IRremote
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ir_Denon.hpp
Go to the documentation of this file.
1 /*
2  * ir_Denon.cpp
3  *
4  * Contains functions for receiving and sending Denon/Sharp IR Protocol
5  *
6  * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
7  *
8  ************************************************************************************
9  * MIT License
10  *
11  * Copyright (c) 2020-2023 Armin Joachimsmeyer
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a copy
14  * of this software and associated documentation files (the "Software"), to deal
15  * in the Software without restriction, including without limitation the rights
16  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17  * copies of the Software, and to permit persons to whom the Software is furnished
18  * to do so, subject to the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be included in all
21  * copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
24  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
25  * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
27  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
28  * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29  *
30  ************************************************************************************
31  */
32 #ifndef _IR_DENON_HPP
33 #define _IR_DENON_HPP
34 
35 #if defined(DEBUG)
36 #define LOCAL_DEBUG
37 #else
38 //#define LOCAL_DEBUG // This enables debug output only for this file
39 #endif
40 
44 //==============================================================================
45 // DDDD EEEEE N N OOO N N
46 // D D E NN N O O NN N
47 // D D EEE N N N O O N N N
48 // D D E N NN O O N NN
49 // DDDD EEEEE N N OOO N N
50 //==============================================================================
51 // SSSS H H AAA RRRR PPPP
52 // S H H A A R R P P
53 // SSS HHHHH AAAAA RRRR PPPP
54 // S H H A A R R P
55 // SSSS H H A A R R P
56 //==============================================================================
57 /*
58  Protocol=Denon Address=0x11 Command=0x76 Raw-Data=0xED1 15 bits LSB first
59  + 200,-1800 + 300,- 750 + 300,- 800 + 200,- 800
60  + 250,-1800 + 250,- 800 + 250,-1800 + 300,-1750
61  + 300,- 750 + 300,-1800 + 250,-1800 + 250,-1850
62  + 250,- 750 + 300,- 800 + 250,- 800 + 250
63  Sum: 23050
64 
65  Denon/Sharp variant
66  Protocol=Denon Address=0x11 Command=0x76 Raw-Data=0x4ED1 15 bits LSB first
67  + 200,-1800 + 300,- 750 + 250,- 800 + 250,- 750
68  + 300,-1800 + 250,- 800 + 250,-1800 + 300,-1750
69  + 300,- 750 + 300,-1800 + 250,-1800 + 250,-1800
70  + 300,- 750 + 300,- 750 + 300,-1800 + 250
71  Sum: 23050
72  */
73 /*
74  * https://www.mikrocontroller.net/articles/IRMP_-_english#DENON
75  * Denon published all their IR codes:
76  * http://assets.denon.com/documentmaster/us/denon%20master%20ir%20hex.xls
77  * Example:
78  * 0000 006D 0000 0020 000A 001E 000A 0046 000A 001E 000A 001E 000A 001E // 5 address bits
79  * 000A 001E 000A 001E 000A 0046 000A 0046 000A 0046 000A 001E 000A 0046 000A 0046 // 8 command bits
80  * 000A 001E 000A 001E 000A 0679 // 2 frame bits 0,0 + stop bit + space for AutoRepeat
81  * 000A 001E 000A 0046 000A 001E 000A 001E 000A 001E // 5 address bits
82  * 000A 0046 000A 0046 000A 001E 000A 001E 000A 001E 000A 0046 000A 001E 000A 001E // 8 inverted command bits
83  * 000A 0046 000A 0046 000A 0679 // 2 frame bits 1,1 + stop bit + space for Repeat
84  * From analyzing the codes for Tuner preset 1 to 8 in tab Main Zone ID#1 it is obvious, that the protocol is LSB first at least for command.
85  * All Denon codes with 32 as 3. value use the Kaseikyo Denon variant.
86  */
87 // LSB first, no start bit, 5 address + 8 command + 2 frame (0,0) + 1 stop bit - each frame 2 times
88 // Every frame is auto repeated with a space period of 45 ms and the command and frame inverted to (1,1) or (0,1) for SHARP.
89 //
90 #define DENON_ADDRESS_BITS 5
91 #define DENON_COMMAND_BITS 8
92 #define DENON_FRAME_BITS 2 // 00/10 for 1. frame Denon/Sharp, inverted for autorepeat frame
93 
94 #define DENON_BITS (DENON_ADDRESS_BITS + DENON_COMMAND_BITS + DENON_FRAME_BITS) // 15 - The number of bits in the command
95 #define DENON_UNIT 260
96 
97 #define DENON_BIT_MARK DENON_UNIT // The length of a Bit:Mark
98 #define DENON_ONE_SPACE (7 * DENON_UNIT) // 1820 // The length of a Bit:Space for 1's
99 #define DENON_ZERO_SPACE (3 * DENON_UNIT) // 780 // The length of a Bit:Space for 0's
100 
101 #define DENON_AUTO_REPEAT_DISTANCE 45000 // Every frame is auto repeated with a space period of 45 ms and the command and frame inverted.
102 #define DENON_REPEAT_PERIOD 110000 // Commands are repeated every 110 ms (measured from start to start) for as long as the key on the remote control is held down.
103 
104 // for old decoder
105 #define DENON_HEADER_MARK DENON_UNIT // The length of the Header:Mark
106 #define DENON_HEADER_SPACE (3 * DENON_UNIT) // 780 // The length of the Header:Space
107 
111 
112 /************************************
113  * Start of send and decode functions
114  ************************************/
115 
116 void IRsend::sendSharp(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats) {
117  sendDenon(aAddress, aCommand, aNumberOfRepeats, 1);
118  // see https://github.com/Arduino-IRremote/Arduino-IRremote/issues/1272
119 }
120 
121 void IRsend::sendSharp2(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats) {
122  sendDenon(aAddress, aCommand, aNumberOfRepeats, 2);
123 }
124 
125 /*
126  * Denon frames are always sent 3 times. A non inverted (normal), an inverted frame, ending with a normal frame.
127  * Repeats are done by just adding an inverted and a normal frame with no extra delay, so it is quite responsible :-)
128  * If you specify a repeat of e.g. 3, then 3 + 6 frames are sent.
129  * Measured at Denon RC 1081.
130  */
131 void IRsend::sendDenon(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, uint8_t aSendSharpFrameMarker) {
132  // Set IR carrier frequency
133  enableIROut (DENON_KHZ); // 38 kHz
134 
135  // Add frame marker for sharp
136  uint16_t tCommand = aCommand;
137  // see https://github.com/Arduino-IRremote/Arduino-IRremote/issues/1272
138  tCommand |= aSendSharpFrameMarker << 8; // the 2 upper bits are 00 for Denon and 01 or 10 for Sharp
139 
140  uint16_t tData = aAddress | ((uint16_t) tCommand << DENON_ADDRESS_BITS);
141  uint16_t tInvertedData = (tData ^ 0x7FE0); // Command and frame (upper 10 bits) are inverted
142 
143  uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
144  while (tNumberOfCommands > 0) {
145 
146  // Data
147  sendPulseDistanceWidthData_P(&DenonProtocolConstants, tData, DENON_BITS);
148 
149  // Inverted autorepeat frame
151  sendPulseDistanceWidthData_P(&DenonProtocolConstants, tInvertedData, DENON_BITS);
152 
153  tNumberOfCommands--;
154  // send repeated command with a fixed space gap
156  }
157  /*
158  * always end with a normal frame
159  * skip last delay!
160  */
161  sendPulseDistanceWidthData_P(&DenonProtocolConstants, tData, DENON_BITS);
162 
163 }
164 
166  return decodeDenon();
167 }
168 
170 
171  // we have no start bit, so check for the exact amount of data bits
172  // Check we have the right amount of data (32). The + 2 is for initial gap + stop bit mark
173  if (decodedIRData.rawlen != (2 * DENON_BITS) + 2) {
174  IR_DEBUG_PRINT(F("Denon: "));
175  IR_DEBUG_PRINT(F("Data length="));
177  IR_DEBUG_PRINTLN(F(" is not 32"));
178  return false;
179  }
180 
181  // Try to decode as Denon protocol
182  if (!decodePulseDistanceWidthData_P(&DenonProtocolConstants, DENON_BITS, 1)) {
183 #if defined(LOCAL_DEBUG)
184  Serial.print(F("Denon: "));
185  Serial.println(F("Decode failed"));
186 #endif
187  return false;
188  }
189 
190  // Check for stop mark
192 #if defined(LOCAL_DEBUG)
193  Serial.print(F("Denon: "));
194  Serial.println(F("Stop bit mark length is wrong"));
195 #endif
196  return false;
197  }
198 
199  // Success
202  uint8_t tFrameBits = (decodedIRData.command >> 8) & 0x03;
203  decodedIRData.command &= 0xFF;
204 
205  // Check for (auto) repeat
207  repeatCount++;
208  if (repeatCount > 1) { // skip first auto repeat
210  }
211 
212  if (tFrameBits & 0x01) {
213  /*
214  * Here we are in the auto repeated frame with the inverted command
215  */
216 #if defined(LOCAL_DEBUG)
217  Serial.print(F("Denon: "));
218  Serial.println(F("Autorepeat received="));
219 #endif
221  // Check parity of consecutive received commands. There is no parity in one data set.
222  if ((uint8_t) lastDecodedCommand != (uint8_t)(~decodedIRData.command)) {
224 #if defined(LOCAL_DEBUG)
225  Serial.print(F("Denon: "));
226  Serial.print(F("Parity check for repeat failed. Last command="));
227  Serial.print(lastDecodedCommand, HEX);
228  Serial.print(F(" current="));
229  Serial.println(~decodedIRData.command, HEX);
230 #endif
231  }
232  // always take non inverted command
234  }
235 
236  // repeated command here
237  if (tFrameBits == 1 || tFrameBits == 2) {
239  } else {
241  }
242  } else {
243  repeatCount = 0;
244  // first command here
245  if (tFrameBits == 2) {
247  } else {
249  }
250  }
251 
253 
254  return true;
255 }
256 
257 /*********************************************************************************
258  * Old deprecated functions, kept for backward compatibility to old 2.0 tutorials
259  *********************************************************************************/
260 /*
261  * Only for backwards compatibility
262  */
263 void IRsend::sendDenonRaw(uint16_t aRawData, int_fast8_t aNumberOfRepeats) {
264  sendDenon(aRawData >> (DENON_COMMAND_BITS + DENON_FRAME_BITS), (aRawData >> DENON_FRAME_BITS) & 0xFF, aNumberOfRepeats);
265 }
266 
267 /*
268  * Old function with parameter data
269  */
270 void IRsend::sendDenon(unsigned long data, int nbits) {
271  // Set IR carrier frequency
273 #if !(defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__))
274 // Serial.println(
275 // "The function sendDenon(data, nbits) is deprecated and may not work as expected! Use sendDenonRaw(data, NumberOfRepeats) or better sendDenon(Address, Command, NumberOfRepeats).");
276 #endif
277 
278  // Header
281 
282  // Data
285 }
286 
287 /*
288  * Old function without parameter aNumberOfRepeats
289  */
290 void IRsend::sendSharp(uint16_t aAddress, uint16_t aCommand) {
291  sendDenon(aAddress, aCommand, 0, true);
292 }
293 
295 
296  // Check we have the right amount of data
297  if (decodedIRData.rawlen != 1 + 2 + (2 * DENON_BITS) + 1) {
298  return false;
299  }
300 
301  // Check initial Mark+Space match
302  if (!matchMark(aResults->rawbuf[1], DENON_HEADER_MARK)) {
303  return false;
304  }
305 
306  if (!matchSpace(aResults->rawbuf[2], DENON_HEADER_SPACE)) {
307  return false;
308  }
309 
310  // Try to decode as Denon protocol.
312  return false;
313  }
314 
315  // Success
316  aResults->value = decodedIRData.decodedRawData;
317  aResults->bits = DENON_BITS;
318  aResults->decode_type = DENON;
320  return true;
321 }
322 
324 #if defined(LOCAL_DEBUG)
325 #undef LOCAL_DEBUG
326 #endif
327 #endif // _IR_DENON_HPP
IRData::address
uint16_t address
Decoded address, Distance protocol (tMarkTicksLong (if tMarkTicksLong == 0, then tMarkTicksShort) << ...
Definition: IRProtocol.h:111
MICROS_PER_TICK
#define MICROS_PER_TICK
microseconds per clock interrupt tick
Definition: IRremote.hpp:250
DENON_COMMAND_BITS
#define DENON_COMMAND_BITS
Definition: ir_Denon.hpp:91
decode_results
Results returned from old decoders !!!deprecated!!!
Definition: IRremoteInt.h:188
decode_results::rawbuf
uint16_t * rawbuf
Definition: IRremoteInt.h:199
PROTOCOL_IS_MSB_FIRST
#define PROTOCOL_IS_MSB_FIRST
Definition: IRProtocol.h:150
IRData::numberOfBits
uint16_t numberOfBits
Number of bits received for data (address + command + parity) - to determine protocol length if diffe...
Definition: IRProtocol.h:120
IRsend::aNumberOfRepeats
void int_fast8_t aNumberOfRepeats
Definition: IRremoteInt.h:580
MICROS_IN_ONE_MILLI
#define MICROS_IN_ONE_MILLI
Definition: IRremote.hpp:255
DENON_FRAME_BITS
#define DENON_FRAME_BITS
Definition: ir_Denon.hpp:92
IRsend::sendSharp2
void sendSharp2(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats)
Definition: ir_Denon.hpp:121
IRsend::mark
void mark(uint16_t aMarkMicros)
Sends an IR mark for the specified number of microseconds.
Definition: IRSend.hpp:1143
IRDATA_FLAGS_IS_REPEAT
#define IRDATA_FLAGS_IS_REPEAT
The gap between the preceding frame is as smaller than the maximum gap expected for a repeat....
Definition: IRProtocol.h:93
IRrecv::decodeSharp
bool decodeSharp()
Definition: ir_Denon.hpp:165
IRsend::sendDenonRaw
void sendDenonRaw(uint16_t aRawData, int_fast8_t aNumberOfRepeats=NO_REPEATS) void sendFAST(uint8_t aCommand
Definition: ir_Denon.hpp:263
IRData::rawDataPtr
irparams_struct * rawDataPtr
Pointer of the raw timing data to be decoded. Mainly the OverflowFlag and the data buffer filled by r...
Definition: IRProtocol.h:132
IRDATA_FLAGS_IS_AUTO_REPEAT
#define IRDATA_FLAGS_IS_AUTO_REPEAT
The current repeat frame is a repeat, that is always sent after a regular frame and cannot be avoided...
Definition: IRProtocol.h:94
decode_results::bits
uint8_t bits
Definition: IRremoteInt.h:194
decode_results::decode_type
decode_type_t decode_type
Definition: IRremoteInt.h:191
IRData::decodedRawData
IRRawDataType decodedRawData
Up to 32/64 bit decoded raw data, to be used for send functions.
Definition: IRProtocol.h:114
DENON_HEADER_MARK
#define DENON_HEADER_MARK
Definition: ir_Denon.hpp:105
IR_DEBUG_PRINT
#define IR_DEBUG_PRINT(...)
If DEBUG, print the arguments, otherwise do nothing.
Definition: IRremoteInt.h:166
matchSpace
bool matchSpace(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros)
Compensate for spaces shortened by demodulator hardware.
Definition: IRReceive.hpp:1285
DENON_REPEAT_PERIOD
#define DENON_REPEAT_PERIOD
Definition: ir_Denon.hpp:102
DENON_ZERO_SPACE
#define DENON_ZERO_SPACE
Definition: ir_Denon.hpp:99
DENON_HEADER_SPACE
#define DENON_HEADER_SPACE
Definition: ir_Denon.hpp:106
IRsend::sendDenon
void sendDenon(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, uint8_t aSendSharpFrameMarker=0)
Definition: ir_Denon.hpp:131
IRDATA_FLAGS_PARITY_FAILED
#define IRDATA_FLAGS_PARITY_FAILED
The current (autorepeat) frame violated parity check.
Definition: IRProtocol.h:95
decode_results::value
uint32_t value
Definition: IRremoteInt.h:193
PulseDistanceWidthProtocolConstants
Definition: IRProtocol.h:137
IRsend::sendPulseDistanceWidthData_P
void sendPulseDistanceWidthData_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, IRRawDataType aData, uint_fast8_t aNumberOfBits)
Definition: IRSend.hpp:1007
DENON_ONE_SPACE
#define DENON_ONE_SPACE
Definition: ir_Denon.hpp:98
IRrecv::decodedIRData
IRData decodedIRData
Definition: IRremoteInt.h:367
IRData::flags
uint8_t flags
IRDATA_FLAGS_IS_REPEAT, IRDATA_FLAGS_WAS_OVERFLOW etc. See IRDATA_FLAGS_* definitions above.
Definition: IRProtocol.h:121
PROTOCOL_IS_LSB_FIRST
#define PROTOCOL_IS_LSB_FIRST
Definition: IRProtocol.h:151
IRsend::sendSharp
void sendSharp(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats)
Definition: ir_Denon.hpp:116
IRrecv::decodePulseDistanceWidthData
bool decodePulseDistanceWidthData(PulseDistanceWidthProtocolConstants *aProtocolConstants, uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset=3)
Decode pulse distance protocols for PulseDistanceWidthProtocolConstants.
Definition: IRReceive.hpp:983
IRData::command
uint16_t command
Decoded command, Distance protocol (tMarkTicksShort << 8) | tSpaceTicksShort.
Definition: IRProtocol.h:112
matchMark
bool matchMark(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros)
Compensate for marks exceeded by demodulator hardware.
Definition: IRReceive.hpp:1251
irparams_struct::rawbuf
IRRawbufType rawbuf[RAW_BUFFER_LENGTH]
raw data / tick counts per mark/space. With 8 bit we can only store up to 12.7 ms....
Definition: IRremoteInt.h:147
IRrecv::decodeDenonOld
bool decodeDenonOld(decode_results *aResults)
Definition: ir_Denon.hpp:294
IRrecv::lastDecodedCommand
uint16_t lastDecodedCommand
Definition: IRremoteInt.h:372
DENON
@ DENON
Definition: IRProtocol.h:45
PROGMEM
struct PulseDistanceWidthProtocolConstants const DenonProtocolConstants PROGMEM
Definition: ir_Denon.hpp:108
IRrecv::decodePulseDistanceWidthData_P
bool decodePulseDistanceWidthData_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset=3)
Definition: IRReceive.hpp:991
DENON_AUTO_REPEAT_DISTANCE
#define DENON_AUTO_REPEAT_DISTANCE
Definition: ir_Denon.hpp:101
IRsend::space
static void space(uint16_t aSpaceMicros)
Sends an IR space for the specified number of microseconds.
Definition: IRSend.hpp:1344
DENON_BITS
#define DENON_BITS
Definition: ir_Denon.hpp:94
IRData::rawlen
IRRawlenType rawlen
counter of entries in rawbuf of last received frame.
Definition: IRProtocol.h:129
DENON_ADDRESS_BITS
#define DENON_ADDRESS_BITS
Definition: ir_Denon.hpp:90
IRrecv::decodeDenon
bool decodeDenon()
Definition: ir_Denon.hpp:169
IRsend::sendPulseDistanceWidthData
void sendPulseDistanceWidthData(PulseDistanceWidthProtocolConstants *aProtocolConstants, IRRawDataType aData, uint_fast8_t aNumberOfBits)
Sends PulseDistance from data contained in parameter using ProtocolConstants structure for timing etc...
Definition: IRSend.hpp:999
DENON_BIT_MARK
#define DENON_BIT_MARK
Definition: ir_Denon.hpp:97
IR_DEBUG_PRINTLN
#define IR_DEBUG_PRINTLN(...)
If DEBUG, print the arguments as a line, otherwise do nothing.
Definition: IRremoteInt.h:170
DENON_KHZ
#define DENON_KHZ
Definition: IRProtocol.h:161
IRData::protocol
decode_type_t protocol
UNKNOWN, NEC, SONY, RC5, PULSE_DISTANCE, ...
Definition: IRProtocol.h:110
IRsend::aCommand
void aCommand
Definition: IRremoteInt.h:646
IRData::initialGapTicks
uint16_t initialGapTicks
contains the initial gap (pre 4.4: the value in rawbuf[0]) of the last received frame.
Definition: IRProtocol.h:130
IRsend::enableIROut
void enableIROut(uint_fast8_t aFrequencyKHz)
Enables IR output.
Definition: IRSend.hpp:1384
SHARP
@ SHARP
Definition: IRProtocol.h:64
IRrecv::repeatCount
uint8_t repeatCount
Definition: IRremoteInt.h:377