BrickUp API Service for Docker version.

ir_Sony.cpp 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include "IRremote.h"
  2. #include "IRremoteInt.h"
  3. //==============================================================================
  4. // SSSS OOO N N Y Y
  5. // S O O NN N Y Y
  6. // SSS O O N N N Y
  7. // S O O N NN Y
  8. // SSSS OOO N N Y
  9. //==============================================================================
  10. #define SONY_BITS 12
  11. #define SONY_HDR_MARK 2400
  12. #define SONY_HDR_SPACE 600
  13. #define SONY_ONE_MARK 1200
  14. #define SONY_ZERO_MARK 600
  15. #define SONY_RPT_LENGTH 45000
  16. #define SONY_DOUBLE_SPACE_USECS 500 // usually ssee 713 - not using ticks as get number wrapround
  17. //+=============================================================================
  18. #if SEND_SONY
  19. void IRsend::sendSony (unsigned long data, int nbits)
  20. {
  21. // Set IR carrier frequency
  22. enableIROut(40);
  23. // Header
  24. mark(SONY_HDR_MARK);
  25. space(SONY_HDR_SPACE);
  26. // Data
  27. for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) {
  28. if (data & mask) {
  29. mark(SONY_ONE_MARK);
  30. space(SONY_HDR_SPACE);
  31. } else {
  32. mark(SONY_ZERO_MARK);
  33. space(SONY_HDR_SPACE);
  34. }
  35. }
  36. // We will have ended with LED off
  37. }
  38. #endif
  39. //+=============================================================================
  40. #if DECODE_SONY
  41. bool IRrecv::decodeSony (decode_results *results)
  42. {
  43. long data = 0;
  44. int offset = 0; // Dont skip first space, check its size
  45. if (irparams.rawlen < (2 * SONY_BITS) + 2) return false ;
  46. // Some Sony's deliver repeats fast after first
  47. // unfortunately can't spot difference from of repeat from two fast clicks
  48. if (results->rawbuf[offset] < SONY_DOUBLE_SPACE_USECS) {
  49. // Serial.print("IR Gap found: ");
  50. results->bits = 0;
  51. results->value = REPEAT;
  52. # ifdef DECODE_SANYO
  53. results->decode_type = SANYO;
  54. # else
  55. results->decode_type = UNKNOWN;
  56. # endif
  57. return true;
  58. }
  59. offset++;
  60. // Initial mark
  61. if (!MATCH_MARK(results->rawbuf[offset++], SONY_HDR_MARK)) return false ;
  62. while (offset + 1 < irparams.rawlen) {
  63. if (!MATCH_SPACE(results->rawbuf[offset++], SONY_HDR_SPACE)) break ;
  64. if (MATCH_MARK(results->rawbuf[offset], SONY_ONE_MARK)) data = (data << 1) | 1 ;
  65. else if (MATCH_MARK(results->rawbuf[offset], SONY_ZERO_MARK)) data = (data << 1) | 0 ;
  66. else return false ;
  67. offset++;
  68. }
  69. // Success
  70. results->bits = (offset - 1) / 2;
  71. if (results->bits < 12) {
  72. results->bits = 0;
  73. return false;
  74. }
  75. results->value = data;
  76. results->decode_type = SONY;
  77. return true;
  78. }
  79. #endif