| 1 | /* IRLib_P08_Samsung36.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 | /* |
|---|
| 7 | * This 36 bit protocol is used by some Samsung devices such as Blu-ray players. |
|---|
| 8 | * It consists of a 16 bit address and 20 bits of data with strange timing in between. |
|---|
| 9 | */ |
|---|
| 10 | /* The IRP notation for this protocol is: |
|---|
| 11 | * {38k,500}<1,-1|1,-3>(9,-9,D:8,S:8,1,-9,E:4,F:8,-68u,~F:8,1,-118)+ |
|---|
| 12 | * This means it uses 38k frequency. Base timing is multiples of 500. |
|---|
| 13 | * A "0" is mark(500) space(500). A "1" is mark (500) space(500*3) |
|---|
| 14 | * The header is mark(500*9) space(500*9). |
|---|
| 15 | * The header is followed by 16 bit address (8 device, 8 sub device) |
|---|
| 16 | * This is followed by a mark(500) space(500*9). |
|---|
| 17 | * This is followed by 12 more bits (4+8) |
|---|
| 18 | * This is followed by 68us of space. Actually this means that the space |
|---|
| 19 | * of the last bit of that segment is simply 68us longer than normal. |
|---|
| 20 | * This is followed by 8 more bits and a final stop bit. |
|---|
| 21 | */ |
|---|
| 22 | #ifndef IRLIB_PROTOCOL_08_H |
|---|
| 23 | #define IRLIB_PROTOCOL_08_H |
|---|
| 24 | #define IR_SEND_PROTOCOL_08 case 8: IRsendSamsung36::send(data,data2); break; |
|---|
| 25 | #define IR_DECODE_PROTOCOL_08 if(IRdecodeSamsung36::decode()) return true; |
|---|
| 26 | #ifdef IRLIB_HAVE_COMBO |
|---|
| 27 | #define PV_IR_DECODE_PROTOCOL_08 ,public virtual IRdecodeSamsung36 |
|---|
| 28 | #define PV_IR_SEND_PROTOCOL_08 ,public virtual IRsendSamsung36 |
|---|
| 29 | #else |
|---|
| 30 | #define PV_IR_DECODE_PROTOCOL_08 public virtual IRdecodeSamsung36 |
|---|
| 31 | #define PV_IR_SEND_PROTOCOL_08 public virtual IRsendSamsung36 |
|---|
| 32 | #endif |
|---|
| 33 | |
|---|
| 34 | #ifdef IRLIBSENDBASE_H |
|---|
| 35 | class IRsendSamsung36: public virtual IRsendBase { |
|---|
| 36 | public: |
|---|
| 37 | void send(uint32_t data, uint32_t address) { |
|---|
| 38 | data <<= 32-20; |
|---|
| 39 | address <<= 32-16; |
|---|
| 40 | enableIROut(38); |
|---|
| 41 | mark(500*9); space(500*9); //Send header |
|---|
| 42 | putBits (address, 16); //Send address 16 bits |
|---|
| 43 | mark (500); space (500*9); //Send break |
|---|
| 44 | putBits (data, 12); //Send 12 bits |
|---|
| 45 | space(68); //Send tiny break |
|---|
| 46 | data <<= 12; |
|---|
| 47 | putBits (data, 8);mark(500); //Final eight bits and one stop bit |
|---|
| 48 | space(118*500); //Lead out is 118 times the base time 500 |
|---|
| 49 | }; |
|---|
| 50 | private: |
|---|
| 51 | /* Because not all of the data bits are contiguous in the stream, |
|---|
| 52 | * we created this little routine to be called multiple times to send a |
|---|
| 53 | * segment of the data. |
|---|
| 54 | */ |
|---|
| 55 | void putBits (uint32_t data, uint8_t nbits) { |
|---|
| 56 | for (uint8_t i = 0; i < nbits; i++) { |
|---|
| 57 | if (data & TOPBIT) { |
|---|
| 58 | mark(500); space(500*3); |
|---|
| 59 | } else { |
|---|
| 60 | mark(500); space(500); |
|---|
| 61 | }; |
|---|
| 62 | data <<= 1; |
|---|
| 63 | } |
|---|
| 64 | } |
|---|
| 65 | }; |
|---|
| 66 | |
|---|
| 67 | #endif //IRLIBSENDBASE_H |
|---|
| 68 | |
|---|
| 69 | #ifdef IRLIBDECODEBASE_H |
|---|
| 70 | class IRdecodeSamsung36: public virtual IRdecodeBase { |
|---|
| 71 | public: |
|---|
| 72 | bool decode(void) { |
|---|
| 73 | IRLIB_ATTEMPT_MESSAGE(F("Samsung36")); |
|---|
| 74 | if (recvGlobal.decodeLength != 78) return RAW_COUNT_ERROR; |
|---|
| 75 | if (!MATCH(recvGlobal.decodeBuffer[1],500*9)) return HEADER_MARK_ERROR(500*9); |
|---|
| 76 | if (!MATCH(recvGlobal.decodeBuffer[2],500*9)) return HEADER_SPACE_ERROR(500*9); |
|---|
| 77 | offset=3; data=0; |
|---|
| 78 | //Get first 16 bits |
|---|
| 79 | if(!getBits(16*2+2))return false; |
|---|
| 80 | //Skip middle header |
|---|
| 81 | if (!MATCH(recvGlobal.decodeBuffer[offset],500)) return DATA_MARK_ERROR(500); |
|---|
| 82 | offset++; |
|---|
| 83 | if (!MATCH(recvGlobal.decodeBuffer[offset],500*9)) return DATA_SPACE_ERROR(4400); |
|---|
| 84 | //save first 16 bits in "address" and reset data |
|---|
| 85 | offset++; address=data; data=0; |
|---|
| 86 | //12 bits into this second segment, the space is extended by 68us. |
|---|
| 87 | // so we adjust the value to its normal length without the extra 68us. |
|---|
| 88 | recvGlobal.decodeBuffer[62]-=68; |
|---|
| 89 | //Now get the remaining 20 bits |
|---|
| 90 | if(!getBits(77))return false; |
|---|
| 91 | bits =36; //set bit length |
|---|
| 92 | value = data; //put remaining 20 bits in value |
|---|
| 93 | protocolNum= SAMSUNG36; |
|---|
| 94 | return true; |
|---|
| 95 | }; |
|---|
| 96 | private: |
|---|
| 97 | /* Because not all of the data bits are contiguous in the stream |
|---|
| 98 | * we created this little routine to be called multiple times |
|---|
| 99 | * to decode a segment of the data. Parameter "last_offset" is when we |
|---|
| 100 | * stop decoding the segment. |
|---|
| 101 | */ |
|---|
| 102 | bool getBits(uint8_t last_offset) { |
|---|
| 103 | while (offset < last_offset) { |
|---|
| 104 | if (!MATCH(recvGlobal.decodeBuffer[offset],500)) return DATA_MARK_ERROR(500); |
|---|
| 105 | offset++; |
|---|
| 106 | if (MATCH(recvGlobal.decodeBuffer[offset],500*3)) |
|---|
| 107 | data = (data << 1) | 1; |
|---|
| 108 | else if (MATCH(recvGlobal.decodeBuffer[offset],500)) |
|---|
| 109 | data <<= 1; |
|---|
| 110 | else return DATA_SPACE_ERROR(500*3); |
|---|
| 111 | offset++; |
|---|
| 112 | }; |
|---|
| 113 | return true; |
|---|
| 114 | }; |
|---|
| 115 | uint8_t offset; |
|---|
| 116 | uint32_t data; |
|---|
| 117 | }; |
|---|
| 118 | #endif //IRLIBDECODEBASE_H |
|---|
| 119 | |
|---|
| 120 | #define IRLIB_HAVE_COMBO |
|---|
| 121 | |
|---|
| 122 | #endif //IRLIB_PROTOCOL_08_H |
|---|