mirror of
https://github.com/Theaninova/Arduino-IRremote.git
synced 2025-12-12 17:36:15 +00:00
Added a template for new protocols with full instructions in a big comment at the top
This commit is contained in:
172
ir_Template.cpp
Normal file
172
ir_Template.cpp
Normal file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
Assuming the protocol we are adding is for the (imaginary) manufacturer: Shuzu
|
||||
|
||||
Our fantasy protocol is a standard protocol, so we can use this standard
|
||||
template without too much work. Some protocols are quite unique and will require
|
||||
considerably more work in this file! It is way beyond the scope of this text to
|
||||
explain how to reverse engineer "unusual" IR protocols. But, unless you own an
|
||||
oscilloscope, the starting point is probably to use the rawDump.ino sketch and
|
||||
try to spot the pattern!
|
||||
|
||||
Before you start, make sure the IR library is working OK:
|
||||
# Open up the Arduino IDE
|
||||
# Load up the rawDump.ino example sketch
|
||||
# Run it
|
||||
|
||||
Now we can start to add our new protocol...
|
||||
|
||||
1. Copy this file to : ir_Shuzu.cpp
|
||||
|
||||
2. Replace all occurrences of "Shuzu" with the name of your protocol.
|
||||
|
||||
3. Tweak the #defines to suit your protocol.
|
||||
|
||||
4. If you're lucky, tweaking the #defines will make the default send() function
|
||||
work.
|
||||
|
||||
5. Again, if you're lucky, tweaking the #defines will have made the default
|
||||
decode() function work.
|
||||
|
||||
You have written the code to support your new protocol!
|
||||
|
||||
Now you must do a few things to add it to the IRremote system:
|
||||
|
||||
1. Open IRremote.h and make the following changes:
|
||||
REMEMEBER to change occurences of "SHUZU" with the name of your protocol
|
||||
|
||||
A. At the top, in the section "Supported Protocols", add:
|
||||
#define DECODE_SHUZU 1
|
||||
#define SEND_SHUZU 1
|
||||
|
||||
B. In the section "enumerated list of all supported formats", add:
|
||||
SHUZU,
|
||||
to the end of the list (notice there is a comma after the protocol name)
|
||||
|
||||
C. Further down in "Main class for receiving IR", add:
|
||||
//......................................................................
|
||||
#if DECODE_SHUZU
|
||||
bool decodeShuzu (decode_results *results) ;
|
||||
#endif
|
||||
|
||||
D. Further down in "Main class for sending IR", add:
|
||||
//......................................................................
|
||||
#if SEND_SHUZU
|
||||
void sendShuzu (unsigned long data, int nbits) ;
|
||||
#endif
|
||||
|
||||
E. Save your changes and close the file
|
||||
|
||||
2. Now open irRecv.cpp and make the following change:
|
||||
|
||||
A. In the function IRrecv::decode(), add:
|
||||
#ifdef DECODE_NEC
|
||||
DBG_PRINTLN("Attempting Shuzu decode");
|
||||
if (decodeShuzu(results)) return true ;
|
||||
#endif
|
||||
|
||||
B. Save your changes and close the file
|
||||
|
||||
Now open the Arduino IDE, load up the rawDump.ino sketch, and run it.
|
||||
Hopefully it will compile and upload.
|
||||
If it doesn't, you've done something wrong. Check your work.
|
||||
If you can't get it to work - seek help from somewhere.
|
||||
|
||||
If you get this far, I will assume you have successfully added your new protocol
|
||||
There is one last thing to do.
|
||||
|
||||
1. Delete this giant instructional comment.
|
||||
|
||||
2. Send a copy of your work to us so we can include it in the library and
|
||||
others may benefit from your hard work and maybe even write a song about how
|
||||
great you are for helping them! :)
|
||||
|
||||
Regards,
|
||||
BlueChip
|
||||
*/
|
||||
|
||||
#include "IRremote.h"
|
||||
#include "IRremoteInt.h"
|
||||
|
||||
//==============================================================================
|
||||
//
|
||||
//
|
||||
// S H U Z U
|
||||
//
|
||||
//
|
||||
//==============================================================================
|
||||
|
||||
#define SHUZU_BITS 32 // The number of bits in the command
|
||||
|
||||
#define SHUZU_HDR_MARK 1000 // The length of the Header:Mark
|
||||
#define SHUZU_HDR_SPACE 2000 // The lenght of the Header:Space
|
||||
|
||||
#define SHUZU_BIT_MARK 3000 // The length of a Bit:Mark
|
||||
#define SHUZU_ONE_SPACE 4000 // The length of a Bit:Space for 1's
|
||||
#define SHUZU_ZERO_SPACE 5000 // The length of a Bit:Space for 0's
|
||||
|
||||
#define SHUZU_OTHER 1234 // Other things you may need to define
|
||||
|
||||
//+=============================================================================
|
||||
//
|
||||
#if SEND_SHUZU
|
||||
void IRsend::sendShuzu (unsigned long data, int nbits)
|
||||
{
|
||||
// Set IR carrier frequency
|
||||
enableIROut(38);
|
||||
|
||||
// Header
|
||||
mark (SHUZU_HDR_MARK);
|
||||
space(SHUZU_HDR_SPACE);
|
||||
|
||||
// Data
|
||||
for (unsigned long mask = 1 << (nbits - 1); mask; mask >>= 1) {
|
||||
if (data & mask) {
|
||||
mark (SHUZU_BIT_MARK);
|
||||
space(SHUZU_ONE_SPACE);
|
||||
} else {
|
||||
mark (SHUZU_BIT_MARK);
|
||||
space(SHUZU_ZERO_SPACE);
|
||||
}
|
||||
}
|
||||
|
||||
// Footer
|
||||
mark(SHUZU_BIT_MARK);
|
||||
space(0); // Always end with the LED off
|
||||
}
|
||||
#endif
|
||||
|
||||
//+=============================================================================
|
||||
//
|
||||
#if DECODE_SHUZU
|
||||
bool IRrecv::decodeShuzu (decode_results *results)
|
||||
{
|
||||
unsigned long data = 0; // Somewhere to build our code
|
||||
int offset = 1; // Skip the Gap reading
|
||||
|
||||
// Check we have the right amount of data
|
||||
if (irparams.rawlen != 1 + 2 + (2 * SHUZU_BITS) + 1) return false ;
|
||||
|
||||
// Check initial Mark+Space match
|
||||
if (!MATCH_MARK (results->rawbuf[offset++], SHUZU_HDR_MARK )) return false ;
|
||||
if (!MATCH_SPACE(results->rawbuf[offset++], SHUZU_HDR_SPACE)) return false ;
|
||||
|
||||
// Read the bits in
|
||||
for (int i = 0; i < SHUZU_BITS; i++) {
|
||||
// Each bit looks like: MARK + SPACE_1 -> 1
|
||||
// or : MARK + SPACE_0 -> 0
|
||||
if (!MATCH_MARK(results->rawbuf[offset++], SAMSUNG_BIT_MARK)) return false ;
|
||||
|
||||
// IR data is big-endian, so we shuffle it in from the right:
|
||||
if (MATCH_SPACE(results->rawbuf[offset], SHUZU_ONE_SPACE)) data = (data << 1) | 1 ;
|
||||
else if (MATCH_SPACE(results->rawbuf[offset], SHUZU_ZERO_SPACE)) data = (data << 1) | 0 ;
|
||||
else return false ;
|
||||
offset++;
|
||||
}
|
||||
|
||||
// Success
|
||||
results->bits = SHUZU_BITS;
|
||||
results->value = data;
|
||||
results->decode_type = SHUZU;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user