Infrared remote library for Arduino: send and receive infrared signals with multiple protocols Port from Arduino-IRremote https://github.com/z3t0/Arduino-IRremote

Dependents:   Lilnija_29012017 NucleoF042K6_IRReceiver

Committer:
yuhki50
Date:
Thu Mar 10 15:39:34 2016 +0000
Revision:
7:c82a0d54a024
Parent:
0:70c8e56bac45
change USECPERTICK

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yuhki50 0:70c8e56bac45 1 #include "IRremote.h"
yuhki50 0:70c8e56bac45 2 #include "IRremoteInt.h"
yuhki50 0:70c8e56bac45 3
yuhki50 0:70c8e56bac45 4 // Reverse Engineered by looking at RAW dumps generated by IRremote
yuhki50 0:70c8e56bac45 5
yuhki50 0:70c8e56bac45 6 // I have since discovered that Denon publish all their IR codes:
yuhki50 0:70c8e56bac45 7 // https://www.google.co.uk/search?q=DENON+MASTER+IR+Hex+Command+Sheet
yuhki50 0:70c8e56bac45 8 // -> http://assets.denon.com/documentmaster/us/denon%20master%20ir%20hex.xls
yuhki50 0:70c8e56bac45 9
yuhki50 0:70c8e56bac45 10 // Having looked at the official Denon Pronto sheet and reverse engineered
yuhki50 0:70c8e56bac45 11 // the timing values from it, it is obvious that Denon have a range of
yuhki50 0:70c8e56bac45 12 // different timings and protocols ...the values here work for my AVR-3801 Amp!
yuhki50 0:70c8e56bac45 13
yuhki50 0:70c8e56bac45 14 //==============================================================================
yuhki50 0:70c8e56bac45 15 // DDDD EEEEE N N OOO N N
yuhki50 0:70c8e56bac45 16 // D D E NN N O O NN N
yuhki50 0:70c8e56bac45 17 // D D EEE N N N O O N N N
yuhki50 0:70c8e56bac45 18 // D D E N NN O O N NN
yuhki50 0:70c8e56bac45 19 // DDDD EEEEE N N OOO N N
yuhki50 0:70c8e56bac45 20 //==============================================================================
yuhki50 0:70c8e56bac45 21
yuhki50 0:70c8e56bac45 22 #define BITS 14 // The number of bits in the command
yuhki50 0:70c8e56bac45 23
yuhki50 0:70c8e56bac45 24 #define HDR_MARK 300 // The length of the Header:Mark
yuhki50 0:70c8e56bac45 25 #define HDR_SPACE 750 // The lenght of the Header:Space
yuhki50 0:70c8e56bac45 26
yuhki50 0:70c8e56bac45 27 #define BIT_MARK 300 // The length of a Bit:Mark
yuhki50 0:70c8e56bac45 28 #define ONE_SPACE 1800 // The length of a Bit:Space for 1's
yuhki50 0:70c8e56bac45 29 #define ZERO_SPACE 750 // The length of a Bit:Space for 0's
yuhki50 0:70c8e56bac45 30
yuhki50 0:70c8e56bac45 31 //+=============================================================================
yuhki50 0:70c8e56bac45 32 //
yuhki50 0:70c8e56bac45 33 #if SEND_DENON
yuhki50 0:70c8e56bac45 34 void IRsend::sendDenon (unsigned long data, int nbits)
yuhki50 0:70c8e56bac45 35 {
yuhki50 0:70c8e56bac45 36 // Set IR carrier frequency
yuhki50 0:70c8e56bac45 37 enableIROut(38);
yuhki50 0:70c8e56bac45 38
yuhki50 0:70c8e56bac45 39 // Header
yuhki50 0:70c8e56bac45 40 mark (HDR_MARK);
yuhki50 0:70c8e56bac45 41 space(HDR_SPACE);
yuhki50 0:70c8e56bac45 42
yuhki50 0:70c8e56bac45 43 // Data
yuhki50 0:70c8e56bac45 44 for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) {
yuhki50 0:70c8e56bac45 45 if (data & mask) {
yuhki50 0:70c8e56bac45 46 mark (BIT_MARK);
yuhki50 0:70c8e56bac45 47 space(ONE_SPACE);
yuhki50 0:70c8e56bac45 48 } else {
yuhki50 0:70c8e56bac45 49 mark (BIT_MARK);
yuhki50 0:70c8e56bac45 50 space(ZERO_SPACE);
yuhki50 0:70c8e56bac45 51 }
yuhki50 0:70c8e56bac45 52 }
yuhki50 0:70c8e56bac45 53
yuhki50 0:70c8e56bac45 54 // Footer
yuhki50 0:70c8e56bac45 55 mark(BIT_MARK);
yuhki50 0:70c8e56bac45 56 space(0); // Always end with the LED off
yuhki50 0:70c8e56bac45 57 }
yuhki50 0:70c8e56bac45 58 #endif
yuhki50 0:70c8e56bac45 59
yuhki50 0:70c8e56bac45 60 //+=============================================================================
yuhki50 0:70c8e56bac45 61 //
yuhki50 0:70c8e56bac45 62 #if DECODE_DENON
yuhki50 0:70c8e56bac45 63 bool IRrecv::decodeDenon (decode_results *results)
yuhki50 0:70c8e56bac45 64 {
yuhki50 0:70c8e56bac45 65 unsigned long data = 0; // Somewhere to build our code
yuhki50 0:70c8e56bac45 66 int offset = 1; // Skip the Gap reading
yuhki50 0:70c8e56bac45 67
yuhki50 0:70c8e56bac45 68 // Check we have the right amount of data
yuhki50 0:70c8e56bac45 69 if (irparams.rawlen != 1 + 2 + (2 * BITS) + 1) return false ;
yuhki50 0:70c8e56bac45 70
yuhki50 0:70c8e56bac45 71 // Check initial Mark+Space match
yuhki50 0:70c8e56bac45 72 if (!MATCH_MARK (results->rawbuf[offset++], HDR_MARK )) return false ;
yuhki50 0:70c8e56bac45 73 if (!MATCH_SPACE(results->rawbuf[offset++], HDR_SPACE)) return false ;
yuhki50 0:70c8e56bac45 74
yuhki50 0:70c8e56bac45 75 // Read the bits in
yuhki50 0:70c8e56bac45 76 for (int i = 0; i < BITS; i++) {
yuhki50 0:70c8e56bac45 77 // Each bit looks like: MARK + SPACE_1 -> 1
yuhki50 0:70c8e56bac45 78 // or : MARK + SPACE_0 -> 0
yuhki50 0:70c8e56bac45 79 if (!MATCH_MARK(results->rawbuf[offset++], BIT_MARK)) return false ;
yuhki50 0:70c8e56bac45 80
yuhki50 0:70c8e56bac45 81 // IR data is big-endian, so we shuffle it in from the right:
yuhki50 0:70c8e56bac45 82 if (MATCH_SPACE(results->rawbuf[offset], ONE_SPACE)) data = (data << 1) | 1 ;
yuhki50 0:70c8e56bac45 83 else if (MATCH_SPACE(results->rawbuf[offset], ZERO_SPACE)) data = (data << 1) | 0 ;
yuhki50 0:70c8e56bac45 84 else return false ;
yuhki50 0:70c8e56bac45 85 offset++;
yuhki50 0:70c8e56bac45 86 }
yuhki50 0:70c8e56bac45 87
yuhki50 0:70c8e56bac45 88 // Success
yuhki50 0:70c8e56bac45 89 results->bits = BITS;
yuhki50 0:70c8e56bac45 90 results->value = data;
yuhki50 0:70c8e56bac45 91 results->decode_type = DENON;
yuhki50 0:70c8e56bac45 92 return true;
yuhki50 0:70c8e56bac45 93 }
yuhki50 0:70c8e56bac45 94 #endif