|
| 1 | +// Copyright 2020 David Conran |
| 2 | + |
| 3 | +// Send & decode support for Symphony added by David Conran |
| 4 | + |
| 5 | +// Supports: |
| 6 | +// Brand: Symphony, Model: Air Cooler 3Di |
| 7 | + |
| 8 | +#include <algorithm> |
| 9 | +#include "IRrecv.h" |
| 10 | +#include "IRsend.h" |
| 11 | +#include "IRtimer.h" |
| 12 | +#include "IRutils.h" |
| 13 | + |
| 14 | +// Constants |
| 15 | +// Ref: |
| 16 | +// https://github.com/crankyoldgit/IRremoteESP8266/issues/1057 |
| 17 | +const uint16_t kSymphonyZeroMark = 1250; |
| 18 | +const uint16_t kSymphonyZeroSpace = 400; |
| 19 | +const uint16_t kSymphonyOneMark = kSymphonyZeroSpace; |
| 20 | +const uint16_t kSymphonyOneSpace = kSymphonyZeroMark; |
| 21 | +const uint16_t kSymphonyFooterMark = kSymphonyOneMark; |
| 22 | +const uint32_t kSymphonyFooterGap = 8000; |
| 23 | + |
| 24 | +#if SEND_SYMPHONY |
| 25 | +// Send a Symphony packet. |
| 26 | +// |
| 27 | +// Args: |
| 28 | +// data: The data we want to send. MSB first. |
| 29 | +// nbits: The number of bits of data to send. (Typically 12, 24, or 32[Nokia]) |
| 30 | +// repeat: The nr. of times the message should be sent. |
| 31 | +// |
| 32 | +// Status: BETA / Should be working. |
| 33 | +// |
| 34 | +// Ref: |
| 35 | +// https://github.com/crankyoldgit/IRremoteESP8266/issues/1057 |
| 36 | +void IRsend::sendSymphony(uint64_t data, uint16_t nbits, uint16_t repeat) { |
| 37 | + sendGeneric(0, 0, |
| 38 | + kSymphonyOneMark, kSymphonyOneSpace, |
| 39 | + kSymphonyZeroMark, kSymphonyZeroSpace, |
| 40 | + kSymphonyFooterMark, kSymphonyFooterGap, |
| 41 | + data, nbits, 38000, true, repeat, kDutyDefault); |
| 42 | +} |
| 43 | +#endif // SEND_SYMPHONY |
| 44 | + |
| 45 | +#if DECODE_SYMPHONY |
| 46 | +// Decode a Symphony packet if possible. |
| 47 | +// Places successful decode information in the results pointer. |
| 48 | +// Args: |
| 49 | +// results: Ptr to the data to decode and where to store the decode result. |
| 50 | +// offset: The starting index to use when attempting to decode the raw data. |
| 51 | +// Typically/Defaults to kStartOffset. |
| 52 | +// nbits: Nr. of bits to expect in the data portion. Typically kSymphonyBits |
| 53 | +// strict: Flag to indicate if we strictly adhere to the specification. |
| 54 | +// Returns: |
| 55 | +// boolean: True if it can decode it, false if it can't. |
| 56 | +// |
| 57 | +// Status: BETA / Should be working. |
| 58 | +// |
| 59 | +// Ref: |
| 60 | +// |
| 61 | +bool IRrecv::decodeSymphony(decode_results *results, uint16_t offset, |
| 62 | + const uint16_t nbits, const bool strict) { |
| 63 | + uint64_t data = 0; |
| 64 | + |
| 65 | + if (results->rawlen < 2 * nbits + kFooter + offset - 1) |
| 66 | + return false; // Not enough entries to ever be SYMPHONY. |
| 67 | + // Compliance |
| 68 | + if (strict && nbits != kSymphonyBits) return false; |
| 69 | + |
| 70 | + if (!matchGeneric(results->rawbuf + offset, &data, results->rawlen - offset, |
| 71 | + nbits, |
| 72 | + 0, 0, // No Header |
| 73 | + kSymphonyOneMark, kSymphonyOneSpace, |
| 74 | + kSymphonyZeroMark, kSymphonyZeroSpace, |
| 75 | + kSymphonyFooterMark, kSymphonyFooterGap, true, |
| 76 | + _tolerance, 0)) |
| 77 | + return false; |
| 78 | + |
| 79 | + // Success |
| 80 | + results->value = data; |
| 81 | + results->decode_type = decode_type_t::SYMPHONY; |
| 82 | + results->bits = nbits; |
| 83 | + results->address = 0; |
| 84 | + results->command = 0; |
| 85 | + return true; |
| 86 | +} |
| 87 | +#endif // DECODE_SYMPHONY |
0 commit comments