|
| 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 rawDump.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 rawDump.ino example sketch |
| 14 | + # Run it |
| 15 | +
|
| 16 | +Now we can start to add our new protocol... |
| 17 | +
|
| 18 | +1. Copy this file to : ir_Shuzu.cpp |
| 19 | +
|
| 20 | +2. Replace all occurrences of "Shuzu" with the name of your protocol. |
| 21 | +
|
| 22 | +3. Tweak the #defines to suit your protocol. |
| 23 | +
|
| 24 | +4. If you're lucky, tweaking the #defines will make the default send() function |
| 25 | + work. |
| 26 | +
|
| 27 | +5. Again, if you're lucky, tweaking the #defines will have made the default |
| 28 | + decode() function work. |
| 29 | +
|
| 30 | +You have written the code to support your new protocol! |
| 31 | +
|
| 32 | +Now you must do a few things to add it to the IRremote system: |
| 33 | +
|
| 34 | +1. Open IRremote.h and make the following changes: |
| 35 | + REMEMEBER to change occurences of "SHUZU" with the name of your protocol |
| 36 | +
|
| 37 | + A. At the top, in the section "Supported Protocols", add: |
| 38 | + #define DECODE_SHUZU 1 |
| 39 | + #define SEND_SHUZU 1 |
| 40 | +
|
| 41 | + B. In the section "enumerated list of all supported formats", add: |
| 42 | + SHUZU, |
| 43 | + to the end of the list (notice there is a comma after the protocol name) |
| 44 | +
|
| 45 | + C. Further down in "Main class for receiving IR", add: |
| 46 | + //...................................................................... |
| 47 | + #if DECODE_SHUZU |
| 48 | + bool decodeShuzu (decode_results *results) ; |
| 49 | + #endif |
| 50 | +
|
| 51 | + D. Further down in "Main class for sending IR", add: |
| 52 | + //...................................................................... |
| 53 | + #if SEND_SHUZU |
| 54 | + void sendShuzu (unsigned long data, int nbits) ; |
| 55 | + #endif |
| 56 | +
|
| 57 | + E. Save your changes and close the file |
| 58 | +
|
| 59 | +2. Now open irRecv.cpp and make the following change: |
| 60 | +
|
| 61 | + A. In the function IRrecv::decode(), add: |
| 62 | + #ifdef DECODE_NEC |
| 63 | + DBG_PRINTLN("Attempting Shuzu decode"); |
| 64 | + if (decodeShuzu(results)) return true ; |
| 65 | + #endif |
| 66 | +
|
| 67 | + B. Save your changes and close the file |
| 68 | +
|
| 69 | +Now open the Arduino IDE, load up the rawDump.ino sketch, and run it. |
| 70 | +Hopefully it will compile and upload. |
| 71 | +If it doesn't, you've done something wrong. Check your work. |
| 72 | +If you can't get it to work - seek help from somewhere. |
| 73 | +
|
| 74 | +If you get this far, I will assume you have successfully added your new protocol |
| 75 | +There is one last thing to do. |
| 76 | +
|
| 77 | +1. Delete this giant instructional comment. |
| 78 | +
|
| 79 | +2. Send a copy of your work to us so we can include it in the library and |
| 80 | + others may benefit from your hard work and maybe even write a song about how |
| 81 | + great you are for helping them! :) |
| 82 | +
|
| 83 | +Regards, |
| 84 | + BlueChip |
| 85 | +*/ |
| 86 | + |
| 87 | +#include "IRremote.h" |
| 88 | +#include "IRremoteInt.h" |
| 89 | + |
| 90 | +//============================================================================== |
| 91 | +// |
| 92 | +// |
| 93 | +// S H U Z U |
| 94 | +// |
| 95 | +// |
| 96 | +//============================================================================== |
| 97 | + |
| 98 | +#define SHUZU_BITS 32 // The number of bits in the command |
| 99 | + |
| 100 | +#define SHUZU_HDR_MARK 1000 // The length of the Header:Mark |
| 101 | +#define SHUZU_HDR_SPACE 2000 // The lenght of the Header:Space |
| 102 | + |
| 103 | +#define SHUZU_BIT_MARK 3000 // The length of a Bit:Mark |
| 104 | +#define SHUZU_ONE_SPACE 4000 // The length of a Bit:Space for 1's |
| 105 | +#define SHUZU_ZERO_SPACE 5000 // The length of a Bit:Space for 0's |
| 106 | + |
| 107 | +#define SHUZU_OTHER 1234 // Other things you may need to define |
| 108 | + |
| 109 | +//+============================================================================= |
| 110 | +// |
| 111 | +#if SEND_SHUZU |
| 112 | +void IRsend::sendShuzu (unsigned long data, int nbits) |
| 113 | +{ |
| 114 | + // Set IR carrier frequency |
| 115 | + enableIROut(38); |
| 116 | + |
| 117 | + // Header |
| 118 | + mark (SHUZU_HDR_MARK); |
| 119 | + space(SHUZU_HDR_SPACE); |
| 120 | + |
| 121 | + // Data |
| 122 | + for (unsigned long mask = 1 << (nbits - 1); mask; mask >>= 1) { |
| 123 | + if (data & mask) { |
| 124 | + mark (SHUZU_BIT_MARK); |
| 125 | + space(SHUZU_ONE_SPACE); |
| 126 | + } else { |
| 127 | + mark (SHUZU_BIT_MARK); |
| 128 | + space(SHUZU_ZERO_SPACE); |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + // Footer |
| 133 | + mark(SHUZU_BIT_MARK); |
| 134 | + space(0); // Always end with the LED off |
| 135 | +} |
| 136 | +#endif |
| 137 | + |
| 138 | +//+============================================================================= |
| 139 | +// |
| 140 | +#if DECODE_SHUZU |
| 141 | +bool IRrecv::decodeShuzu (decode_results *results) |
| 142 | +{ |
| 143 | + unsigned long data = 0; // Somewhere to build our code |
| 144 | + int offset = 1; // Skip the Gap reading |
| 145 | + |
| 146 | + // Check we have the right amount of data |
| 147 | + if (irparams.rawlen != 1 + 2 + (2 * SHUZU_BITS) + 1) return false ; |
| 148 | + |
| 149 | + // Check initial Mark+Space match |
| 150 | + if (!MATCH_MARK (results->rawbuf[offset++], SHUZU_HDR_MARK )) return false ; |
| 151 | + if (!MATCH_SPACE(results->rawbuf[offset++], SHUZU_HDR_SPACE)) return false ; |
| 152 | + |
| 153 | + // Read the bits in |
| 154 | + for (int i = 0; i < SHUZU_BITS; i++) { |
| 155 | + // Each bit looks like: MARK + SPACE_1 -> 1 |
| 156 | + // or : MARK + SPACE_0 -> 0 |
| 157 | + if (!MATCH_MARK(results->rawbuf[offset++], SAMSUNG_BIT_MARK)) return false ; |
| 158 | + |
| 159 | + // IR data is big-endian, so we shuffle it in from the right: |
| 160 | + if (MATCH_SPACE(results->rawbuf[offset], SHUZU_ONE_SPACE)) data = (data << 1) | 1 ; |
| 161 | + else if (MATCH_SPACE(results->rawbuf[offset], SHUZU_ZERO_SPACE)) data = (data << 1) | 0 ; |
| 162 | + else return false ; |
| 163 | + offset++; |
| 164 | + } |
| 165 | + |
| 166 | + // Success |
| 167 | + results->bits = SHUZU_BITS; |
| 168 | + results->value = data; |
| 169 | + results->decode_type = SHUZU; |
| 170 | + return true; |
| 171 | +} |
| 172 | +#endif |
0 commit comments