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

Dependents:   mbed-os-example-FinalReal mbed-os-example-FinalReal

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 // JJJJJ V V CCCC
yuhki50 0:70c8e56bac45 6 // J V V C
yuhki50 0:70c8e56bac45 7 // J V V C
yuhki50 0:70c8e56bac45 8 // J J V V C
yuhki50 0:70c8e56bac45 9 // J V CCCC
yuhki50 0:70c8e56bac45 10 //==============================================================================
yuhki50 0:70c8e56bac45 11
yuhki50 0:70c8e56bac45 12 #define JVC_BITS 16
yuhki50 0:70c8e56bac45 13 #define JVC_HDR_MARK 8000
yuhki50 0:70c8e56bac45 14 #define JVC_HDR_SPACE 4000
yuhki50 0:70c8e56bac45 15 #define JVC_BIT_MARK 600
yuhki50 0:70c8e56bac45 16 #define JVC_ONE_SPACE 1600
yuhki50 0:70c8e56bac45 17 #define JVC_ZERO_SPACE 550
yuhki50 0:70c8e56bac45 18 #define JVC_RPT_LENGTH 60000
yuhki50 0:70c8e56bac45 19
yuhki50 0:70c8e56bac45 20 //+=============================================================================
yuhki50 0:70c8e56bac45 21 // JVC does NOT repeat by sending a separate code (like NEC does).
yuhki50 0:70c8e56bac45 22 // The JVC protocol repeats by skipping the header.
yuhki50 0:70c8e56bac45 23 // To send a JVC repeat signal, send the original code value
yuhki50 0:70c8e56bac45 24 // and set 'repeat' to true
yuhki50 0:70c8e56bac45 25 //
yuhki50 0:70c8e56bac45 26 #if SEND_JVC
yuhki50 0:70c8e56bac45 27 void IRsend::sendJVC (unsigned long data, int nbits, bool repeat)
yuhki50 0:70c8e56bac45 28 {
yuhki50 0:70c8e56bac45 29 // Set IR carrier frequency
yuhki50 0:70c8e56bac45 30 enableIROut(38);
yuhki50 0:70c8e56bac45 31
yuhki50 0:70c8e56bac45 32 // Only send the Header if this is NOT a repeat command
yuhki50 0:70c8e56bac45 33 if (!repeat){
yuhki50 0:70c8e56bac45 34 mark(JVC_HDR_MARK);
yuhki50 0:70c8e56bac45 35 space(JVC_HDR_SPACE);
yuhki50 0:70c8e56bac45 36 }
yuhki50 0:70c8e56bac45 37
yuhki50 0:70c8e56bac45 38 // Data
yuhki50 0:70c8e56bac45 39 for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) {
yuhki50 0:70c8e56bac45 40 if (data & mask) {
yuhki50 0:70c8e56bac45 41 mark(JVC_BIT_MARK);
yuhki50 0:70c8e56bac45 42 space(JVC_ONE_SPACE);
yuhki50 0:70c8e56bac45 43 } else {
yuhki50 0:70c8e56bac45 44 mark(JVC_BIT_MARK);
yuhki50 0:70c8e56bac45 45 space(JVC_ZERO_SPACE);
yuhki50 0:70c8e56bac45 46 }
yuhki50 0:70c8e56bac45 47 }
yuhki50 0:70c8e56bac45 48
yuhki50 0:70c8e56bac45 49 // Footer
yuhki50 0:70c8e56bac45 50 mark(JVC_BIT_MARK);
yuhki50 0:70c8e56bac45 51 space(0); // Always end with the LED off
yuhki50 0:70c8e56bac45 52 }
yuhki50 0:70c8e56bac45 53 #endif
yuhki50 0:70c8e56bac45 54
yuhki50 0:70c8e56bac45 55 //+=============================================================================
yuhki50 0:70c8e56bac45 56 #if DECODE_JVC
yuhki50 0:70c8e56bac45 57 bool IRrecv::decodeJVC (decode_results *results)
yuhki50 0:70c8e56bac45 58 {
yuhki50 0:70c8e56bac45 59 long data = 0;
yuhki50 0:70c8e56bac45 60 int offset = 1; // Skip first space
yuhki50 0:70c8e56bac45 61
yuhki50 0:70c8e56bac45 62 // Check for repeat
yuhki50 0:70c8e56bac45 63 if ( (irparams.rawlen - 1 == 33)
yuhki50 0:70c8e56bac45 64 && MATCH_MARK(results->rawbuf[offset], JVC_BIT_MARK)
yuhki50 0:70c8e56bac45 65 && MATCH_MARK(results->rawbuf[irparams.rawlen-1], JVC_BIT_MARK)
yuhki50 0:70c8e56bac45 66 ) {
yuhki50 0:70c8e56bac45 67 results->bits = 0;
yuhki50 0:70c8e56bac45 68 results->value = REPEAT;
yuhki50 0:70c8e56bac45 69 results->decode_type = JVC;
yuhki50 0:70c8e56bac45 70 return true;
yuhki50 0:70c8e56bac45 71 }
yuhki50 0:70c8e56bac45 72
yuhki50 0:70c8e56bac45 73 // Initial mark
yuhki50 0:70c8e56bac45 74 if (!MATCH_MARK(results->rawbuf[offset++], JVC_HDR_MARK)) return false ;
yuhki50 0:70c8e56bac45 75
yuhki50 0:70c8e56bac45 76 if (irparams.rawlen < (2 * JVC_BITS) + 1 ) return false ;
yuhki50 0:70c8e56bac45 77
yuhki50 0:70c8e56bac45 78 // Initial space
yuhki50 0:70c8e56bac45 79 if (!MATCH_SPACE(results->rawbuf[offset++], JVC_HDR_SPACE)) return false ;
yuhki50 0:70c8e56bac45 80
yuhki50 0:70c8e56bac45 81 for (int i = 0; i < JVC_BITS; i++) {
yuhki50 0:70c8e56bac45 82 if (!MATCH_MARK(results->rawbuf[offset++], JVC_BIT_MARK)) return false ;
yuhki50 0:70c8e56bac45 83
yuhki50 0:70c8e56bac45 84 if (MATCH_SPACE(results->rawbuf[offset], JVC_ONE_SPACE)) data = (data << 1) | 1 ;
yuhki50 0:70c8e56bac45 85 else if (MATCH_SPACE(results->rawbuf[offset], JVC_ZERO_SPACE)) data = (data << 1) | 0 ;
yuhki50 0:70c8e56bac45 86 else return false ;
yuhki50 0:70c8e56bac45 87 offset++;
yuhki50 0:70c8e56bac45 88 }
yuhki50 0:70c8e56bac45 89
yuhki50 0:70c8e56bac45 90 // Stop bit
yuhki50 0:70c8e56bac45 91 if (!MATCH_MARK(results->rawbuf[offset], JVC_BIT_MARK)) return false ;
yuhki50 0:70c8e56bac45 92
yuhki50 0:70c8e56bac45 93 // Success
yuhki50 0:70c8e56bac45 94 results->bits = JVC_BITS;
yuhki50 0:70c8e56bac45 95 results->value = data;
yuhki50 0:70c8e56bac45 96 results->decode_type = JVC;
yuhki50 0:70c8e56bac45 97
yuhki50 0:70c8e56bac45 98 return true;
yuhki50 0:70c8e56bac45 99 }
yuhki50 0:70c8e56bac45 100 #endif
yuhki50 0:70c8e56bac45 101