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 #include "LocalDebugLevelStart.h"
96 
97 //==============================================================================
98 //
99 //
100 // S H U Z U
101 //
102 //
103 //==============================================================================
104 // see: https://www....
105 
106 // LSB first, 1 start bit + 16 bit address + 8 bit command + 1 stop bit.
107 #define SHUZU_ADDRESS_BITS 16 // 16 bit address
108 #define SHUZU_COMMAND_BITS 8 // Command
109 
110 #define SHUZU_BITS (SHUZU_ADDRESS_BITS + SHUZU_COMMAND_BITS) // The number of bits in the protocol
111 #define SHUZU_UNIT 560 // All timings are in microseconds
112 
113 #define SHUZU_HEADER_MARK (16 * SHUZU_UNIT) // The length of the Header:Mark
114 #define SHUZU_HEADER_SPACE (8 * SHUZU_UNIT) // The length of the Header:Space
115 
116 #define SHUZU_BIT_MARK SHUZU_UNIT // The length of a Bit:Mark
117 #define SHUZU_ONE_SPACE (3 * SHUZU_UNIT) // The length of a Bit:Space for 1's
118 #define SHUZU_ZERO_SPACE SHUZU_UNIT // The length of a Bit:Space for 0's
119 
120 #define SHUZU_REPEAT_HEADER_SPACE (4 * SHUZU_UNIT) // 2250
121 
122 #define SHUZU_REPEAT_PERIOD 110000 // From start to start
123 #define SHUZU_REPEAT_SPACE 45000 // SHUZU_REPEAT_PERIOD - default frame duration. Used for repeat detection.
124 
125 #define SHUZU_OTHER 1234 // Other things you may need to define
126 
127 // use BOSEWAVE, we have no SHUZU code
130  / MICROS_IN_ONE_MILLI), nullptr};
131 
132 /************************************
133  * Start of send and decode functions
134  ************************************/
135 
136 void IRsend::sendShuzu(uint16_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats) {
137 
138  sendPulseDistanceWidth_P(&ShuzuProtocolConstants, (uint32_t) aCommand << 8 | aCommand, SHUZU_BITS, aNumberOfRepeats);
139 }
140 
142  /*
143  * First check for right data length
144  * Next check start bit / header
145  * Next try the decode
146  */
147  // Check we have the right amount of data (28). The +4 is for initial gap, start bit mark and space + stop bit mark
148  if (irparams.rawlen != (2 * SHUZU_BITS) + 4) {
149  // no debug output, since this check is mainly to determine the received protocol
150  return false;
151  }
152 
153  // Check header
154  if (!checkHeader_P(&ShuzuProtocolConstants)) {
155  return false;
156  }
157 
158  // Decode
159  if (!decodePulseDistanceData_P(&ShuzuProtocolConstants, SHUZU_BITS)) {
160  DEBUG_PRINTLN(F("Shuzu: Decode failed"));
161  return false;
162  }
163 
164  // Success, interpret raw data
165 // decodedIRData.flags = IRDATA_FLAGS_IS_LSB_FIRST; // Not required, since this is the start value
166  decodedIRData.command = decodedIRData.decodedRawData >> SHUZU_ADDRESS_BITS; // upper 8 bits of LSB first value
167  decodedIRData.address = decodedIRData.decodedRawData & 0xFFFF; // lowest 16 bit of LSB first value
169  decodedIRData.protocol = BOSEWAVE; // we have no SHUZU code
170 
171  //Check for repeat
172  checkForRepeatSpaceAndSetFlag(SHUZU_REPEAT_SPACE / MICROS_IN_ONE_MILLI);
173 
174  return true;
175 }
176 
177 #include "LocalDebugLevelEnd.h"
178 
179 #endif // _IR_SHUZU_HPP
IRData::address
uint16_t address
Decoded address, Distance protocol (tMarkTicksLong (if tMarkTicksLong == 0, then tMarkTicksShort) << ...
Definition: IRremoteInt.h:164
SHUZU_REPEAT_SPACE
#define SHUZU_REPEAT_SPACE
Definition: ir_Template.hpp:123
IRsend::sendShuzu
void sendShuzu(uint16_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats)
Definition: ir_Template.hpp:136
SHUZU_BIT_MARK
#define SHUZU_BIT_MARK
Definition: ir_Template.hpp:116
SHUZU_ZERO_SPACE
#define SHUZU_ZERO_SPACE
Definition: ir_Template.hpp:118
PROGMEM
struct PulseDistanceWidthProtocolConstants const ShuzuProtocolConstants PROGMEM
Definition: ir_Template.hpp:128
SHUZU_REPEAT_PERIOD
#define SHUZU_REPEAT_PERIOD
Definition: ir_Template.hpp:122
IRData::numberOfBits
uint16_t numberOfBits
Number of bits received for data (address + command + parity) - to determine protocol length if diffe...
Definition: IRremoteInt.h:173
IRsend::aNumberOfRepeats
void int_fast8_t aNumberOfRepeats
Definition: IRremoteInt.h:528
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
BOSEWAVE
@ BOSEWAVE
Definition: IRProtocol.h:103
LocalDebugLevelStart.h
PulseDistanceWidthProtocolConstants
Definition: IRProtocol.h:139
IRsend::sendPulseDistanceWidth_P
void sendPulseDistanceWidth_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, IRDecodedRawDataType aData, uint_fast8_t aNumberOfBits, int_fast8_t aNumberOfRepeats)
Definition: IRSend.hpp:1158
irparams_struct::rawlen
IRRawlenType rawlen
counter of entries in rawbuf
Definition: IRremoteInt.h:145
IRrecv::decodedIRData
IRData decodedIRData
Definition: IRremoteInt.h:401
PROTOCOL_IS_LSB_FIRST
#define PROTOCOL_IS_LSB_FIRST
Definition: IRProtocol.h:157
SHUZU_HEADER_SPACE
#define SHUZU_HEADER_SPACE
Definition: ir_Template.hpp:114
IRData::command
uint16_t command
Decoded command, Distance protocol (tMarkTicksShort << 8) | tSpaceTicksShort.
Definition: IRremoteInt.h:165
SHUZU_BITS
#define SHUZU_BITS
Definition: ir_Template.hpp:110
IRData::decodedRawData
IRDecodedRawDataType decodedRawData
Up to 32/64 bit decoded raw data, to be used for send<protocol>Raw functions.
Definition: IRremoteInt.h:167
SHUZU_ADDRESS_BITS
#define SHUZU_ADDRESS_BITS
Definition: ir_Template.hpp:107
SHUZU_ONE_SPACE
#define SHUZU_ONE_SPACE
Definition: ir_Template.hpp:117
IRrecv::irparams
irparams_struct irparams
Definition: IRremoteInt.h:400
DEBUG_PRINTLN
#define DEBUG_PRINTLN(...)
Definition: LocalDebugLevelStart.h:80
SHUZU_HEADER_MARK
#define SHUZU_HEADER_MARK
Definition: ir_Template.hpp:113
IRData::protocol
decode_type_t protocol
UNKNOWN, NEC, SONY, RC5, PULSE_DISTANCE, ...
Definition: IRremoteInt.h:163
IRrecv::decodeShuzu
bool decodeShuzu()
Definition: ir_Template.hpp:141
IRsend::aCommand
void aCommand
Definition: IRremoteInt.h:617
LocalDebugLevelEnd.h