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 #include "LocalDebugLevelStart.h"
36 
40 //==============================================================================
41 // JJJJJ V V CCCC
42 // J V V C
43 // J V V C
44 // J J V V C
45 // J V CCCC
46 //==============================================================================
47 /*
48  +8400,-4150
49  + 550,-1550 + 550,- 500 + 550,- 500 + 550,- 500
50  + 550,-1500 + 600,-1500 + 600,-1500 + 550,-1550
51  + 550,- 500 + 550,-1550 + 550,-1550 + 550,- 500
52  + 500,-1600 + 550,-1550 + 550,-1500 + 600,- 500
53  + 550
54  Sum: 40350
55  */
56 // https://www.sbprojects.net/knowledge/ir/jvc.php
57 // http://www.hifi-remote.com/johnsfine/DecodeIR.html#JVC
58 // IRP: {38k,525}<1,-1|1,-3>(16,-8,(D:8,F:8,1,-45)+)
59 // LSB first, 1 start bit + 8 bit address + 8 bit command + 1 stop bit.
60 // The JVC protocol repeats by skipping the header mark and space -> this leads to a poor repeat detection for JVC protocol.
61 // Some JVC devices require to send 3 repeats.
62 
63 #define JVC_ADDRESS_BITS 8 // 8 bit address
64 #define JVC_COMMAND_BITS 8 // Command
65 
66 #define JVC_BITS (JVC_ADDRESS_BITS + JVC_COMMAND_BITS) // 16 - The number of bits in the protocol
67 #define JVC_UNIT 526 // 20 periods of 38 kHz (526.315789)
68 
69 #define JVC_HEADER_MARK (16 * JVC_UNIT) // 8400
70 #define JVC_HEADER_SPACE (8 * JVC_UNIT) // 4200
71 
72 #define JVC_BIT_MARK JVC_UNIT // The length of a Bit:Mark
73 #define JVC_ONE_SPACE (3 * JVC_UNIT) // 1578 - The length of a Bit:Space for 1's
74 #define JVC_ZERO_SPACE JVC_UNIT // The length of a Bit:Space for 0's
75 
76 #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.
77 #define JVC_REPEAT_PERIOD 65000 // assume around 40 ms for a JVC frame. JVC IR Remotes: RM-SA911U, RM-SX463U have 45 ms period
78 
81 
82 /************************************
83  * Start of send and decode functions
84  ************************************/
85 
89 void IRsend::sendJVC(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats) {
90  // Set IR carrier frequency
91  enableIROut (JVC_KHZ); // 38 kHz
92 
93  if (aNumberOfRepeats < 0) {
94  // The JVC protocol repeats by skipping the header.
95  aNumberOfRepeats = 0;
96  } else {
99  }
100 
101  uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
102  while (tNumberOfCommands > 0) {
103 
104  // Address + command
105  sendPulseDistanceWidthData_P(&JVCProtocolConstants, aAddress | (aCommand << JVC_ADDRESS_BITS), JVC_BITS);
106 
107  tNumberOfCommands--;
108  // skip last delay!
109  if (tNumberOfCommands > 0) {
110  // send repeated command in a fixed raster
112  }
113  }
114 }
115 
117 
118 // uint_fast8_t tRawlen = decodedIRData.rawlen; // Using a local variable does not improve code size
119 
120  // 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.
121  // +4 is for first frame, +2 is for repeats
122  if (decodedIRData.rawlen != ((2 * JVC_BITS) + 2) && decodedIRData.rawlen != ((2 * JVC_BITS) + 4)) {
123  DEBUG_PRINT(F("JVC: Data length="));
125  DEBUG_PRINTLN(F(" is not 34 or 36"));
126  return false;
127  }
128 
129  if (decodedIRData.rawlen == ((2 * JVC_BITS) + 2)) {
130  /*
131  * Check for repeat
132  * Check leading space and first and last mark length
133  */
137  /*
138  * We have a repeat here, so do not check for start bit
139  */
144  }
145  } else {
146 
147  if (!checkHeader_P(&JVCProtocolConstants)) {
148  return false;
149  }
150 
151  decodePulseDistanceWidthData_P(&JVCProtocolConstants, JVC_BITS);
152 
153 // decodedIRData.flags = IRDATA_FLAGS_IS_LSB_FIRST; // Not required, since this is the start value
154  decodedIRData.command = decodedIRData.decodedRawData >> JVC_ADDRESS_BITS; // upper 8 bits of LSB first value
155  decodedIRData.address = decodedIRData.decodedRawData & 0xFF; // lowest 8 bit of LSB first value
158  }
159 
160  return true;
161 }
162 
163 /*********************************************************************************
164  * Old deprecated functions, kept for backward compatibility to old 2.0 tutorials
165  *********************************************************************************/
167  unsigned int offset = 1; // Skip first space
168 
169  // Check for repeat
170  if ((aResults->rawlen - 1 == 33) && matchMark(aResults->rawbuf[offset], JVC_BIT_MARK)
171  && matchMark(aResults->rawbuf[aResults->rawlen - 1], JVC_BIT_MARK)) {
172  aResults->bits = 0;
173  aResults->value = 0xFFFFFFFF;
176  return true;
177  }
178 
179  // Initial mark
180  if (!matchMark(aResults->rawbuf[offset], JVC_HEADER_MARK)) {
181  return false;
182  }
183  offset++;
184 
185  // Check we have enough data - +3 for start bit mark and space + stop bit mark
186  if (aResults->rawlen <= (2 * JVC_BITS) + 3) {
187  DEBUG_PRINT(F("Data length="));
188  DEBUG_PRINT(aResults->rawlen);
189  DEBUG_PRINTLN(F(" is too small. >= 36 is required."));
190  return false;
191  }
192 
193  // Initial space
194  if (!matchSpace(aResults->rawbuf[offset], JVC_HEADER_SPACE)) {
195  return false;
196  }
197  offset++;
198 
200 
201  // Stop bit
202  if (!matchMark(aResults->rawbuf[offset + (2 * JVC_BITS)], JVC_BIT_MARK)) {
203  DEBUG_PRINTLN(F("Stop bit mark length is wrong"));
204  return false;
205  }
206 
207  // Success
208  aResults->value = decodedIRData.decodedRawData;
209  aResults->bits = JVC_BITS;
210  aResults->decode_type = JVC;
212 
213  return true;
214 }
215 
227 void IRsend::sendJVCMSB(unsigned long data, int nbits, bool repeat) {
228  // Set IR carrier frequency
230 
231  // Only send the Header if this is NOT a repeat command
232  if (!repeat) {
235  }
236 
237  // Old version with MSB first Data
239 }
240 
242 #include "LocalDebugLevelEnd.h"
243 
244 #endif // _IR_JVC_HPP
IRData::address
uint16_t address
Decoded address, Distance protocol (tMarkTicksLong (if tMarkTicksLong == 0, then tMarkTicksShort) << ...
Definition: IRremoteInt.h:164
MICROS_PER_TICK
#define MICROS_PER_TICK
microseconds per clock interrupt tick
Definition: IRremote.hpp:133
decode_results
Results returned from old decoders !!!deprecated!!!
Definition: IRremoteInt.h:193
decode_results::rawbuf
uint16_t * rawbuf
Definition: IRremoteInt.h:204
IRrecv::decodePulseDistanceWidthData
void decodePulseDistanceWidthData(PulseDistanceWidthProtocolConstants *aProtocolConstants, uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset=3)
Decode pulse distance protocols for PulseDistanceWidthProtocolConstants.
Definition: IRReceive.hpp:1076
PROTOCOL_IS_MSB_FIRST
#define PROTOCOL_IS_MSB_FIRST
Definition: IRProtocol.h:156
JVC
@ JVC
Definition: IRProtocol.h:98
IRData::numberOfBits
uint16_t numberOfBits
Number of bits received for data (address + command + parity) - to determine protocol length if diffe...
Definition: IRremoteInt.h:173
DEBUG_PRINT
#define DEBUG_PRINT(...)
Definition: LocalDebugLevelStart.h:79
IRsend::aNumberOfRepeats
void int_fast8_t aNumberOfRepeats
Definition: IRremoteInt.h:528
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:89
IRrecv::decodePulseDistanceWidthData_P
void decodePulseDistanceWidthData_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset=3)
Definition: IRReceive.hpp:1112
MICROS_IN_ONE_MILLI
#define MICROS_IN_ONE_MILLI
Definition: IRremote.hpp:217
IRrecv::checkHeader_P
bool checkHeader_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM)
Definition: IRReceive.hpp:1228
JVC_KHZ
#define JVC_KHZ
Definition: IRProtocol.h:169
PROTOCOL_IS_PULSE_DISTANCE
#define PROTOCOL_IS_PULSE_DISTANCE
Definition: IRProtocol.h:151
IRsend::mark
void mark(uint16_t aMarkMicros)
Sends an IR mark for the specified number of microseconds.
Definition: IRSend.hpp:1247
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:125
JVC_ZERO_SPACE
#define JVC_ZERO_SPACE
Definition: ir_JVC.hpp:74
decode_results::bits
uint8_t bits
Definition: IRremoteInt.h:199
decode_results::decode_type
decode_type_t decode_type
Definition: IRremoteInt.h:196
JVC_REPEAT_PERIOD
#define JVC_REPEAT_PERIOD
Definition: ir_JVC.hpp:77
matchSpace
bool matchSpace(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros)
Compensate for spaces shortened by demodulator hardware.
Definition: IRReceive.hpp:1375
LocalDebugLevelStart.h
JVC_HEADER_MARK
#define JVC_HEADER_MARK
Definition: ir_JVC.hpp:69
decode_results::value
uint32_t value
Definition: IRremoteInt.h:198
PulseDistanceWidthProtocolConstants
Definition: IRProtocol.h:139
IRrecv::decodedIRData
IRData decodedIRData
Definition: IRremoteInt.h:401
IRData::flags
uint8_t flags
IRDATA_FLAGS_IS_REPEAT, IRDATA_FLAGS_WAS_OVERFLOW etc. See IRDATA_FLAGS_* definitions above.
Definition: IRremoteInt.h:174
PROTOCOL_IS_LSB_FIRST
#define PROTOCOL_IS_LSB_FIRST
Definition: IRProtocol.h:157
JVC_HEADER_SPACE
#define JVC_HEADER_SPACE
Definition: ir_JVC.hpp:70
IRData::command
uint16_t command
Decoded command, Distance protocol (tMarkTicksShort << 8) | tSpaceTicksShort.
Definition: IRremoteInt.h:165
IRData::decodedRawData
IRDecodedRawDataType decodedRawData
Up to 32/64 bit decoded raw data, to be used for send<protocol>Raw functions.
Definition: IRremoteInt.h:167
IRsend::sendPulseDistanceWidthData_P
void sendPulseDistanceWidthData_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, IRDecodedRawDataType aData, uint_fast8_t aNumberOfBits)
Definition: IRSend.hpp:670
matchMark
bool matchMark(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros)
Compensate for marks exceeded by demodulator hardware.
Definition: IRReceive.hpp:1327
PROGMEM
struct PulseDistanceWidthProtocolConstants const JVCProtocolConstants PROGMEM
Definition: ir_JVC.hpp:79
JVC_REPEAT_DISTANCE
#define JVC_REPEAT_DISTANCE
Definition: ir_JVC.hpp:76
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
JVC_BIT_MARK
#define JVC_BIT_MARK
Definition: ir_JVC.hpp:72
IRrecv::irparams
irparams_struct irparams
Definition: IRremoteInt.h:400
IRrecv::lastDecodedCommand
uint16_t lastDecodedCommand
Definition: IRremoteInt.h:406
DEBUG_PRINTLN
#define DEBUG_PRINTLN(...)
Definition: LocalDebugLevelStart.h:80
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:227
IRDATA_FLAGS_IS_LSB_FIRST
#define IRDATA_FLAGS_IS_LSB_FIRST
Definition: IRProtocol.h:134
IRsend::space
static void space(uint16_t aSpaceMicros)
Sends an IR space for the specified number of microseconds.
Definition: IRSend.hpp:1458
JVC_ADDRESS_BITS
#define JVC_ADDRESS_BITS
Definition: ir_JVC.hpp:63
IRData::rawlen
IRRawlenType rawlen
Counter of entries in rawbuf of last received frame.
Definition: IRremoteInt.h:182
IRsend::sendPulseDistanceWidthData
void sendPulseDistanceWidthData(PulseDistanceWidthProtocolConstants *aProtocolConstants, IRDecodedRawDataType aData, uint_fast8_t aNumberOfBits)
Sends PulseDistance from data contained in parameter using ProtocolConstants structure for timing etc...
Definition: IRSend.hpp:662
JVC_ONE_SPACE
#define JVC_ONE_SPACE
Definition: ir_JVC.hpp:73
IRrecv::decodeJVC
bool decodeJVC()
Definition: ir_JVC.hpp:116
JVC_BITS
#define JVC_BITS
Definition: ir_JVC.hpp:66
decode_results::rawlen
uint_fast8_t rawlen
Definition: IRremoteInt.h:205
IRData::protocol
decode_type_t protocol
UNKNOWN, NEC, SONY, RC5, PULSE_DISTANCE, ...
Definition: IRremoteInt.h:163
IRrecv::lastDecodedAddress
uint16_t lastDecodedAddress
Definition: IRremoteInt.h:405
IRsend::aCommand
void aCommand
Definition: IRremoteInt.h:617
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:183
IRsend::enableIROut
void enableIROut(uint_fast8_t aFrequencyKHz)
Enables IR output.
Definition: IRSend.hpp:1498
LocalDebugLevelEnd.h
IRrecv::decodeJVCMSB
bool decodeJVCMSB(decode_results *aResults)
Definition: ir_JVC.hpp:166