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-2022 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 #define JVC_ADDRESS_BITS 8 // 8 bit address
66 #define JVC_COMMAND_BITS 8 // Command
67 
68 #define JVC_BITS (JVC_ADDRESS_BITS + JVC_COMMAND_BITS) // 16 - The number of bits in the protocol
69 #define JVC_UNIT 526 // 20 periods of 38 kHz (526.315789)
70 
71 #define JVC_HEADER_MARK (16 * JVC_UNIT) // 8400
72 #define JVC_HEADER_SPACE (8 * JVC_UNIT) // 4200
73 
74 #define JVC_BIT_MARK JVC_UNIT // The length of a Bit:Mark
75 #define JVC_ONE_SPACE (3 * JVC_UNIT) // 1578 - The length of a Bit:Space for 1's
76 #define JVC_ZERO_SPACE JVC_UNIT // The length of a Bit:Space for 0's
77 
78 #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.
79 #define JVC_REPEAT_PERIOD 65000 // assume around 40 ms for a JVC frame
80 
83 
84 /************************************
85  * Start of send and decode functions
86  ************************************/
87 
91 void IRsend::sendJVC(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats) {
92  // Set IR carrier frequency
93  enableIROut (JVC_KHZ); // 38 kHz
94 
95  if (aNumberOfRepeats < 0) {
96  // The JVC protocol repeats by skipping the header.
97  aNumberOfRepeats = 0;
98  } else {
101  }
102 
103  uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
104  while (tNumberOfCommands > 0) {
105 
106  // Address + command
108 
109  tNumberOfCommands--;
110  // skip last delay!
111  if (tNumberOfCommands > 0) {
112  // send repeated command in a fixed raster
114  }
115  }
116 #if !defined(DISABLE_CODE_FOR_RECEIVER)
118 #endif
119 }
120 
122 
123 // uint_fast8_t tRawlen = decodedIRData.rawDataPtr->rawlen; // Using a local variable does not improve code size
124 
125  // 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. +4 is for first frame, +2 is for repeats
126  if (decodedIRData.rawDataPtr->rawlen != ((2 * JVC_BITS) + 2) && decodedIRData.rawDataPtr->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.rawDataPtr->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 
153  return false;
154  }
155 
157 #if defined(LOCAL_DEBUG)
158  Serial.print(F("JVC: "));
159  Serial.println(F("Decode failed"));
160 #endif
161  return false;
162  }
163 
164  // Success
165 // decodedIRData.flags = IRDATA_FLAGS_IS_LSB_FIRST; // Not required, since this is the start value
166  decodedIRData.command = decodedIRData.decodedRawData >> JVC_ADDRESS_BITS; // upper 8 bits of LSB first value
167  decodedIRData.address = decodedIRData.decodedRawData & 0xFF; // lowest 8 bit of LSB first value
170  }
171 
172  return true;
173 }
174 
175 /*********************************************************************************
176  * Old deprecated functions, kept for backward compatibility to old 2.0 tutorials
177  *********************************************************************************/
179  unsigned int offset = 1; // Skip first space
180 
181  // Check for repeat
182  if ((aResults->rawlen - 1 == 33) && matchMark(aResults->rawbuf[offset], JVC_BIT_MARK)
183  && matchMark(aResults->rawbuf[aResults->rawlen - 1], JVC_BIT_MARK)) {
184  aResults->bits = 0;
185  aResults->value = 0xFFFFFFFF;
188  return true;
189  }
190 
191  // Initial mark
192  if (!matchMark(aResults->rawbuf[offset], JVC_HEADER_MARK)) {
193  return false;
194  }
195  offset++;
196 
197  // Check we have enough data - +3 for start bit mark and space + stop bit mark
198  if (aResults->rawlen <= (2 * JVC_BITS) + 3) {
199  IR_DEBUG_PRINT(F("Data length="));
200  IR_DEBUG_PRINT(aResults->rawlen);
201  IR_DEBUG_PRINTLN(F(" is too small. >= 36 is required."));
202  return false;
203  }
204 
205  // Initial space
206  if (!matchSpace(aResults->rawbuf[offset], JVC_HEADER_SPACE)) {
207  return false;
208  }
209  offset++;
210 
212  return false;
213  }
214 
215  // Stop bit
216  if (!matchMark(aResults->rawbuf[offset + (2 * JVC_BITS)], JVC_BIT_MARK)) {
217 #if defined(LOCAL_DEBUG)
218  Serial.println(F("Stop bit mark length is wrong"));
219 #endif
220  return false;
221  }
222 
223  // Success
224  aResults->value = decodedIRData.decodedRawData;
225  aResults->bits = JVC_BITS;
226  aResults->decode_type = JVC;
228 
229  return true;
230 }
231 
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  SEND_STOP_BIT);
255 #if !defined(DISABLE_CODE_FOR_RECEIVER)
257 #endif
258 }
259 
261 #if defined(LOCAL_DEBUG)
262 #undef LOCAL_DEBUG
263 #endif
264 #endif // _IR_JVC_HPP
IRData::address
uint16_t address
Decoded address, Distance protocol (tMarkTicksLong (if tMarkTicksLong == 0, then tMarkTicksShort) << ...
Definition: IRProtocol.h:117
MICROS_PER_TICK
#define MICROS_PER_TICK
microseconds per clock interrupt tick
Definition: IRremote.hpp:258
decode_results
Results returned from old decoders !!!deprecated!!!
Definition: IRremoteInt.h:155
PROTOCOL_IS_MSB_FIRST
#define PROTOCOL_IS_MSB_FIRST
Definition: IRProtocol.h:130
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:120
IRsend::aNumberOfRepeats
void uint8_t int_fast8_t aNumberOfRepeats
Definition: IRremoteInt.h:474
MICROS_IN_ONE_MILLI
#define MICROS_IN_ONE_MILLI
Definition: IRremote.hpp:263
JVC_KHZ
#define JVC_KHZ
Definition: IRProtocol.h:141
IRsend::mark
void mark(unsigned int aMarkMicros)
Sends an IR mark for the specified number of microseconds.
Definition: IRSend.hpp:757
IRDATA_FLAGS_IS_REPEAT
#define IRDATA_FLAGS_IS_REPEAT
Definition: IRProtocol.h:94
JVC_ZERO_SPACE
#define JVC_ZERO_SPACE
Definition: ir_JVC.hpp:76
IRrecv::restartAfterSend
void restartAfterSend()
Restarts receiver after send.
Definition: IRReceive.hpp:346
decode_results::rawbuf
unsigned int * rawbuf
Definition: IRremoteInt.h:166
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:126
decode_results::bits
uint8_t bits
Definition: IRremoteInt.h:161
decode_results::decode_type
decode_type_t decode_type
Definition: IRremoteInt.h:158
IRData::decodedRawData
IRRawDataType decodedRawData
Up to 32/64 bit decoded raw data, to be used for send functions.
Definition: IRProtocol.h:122
IR_DEBUG_PRINT
#define IR_DEBUG_PRINT(...)
If DEBUG, print the arguments, otherwise do nothing.
Definition: IRremoteInt.h:133
JVC_REPEAT_PERIOD
#define JVC_REPEAT_PERIOD
Definition: ir_JVC.hpp:79
JVCProtocolConstants
struct PulseDistanceWidthProtocolConstants JVCProtocolConstants
Definition: ir_JVC.hpp:81
irparams_struct::rawlen
uint_fast8_t rawlen
counter of entries in rawbuf
Definition: IRremoteInt.h:109
IRrecv::decodePulseDistanceWidthData
bool decodePulseDistanceWidthData(PulseDistanceWidthProtocolConstants *aProtocolConstants, uint_fast8_t aNumberOfBits, uint_fast8_t aStartOffset=3)
Decode pulse distance protocols for PulseDistanceWidthProtocolConstants.
Definition: IRReceive.hpp:768
JVC_HEADER_MARK
#define JVC_HEADER_MARK
Definition: ir_JVC.hpp:71
decode_results::value
uint32_t value
Definition: IRremoteInt.h:160
PulseDistanceWidthProtocolConstants
Definition: IRProtocol.h:74
IRsend::sendJVC
void sendJVC(unsigned long data, int nbits, bool repeat) __attribute__((deprecated("This old function sends MSB first! Please use sendJVC(aAddress
The JVC protocol repeats by skipping the header mark and space -> this leads to a poor repeat detecti...
Definition: ir_JVC.hpp:91
IRrecv::decodedIRData
IRData decodedIRData
Definition: IRremoteInt.h:305
matchSpace
bool matchSpace(unsigned int aMeasuredTicks, unsigned int aMatchValueMicros)
Compensate for spaces shortened by demodulator hardware.
Definition: IRReceive.hpp:1033
SEND_STOP_BIT
#define SEND_STOP_BIT
Definition: IRremoteInt.h:393
IRData::flags
uint8_t flags
See IRDATA_FLAGS_* definitions above.
Definition: IRProtocol.h:121
PROTOCOL_IS_LSB_FIRST
#define PROTOCOL_IS_LSB_FIRST
Definition: IRProtocol.h:129
IRrecv::checkHeader
bool checkHeader(PulseDistanceWidthProtocolConstants *aProtocolConstants)
Definition: IRReceive.hpp:943
irparams_struct::rawbuf
unsigned int rawbuf[RAW_BUFFER_LENGTH]
raw data / tick counts per mark/space, first entry is the length of the gap between previous and curr...
Definition: IRremoteInt.h:113
JVC_HEADER_SPACE
#define JVC_HEADER_SPACE
Definition: ir_JVC.hpp:72
IRData::command
uint16_t command
Decoded command, Distance protocol (tMarkTicksShort << 8) | tSpaceTicksShort.
Definition: IRProtocol.h:118
JVC_REPEAT_DISTANCE
#define JVC_REPEAT_DISTANCE
Definition: ir_JVC.hpp:78
JVC_BIT_MARK
#define JVC_BIT_MARK
Definition: ir_JVC.hpp:74
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:310
IRsend::space
static void space(unsigned int aSpaceMicros)
Sends an IR space for the specified number of microseconds.
Definition: IRSend.hpp:927
IRDATA_FLAGS_IS_LSB_FIRST
#define IRDATA_FLAGS_IS_LSB_FIRST
Definition: IRProtocol.h:101
JVC_ADDRESS_BITS
#define JVC_ADDRESS_BITS
Definition: ir_JVC.hpp:65
JVC_ONE_SPACE
#define JVC_ONE_SPACE
Definition: ir_JVC.hpp:75
IRsend::sendPulseDistanceWidthData
void sendPulseDistanceWidthData(PulseDistanceWidthProtocolConstants *aProtocolConstants, IRRawDataType aData, uint_fast8_t aNumberOfBits)
Sends PulseDistance data The output always ends with a space Each additional call costs 16 bytes prog...
Definition: IRSend.hpp:643
IRrecv::decodeJVC
bool decodeJVC()
Definition: ir_JVC.hpp:121
IRrecv::lastDecodedAddress
uint32_t lastDecodedAddress
Definition: IRremoteInt.h:309
IR_DEBUG_PRINTLN
#define IR_DEBUG_PRINTLN(...)
If DEBUG, print the arguments as a line, otherwise do nothing.
Definition: IRremoteInt.h:137
matchMark
bool matchMark(unsigned int aMeasuredTicks, unsigned int aMatchValueMicros)
Compensate for marks exceeded by demodulator hardware.
Definition: IRReceive.hpp:1000
JVC_BITS
#define JVC_BITS
Definition: ir_JVC.hpp:68
decode_results::rawlen
uint_fast8_t rawlen
Definition: IRremoteInt.h:167
IRData::protocol
decode_type_t protocol
UNKNOWN, NEC, SONY, RC5, PULSE_DISTANCE, ...
Definition: IRProtocol.h:116
IRsend::aCommand
void uint8_t aCommand
Definition: IRremoteInt.h:474
IrReceiver
IRrecv IrReceiver
The receiver instance.
Definition: IRReceive.hpp:59
IRsend::enableIROut
void enableIROut(uint_fast8_t aFrequencyKHz)
Enables IR output.
Definition: IRSend.hpp:961
IRrecv::decodeJVCMSB
bool decodeJVCMSB(decode_results *aResults)
Definition: ir_JVC.hpp:178