IRremote
ir_Template.hpp
Go to the documentation of this file.
1 /*
2  Assuming the protocol we are adding is for the (imaginary) manufacturer: Shuzu
3 
4  Our fantasy protocol is a standard protocol, so we can use this standard
5  template without too much work. Some protocols are quite unique and will require
6  considerably more work in this file! It is way beyond the scope of this text to
7  explain how to reverse engineer "unusual" IR protocols. But, unless you own an
8  oscilloscope, the starting point is probably to use the ReceiveDump.ino sketch and
9  try to spot the pattern!
10 
11  Before you start, make sure the IR library is working OK:
12  # Open up the Arduino IDE
13  # Load up the ReceiveDump.ino example sketch
14  # Run it
15  # Analyze your data to have an idea, what is the header timing, the bit timing, the address, the command and the checksum of your protocol.
16 
17  Now we can start to add our new protocol...
18 
19  1. Copy this file to : ir_<YourProtocolName>.hpp
20 
21  2. Replace all occurrences of "SHUZU" with the name of your protocol.
22 
23  3. Tweak the #defines to suit your protocol.
24 
25  4. If you're lucky, tweaking the #defines will make the decode and send() function
26  work.
27 
28  You have now written the code to support your new protocol!
29 
30  To integrate it into the IRremote library, you must search for "BOSEWAVE"
31  and add your protocol in the same way as it is already done for BOSEWAVE.
32 
33  You have to change the following files:
34  IRSend.hpp IRsend::write(IRData *aIRSendData + int_fast8_t aNumberOfRepeats)
35  IRProtocol.h Add it to decode_type_t
36  IRReceive.hpp IRrecv::decode() + printActiveIRProtocols(Print *aSerial) + getProtocolString(decode_type_t aProtocol)
37  IRremote.hpp At 3 occurrences of DECODE_XXX
38  IRremoteInt.h Add the declaration of the decode and send function
39 
40  Now open the Arduino IDE, load up the ReceiveDump.ino sketch, and run it.
41  Hopefully it will compile and upload.
42  If it doesn't, you've done something wrong. Check your work and look carefully at the error messages.
43 
44  If you get this far, I will assume you have successfully added your new protocol
45 
46  At last, delete this giant instructional comment.
47 
48  If you want us to include your work in the library so others may benefit
49  from your hard work, you have to extend the examples
50  IRremoteInfo, SmallReceiver, simple Receiver, SendDemo and UnitTest too
51  as well as the Readme.md
52  It is not an act, but required for completeness.
53 
54  Thanks
55  The maintainer
56  */
57 
58 /*
59  * ir_Shuzu.hpp
60  *
61  * Contains functions for receiving and sending Shuzu IR Protocol ...
62  *
63  * Copyright (C) 2022 Shuzu Guru
64  * shuzu.guru@gmail.com
65  *
66  * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
67  *
68  ************************************************************************************
69  * MIT License
70  *
71  * Copyright (c) 2022 Unknown Contributor :-)
72  *
73  * Permission is hereby granted, free of charge, to any person obtaining a copy
74  * of this software and associated documentation files (the "Software"), to deal
75  * in the Software without restriction, including without limitation the rights
76  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
77  * copies of the Software, and to permit persons to whom the Software is furnished
78  * to do so, subject to the following conditions:
79  *
80  * The above copyright notice and this permission notice shall be included in all
81  * copies or substantial portions of the Software.
82  *
83  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
84  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
85  * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
86  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
87  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
88  * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
89  *
90  ************************************************************************************
91  */
92 #ifndef _IR_SHUZU_HPP
93 #define _IR_SHUZU_HPP
94 
95 //==============================================================================
96 //
97 //
98 // S H U Z U
99 //
100 //
101 //==============================================================================
102 // see: https://www....
103 
104 // LSB first, 1 start bit + 16 bit address + 8 bit command + 1 stop bit.
105 #define SHUZU_ADDRESS_BITS 16 // 16 bit address
106 #define SHUZU_COMMAND_BITS 8 // Command
107 
108 #define SHUZU_BITS (SHUZU_ADDRESS_BITS + SHUZU_COMMAND_BITS) // The number of bits in the protocol
109 #define SHUZU_UNIT 560 // All timings are in microseconds
110 
111 #define SHUZU_HEADER_MARK (16 * SHUZU_UNIT) // The length of the Header:Mark
112 #define SHUZU_HEADER_SPACE (8 * SHUZU_UNIT) // The length of the Header:Space
113 
114 #define SHUZU_BIT_MARK SHUZU_UNIT // The length of a Bit:Mark
115 #define SHUZU_ONE_SPACE (3 * SHUZU_UNIT) // The length of a Bit:Space for 1's
116 #define SHUZU_ZERO_SPACE SHUZU_UNIT // The length of a Bit:Space for 0's
117 
118 #define SHUZU_REPEAT_HEADER_SPACE (4 * SHUZU_UNIT) // 2250
119 
120 #define SHUZU_REPEAT_PERIOD 110000 // From start to start
121 #define SHUZU_REPEAT_SPACE 45000 // SHUZU_REPEAT_PERIOD - default frame duration. Used for repeat detection.
122 
123 #define SHUZU_OTHER 1234 // Other things you may need to define
124 
125 // use BOSEWAVE, we have no SHUZU code
128  / MICROS_IN_ONE_MILLI), NULL };
129 
130 /************************************
131  * Start of send and decode functions
132  ************************************/
133 
134 void IRsend::sendShuzu(uint16_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats) {
135 
137 }
138 
140  /*
141  * First check for right data length
142  * Next check start bit / header
143  * Next try the decode
144  */
145  // Check we have the right amount of data (28). The +4 is for initial gap, start bit mark and space + stop bit mark
146  if (decodedIRData.rawDataPtr->rawlen != (2 * SHUZU_BITS) + 4) {
147  // no debug output, since this check is mainly to determine the received protocol
148  return false;
149  }
150 
151  // Check header
153  return false;
154  }
155 
156  // Decode
157  if (!decodePulseDistanceData(&ShuzuProtocolConstants, SHUZU_BITS)) {
158  IR_DEBUG_PRINT(F("Shuzu: "));
159  IR_DEBUG_PRINTLN(F("Decode failed"));
160  return false;
161  }
162 
163  // Success, interpret raw data
164 // decodedIRData.flags = IRDATA_FLAGS_IS_LSB_FIRST; // Not required, since this is the start value
165  decodedIRData.command = decodedIRData.decodedRawData >> SHUZU_ADDRESS_BITS; // upper 8 bits of LSB first value
166  decodedIRData.address = decodedIRData.decodedRawData & 0xFFFF; // lowest 16 bit of LSB first value
168  decodedIRData.protocol = BOSEWAVE; // we have no SHUZU code
169 
170  //Check for repeat
171  checkForRepeatSpaceAndSetFlag(SHUZU_REPEAT_SPACE / MICROS_IN_ONE_MILLI);
172 
173  return true;
174 }
175 #endif // _IR_SHUZU_HPP
IRData::address
uint16_t address
Decoded address, Distance protocol (tMarkTicksLong (if tMarkTicksLong == 0, then tMarkTicksShort) << ...
Definition: IRProtocol.h:109
SHUZU_REPEAT_SPACE
#define SHUZU_REPEAT_SPACE
Definition: ir_Template.hpp:121
IRsend::sendShuzu
void sendShuzu(uint16_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats)
Definition: ir_Template.hpp:134
SHUZU_BIT_MARK
#define SHUZU_BIT_MARK
Definition: ir_Template.hpp:114
SHUZU_ZERO_SPACE
#define SHUZU_ZERO_SPACE
Definition: ir_Template.hpp:116
SHUZU_REPEAT_PERIOD
#define SHUZU_REPEAT_PERIOD
Definition: ir_Template.hpp:120
IRData::numberOfBits
uint16_t numberOfBits
Number of bits received for data (address + command + parity) - to determine protocol length if diffe...
Definition: IRProtocol.h:118
IRsend::aNumberOfRepeats
void int_fast8_t aNumberOfRepeats
Definition: IRremoteInt.h:520
MICROS_IN_ONE_MILLI
#define MICROS_IN_ONE_MILLI
Definition: IRremote.hpp:254
IRsend::sendPulseDistanceWidth
void sendPulseDistanceWidth(PulseDistanceWidthProtocolConstants *aProtocolConstants, IRRawDataType aData, uint_fast8_t aNumberOfBits, int_fast8_t aNumberOfRepeats)
Sends PulseDistance frames and repeats and enables receiver again.
Definition: IRSend.hpp:702
BOSEWAVE
@ BOSEWAVE
Definition: IRProtocol.h:67
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:129
IRData::decodedRawData
IRRawDataType decodedRawData
Up to 32/64 bit decoded raw data, to be used for send functions.
Definition: IRProtocol.h:112
IR_DEBUG_PRINT
#define IR_DEBUG_PRINT(...)
If DEBUG, print the arguments, otherwise do nothing.
Definition: IRremoteInt.h:137
ShuzuProtocolConstants
struct PulseDistanceWidthProtocolConstants ShuzuProtocolConstants
Definition: ir_Template.hpp:126
irparams_struct::rawlen
uint_fast8_t rawlen
counter of entries in rawbuf
Definition: IRremoteInt.h:109
PulseDistanceWidthProtocolConstants
Definition: IRProtocol.h:132
IRrecv::decodedIRData
IRData decodedIRData
Definition: IRremoteInt.h:321
PROTOCOL_IS_LSB_FIRST
#define PROTOCOL_IS_LSB_FIRST
Definition: IRProtocol.h:146
IRrecv::checkHeader
bool checkHeader(PulseDistanceWidthProtocolConstants *aProtocolConstants)
Definition: IRReceive.hpp:1018
SHUZU_HEADER_SPACE
#define SHUZU_HEADER_SPACE
Definition: ir_Template.hpp:112
IRData::command
uint16_t command
Decoded command, Distance protocol (tMarkTicksShort << 8) | tSpaceTicksShort.
Definition: IRProtocol.h:110
SHUZU_BITS
#define SHUZU_BITS
Definition: ir_Template.hpp:108
SHUZU_ADDRESS_BITS
#define SHUZU_ADDRESS_BITS
Definition: ir_Template.hpp:105
SHUZU_ONE_SPACE
#define SHUZU_ONE_SPACE
Definition: ir_Template.hpp:115
SHUZU_HEADER_MARK
#define SHUZU_HEADER_MARK
Definition: ir_Template.hpp:111
IR_DEBUG_PRINTLN
#define IR_DEBUG_PRINTLN(...)
If DEBUG, print the arguments as a line, otherwise do nothing.
Definition: IRremoteInt.h:141
IRData::protocol
decode_type_t protocol
UNKNOWN, NEC, SONY, RC5, PULSE_DISTANCE, ...
Definition: IRProtocol.h:108
IRrecv::decodeShuzu
bool decodeShuzu()
Definition: ir_Template.hpp:139
IRsend::aCommand
void aCommand
Definition: IRremoteInt.h:582