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

Committer:
yuhki50
Date:
Sat Jan 23 06:16:48 2016 +0000
Revision:
0:70c8e56bac45
import https://github.com/z3t0/Arduino-IRremote e3ec11d

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 //==============================================================================
yuhki50 0:70c8e56bac45 5 // SSSS AAA MMM SSSS U U N N GGGG
yuhki50 0:70c8e56bac45 6 // S A A M M M S U U NN N G
yuhki50 0:70c8e56bac45 7 // SSS AAAAA M M M SSS U U N N N G GG
yuhki50 0:70c8e56bac45 8 // S A A M M S U U N NN G G
yuhki50 0:70c8e56bac45 9 // SSSS A A M M SSSS UUU N N GGG
yuhki50 0:70c8e56bac45 10 //==============================================================================
yuhki50 0:70c8e56bac45 11
yuhki50 0:70c8e56bac45 12 #define SAMSUNG_BITS 32
yuhki50 0:70c8e56bac45 13 #define SAMSUNG_HDR_MARK 5000
yuhki50 0:70c8e56bac45 14 #define SAMSUNG_HDR_SPACE 5000
yuhki50 0:70c8e56bac45 15 #define SAMSUNG_BIT_MARK 560
yuhki50 0:70c8e56bac45 16 #define SAMSUNG_ONE_SPACE 1600
yuhki50 0:70c8e56bac45 17 #define SAMSUNG_ZERO_SPACE 560
yuhki50 0:70c8e56bac45 18 #define SAMSUNG_RPT_SPACE 2250
yuhki50 0:70c8e56bac45 19
yuhki50 0:70c8e56bac45 20 //+=============================================================================
yuhki50 0:70c8e56bac45 21 #if SEND_SAMSUNG
yuhki50 0:70c8e56bac45 22 void IRsend::sendSAMSUNG (unsigned long data, int nbits)
yuhki50 0:70c8e56bac45 23 {
yuhki50 0:70c8e56bac45 24 // Set IR carrier frequency
yuhki50 0:70c8e56bac45 25 enableIROut(38);
yuhki50 0:70c8e56bac45 26
yuhki50 0:70c8e56bac45 27 // Header
yuhki50 0:70c8e56bac45 28 mark(SAMSUNG_HDR_MARK);
yuhki50 0:70c8e56bac45 29 space(SAMSUNG_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(SAMSUNG_BIT_MARK);
yuhki50 0:70c8e56bac45 35 space(SAMSUNG_ONE_SPACE);
yuhki50 0:70c8e56bac45 36 } else {
yuhki50 0:70c8e56bac45 37 mark(SAMSUNG_BIT_MARK);
yuhki50 0:70c8e56bac45 38 space(SAMSUNG_ZERO_SPACE);
yuhki50 0:70c8e56bac45 39 }
yuhki50 0:70c8e56bac45 40 }
yuhki50 0:70c8e56bac45 41
yuhki50 0:70c8e56bac45 42 // Footer
yuhki50 0:70c8e56bac45 43 mark(SAMSUNG_BIT_MARK);
yuhki50 0:70c8e56bac45 44 space(0); // Always end with the LED off
yuhki50 0:70c8e56bac45 45 }
yuhki50 0:70c8e56bac45 46 #endif
yuhki50 0:70c8e56bac45 47
yuhki50 0:70c8e56bac45 48 //+=============================================================================
yuhki50 0:70c8e56bac45 49 // SAMSUNGs have a repeat only 4 items long
yuhki50 0:70c8e56bac45 50 //
yuhki50 0:70c8e56bac45 51 #if DECODE_SAMSUNG
yuhki50 0:70c8e56bac45 52 bool IRrecv::decodeSAMSUNG (decode_results *results)
yuhki50 0:70c8e56bac45 53 {
yuhki50 0:70c8e56bac45 54 long data = 0;
yuhki50 0:70c8e56bac45 55 int offset = 1; // Skip first space
yuhki50 0:70c8e56bac45 56
yuhki50 0:70c8e56bac45 57 // Initial mark
yuhki50 0:70c8e56bac45 58 if (!MATCH_MARK(results->rawbuf[offset], SAMSUNG_HDR_MARK)) return false ;
yuhki50 0:70c8e56bac45 59 offset++;
yuhki50 0:70c8e56bac45 60
yuhki50 0:70c8e56bac45 61 // Check for repeat
yuhki50 0:70c8e56bac45 62 if ( (irparams.rawlen == 4)
yuhki50 0:70c8e56bac45 63 && MATCH_SPACE(results->rawbuf[offset], SAMSUNG_RPT_SPACE)
yuhki50 0:70c8e56bac45 64 && MATCH_MARK(results->rawbuf[offset+1], SAMSUNG_BIT_MARK)
yuhki50 0:70c8e56bac45 65 ) {
yuhki50 0:70c8e56bac45 66 results->bits = 0;
yuhki50 0:70c8e56bac45 67 results->value = REPEAT;
yuhki50 0:70c8e56bac45 68 results->decode_type = SAMSUNG;
yuhki50 0:70c8e56bac45 69 return true;
yuhki50 0:70c8e56bac45 70 }
yuhki50 0:70c8e56bac45 71 if (irparams.rawlen < (2 * SAMSUNG_BITS) + 4) return false ;
yuhki50 0:70c8e56bac45 72
yuhki50 0:70c8e56bac45 73 // Initial space
yuhki50 0:70c8e56bac45 74 if (!MATCH_SPACE(results->rawbuf[offset++], SAMSUNG_HDR_SPACE)) return false ;
yuhki50 0:70c8e56bac45 75
yuhki50 0:70c8e56bac45 76 for (int i = 0; i < SAMSUNG_BITS; i++) {
yuhki50 0:70c8e56bac45 77 if (!MATCH_MARK(results->rawbuf[offset++], SAMSUNG_BIT_MARK)) return false ;
yuhki50 0:70c8e56bac45 78
yuhki50 0:70c8e56bac45 79 if (MATCH_SPACE(results->rawbuf[offset], SAMSUNG_ONE_SPACE)) data = (data << 1) | 1 ;
yuhki50 0:70c8e56bac45 80 else if (MATCH_SPACE(results->rawbuf[offset], SAMSUNG_ZERO_SPACE)) data = (data << 1) | 0 ;
yuhki50 0:70c8e56bac45 81 else return false ;
yuhki50 0:70c8e56bac45 82 offset++;
yuhki50 0:70c8e56bac45 83 }
yuhki50 0:70c8e56bac45 84
yuhki50 0:70c8e56bac45 85 // Success
yuhki50 0:70c8e56bac45 86 results->bits = SAMSUNG_BITS;
yuhki50 0:70c8e56bac45 87 results->value = data;
yuhki50 0:70c8e56bac45 88 results->decode_type = SAMSUNG;
yuhki50 0:70c8e56bac45 89 return true;
yuhki50 0:70c8e56bac45 90 }
yuhki50 0:70c8e56bac45 91 #endif
yuhki50 0:70c8e56bac45 92