Infrared remote library for Arduino: send and receive infrared signals with multiple protocols Port from Arduino-IRremote https://github.com/z3t0/Arduino-IRremote
ir_Aiwa.cpp@8:0650578366fd, 2019-06-16 (annotated)
- Committer:
- eunmango
- Date:
- Sun Jun 16 04:36:58 2019 +0000
- Revision:
- 8:0650578366fd
- Parent:
- 0:70c8e56bac45
dd
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 | // AAA IIIII W W AAA |
yuhki50 | 0:70c8e56bac45 | 6 | // A A I W W A A |
yuhki50 | 0:70c8e56bac45 | 7 | // AAAAA I W W W AAAAA |
yuhki50 | 0:70c8e56bac45 | 8 | // A A I W W W A A |
yuhki50 | 0:70c8e56bac45 | 9 | // A A IIIII WWW A A |
yuhki50 | 0:70c8e56bac45 | 10 | //============================================================================== |
yuhki50 | 0:70c8e56bac45 | 11 | |
yuhki50 | 0:70c8e56bac45 | 12 | // Based off the RC-T501 RCU |
yuhki50 | 0:70c8e56bac45 | 13 | // Lirc file http://lirc.sourceforge.net/remotes/aiwa/RC-T501 |
yuhki50 | 0:70c8e56bac45 | 14 | |
yuhki50 | 0:70c8e56bac45 | 15 | #define AIWA_RC_T501_HZ 38 |
yuhki50 | 0:70c8e56bac45 | 16 | #define AIWA_RC_T501_BITS 15 |
yuhki50 | 0:70c8e56bac45 | 17 | #define AIWA_RC_T501_PRE_BITS 26 |
yuhki50 | 0:70c8e56bac45 | 18 | #define AIWA_RC_T501_POST_BITS 1 |
yuhki50 | 0:70c8e56bac45 | 19 | #define AIWA_RC_T501_SUM_BITS (AIWA_RC_T501_PRE_BITS + AIWA_RC_T501_BITS + AIWA_RC_T501_POST_BITS) |
yuhki50 | 0:70c8e56bac45 | 20 | #define AIWA_RC_T501_HDR_MARK 8800 |
yuhki50 | 0:70c8e56bac45 | 21 | #define AIWA_RC_T501_HDR_SPACE 4500 |
yuhki50 | 0:70c8e56bac45 | 22 | #define AIWA_RC_T501_BIT_MARK 500 |
yuhki50 | 0:70c8e56bac45 | 23 | #define AIWA_RC_T501_ONE_SPACE 600 |
yuhki50 | 0:70c8e56bac45 | 24 | #define AIWA_RC_T501_ZERO_SPACE 1700 |
yuhki50 | 0:70c8e56bac45 | 25 | |
yuhki50 | 0:70c8e56bac45 | 26 | //+============================================================================= |
yuhki50 | 0:70c8e56bac45 | 27 | #if SEND_AIWA_RC_T501 |
yuhki50 | 0:70c8e56bac45 | 28 | void IRsend::sendAiwaRCT501 (int code) |
yuhki50 | 0:70c8e56bac45 | 29 | { |
yuhki50 | 0:70c8e56bac45 | 30 | unsigned long pre = 0x0227EEC0; // 26-bits |
yuhki50 | 0:70c8e56bac45 | 31 | |
yuhki50 | 0:70c8e56bac45 | 32 | // Set IR carrier frequency |
yuhki50 | 0:70c8e56bac45 | 33 | enableIROut(AIWA_RC_T501_HZ); |
yuhki50 | 0:70c8e56bac45 | 34 | |
yuhki50 | 0:70c8e56bac45 | 35 | // Header |
yuhki50 | 0:70c8e56bac45 | 36 | mark(AIWA_RC_T501_HDR_MARK); |
yuhki50 | 0:70c8e56bac45 | 37 | space(AIWA_RC_T501_HDR_SPACE); |
yuhki50 | 0:70c8e56bac45 | 38 | |
yuhki50 | 0:70c8e56bac45 | 39 | // Send "pre" data |
yuhki50 | 0:70c8e56bac45 | 40 | for (unsigned long mask = 1UL << (26 - 1); mask; mask >>= 1) { |
yuhki50 | 0:70c8e56bac45 | 41 | mark(AIWA_RC_T501_BIT_MARK); |
yuhki50 | 0:70c8e56bac45 | 42 | if (pre & mask) space(AIWA_RC_T501_ONE_SPACE) ; |
yuhki50 | 0:70c8e56bac45 | 43 | else space(AIWA_RC_T501_ZERO_SPACE) ; |
yuhki50 | 0:70c8e56bac45 | 44 | } |
yuhki50 | 0:70c8e56bac45 | 45 | |
yuhki50 | 0:70c8e56bac45 | 46 | //-v- THIS CODE LOOKS LIKE IT MIGHT BE WRONG - CHECK! |
yuhki50 | 0:70c8e56bac45 | 47 | // it only send 15bits and ignores the top bit |
yuhki50 | 0:70c8e56bac45 | 48 | // then uses TOPBIT which is 0x80000000 to check the bit code |
yuhki50 | 0:70c8e56bac45 | 49 | // I suspect TOPBIT should be changed to 0x00008000 |
yuhki50 | 0:70c8e56bac45 | 50 | |
yuhki50 | 0:70c8e56bac45 | 51 | // Skip first code bit |
yuhki50 | 0:70c8e56bac45 | 52 | code <<= 1; |
yuhki50 | 0:70c8e56bac45 | 53 | // Send code |
yuhki50 | 0:70c8e56bac45 | 54 | for (int i = 0; i < 15; i++) { |
yuhki50 | 0:70c8e56bac45 | 55 | mark(AIWA_RC_T501_BIT_MARK); |
yuhki50 | 0:70c8e56bac45 | 56 | if (code & 0x80000000) space(AIWA_RC_T501_ONE_SPACE) ; |
yuhki50 | 0:70c8e56bac45 | 57 | else space(AIWA_RC_T501_ZERO_SPACE) ; |
yuhki50 | 0:70c8e56bac45 | 58 | code <<= 1; |
yuhki50 | 0:70c8e56bac45 | 59 | } |
yuhki50 | 0:70c8e56bac45 | 60 | |
yuhki50 | 0:70c8e56bac45 | 61 | //-^- THIS CODE LOOKS LIKE IT MIGHT BE WRONG - CHECK! |
yuhki50 | 0:70c8e56bac45 | 62 | |
yuhki50 | 0:70c8e56bac45 | 63 | // POST-DATA, 1 bit, 0x0 |
yuhki50 | 0:70c8e56bac45 | 64 | mark(AIWA_RC_T501_BIT_MARK); |
yuhki50 | 0:70c8e56bac45 | 65 | space(AIWA_RC_T501_ZERO_SPACE); |
yuhki50 | 0:70c8e56bac45 | 66 | |
yuhki50 | 0:70c8e56bac45 | 67 | mark(AIWA_RC_T501_BIT_MARK); |
yuhki50 | 0:70c8e56bac45 | 68 | space(0); |
yuhki50 | 0:70c8e56bac45 | 69 | } |
yuhki50 | 0:70c8e56bac45 | 70 | #endif |
yuhki50 | 0:70c8e56bac45 | 71 | |
yuhki50 | 0:70c8e56bac45 | 72 | //+============================================================================= |
yuhki50 | 0:70c8e56bac45 | 73 | #if DECODE_AIWA_RC_T501 |
yuhki50 | 0:70c8e56bac45 | 74 | bool IRrecv::decodeAiwaRCT501 (decode_results *results) |
yuhki50 | 0:70c8e56bac45 | 75 | { |
yuhki50 | 0:70c8e56bac45 | 76 | int data = 0; |
yuhki50 | 0:70c8e56bac45 | 77 | int offset = 1; |
yuhki50 | 0:70c8e56bac45 | 78 | |
yuhki50 | 0:70c8e56bac45 | 79 | // Check SIZE |
yuhki50 | 0:70c8e56bac45 | 80 | if (irparams.rawlen < 2 * (AIWA_RC_T501_SUM_BITS) + 4) return false ; |
yuhki50 | 0:70c8e56bac45 | 81 | |
yuhki50 | 0:70c8e56bac45 | 82 | // Check HDR Mark/Space |
yuhki50 | 0:70c8e56bac45 | 83 | if (!MATCH_MARK (results->rawbuf[offset++], AIWA_RC_T501_HDR_MARK )) return false ; |
yuhki50 | 0:70c8e56bac45 | 84 | if (!MATCH_SPACE(results->rawbuf[offset++], AIWA_RC_T501_HDR_SPACE)) return false ; |
yuhki50 | 0:70c8e56bac45 | 85 | |
yuhki50 | 0:70c8e56bac45 | 86 | offset += 26; // skip pre-data - optional |
yuhki50 | 0:70c8e56bac45 | 87 | while(offset < irparams.rawlen - 4) { |
yuhki50 | 0:70c8e56bac45 | 88 | if (MATCH_MARK(results->rawbuf[offset], AIWA_RC_T501_BIT_MARK)) offset++ ; |
yuhki50 | 0:70c8e56bac45 | 89 | else return false ; |
yuhki50 | 0:70c8e56bac45 | 90 | |
yuhki50 | 0:70c8e56bac45 | 91 | // ONE & ZERO |
yuhki50 | 0:70c8e56bac45 | 92 | if (MATCH_SPACE(results->rawbuf[offset], AIWA_RC_T501_ONE_SPACE)) data = (data << 1) | 1 ; |
yuhki50 | 0:70c8e56bac45 | 93 | else if (MATCH_SPACE(results->rawbuf[offset], AIWA_RC_T501_ZERO_SPACE)) data = (data << 1) | 0 ; |
yuhki50 | 0:70c8e56bac45 | 94 | else break ; // End of one & zero detected |
yuhki50 | 0:70c8e56bac45 | 95 | offset++; |
yuhki50 | 0:70c8e56bac45 | 96 | } |
yuhki50 | 0:70c8e56bac45 | 97 | |
yuhki50 | 0:70c8e56bac45 | 98 | results->bits = (offset - 1) / 2; |
yuhki50 | 0:70c8e56bac45 | 99 | if (results->bits < 42) return false ; |
yuhki50 | 0:70c8e56bac45 | 100 | |
yuhki50 | 0:70c8e56bac45 | 101 | results->value = data; |
yuhki50 | 0:70c8e56bac45 | 102 | results->decode_type = AIWA_RC_T501; |
yuhki50 | 0:70c8e56bac45 | 103 | return true; |
yuhki50 | 0:70c8e56bac45 | 104 | } |
yuhki50 | 0:70c8e56bac45 | 105 | #endif |