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

Committer:
eunmango
Date:
Sun Jun 16 04:36:58 2019 +0000
Revision:
8:0650578366fd
Parent:
0:70c8e56bac45
dd

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 // PPPP AAA N N AAA SSSS OOO N N IIIII CCCC
yuhki50 0:70c8e56bac45 6 // P P A A NN N A A S O O NN N I C
yuhki50 0:70c8e56bac45 7 // PPPP AAAAA N N N AAAAA SSS O O N N N I C
yuhki50 0:70c8e56bac45 8 // P A A N NN A A S O O N NN I C
yuhki50 0:70c8e56bac45 9 // P A A N N A A SSSS OOO N N IIIII CCCC
yuhki50 0:70c8e56bac45 10 //==============================================================================
yuhki50 0:70c8e56bac45 11
yuhki50 0:70c8e56bac45 12 #define PANASONIC_BITS 48
yuhki50 0:70c8e56bac45 13 #define PANASONIC_HDR_MARK 3502
yuhki50 0:70c8e56bac45 14 #define PANASONIC_HDR_SPACE 1750
yuhki50 0:70c8e56bac45 15 #define PANASONIC_BIT_MARK 502
yuhki50 0:70c8e56bac45 16 #define PANASONIC_ONE_SPACE 1244
yuhki50 0:70c8e56bac45 17 #define PANASONIC_ZERO_SPACE 400
yuhki50 0:70c8e56bac45 18
yuhki50 0:70c8e56bac45 19 //+=============================================================================
yuhki50 0:70c8e56bac45 20 #if SEND_PANASONIC
yuhki50 0:70c8e56bac45 21 void IRsend::sendPanasonic (unsigned int address, unsigned long data)
yuhki50 0:70c8e56bac45 22 {
yuhki50 0:70c8e56bac45 23 // Set IR carrier frequency
yuhki50 0:70c8e56bac45 24 enableIROut(35);
yuhki50 0:70c8e56bac45 25
yuhki50 0:70c8e56bac45 26 // Header
yuhki50 0:70c8e56bac45 27 mark(PANASONIC_HDR_MARK);
yuhki50 0:70c8e56bac45 28 space(PANASONIC_HDR_SPACE);
yuhki50 0:70c8e56bac45 29
yuhki50 0:70c8e56bac45 30 // Address
yuhki50 0:70c8e56bac45 31 for (unsigned long mask = 1UL << (16 - 1); mask; mask >>= 1) {
yuhki50 0:70c8e56bac45 32 mark(PANASONIC_BIT_MARK);
yuhki50 0:70c8e56bac45 33 if (address & mask) space(PANASONIC_ONE_SPACE) ;
yuhki50 0:70c8e56bac45 34 else space(PANASONIC_ZERO_SPACE) ;
yuhki50 0:70c8e56bac45 35 }
yuhki50 0:70c8e56bac45 36
yuhki50 0:70c8e56bac45 37 // Data
yuhki50 0:70c8e56bac45 38 for (unsigned long mask = 1UL << (32 - 1); mask; mask >>= 1) {
yuhki50 0:70c8e56bac45 39 mark(PANASONIC_BIT_MARK);
yuhki50 0:70c8e56bac45 40 if (data & mask) space(PANASONIC_ONE_SPACE) ;
yuhki50 0:70c8e56bac45 41 else space(PANASONIC_ZERO_SPACE) ;
yuhki50 0:70c8e56bac45 42 }
yuhki50 0:70c8e56bac45 43
yuhki50 0:70c8e56bac45 44 // Footer
yuhki50 0:70c8e56bac45 45 mark(PANASONIC_BIT_MARK);
yuhki50 0:70c8e56bac45 46 space(0); // Always end with the LED off
yuhki50 0:70c8e56bac45 47 }
yuhki50 0:70c8e56bac45 48 #endif
yuhki50 0:70c8e56bac45 49
yuhki50 0:70c8e56bac45 50 //+=============================================================================
yuhki50 0:70c8e56bac45 51 #if DECODE_PANASONIC
yuhki50 0:70c8e56bac45 52 bool IRrecv::decodePanasonic (decode_results *results)
yuhki50 0:70c8e56bac45 53 {
yuhki50 0:70c8e56bac45 54 unsigned long long data = 0;
yuhki50 0:70c8e56bac45 55 int offset = 1;
yuhki50 0:70c8e56bac45 56
yuhki50 0:70c8e56bac45 57 if (!MATCH_MARK(results->rawbuf[offset++], PANASONIC_HDR_MARK )) return false ;
yuhki50 0:70c8e56bac45 58 if (!MATCH_MARK(results->rawbuf[offset++], PANASONIC_HDR_SPACE)) return false ;
yuhki50 0:70c8e56bac45 59
yuhki50 0:70c8e56bac45 60 // decode address
yuhki50 0:70c8e56bac45 61 for (int i = 0; i < PANASONIC_BITS; i++) {
yuhki50 0:70c8e56bac45 62 if (!MATCH_MARK(results->rawbuf[offset++], PANASONIC_BIT_MARK)) return false ;
yuhki50 0:70c8e56bac45 63
yuhki50 0:70c8e56bac45 64 if (MATCH_SPACE(results->rawbuf[offset],PANASONIC_ONE_SPACE )) data = (data << 1) | 1 ;
yuhki50 0:70c8e56bac45 65 else if (MATCH_SPACE(results->rawbuf[offset],PANASONIC_ZERO_SPACE)) data = (data << 1) | 0 ;
yuhki50 0:70c8e56bac45 66 else return false ;
yuhki50 0:70c8e56bac45 67 offset++;
yuhki50 0:70c8e56bac45 68 }
yuhki50 0:70c8e56bac45 69
yuhki50 0:70c8e56bac45 70 results->value = (unsigned long)data;
yuhki50 0:70c8e56bac45 71 results->address = (unsigned int)(data >> 32);
yuhki50 0:70c8e56bac45 72 results->decode_type = PANASONIC;
yuhki50 0:70c8e56bac45 73 results->bits = PANASONIC_BITS;
yuhki50 0:70c8e56bac45 74
yuhki50 0:70c8e56bac45 75 return true;
yuhki50 0:70c8e56bac45 76 }
yuhki50 0:70c8e56bac45 77 #endif
yuhki50 0:70c8e56bac45 78