Infrared remote library for Arduino: send and receive infrared signals with multiple protocols Port from Arduino-IRremote https://github.com/z3t0/Arduino-IRremote
ir_Whynter.cpp@8:629ef37f2853, 2019-09-25 (annotated)
- Committer:
- JRM1986
- Date:
- Wed Sep 25 13:20:19 2019 +0000
- Revision:
- 8:629ef37f2853
- Parent:
- 0:70c8e56bac45
Remote Control Decoded - recieving codes from module;
Who changed what in which revision?
User | Revision | Line number | New 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 | // W W H H Y Y N N TTTTT EEEEE RRRRR |
yuhki50 | 0:70c8e56bac45 | 6 | // W W H H Y Y NN N T E R R |
yuhki50 | 0:70c8e56bac45 | 7 | // W W W HHHHH Y N N N T EEE RRRR |
yuhki50 | 0:70c8e56bac45 | 8 | // W W W H H Y N NN T E R R |
yuhki50 | 0:70c8e56bac45 | 9 | // WWW H H Y N N T EEEEE R R |
yuhki50 | 0:70c8e56bac45 | 10 | //============================================================================== |
yuhki50 | 0:70c8e56bac45 | 11 | |
yuhki50 | 0:70c8e56bac45 | 12 | #define WHYNTER_BITS 32 |
yuhki50 | 0:70c8e56bac45 | 13 | #define WHYNTER_HDR_MARK 2850 |
yuhki50 | 0:70c8e56bac45 | 14 | #define WHYNTER_HDR_SPACE 2850 |
yuhki50 | 0:70c8e56bac45 | 15 | #define WHYNTER_BIT_MARK 750 |
yuhki50 | 0:70c8e56bac45 | 16 | #define WHYNTER_ONE_MARK 750 |
yuhki50 | 0:70c8e56bac45 | 17 | #define WHYNTER_ONE_SPACE 2150 |
yuhki50 | 0:70c8e56bac45 | 18 | #define WHYNTER_ZERO_MARK 750 |
yuhki50 | 0:70c8e56bac45 | 19 | #define WHYNTER_ZERO_SPACE 750 |
yuhki50 | 0:70c8e56bac45 | 20 | |
yuhki50 | 0:70c8e56bac45 | 21 | //+============================================================================= |
yuhki50 | 0:70c8e56bac45 | 22 | #if SEND_WHYNTER |
yuhki50 | 0:70c8e56bac45 | 23 | void IRsend::sendWhynter (unsigned long data, int nbits) |
yuhki50 | 0:70c8e56bac45 | 24 | { |
yuhki50 | 0:70c8e56bac45 | 25 | // Set IR carrier frequency |
yuhki50 | 0:70c8e56bac45 | 26 | enableIROut(38); |
yuhki50 | 0:70c8e56bac45 | 27 | |
yuhki50 | 0:70c8e56bac45 | 28 | // Start |
yuhki50 | 0:70c8e56bac45 | 29 | mark(WHYNTER_ZERO_MARK); |
yuhki50 | 0:70c8e56bac45 | 30 | space(WHYNTER_ZERO_SPACE); |
yuhki50 | 0:70c8e56bac45 | 31 | |
yuhki50 | 0:70c8e56bac45 | 32 | // Header |
yuhki50 | 0:70c8e56bac45 | 33 | mark(WHYNTER_HDR_MARK); |
yuhki50 | 0:70c8e56bac45 | 34 | space(WHYNTER_HDR_SPACE); |
yuhki50 | 0:70c8e56bac45 | 35 | |
yuhki50 | 0:70c8e56bac45 | 36 | // Data |
yuhki50 | 0:70c8e56bac45 | 37 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { |
yuhki50 | 0:70c8e56bac45 | 38 | if (data & mask) { |
yuhki50 | 0:70c8e56bac45 | 39 | mark(WHYNTER_ONE_MARK); |
yuhki50 | 0:70c8e56bac45 | 40 | space(WHYNTER_ONE_SPACE); |
yuhki50 | 0:70c8e56bac45 | 41 | } else { |
yuhki50 | 0:70c8e56bac45 | 42 | mark(WHYNTER_ZERO_MARK); |
yuhki50 | 0:70c8e56bac45 | 43 | space(WHYNTER_ZERO_SPACE); |
yuhki50 | 0:70c8e56bac45 | 44 | } |
yuhki50 | 0:70c8e56bac45 | 45 | } |
yuhki50 | 0:70c8e56bac45 | 46 | |
yuhki50 | 0:70c8e56bac45 | 47 | // Footer |
yuhki50 | 0:70c8e56bac45 | 48 | mark(WHYNTER_ZERO_MARK); |
yuhki50 | 0:70c8e56bac45 | 49 | space(WHYNTER_ZERO_SPACE); // Always end with the LED off |
yuhki50 | 0:70c8e56bac45 | 50 | } |
yuhki50 | 0:70c8e56bac45 | 51 | #endif |
yuhki50 | 0:70c8e56bac45 | 52 | |
yuhki50 | 0:70c8e56bac45 | 53 | //+============================================================================= |
yuhki50 | 0:70c8e56bac45 | 54 | #if DECODE_WHYNTER |
yuhki50 | 0:70c8e56bac45 | 55 | bool IRrecv::decodeWhynter (decode_results *results) |
yuhki50 | 0:70c8e56bac45 | 56 | { |
yuhki50 | 0:70c8e56bac45 | 57 | long data = 0; |
yuhki50 | 0:70c8e56bac45 | 58 | int offset = 1; // skip initial space |
yuhki50 | 0:70c8e56bac45 | 59 | |
yuhki50 | 0:70c8e56bac45 | 60 | // Check we have the right amount of data |
yuhki50 | 0:70c8e56bac45 | 61 | if (irparams.rawlen < (2 * WHYNTER_BITS) + 6) return false ; |
yuhki50 | 0:70c8e56bac45 | 62 | |
yuhki50 | 0:70c8e56bac45 | 63 | // Sequence begins with a bit mark and a zero space |
yuhki50 | 0:70c8e56bac45 | 64 | if (!MATCH_MARK (results->rawbuf[offset++], WHYNTER_BIT_MARK )) return false ; |
yuhki50 | 0:70c8e56bac45 | 65 | if (!MATCH_SPACE(results->rawbuf[offset++], WHYNTER_ZERO_SPACE)) return false ; |
yuhki50 | 0:70c8e56bac45 | 66 | |
yuhki50 | 0:70c8e56bac45 | 67 | // header mark and space |
yuhki50 | 0:70c8e56bac45 | 68 | if (!MATCH_MARK (results->rawbuf[offset++], WHYNTER_HDR_MARK )) return false ; |
yuhki50 | 0:70c8e56bac45 | 69 | if (!MATCH_SPACE(results->rawbuf[offset++], WHYNTER_HDR_SPACE)) return false ; |
yuhki50 | 0:70c8e56bac45 | 70 | |
yuhki50 | 0:70c8e56bac45 | 71 | // data bits |
yuhki50 | 0:70c8e56bac45 | 72 | for (int i = 0; i < WHYNTER_BITS; i++) { |
yuhki50 | 0:70c8e56bac45 | 73 | if (!MATCH_MARK(results->rawbuf[offset++], WHYNTER_BIT_MARK)) return false ; |
yuhki50 | 0:70c8e56bac45 | 74 | |
yuhki50 | 0:70c8e56bac45 | 75 | if (MATCH_SPACE(results->rawbuf[offset], WHYNTER_ONE_SPACE )) data = (data << 1) | 1 ; |
yuhki50 | 0:70c8e56bac45 | 76 | else if (MATCH_SPACE(results->rawbuf[offset], WHYNTER_ZERO_SPACE)) data = (data << 1) | 0 ; |
yuhki50 | 0:70c8e56bac45 | 77 | else return false ; |
yuhki50 | 0:70c8e56bac45 | 78 | offset++; |
yuhki50 | 0:70c8e56bac45 | 79 | } |
yuhki50 | 0:70c8e56bac45 | 80 | |
yuhki50 | 0:70c8e56bac45 | 81 | // trailing mark |
yuhki50 | 0:70c8e56bac45 | 82 | if (!MATCH_MARK(results->rawbuf[offset], WHYNTER_BIT_MARK)) return false ; |
yuhki50 | 0:70c8e56bac45 | 83 | |
yuhki50 | 0:70c8e56bac45 | 84 | // Success |
yuhki50 | 0:70c8e56bac45 | 85 | results->bits = WHYNTER_BITS; |
yuhki50 | 0:70c8e56bac45 | 86 | results->value = data; |
yuhki50 | 0:70c8e56bac45 | 87 | results->decode_type = WHYNTER; |
yuhki50 | 0:70c8e56bac45 | 88 | return true; |
yuhki50 | 0:70c8e56bac45 | 89 | } |
yuhki50 | 0:70c8e56bac45 | 90 | #endif |
yuhki50 | 0:70c8e56bac45 | 91 |