IRremote
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) && !defined(LOCAL_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 Kaseyikyo 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, true);
118 }
119 
120 void IRsend::sendDenon(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, bool aSendSharp) {
121  // Set IR carrier frequency
122  enableIROut (DENON_KHZ); // 38 kHz
123 
124  // Add frame marker for sharp
125  uint16_t tCommand = aCommand;
126  if (aSendSharp) {
127  tCommand |= 0x0200; // the 2 upper bits are 00 for Denon and 10 for Sharp
128  }
129  uint16_t tData = aAddress | ((uint16_t) tCommand << DENON_ADDRESS_BITS);
130  uint16_t tInvertedData = (tData ^ 0x7FE0); // Command and frame (upper 10 bits) are inverted
131 
132  uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
133  while (tNumberOfCommands > 0) {
134 
135  // Data
137 
138  // Inverted autorepeat frame
141 
142  tNumberOfCommands--;
143  // skip last delay!
144  if (tNumberOfCommands > 0) {
145  // send repeated command with a fixed space gap
147  }
148  }
149 }
150 
152  return decodeDenon();
153 }
154 
156 
157  // we have no start bit, so check for the exact amount of data bits
158  // Check we have the right amount of data (32). The + 2 is for initial gap + stop bit mark
159  if (decodedIRData.rawlen != (2 * DENON_BITS) + 2) {
160  IR_DEBUG_PRINT(F("Denon: "));
161  IR_DEBUG_PRINT(F("Data length="));
163  IR_DEBUG_PRINTLN(F(" is not 32"));
164  return false;
165  }
166 
167  // Try to decode as Denon protocol
169 #if defined(LOCAL_DEBUG)
170  Serial.print(F("Denon: "));
171  Serial.println(F("Decode failed"));
172 #endif
173  return false;
174  }
175 
176  // Check for stop mark
178 #if defined(LOCAL_DEBUG)
179  Serial.print(F("Denon: "));
180  Serial.println(F("Stop bit mark length is wrong"));
181 #endif
182  return false;
183  }
184 
185  // Success
188  uint8_t tFrameBits = (decodedIRData.command >> 8) & 0x03;
189  decodedIRData.command &= 0xFF;
190 
191  // Check for (auto) repeat
193  repeatCount++;
194  if (repeatCount > 1) { // skip first auto repeat
196  }
197 
198  if (tFrameBits & 0x01) {
199  /*
200  * Here we are in the auto repeated frame with the inverted command
201  */
202 #if defined(LOCAL_DEBUG)
203  Serial.print(F("Denon: "));
204  Serial.println(F("Autorepeat received="));
205 #endif
207  // Check parity of consecutive received commands. There is no parity in one data set.
208  if ((uint8_t) lastDecodedCommand != (uint8_t)(~decodedIRData.command)) {
210 #if defined(LOCAL_DEBUG)
211  Serial.print(F("Denon: "));
212  Serial.print(F("Parity check for repeat failed. Last command="));
213  Serial.print(lastDecodedCommand, HEX);
214  Serial.print(F(" current="));
215  Serial.println(~decodedIRData.command, HEX);
216 #endif
217  }
218  // always take non inverted command
220  }
221 
222  // repeated command here
223  if (tFrameBits == 1 || tFrameBits == 2) {
225  } else {
227  }
228  } else {
229  repeatCount = 0;
230  // first command here
231  if (tFrameBits == 2) {
233  } else {
235  }
236  }
237 
239 
240  return true;
241 }
242 
243 /*********************************************************************************
244  * Old deprecated functions, kept for backward compatibility to old 2.0 tutorials
245  *********************************************************************************/
246 /*
247  * Only for backwards compatibility
248  */
249 void IRsend::sendDenonRaw(uint16_t aRawData, int_fast8_t aNumberOfRepeats) {
250  sendDenon(aRawData >> (DENON_COMMAND_BITS + DENON_FRAME_BITS), (aRawData >> DENON_FRAME_BITS) & 0xFF, aNumberOfRepeats);
251 }
252 
253 /*
254  * Old function with parameter data
255  */
256 void IRsend::sendDenon(unsigned long data, int nbits) {
257  // Set IR carrier frequency
259 #if !(defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__))
260 // Serial.println(
261 // "The function sendDenon(data, nbits) is deprecated and may not work as expected! Use sendDenonRaw(data, NumberOfRepeats) or better sendDenon(Address, Command, NumberOfRepeats).");
262 #endif
263 
264  // Header
267 
268  // Data
271 }
272 
273 /*
274  * Old function without parameter aNumberOfRepeats
275  */
276 void IRsend::sendSharp(uint16_t aAddress, uint16_t aCommand) {
277  sendDenon(aAddress, aCommand, true, 0);
278 }
279 
281 
282  // Check we have the right amount of data
283  if (decodedIRData.rawlen != 1 + 2 + (2 * DENON_BITS) + 1) {
284  return false;
285  }
286 
287  // Check initial Mark+Space match
288  if (!matchMark(aResults->rawbuf[1], DENON_HEADER_MARK)) {
289  return false;
290  }
291 
292  if (!matchSpace(aResults->rawbuf[2], DENON_HEADER_SPACE)) {
293  return false;
294  }
295 
296  // Try to decode as Denon protocol.
298  return false;
299  }
300 
301  // Success
302  aResults->value = decodedIRData.decodedRawData;
303  aResults->bits = DENON_BITS;
304  aResults->decode_type = DENON;
306  return true;
307 }
308 
310 #if defined(LOCAL_DEBUG)
311 #undef LOCAL_DEBUG
312 #endif
313 #endif // _IR_DENON_HPP
IRData::address
uint16_t address
Decoded address, Distance protocol (tMarkTicksLong (if tMarkTicksLong == 0, then tMarkTicksShort) << ...
Definition: IRProtocol.h:110
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:183
decode_results::rawbuf
uint16_t * rawbuf
Definition: IRremoteInt.h:194
PROTOCOL_IS_MSB_FIRST
#define PROTOCOL_IS_MSB_FIRST
Definition: IRProtocol.h:147
IRData::numberOfBits
uint16_t numberOfBits
Number of bits received for data (address + command + parity) - to determine protocol length if diffe...
Definition: IRProtocol.h:119
IRsend::aNumberOfRepeats
void int_fast8_t aNumberOfRepeats
Definition: IRremoteInt.h:547
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
DenonProtocolConstants
struct PulseDistanceWidthProtocolConstants DenonProtocolConstants
Definition: ir_Denon.hpp:108
IRsend::mark
void mark(uint16_t aMarkMicros)
Sends an IR mark for the specified number of microseconds.
Definition: IRSend.hpp:947
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:92
IRrecv::decodeSharp
bool decodeSharp()
Definition: ir_Denon.hpp:151
IRsend::sendDenonRaw
void sendDenonRaw(uint16_t aRawData, int_fast8_t aNumberOfRepeats=NO_REPEATS) void sendFAST(uint8_t aCommand
Definition: ir_Denon.hpp:249
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:131
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:93
decode_results::bits
uint8_t bits
Definition: IRremoteInt.h:189
decode_results::decode_type
decode_type_t decode_type
Definition: IRremoteInt.h:186
IRData::decodedRawData
IRRawDataType decodedRawData
Up to 32/64 bit decoded raw data, to be used for send functions.
Definition: IRProtocol.h:113
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:161
matchSpace
bool matchSpace(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros)
Compensate for spaces shortened by demodulator hardware.
Definition: IRReceive.hpp:1227
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
IRDATA_FLAGS_PARITY_FAILED
#define IRDATA_FLAGS_PARITY_FAILED
The current (autorepeat) frame violated parity check.
Definition: IRProtocol.h:94
decode_results::value
uint32_t value
Definition: IRremoteInt.h:188
PulseDistanceWidthProtocolConstants
Definition: IRProtocol.h:134
DENON_ONE_SPACE
#define DENON_ONE_SPACE
Definition: ir_Denon.hpp:98
IRrecv::decodedIRData
IRData decodedIRData
Definition: IRremoteInt.h:358
IRData::flags
uint8_t flags
IRDATA_FLAGS_IS_REPEAT, IRDATA_FLAGS_WAS_OVERFLOW etc. See IRDATA_FLAGS_* definitions above.
Definition: IRProtocol.h:120
PROTOCOL_IS_LSB_FIRST
#define PROTOCOL_IS_LSB_FIRST
Definition: IRProtocol.h:148
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:954
IRData::command
uint16_t command
Decoded command, Distance protocol (tMarkTicksShort << 8) | tSpaceTicksShort.
Definition: IRProtocol.h:111
matchMark
bool matchMark(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros)
Compensate for marks exceeded by demodulator hardware.
Definition: IRReceive.hpp:1193
IRsend::sendDenon
void sendDenon(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, bool aSendSharp=false)
Definition: ir_Denon.hpp:120
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:144
IRrecv::decodeDenonOld
bool decodeDenonOld(decode_results *aResults)
Definition: ir_Denon.hpp:280
DENON
@ DENON
Definition: IRProtocol.h:45
IRrecv::lastDecodedCommand
uint32_t lastDecodedCommand
Definition: IRremoteInt.h:363
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:1148
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:128
DENON_ADDRESS_BITS
#define DENON_ADDRESS_BITS
Definition: ir_Denon.hpp:90
IRrecv::decodeDenon
bool decodeDenon()
Definition: ir_Denon.hpp:155
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:812
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:165
DENON_KHZ
#define DENON_KHZ
Definition: IRProtocol.h:158
IRData::protocol
decode_type_t protocol
UNKNOWN, NEC, SONY, RC5, PULSE_DISTANCE, ...
Definition: IRProtocol.h:109
IRsend::aCommand
void aCommand
Definition: IRremoteInt.h:610
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:129
IRsend::enableIROut
void enableIROut(uint_fast8_t aFrequencyKHz)
Enables IR output.
Definition: IRSend.hpp:1188
SHARP
@ SHARP
Definition: IRProtocol.h:63
IRrecv::repeatCount
uint8_t repeatCount
Definition: IRremoteInt.h:365