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)
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.
66 
67 #define JVC_ADDRESS_BITS 8 // 8 bit address
68 #define JVC_COMMAND_BITS 8 // Command
69 
70 #define JVC_BITS (JVC_ADDRESS_BITS + JVC_COMMAND_BITS) // 16 - The number of bits in the protocol
71 #define JVC_UNIT 526 // 20 periods of 38 kHz (526.315789)
72 
73 #define JVC_HEADER_MARK (16 * JVC_UNIT) // 8400
74 #define JVC_HEADER_SPACE (8 * JVC_UNIT) // 4200
75 
76 #define JVC_BIT_MARK JVC_UNIT // The length of a Bit:Mark
77 #define JVC_ONE_SPACE (3 * JVC_UNIT) // 1578 - The length of a Bit:Space for 1's
78 #define JVC_ZERO_SPACE JVC_UNIT // The length of a Bit:Space for 0's
79 
80 #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.
81 #define JVC_REPEAT_PERIOD 65000 // assume around 40 ms for a JVC frame. JVC IR Remotes: RM-SA911U, RM-SX463U have 45 ms period
82 
85 
86 /************************************
87  * Start of send and decode functions
88  ************************************/
89 
93 void IRsend::sendJVC(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats) {
94  // Set IR carrier frequency
95  enableIROut (JVC_KHZ); // 38 kHz
96 
97  if (aNumberOfRepeats < 0) {
98  // The JVC protocol repeats by skipping the header.
99  aNumberOfRepeats = 0;
100  } else {
103  }
104 
105  uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
106  while (tNumberOfCommands > 0) {
107 
108  // Address + command
109  sendPulseDistanceWidthData_P(&JVCProtocolConstants, aAddress | (aCommand << JVC_ADDRESS_BITS), JVC_BITS);
110 
111  tNumberOfCommands--;
112  // skip last delay!
113  if (tNumberOfCommands > 0) {
114  // send repeated command in a fixed raster
116  }
117  }
118 }
119 
121 
122 // uint_fast8_t tRawlen = decodedIRData.rawlen; // Using a local variable does not improve code size
123 
124  // 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.
125  // +4 is for first frame, +2 is for repeats
126  if (decodedIRData.rawlen != ((2 * JVC_BITS) + 2) && decodedIRData.rawlen != ((2 * JVC_BITS) + 4)) {
127  IR_DEBUG_PRINT(F("JVC: "));
128  IR_DEBUG_PRINT(F("Data length="));
130  IR_DEBUG_PRINTLN(F(" is not 34 or 36"));
131  return false;
132  }
133 
134  if (decodedIRData.rawlen == ((2 * JVC_BITS) + 2)) {
135  /*
136  * Check for repeat
137  * Check leading space and first and last mark length
138  */
142  /*
143  * We have a repeat here, so do not check for start bit
144  */
149  }
150  } else {
151 
152  if (!checkHeader_P(&JVCProtocolConstants)) {
153  return false;
154  }
155 
156  decodePulseDistanceWidthData_P(&JVCProtocolConstants, JVC_BITS);
157 
158 // decodedIRData.flags = IRDATA_FLAGS_IS_LSB_FIRST; // Not required, since this is the start value
159  decodedIRData.command = decodedIRData.decodedRawData >> JVC_ADDRESS_BITS; // upper 8 bits of LSB first value
160  decodedIRData.address = decodedIRData.decodedRawData & 0xFF; // lowest 8 bit of LSB first value
163  }
164 
165  return true;
166 }
167 
168 /*********************************************************************************
169  * Old deprecated functions, kept for backward compatibility to old 2.0 tutorials
170  *********************************************************************************/
172  unsigned int offset = 1; // Skip first space
173 
174  // Check for repeat
175  if ((aResults->rawlen - 1 == 33) && matchMark(aResults->rawbuf[offset], JVC_BIT_MARK)
176  && matchMark(aResults->rawbuf[aResults->rawlen - 1], JVC_BIT_MARK)) {
177  aResults->bits = 0;
178  aResults->value = 0xFFFFFFFF;
181  return true;
182  }
183 
184  // Initial mark
185  if (!matchMark(aResults->rawbuf[offset], JVC_HEADER_MARK)) {
186  return false;
187  }
188  offset++;
189 
190  // Check we have enough data - +3 for start bit mark and space + stop bit mark
191  if (aResults->rawlen <= (2 * JVC_BITS) + 3) {
192  IR_DEBUG_PRINT(F("Data length="));
193  IR_DEBUG_PRINT(aResults->rawlen);
194  IR_DEBUG_PRINTLN(F(" is too small. >= 36 is required."));
195  return false;
196  }
197 
198  // Initial space
199  if (!matchSpace(aResults->rawbuf[offset], JVC_HEADER_SPACE)) {
200  return false;
201  }
202  offset++;
203 
205 
206  // Stop bit
207  if (!matchMark(aResults->rawbuf[offset + (2 * JVC_BITS)], JVC_BIT_MARK)) {
208 #if defined(LOCAL_DEBUG)
209  Serial.println(F("Stop bit mark length is wrong"));
210 #endif
211  return false;
212  }
213 
214  // Success
215  aResults->value = decodedIRData.decodedRawData;
216  aResults->bits = JVC_BITS;
217  aResults->decode_type = JVC;
219 
220  return true;
221 }
222 
234 void IRsend::sendJVCMSB(unsigned long data, int nbits, bool repeat) {
235  // Set IR carrier frequency
237 
238  // Only send the Header if this is NOT a repeat command
239  if (!repeat) {
242  }
243 
244  // Old version with MSB first Data
246 }
247 
249 #if defined(LOCAL_DEBUG)
250 #undef LOCAL_DEBUG
251 #endif
252 #endif // _IR_JVC_HPP
IRData::address
uint16_t address
Decoded address, Distance protocol (tMarkTicksLong (if tMarkTicksLong == 0, then tMarkTicksShort) << ...
Definition: IRremoteInt.h:152
MICROS_PER_TICK
#define MICROS_PER_TICK
microseconds per clock interrupt tick
Definition: IRremote.hpp:207
decode_results
Results returned from old decoders !!!deprecated!!!
Definition: IRremoteInt.h:208
decode_results::rawbuf
uint16_t * rawbuf
Definition: IRremoteInt.h:219
IRrecv::decodePulseDistanceWidthData
void decodePulseDistanceWidthData(PulseDistanceWidthProtocolConstants *aProtocolConstants, uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset=3)
Decode pulse distance protocols for PulseDistanceWidthProtocolConstants.
Definition: IRReceive.hpp:1081
PROTOCOL_IS_MSB_FIRST
#define PROTOCOL_IS_MSB_FIRST
Definition: IRProtocol.h:178
JVC
@ JVC
Definition: IRProtocol.h:99
IRData::numberOfBits
uint16_t numberOfBits
Number of bits received for data (address + command + parity) - to determine protocol length if diffe...
Definition: IRremoteInt.h:161
IRsend::aNumberOfRepeats
void int_fast8_t aNumberOfRepeats
Definition: IRremoteInt.h:538
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:93
IRrecv::decodePulseDistanceWidthData_P
void decodePulseDistanceWidthData_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset=3)
Definition: IRReceive.hpp:1117
MICROS_IN_ONE_MILLI
#define MICROS_IN_ONE_MILLI
Definition: IRremote.hpp:212
IRrecv::checkHeader_P
bool checkHeader_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM)
Definition: IRReceive.hpp:1309
JVC_KHZ
#define JVC_KHZ
Definition: IRProtocol.h:191
PROTOCOL_IS_PULSE_DISTANCE
#define PROTOCOL_IS_PULSE_DISTANCE
Definition: IRProtocol.h:173
IRsend::mark
void mark(uint16_t aMarkMicros)
Sends an IR mark for the specified number of microseconds.
Definition: IRSend.hpp:1153
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:147
JVC_ZERO_SPACE
#define JVC_ZERO_SPACE
Definition: ir_JVC.hpp:78
decode_results::bits
uint8_t bits
Definition: IRremoteInt.h:214
decode_results::decode_type
decode_type_t decode_type
Definition: IRremoteInt.h:211
IRData::decodedRawData
IRRawDataType decodedRawData
Up to 32/64 bit decoded raw data, to be used for send<protocol>Raw functions.
Definition: IRremoteInt.h:155
IR_DEBUG_PRINT
#define IR_DEBUG_PRINT(...)
If DEBUG, print the arguments, otherwise do nothing.
Definition: IRremoteInt.h:186
JVC_REPEAT_PERIOD
#define JVC_REPEAT_PERIOD
Definition: ir_JVC.hpp:81
matchSpace
bool matchSpace(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros)
Compensate for spaces shortened by demodulator hardware.
Definition: IRReceive.hpp:1459
JVC_HEADER_MARK
#define JVC_HEADER_MARK
Definition: ir_JVC.hpp:73
decode_results::value
uint32_t value
Definition: IRremoteInt.h:213
PulseDistanceWidthProtocolConstants
Definition: IRProtocol.h:161
IRsend::sendPulseDistanceWidthData_P
void sendPulseDistanceWidthData_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, IRRawDataType aData, uint_fast8_t aNumberOfBits)
Definition: IRSend.hpp:586
IRrecv::decodedIRData
IRData decodedIRData
Definition: IRremoteInt.h:409
IRData::flags
uint8_t flags
IRDATA_FLAGS_IS_REPEAT, IRDATA_FLAGS_WAS_OVERFLOW etc. See IRDATA_FLAGS_* definitions above.
Definition: IRremoteInt.h:162
PROTOCOL_IS_LSB_FIRST
#define PROTOCOL_IS_LSB_FIRST
Definition: IRProtocol.h:179
JVC_HEADER_SPACE
#define JVC_HEADER_SPACE
Definition: ir_JVC.hpp:74
IRData::command
uint16_t command
Decoded command, Distance protocol (tMarkTicksShort << 8) | tSpaceTicksShort.
Definition: IRremoteInt.h:153
matchMark
bool matchMark(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros)
Compensate for marks exceeded by demodulator hardware.
Definition: IRReceive.hpp:1411
PROGMEM
struct PulseDistanceWidthProtocolConstants const JVCProtocolConstants PROGMEM
Definition: ir_JVC.hpp:83
JVC_REPEAT_DISTANCE
#define JVC_REPEAT_DISTANCE
Definition: ir_JVC.hpp:80
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:140
JVC_BIT_MARK
#define JVC_BIT_MARK
Definition: ir_JVC.hpp:76
IRrecv::irparams
irparams_struct irparams
Definition: IRremoteInt.h:408
IRrecv::lastDecodedCommand
uint16_t lastDecodedCommand
Definition: IRremoteInt.h:414
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:234
IRDATA_FLAGS_IS_LSB_FIRST
#define IRDATA_FLAGS_IS_LSB_FIRST
Definition: IRProtocol.h:156
IRsend::space
static void space(uint16_t aSpaceMicros)
Sends an IR space for the specified number of microseconds.
Definition: IRSend.hpp:1364
JVC_ADDRESS_BITS
#define JVC_ADDRESS_BITS
Definition: ir_JVC.hpp:67
IRData::rawlen
IRRawlenType rawlen
Counter of entries in rawbuf of last received frame.
Definition: IRremoteInt.h:170
JVC_ONE_SPACE
#define JVC_ONE_SPACE
Definition: ir_JVC.hpp:77
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:578
IRrecv::decodeJVC
bool decodeJVC()
Definition: ir_JVC.hpp:120
IR_DEBUG_PRINTLN
#define IR_DEBUG_PRINTLN(...)
If DEBUG, print the arguments as a line, otherwise do nothing.
Definition: IRremoteInt.h:190
JVC_BITS
#define JVC_BITS
Definition: ir_JVC.hpp:70
decode_results::rawlen
uint_fast8_t rawlen
Definition: IRremoteInt.h:220
IRData::protocol
decode_type_t protocol
UNKNOWN, NEC, SONY, RC5, PULSE_DISTANCE, ...
Definition: IRremoteInt.h:151
IRrecv::lastDecodedAddress
uint16_t lastDecodedAddress
Definition: IRremoteInt.h:413
IRsend::aCommand
void aCommand
Definition: IRremoteInt.h:688
IRData::initialGapTicks
uint16_t initialGapTicks
Contains the initial gap (pre 4.4: the value in rawbuf[0]) of the last received frame.
Definition: IRremoteInt.h:171
IRsend::enableIROut
void enableIROut(uint_fast8_t aFrequencyKHz)
Enables IR output.
Definition: IRSend.hpp:1404
IRrecv::decodeJVCMSB
bool decodeJVCMSB(decode_results *aResults)
Definition: ir_JVC.hpp:171