| 1 | /* IRLib_P01_NEC.h |
|---|
| 2 | * Part of IRLib Library for Arduino receiving, decoding, and sending |
|---|
| 3 | * infrared signals. See COPYRIGHT.txt and LICENSE.txt for more information. |
|---|
| 4 | */ |
|---|
| 5 | /* |
|---|
| 6 | * NEC is an extremely common protocol. There are two variations NEC1 and NEC2. |
|---|
| 7 | * They differ only in the way in which they handle repeat codes. If you hold a button |
|---|
| 8 | * using NEC1 it does not repeat the same sequence. Rather it sends a special sequence |
|---|
| 9 | * consisting of the usual header mark, a half-size header space, a normal mark. |
|---|
| 10 | * When IRLib receives one of these special repeat sequences, it returns the |
|---|
| 11 | * value REPEAT_CODE which is defined in IRLibProtocols.h as the value 0xffffffff. If you |
|---|
| 12 | * send REPEAT_CODE, the send routine will create a special sequence for you. |
|---|
| 13 | * NOTE that the timing for this special did sequence is nearly identical to a ditto |
|---|
| 14 | * used by the G.I.Cable protocol and IRLib generally not distinguish between the two. |
|---|
| 15 | * The header timing for G.I. Cable ditto is 8820,1960 and for NEC is 9024,2256 |
|---|
| 16 | * If you are using both protocols and you receive an NEC ditto immediately after |
|---|
| 17 | * receiving a G.I.Cable then you should presume it is a G.I.Cable and vice versa. |
|---|
| 18 | * Whether it is a normal code or a repeat code the entire frame has a 108ms extent. |
|---|
| 19 | * The IRP notation for these protocols are: |
|---|
| 20 | * NEC1: {38k,564}<1,-1|1,-3>(16,-8,D:8,S:8,F:8,~F:8,1,^108,(16,-4,1,^108)*) |
|---|
| 21 | * NEC2: {38k,564}<1,-1|1,-3>(16,-8,D:8,S:8,F:8,~F:8,1,^108)+ |
|---|
| 22 | * Other protocols use the same timing and 32 bits of data but they interpret the data fields |
|---|
| 23 | * differently. These include Apple and TiVo. Also Pioneer protocol is identical to NEC2 |
|---|
| 24 | * however uses 40k rather than 38k modulation. Pioneer sometimes requires a 2 frame |
|---|
| 25 | * sequence of different data for a single pushbutton function. The optional 2nd |
|---|
| 26 | * parameter to the "send" method allows you to change the frequency from the default 38. |
|---|
| 27 | */ |
|---|
| 28 | |
|---|
| 29 | #ifndef IRLIB_PROTOCOL_01_H |
|---|
| 30 | #define IRLIB_PROTOCOL_01_H |
|---|
| 31 | #define IR_SEND_PROTOCOL_01 case 1: if(data2==0)data2=38;IRsendNEC::send(data,data2); break; |
|---|
| 32 | #define IR_DECODE_PROTOCOL_01 if(IRdecodeNEC::decode()) return true; |
|---|
| 33 | #ifdef IRLIB_HAVE_COMBO |
|---|
| 34 | #define PV_IR_DECODE_PROTOCOL_01 ,public virtual IRdecodeNEC |
|---|
| 35 | #define PV_IR_SEND_PROTOCOL_01 ,public virtual IRsendNEC |
|---|
| 36 | #else |
|---|
| 37 | #define PV_IR_DECODE_PROTOCOL_01 public virtual IRdecodeNEC |
|---|
| 38 | #define PV_IR_SEND_PROTOCOL_01 public virtual IRsendNEC |
|---|
| 39 | #endif |
|---|
| 40 | #ifdef IRLIBSENDBASE_H |
|---|
| 41 | |
|---|
| 42 | class IRsendNEC: public virtual IRsendBase { |
|---|
| 43 | public: |
|---|
| 44 | void send(uint32_t data, uint8_t kHz=38) { |
|---|
| 45 | if (data==REPEAT_CODE) { |
|---|
| 46 | enableIROut(kHz); |
|---|
| 47 | mark (564* 16); space(564*4); mark(564);space(572);delay(97);//actually 97572us |
|---|
| 48 | } else { |
|---|
| 49 | sendGeneric(data,32, 564*16, 564*8, 564, 564, 564*3, 564, kHz, true,108000); |
|---|
| 50 | } |
|---|
| 51 | }; |
|---|
| 52 | }; |
|---|
| 53 | #endif //IRLIBSENDBASE_H |
|---|
| 54 | |
|---|
| 55 | #ifdef IRLIBDECODEBASE_H |
|---|
| 56 | class IRdecodeNEC: public virtual IRdecodeBase { |
|---|
| 57 | public: |
|---|
| 58 | bool decode(void) { |
|---|
| 59 | resetDecoder();//This used to be in the receiver getResults. |
|---|
| 60 | IRLIB_ATTEMPT_MESSAGE(F("NEC repeat")); |
|---|
| 61 | // Check for repeat |
|---|
| 62 | if (recvGlobal.decodeLength == 4 && MATCH(recvGlobal.decodeBuffer[1],564*16) && MATCH(recvGlobal.decodeBuffer[2],564*4) |
|---|
| 63 | && MATCH(recvGlobal.decodeBuffer[3],564)) { |
|---|
| 64 | bits = 0; |
|---|
| 65 | value = REPEAT_CODE; |
|---|
| 66 | protocolNum = NEC; |
|---|
| 67 | return true; |
|---|
| 68 | } |
|---|
| 69 | IRLIB_ATTEMPT_MESSAGE(F("NEC")); |
|---|
| 70 | if(!decodeGeneric(68, 564*16, 564*8, 564, 564*3, 564)) return false; |
|---|
| 71 | protocolNum = NEC; |
|---|
| 72 | return true; |
|---|
| 73 | } |
|---|
| 74 | }; |
|---|
| 75 | |
|---|
| 76 | #endif //IRLIBDECODEBASE_H |
|---|
| 77 | |
|---|
| 78 | #define IRLIB_HAVE_COMBO |
|---|
| 79 | |
|---|
| 80 | #endif //IRLIB_PROTOCOL_01_H |
|---|