|
5 | 5 | * For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
|
6 | 6 | *
|
7 | 7 | * Modified by Paul Stoffregen <paul@pjrc.com> to support other boards and timers
|
| 8 | + * Modified by Mitra Ardron <mitra@mitra.biz> |
| 9 | + * Added Sanyo and Mitsubishi controllers |
| 10 | + * Modified Sony to spot the repeat codes that some Sony's send |
8 | 11 | *
|
9 | 12 | * Interrupt code based on NECIRrcv by Joe Knapp
|
10 | 13 | * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556
|
@@ -400,6 +403,18 @@ int IRrecv::decode(decode_results *results) {
|
400 | 403 | if (decodeSony(results)) {
|
401 | 404 | return DECODED;
|
402 | 405 | }
|
| 406 | +#ifdef DEBUG |
| 407 | + Serial.println("Attempting Sanyo decode"); |
| 408 | +#endif |
| 409 | + if (decodeSanyo(results)) { |
| 410 | + return DECODED; |
| 411 | + } |
| 412 | +#ifdef DEBUG |
| 413 | + Serial.println("Attempting Mitsubishi decode"); |
| 414 | +#endif |
| 415 | + if (decodeMitsubishi(results)) { |
| 416 | + return DECODED; |
| 417 | + } |
403 | 418 | #ifdef DEBUG
|
404 | 419 | Serial.println("Attempting RC5 decode");
|
405 | 420 | #endif
|
@@ -435,6 +450,7 @@ int IRrecv::decode(decode_results *results) {
|
435 | 450 | return ERR;
|
436 | 451 | }
|
437 | 452 |
|
| 453 | +// NECs have a repeat only 4 items long |
438 | 454 | long IRrecv::decodeNEC(decode_results *results) {
|
439 | 455 | long data = 0;
|
440 | 456 | int offset = 1; // Skip first space
|
@@ -488,7 +504,19 @@ long IRrecv::decodeSony(decode_results *results) {
|
488 | 504 | if (irparams.rawlen < 2 * SONY_BITS + 2) {
|
489 | 505 | return ERR;
|
490 | 506 | }
|
491 |
| - int offset = 1; // Skip first space |
| 507 | + int offset = 0; // Dont skip first space, check its size |
| 508 | + |
| 509 | + // Some Sony's deliver repeats fast after first |
| 510 | + // unfortunately can't spot difference from of repeat from two fast clicks |
| 511 | + if (results->rawbuf[offset] < SONY_DOUBLE_SPACE_USECS) { |
| 512 | + // Serial.print("IR Gap found: "); |
| 513 | + results->bits = 0; |
| 514 | + results->value = REPEAT; |
| 515 | + results->decode_type = SANYO; |
| 516 | + return DECODED; |
| 517 | + } |
| 518 | + offset++; |
| 519 | + |
492 | 520 | // Initial mark
|
493 | 521 | if (!MATCH_MARK(results->rawbuf[offset], SONY_HDR_MARK)) {
|
494 | 522 | return ERR;
|
@@ -523,6 +551,135 @@ long IRrecv::decodeSony(decode_results *results) {
|
523 | 551 | return DECODED;
|
524 | 552 | }
|
525 | 553 |
|
| 554 | +// I think this is a Sanyo decoder - serial = SA 8650B |
| 555 | +// Looks like Sony except for timings, 48 chars of data and time/space different |
| 556 | +long IRrecv::decodeSanyo(decode_results *results) { |
| 557 | + long data = 0; |
| 558 | + if (irparams.rawlen < 2 * SANYO_BITS + 2) { |
| 559 | + return ERR; |
| 560 | + } |
| 561 | + int offset = 0; // Skip first space |
| 562 | + // Initial space |
| 563 | + /* Put this back in for debugging - note can't use #DEBUG as if Debug on we don't see the repeat cos of the delay |
| 564 | + Serial.print("IR Gap: "); |
| 565 | + Serial.println( results->rawbuf[offset]); |
| 566 | + Serial.println( "test against:"); |
| 567 | + Serial.println(results->rawbuf[offset]); |
| 568 | + */ |
| 569 | + if (results->rawbuf[offset] < SANYO_DOUBLE_SPACE_USECS) { |
| 570 | + // Serial.print("IR Gap found: "); |
| 571 | + results->bits = 0; |
| 572 | + results->value = REPEAT; |
| 573 | + results->decode_type = SANYO; |
| 574 | + return DECODED; |
| 575 | + } |
| 576 | + offset++; |
| 577 | + |
| 578 | + // Initial mark |
| 579 | + if (!MATCH_MARK(results->rawbuf[offset], SANYO_HDR_MARK)) { |
| 580 | + return ERR; |
| 581 | + } |
| 582 | + offset++; |
| 583 | + |
| 584 | + // Skip Second Mark |
| 585 | + if (!MATCH_MARK(results->rawbuf[offset], SANYO_HDR_MARK)) { |
| 586 | + return ERR; |
| 587 | + } |
| 588 | + offset++; |
| 589 | + |
| 590 | + while (offset + 1 < irparams.rawlen) { |
| 591 | + if (!MATCH_SPACE(results->rawbuf[offset], SANYO_HDR_SPACE)) { |
| 592 | + break; |
| 593 | + } |
| 594 | + offset++; |
| 595 | + if (MATCH_MARK(results->rawbuf[offset], SANYO_ONE_MARK)) { |
| 596 | + data = (data << 1) | 1; |
| 597 | + } |
| 598 | + else if (MATCH_MARK(results->rawbuf[offset], SANYO_ZERO_MARK)) { |
| 599 | + data <<= 1; |
| 600 | + } |
| 601 | + else { |
| 602 | + return ERR; |
| 603 | + } |
| 604 | + offset++; |
| 605 | + } |
| 606 | + |
| 607 | + // Success |
| 608 | + results->bits = (offset - 1) / 2; |
| 609 | + if (results->bits < 12) { |
| 610 | + results->bits = 0; |
| 611 | + return ERR; |
| 612 | + } |
| 613 | + results->value = data; |
| 614 | + results->decode_type = SANYO; |
| 615 | + return DECODED; |
| 616 | +} |
| 617 | + |
| 618 | +// Looks like Sony except for timings, 48 chars of data and time/space different |
| 619 | +long IRrecv::decodeMitsubishi(decode_results *results) { |
| 620 | + // Serial.print("?!? decoding Mitsubishi:");Serial.print(irparams.rawlen); Serial.print(" want "); Serial.println( 2 * MITSUBISHI_BITS + 2); |
| 621 | + long data = 0; |
| 622 | + if (irparams.rawlen < 2 * MITSUBISHI_BITS + 2) { |
| 623 | + return ERR; |
| 624 | + } |
| 625 | + int offset = 0; // Skip first space |
| 626 | + // Initial space |
| 627 | + /* Put this back in for debugging - note can't use #DEBUG as if Debug on we don't see the repeat cos of the delay |
| 628 | + Serial.print("IR Gap: "); |
| 629 | + Serial.println( results->rawbuf[offset]); |
| 630 | + Serial.println( "test against:"); |
| 631 | + Serial.println(results->rawbuf[offset]); |
| 632 | + */ |
| 633 | + /* Not seeing double keys from Mitsubishi |
| 634 | + if (results->rawbuf[offset] < MITSUBISHI_DOUBLE_SPACE_USECS) { |
| 635 | + // Serial.print("IR Gap found: "); |
| 636 | + results->bits = 0; |
| 637 | + results->value = REPEAT; |
| 638 | + results->decode_type = MITSUBISHI; |
| 639 | + return DECODED; |
| 640 | + } |
| 641 | + */ |
| 642 | + offset++; |
| 643 | + |
| 644 | + // Typical |
| 645 | + // 14200 7 41 7 42 7 42 7 17 7 17 7 18 7 41 7 18 7 17 7 17 7 18 7 41 8 17 7 17 7 18 7 17 7 |
| 646 | + |
| 647 | + // Initial Space |
| 648 | + if (!MATCH_MARK(results->rawbuf[offset], MITSUBISHI_HDR_SPACE)) { |
| 649 | + return ERR; |
| 650 | + } |
| 651 | + offset++; |
| 652 | + while (offset + 1 < irparams.rawlen) { |
| 653 | + if (MATCH_MARK(results->rawbuf[offset], MITSUBISHI_ONE_MARK)) { |
| 654 | + data = (data << 1) | 1; |
| 655 | + } |
| 656 | + else if (MATCH_MARK(results->rawbuf[offset], MITSUBISHI_ZERO_MARK)) { |
| 657 | + data <<= 1; |
| 658 | + } |
| 659 | + else { |
| 660 | + // Serial.println("A"); Serial.println(offset); Serial.println(results->rawbuf[offset]); |
| 661 | + return ERR; |
| 662 | + } |
| 663 | + offset++; |
| 664 | + if (!MATCH_SPACE(results->rawbuf[offset], MITSUBISHI_HDR_SPACE)) { |
| 665 | + // Serial.println("B"); Serial.println(offset); Serial.println(results->rawbuf[offset]); |
| 666 | + break; |
| 667 | + } |
| 668 | + offset++; |
| 669 | + } |
| 670 | + |
| 671 | + // Success |
| 672 | + results->bits = (offset - 1) / 2; |
| 673 | + if (results->bits < MITSUBISHI_BITS) { |
| 674 | + results->bits = 0; |
| 675 | + return ERR; |
| 676 | + } |
| 677 | + results->value = data; |
| 678 | + results->decode_type = MITSUBISHI; |
| 679 | + return DECODED; |
| 680 | +} |
| 681 | + |
| 682 | + |
526 | 683 | // Gets one undecoded level at a time from the raw buffer.
|
527 | 684 | // The RC5/6 decoding is easier if the data is broken into time intervals.
|
528 | 685 | // E.g. if the buffer has MARK for 2 time intervals and SPACE for 1,
|
|
0 commit comments