| 1 | /* IRLib_P02_Sony.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 | * Sony is backwards from most protocols. It uses a variable length mark and a fixed length |
|---|
| 7 | * space rather than a fixed mark and a variable space. Our generic send will still work |
|---|
| 8 | * however we need a custom decoding routine because it's difficult to get the generic |
|---|
| 9 | * decoder to handle a variable length mark without cluttering up the code to much. |
|---|
| 10 | * According to the protocol you must send Sony commands at least three times so we |
|---|
| 11 | * automatically do it here. Sony can be 8, 12, 15, or 20 bits in length. |
|---|
| 12 | * The 8 bit version uses a shorter trailing space at the end. The signal is modulated |
|---|
| 13 | * at 40 kHz however most 38 kHz receivers are broad enough to receive it. |
|---|
| 14 | */ |
|---|
| 15 | |
|---|
| 16 | #ifndef IRLIB_PROTOCOL_02_H |
|---|
| 17 | #define IRLIB_PROTOCOL_02_H |
|---|
| 18 | #define IR_SEND_PROTOCOL_02 case 2: IRsendSony::send(data,data2); break; |
|---|
| 19 | #define IR_DECODE_PROTOCOL_02 if(IRdecodeSony::decode()) return true; |
|---|
| 20 | #ifdef IRLIB_HAVE_COMBO |
|---|
| 21 | #define PV_IR_DECODE_PROTOCOL_02 ,public virtual IRdecodeSony |
|---|
| 22 | #define PV_IR_SEND_PROTOCOL_02 ,public virtual IRsendSony |
|---|
| 23 | #else |
|---|
| 24 | #define PV_IR_DECODE_PROTOCOL_02 public virtual IRdecodeSony |
|---|
| 25 | #define PV_IR_SEND_PROTOCOL_02 public virtual IRsendSony |
|---|
| 26 | #endif |
|---|
| 27 | |
|---|
| 28 | #ifdef IRLIBSENDBASE_H |
|---|
| 29 | class IRsendSony: public virtual IRsendBase { |
|---|
| 30 | public: |
|---|
| 31 | void send(uint32_t data, uint8_t nbits) { |
|---|
| 32 | for(uint8_t i=0; i<3;i++){ |
|---|
| 33 | sendGeneric(data,nbits, 600*4, 600, 600*2, 600, 600, 600, 40, false,45000); |
|---|
| 34 | } |
|---|
| 35 | } |
|---|
| 36 | }; |
|---|
| 37 | #endif //IRLIBSENDBASE_H |
|---|
| 38 | |
|---|
| 39 | #ifdef IRLIBDECODEBASE_H |
|---|
| 40 | class IRdecodeSony: public virtual IRdecodeBase { |
|---|
| 41 | public: |
|---|
| 42 | virtual bool decode(void) { |
|---|
| 43 | IRLIB_ATTEMPT_MESSAGE(F("Sony")); |
|---|
| 44 | resetDecoder();//This used to be in the receiver getResults. |
|---|
| 45 | if(recvGlobal.decodeLength!=2*8+2 && recvGlobal.decodeLength!=2*12+2 && recvGlobal.decodeLength!=2*15+2 |
|---|
| 46 | && recvGlobal.decodeLength!=2*20+2) return RAW_COUNT_ERROR; |
|---|
| 47 | if(!ignoreHeader) { |
|---|
| 48 | if (!MATCH(recvGlobal.decodeBuffer[1],600*4)) return HEADER_MARK_ERROR(600*4); |
|---|
| 49 | } |
|---|
| 50 | offset=2;//skip initial gap plus header Mark. |
|---|
| 51 | while (offset < recvGlobal.decodeLength) { |
|---|
| 52 | if (!MATCH(recvGlobal.decodeBuffer[offset],600)) return DATA_SPACE_ERROR(600); |
|---|
| 53 | offset++; |
|---|
| 54 | if (MATCH(recvGlobal.decodeBuffer[offset],600*2)) { |
|---|
| 55 | value = (value << 1) | 1; |
|---|
| 56 | } |
|---|
| 57 | else if (MATCH(recvGlobal.decodeBuffer[offset],600)) { |
|---|
| 58 | value <<= 1; |
|---|
| 59 | } |
|---|
| 60 | else return DATA_MARK_ERROR(600); |
|---|
| 61 | offset++; |
|---|
| 62 | } |
|---|
| 63 | bits = (offset - 1) / 2; |
|---|
| 64 | protocolNum = SONY; |
|---|
| 65 | return true; |
|---|
| 66 | } |
|---|
| 67 | }; |
|---|
| 68 | #endif //IRLIBDECODEBASE_H |
|---|
| 69 | |
|---|
| 70 | #define IRLIB_HAVE_COMBO |
|---|
| 71 | |
|---|
| 72 | #endif //IRLIB_PROTOCOL_02_H |
|---|