IRremote
ir_JVC.hpp
Go to the documentation of this file.
1 /*
2  * ir_JVC.hpp
3  *
4  * Contains functions for receiving and sending JVC IR Protocol in "raw" and standard format with 8 bit address and 8 bit command
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) 2017-2023 Kristian Lauszus, 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_JVC_HPP
33 #define _IR_JVC_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 // JJJJJ V V CCCC
46 // J V V C
47 // J V V C
48 // J J V V C
49 // J V CCCC
50 //==============================================================================
51 /*
52  +8400,-4150
53  + 550,-1550 + 550,- 500 + 550,- 500 + 550,- 500
54  + 550,-1500 + 600,-1500 + 600,-1500 + 550,-1550
55  + 550,- 500 + 550,-1550 + 550,-1550 + 550,- 500
56  + 500,-1600 + 550,-1550 + 550,-1500 + 600,- 500
57  + 550
58  Sum: 40350
59  */
60 // https://www.sbprojects.net/knowledge/ir/jvc.php
61 // http://www.hifi-remote.com/johnsfine/DecodeIR.html#JVC
62 // IRP: {38k,525}<1,-1|1,-3>(16,-8,(D:8,F:8,1,-45)+)
63 // LSB first, 1 start bit + 8 bit address + 8 bit command + 1 stop bit.
64 // The JVC protocol repeats by skipping the header mark and space -> this leads to a poor repeat detection for JVC protocol.
65 // Some JVC devices require to send 3 repeats. https://github.com/Arduino-IRremote/Arduino-IRremote/issues/21
66 #define JVC_ADDRESS_BITS 8 // 8 bit address
67 #define JVC_COMMAND_BITS 8 // Command
68 
69 #define JVC_BITS (JVC_ADDRESS_BITS + JVC_COMMAND_BITS) // 16 - The number of bits in the protocol
70 #define JVC_UNIT 526 // 20 periods of 38 kHz (526.315789)
71 
72 #define JVC_HEADER_MARK (16 * JVC_UNIT) // 8400
73 #define JVC_HEADER_SPACE (8 * JVC_UNIT) // 4200
74 
75 #define JVC_BIT_MARK JVC_UNIT // The length of a Bit:Mark
76 #define JVC_ONE_SPACE (3 * JVC_UNIT) // 1578 - The length of a Bit:Space for 1's
77 #define JVC_ZERO_SPACE JVC_UNIT // The length of a Bit:Space for 0's
78 
79 #define JVC_REPEAT_DISTANCE (uint16_t)(45 * JVC_UNIT) // 23625 - Commands are repeated with a distance of 23 ms for as long as the key on the remote control is held down.
80 #define JVC_REPEAT_PERIOD 65000 // assume around 40 ms for a JVC frame. JVC IR Remotes: RM-SA911U, RM-SX463U have 45 ms period
81 
84 
85 /************************************
86  * Start of send and decode functions
87  ************************************/
88 
92 void IRsend::sendJVC(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats) {
93  // Set IR carrier frequency
94  enableIROut (JVC_KHZ); // 38 kHz
95 
96  if (aNumberOfRepeats < 0) {
97  // The JVC protocol repeats by skipping the header.
98  aNumberOfRepeats = 0;
99  } else {
102  }
103 
104  uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
105  while (tNumberOfCommands > 0) {
106 
107  // Address + command
109 
110  tNumberOfCommands--;
111  // skip last delay!
112  if (tNumberOfCommands > 0) {
113  // send repeated command in a fixed raster
115  }
116  }
117 }
118 
120 
121 // uint_fast8_t tRawlen = decodedIRData.rawlen; // Using a local variable does not improve code size
122 
123  // Check we have the right amount of data (36 or 34). The +4 is for initial gap, start bit mark and space + stop bit mark.
124  // +4 is for first frame, +2 is for repeats
125  if (decodedIRData.rawlen != ((2 * JVC_BITS) + 2) && decodedIRData.rawlen != ((2 * JVC_BITS) + 4)) {
126  IR_DEBUG_PRINT(F("JVC: "));
127  IR_DEBUG_PRINT(F("Data length="));
129  IR_DEBUG_PRINTLN(F(" is not 34 or 36"));
130  return false;
131  }
132 
133  if (decodedIRData.rawlen == ((2 * JVC_BITS) + 2)) {
134  /*
135  * Check for repeat
136  * Check leading space and first and last mark length
137  */
141  /*
142  * We have a repeat here, so do not check for start bit
143  */
148  }
149  } else {
150 
152  return false;
153  }
154 
156 #if defined(LOCAL_DEBUG)
157  Serial.print(F("JVC: "));
158  Serial.println(F("Decode failed"));
159 #endif
160  return false;
161  }
162 
163  // Success
164 // decodedIRData.flags = IRDATA_FLAGS_IS_LSB_FIRST; // Not required, since this is the start value
165  decodedIRData.command = decodedIRData.decodedRawData >> JVC_ADDRESS_BITS; // upper 8 bits of LSB first value
166  decodedIRData.address = decodedIRData.decodedRawData & 0xFF; // lowest 8 bit of LSB first value
169  }
170 
171  return true;
172 }
173 
174 /*********************************************************************************
175  * Old deprecated functions, kept for backward compatibility to old 2.0 tutorials
176  *********************************************************************************/
178  unsigned int offset = 1; // Skip first space
179 
180  // Check for repeat
181  if ((aResults->rawlen - 1 == 33) && matchMark(aResults->rawbuf[offset], JVC_BIT_MARK)
182  && matchMark(aResults->rawbuf[aResults->rawlen - 1], JVC_BIT_MARK)) {
183  aResults->bits = 0;
184  aResults->value = 0xFFFFFFFF;
187  return true;
188  }
189 
190  // Initial mark
191  if (!matchMark(aResults->rawbuf[offset], JVC_HEADER_MARK)) {
192  return false;
193  }
194  offset++;
195 
196  // Check we have enough data - +3 for start bit mark and space + stop bit mark
197  if (aResults->rawlen <= (2 * JVC_BITS) + 3) {
198  IR_DEBUG_PRINT(F("Data length="));
199  IR_DEBUG_PRINT(aResults->rawlen);
200  IR_DEBUG_PRINTLN(F(" is too small. >= 36 is required."));
201  return false;
202  }
203 
204  // Initial space
205  if (!matchSpace(aResults->rawbuf[offset], JVC_HEADER_SPACE)) {
206  return false;
207  }
208  offset++;
209 
211  return false;
212  }
213 
214  // Stop bit
215  if (!matchMark(aResults->rawbuf[offset + (2 * JVC_BITS)], JVC_BIT_MARK)) {
216 #if defined(LOCAL_DEBUG)
217  Serial.println(F("Stop bit mark length is wrong"));
218 #endif
219  return false;
220  }
221 
222  // Success
223  aResults->value = decodedIRData.decodedRawData;
224  aResults->bits = JVC_BITS;
225  aResults->decode_type = JVC;
227 
228  return true;
229 }
230 
242 void IRsend::sendJVCMSB(unsigned long data, int nbits, bool repeat) {
243  // Set IR carrier frequency
245 
246  // Only send the Header if this is NOT a repeat command
247  if (!repeat) {
250  }
251 
252  // Old version with MSB first Data
254 }
255 
257 #if defined(LOCAL_DEBUG)
258 #undef LOCAL_DEBUG
259 #endif
260 #endif // _IR_JVC_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
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
JVC
@ JVC
Definition: IRProtocol.h:46
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
IRsend::sendJVC
void sendJVC(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats)
The JVC protocol repeats by skipping the header mark and space -> this leads to a poor repeat detecti...
Definition: ir_JVC.hpp:92
MICROS_IN_ONE_MILLI
#define MICROS_IN_ONE_MILLI
Definition: IRremote.hpp:255
JVC_KHZ
#define JVC_KHZ
Definition: IRProtocol.h:159
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
JVC_ZERO_SPACE
#define JVC_ZERO_SPACE
Definition: ir_JVC.hpp:77
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
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
IR_DEBUG_PRINT
#define IR_DEBUG_PRINT(...)
If DEBUG, print the arguments, otherwise do nothing.
Definition: IRremoteInt.h:161
JVC_REPEAT_PERIOD
#define JVC_REPEAT_PERIOD
Definition: ir_JVC.hpp:80
JVCProtocolConstants
struct PulseDistanceWidthProtocolConstants JVCProtocolConstants
Definition: ir_JVC.hpp:82
matchSpace
bool matchSpace(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros)
Compensate for spaces shortened by demodulator hardware.
Definition: IRReceive.hpp:1227
JVC_HEADER_MARK
#define JVC_HEADER_MARK
Definition: ir_JVC.hpp:72
decode_results::value
uint32_t value
Definition: IRremoteInt.h:188
PulseDistanceWidthProtocolConstants
Definition: IRProtocol.h:134
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
IRrecv::checkHeader
bool checkHeader(PulseDistanceWidthProtocolConstants *aProtocolConstants)
Definition: IRReceive.hpp:1126
IRrecv::decodePulseDistanceWidthData
bool decodePulseDistanceWidthData(PulseDistanceWidthProtocolConstants *aProtocolConstants, uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset=3)
Decode pulse distance protocols for PulseDistanceWidthProtocolConstants.
Definition: IRReceive.hpp:954
JVC_HEADER_SPACE
#define JVC_HEADER_SPACE
Definition: ir_JVC.hpp:73
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
JVC_REPEAT_DISTANCE
#define JVC_REPEAT_DISTANCE
Definition: ir_JVC.hpp:79
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
JVC_BIT_MARK
#define JVC_BIT_MARK
Definition: ir_JVC.hpp:75
IRsend::sendJVCMSB
void sendJVCMSB(unsigned long data, int nbits, bool repeat=false)
With Send sendJVCMSB() you can send your old 32 bit codes.
Definition: ir_JVC.hpp:242
IRrecv::lastDecodedCommand
uint32_t lastDecodedCommand
Definition: IRremoteInt.h:363
IRDATA_FLAGS_IS_LSB_FIRST
#define IRDATA_FLAGS_IS_LSB_FIRST
Definition: IRProtocol.h:101
IRsend::space
static void space(uint16_t aSpaceMicros)
Sends an IR space for the specified number of microseconds.
Definition: IRSend.hpp:1148
JVC_ADDRESS_BITS
#define JVC_ADDRESS_BITS
Definition: ir_JVC.hpp:66
IRData::rawlen
IRRawlenType rawlen
counter of entries in rawbuf of last received frame.
Definition: IRProtocol.h:128
JVC_ONE_SPACE
#define JVC_ONE_SPACE
Definition: ir_JVC.hpp:76
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
IRrecv::decodeJVC
bool decodeJVC()
Definition: ir_JVC.hpp:119
IRrecv::lastDecodedAddress
uint32_t lastDecodedAddress
Definition: IRremoteInt.h:362
IR_DEBUG_PRINTLN
#define IR_DEBUG_PRINTLN(...)
If DEBUG, print the arguments as a line, otherwise do nothing.
Definition: IRremoteInt.h:165
JVC_BITS
#define JVC_BITS
Definition: ir_JVC.hpp:69
decode_results::rawlen
uint_fast8_t rawlen
Definition: IRremoteInt.h:195
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
IRrecv::decodeJVCMSB
bool decodeJVCMSB(decode_results *aResults)
Definition: ir_JVC.hpp:177