Infrared remote library for Arduino: send and receive infrared signals with multiple protocols Port from Arduino-IRremote https://github.com/z3t0/Arduino-IRremote
ir_Sony.cpp@0:70c8e56bac45, 2016-01-23 (annotated)
- Committer:
- yuhki50
- Date:
- Sat Jan 23 06:16:48 2016 +0000
- Revision:
- 0:70c8e56bac45
- Child:
- 5:a4dfe2bb80b9
import https://github.com/z3t0/Arduino-IRremote e3ec11d
Who changed what in which revision?
User | Revision | Line number | New 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 | //============================================================================== |
yuhki50 | 0:70c8e56bac45 | 5 | // SSSS OOO N N Y Y |
yuhki50 | 0:70c8e56bac45 | 6 | // S O O NN N Y Y |
yuhki50 | 0:70c8e56bac45 | 7 | // SSS O O N N N Y |
yuhki50 | 0:70c8e56bac45 | 8 | // S O O N NN Y |
yuhki50 | 0:70c8e56bac45 | 9 | // SSSS OOO N N Y |
yuhki50 | 0:70c8e56bac45 | 10 | //============================================================================== |
yuhki50 | 0:70c8e56bac45 | 11 | |
yuhki50 | 0:70c8e56bac45 | 12 | #define SONY_BITS 12 |
yuhki50 | 0:70c8e56bac45 | 13 | #define SONY_HDR_MARK 2400 |
yuhki50 | 0:70c8e56bac45 | 14 | #define SONY_HDR_SPACE 600 |
yuhki50 | 0:70c8e56bac45 | 15 | #define SONY_ONE_MARK 1200 |
yuhki50 | 0:70c8e56bac45 | 16 | #define SONY_ZERO_MARK 600 |
yuhki50 | 0:70c8e56bac45 | 17 | #define SONY_RPT_LENGTH 45000 |
yuhki50 | 0:70c8e56bac45 | 18 | #define SONY_DOUBLE_SPACE_USECS 500 // usually ssee 713 - not using ticks as get number wrapround |
yuhki50 | 0:70c8e56bac45 | 19 | |
yuhki50 | 0:70c8e56bac45 | 20 | //+============================================================================= |
yuhki50 | 0:70c8e56bac45 | 21 | #if SEND_SONY |
yuhki50 | 0:70c8e56bac45 | 22 | void IRsend::sendSony (unsigned long data, int nbits) |
yuhki50 | 0:70c8e56bac45 | 23 | { |
yuhki50 | 0:70c8e56bac45 | 24 | // Set IR carrier frequency |
yuhki50 | 0:70c8e56bac45 | 25 | enableIROut(40); |
yuhki50 | 0:70c8e56bac45 | 26 | |
yuhki50 | 0:70c8e56bac45 | 27 | // Header |
yuhki50 | 0:70c8e56bac45 | 28 | mark(SONY_HDR_MARK); |
yuhki50 | 0:70c8e56bac45 | 29 | space(SONY_HDR_SPACE); |
yuhki50 | 0:70c8e56bac45 | 30 | |
yuhki50 | 0:70c8e56bac45 | 31 | // Data |
yuhki50 | 0:70c8e56bac45 | 32 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { |
yuhki50 | 0:70c8e56bac45 | 33 | if (data & mask) { |
yuhki50 | 0:70c8e56bac45 | 34 | mark(SONY_ONE_MARK); |
yuhki50 | 0:70c8e56bac45 | 35 | space(SONY_HDR_SPACE); |
yuhki50 | 0:70c8e56bac45 | 36 | } else { |
yuhki50 | 0:70c8e56bac45 | 37 | mark(SONY_ZERO_MARK); |
yuhki50 | 0:70c8e56bac45 | 38 | space(SONY_HDR_SPACE); |
yuhki50 | 0:70c8e56bac45 | 39 | } |
yuhki50 | 0:70c8e56bac45 | 40 | } |
yuhki50 | 0:70c8e56bac45 | 41 | |
yuhki50 | 0:70c8e56bac45 | 42 | // We will have ended with LED off |
yuhki50 | 0:70c8e56bac45 | 43 | } |
yuhki50 | 0:70c8e56bac45 | 44 | #endif |
yuhki50 | 0:70c8e56bac45 | 45 | |
yuhki50 | 0:70c8e56bac45 | 46 | //+============================================================================= |
yuhki50 | 0:70c8e56bac45 | 47 | #if DECODE_SONY |
yuhki50 | 0:70c8e56bac45 | 48 | bool IRrecv::decodeSony (decode_results *results) |
yuhki50 | 0:70c8e56bac45 | 49 | { |
yuhki50 | 0:70c8e56bac45 | 50 | long data = 0; |
yuhki50 | 0:70c8e56bac45 | 51 | int offset = 0; // Dont skip first space, check its size |
yuhki50 | 0:70c8e56bac45 | 52 | |
yuhki50 | 0:70c8e56bac45 | 53 | if (irparams.rawlen < (2 * SONY_BITS) + 2) return false ; |
yuhki50 | 0:70c8e56bac45 | 54 | |
yuhki50 | 0:70c8e56bac45 | 55 | // Some Sony's deliver repeats fast after first |
yuhki50 | 0:70c8e56bac45 | 56 | // unfortunately can't spot difference from of repeat from two fast clicks |
yuhki50 | 0:70c8e56bac45 | 57 | if (results->rawbuf[offset] < SONY_DOUBLE_SPACE_USECS) { |
yuhki50 | 0:70c8e56bac45 | 58 | // Serial.print("IR Gap found: "); |
yuhki50 | 0:70c8e56bac45 | 59 | results->bits = 0; |
yuhki50 | 0:70c8e56bac45 | 60 | results->value = REPEAT; |
yuhki50 | 0:70c8e56bac45 | 61 | |
yuhki50 | 0:70c8e56bac45 | 62 | # ifdef DECODE_SANYO |
yuhki50 | 0:70c8e56bac45 | 63 | results->decode_type = SANYO; |
yuhki50 | 0:70c8e56bac45 | 64 | # else |
yuhki50 | 0:70c8e56bac45 | 65 | results->decode_type = UNKNOWN; |
yuhki50 | 0:70c8e56bac45 | 66 | # endif |
yuhki50 | 0:70c8e56bac45 | 67 | |
yuhki50 | 0:70c8e56bac45 | 68 | return true; |
yuhki50 | 0:70c8e56bac45 | 69 | } |
yuhki50 | 0:70c8e56bac45 | 70 | offset++; |
yuhki50 | 0:70c8e56bac45 | 71 | |
yuhki50 | 0:70c8e56bac45 | 72 | // Initial mark |
yuhki50 | 0:70c8e56bac45 | 73 | if (!MATCH_MARK(results->rawbuf[offset++], SONY_HDR_MARK)) return false ; |
yuhki50 | 0:70c8e56bac45 | 74 | |
yuhki50 | 0:70c8e56bac45 | 75 | while (offset + 1 < irparams.rawlen) { |
yuhki50 | 0:70c8e56bac45 | 76 | if (!MATCH_SPACE(results->rawbuf[offset++], SONY_HDR_SPACE)) break ; |
yuhki50 | 0:70c8e56bac45 | 77 | |
yuhki50 | 0:70c8e56bac45 | 78 | if (MATCH_MARK(results->rawbuf[offset], SONY_ONE_MARK)) data = (data << 1) | 1 ; |
yuhki50 | 0:70c8e56bac45 | 79 | else if (MATCH_MARK(results->rawbuf[offset], SONY_ZERO_MARK)) data = (data << 1) | 0 ; |
yuhki50 | 0:70c8e56bac45 | 80 | else return false ; |
yuhki50 | 0:70c8e56bac45 | 81 | offset++; |
yuhki50 | 0:70c8e56bac45 | 82 | } |
yuhki50 | 0:70c8e56bac45 | 83 | |
yuhki50 | 0:70c8e56bac45 | 84 | // Success |
yuhki50 | 0:70c8e56bac45 | 85 | results->bits = (offset - 1) / 2; |
yuhki50 | 0:70c8e56bac45 | 86 | if (results->bits < 12) { |
yuhki50 | 0:70c8e56bac45 | 87 | results->bits = 0; |
yuhki50 | 0:70c8e56bac45 | 88 | return false; |
yuhki50 | 0:70c8e56bac45 | 89 | } |
yuhki50 | 0:70c8e56bac45 | 90 | results->value = data; |
yuhki50 | 0:70c8e56bac45 | 91 | results->decode_type = SONY; |
yuhki50 | 0:70c8e56bac45 | 92 | return true; |
yuhki50 | 0:70c8e56bac45 | 93 | } |
yuhki50 | 0:70c8e56bac45 | 94 | #endif |
yuhki50 | 0:70c8e56bac45 | 95 |