|
| 1 | +// Copyright 2024 Harsh Bhosale (harshbhosale01) |
| 2 | +/// @file |
| 3 | +/// @brief Support for BluestarHeavy protocol |
| 4 | + |
| 5 | +// Supports: |
| 6 | +// Brand: Bluestar, Model: D716LXM0535A2400313 (Remote) |
| 7 | + |
| 8 | +#include "IRrecv.h" |
| 9 | +#include "IRsend.h" |
| 10 | +#include "IRutils.h" |
| 11 | + |
| 12 | +const uint16_t kBluestarHeavyHdrMark = 4912; |
| 13 | +const uint16_t kBluestarHeavyBitMark = 465; |
| 14 | +const uint16_t kBluestarHeavyHdrSpace = 5058; |
| 15 | +const uint16_t kBluestarHeavyOneSpace = 572; |
| 16 | +const uint16_t kBluestarHeavyZeroSpace = 1548; |
| 17 | +const uint16_t kBluestarHeavyFreq = 38000; |
| 18 | +const uint16_t kBluestarHeavyOverhead = 3; |
| 19 | + |
| 20 | +#if SEND_BLUESTARHEAVY |
| 21 | +/// Send a BluestarHeavy formatted message. |
| 22 | +/// Status: BETA / Tested. |
| 23 | +/// @param[in] data An array of bytes containing the IR command. |
| 24 | +/// It is assumed to be in MSB order for this code. |
| 25 | +/// e.g. |
| 26 | +/// @code |
| 27 | +/// uint8_t data[kBluestarHeavyStateLength] = |
| 28 | +/// {0x2A,0x00,0x20,0xD0,0x05,0xA0,0x05,0xA0,0x00,0x80,0xBA,0x02,0x23}; |
| 29 | +/// @endcode |
| 30 | +/// @param[in] nbytes Nr. of bytes of data in the array. |
| 31 | +/// @param[in] repeat Nr. of times the message is to be repeated. |
| 32 | +void IRsend::sendBluestarHeavy(const uint8_t data[], const uint16_t nbytes, |
| 33 | + const uint16_t repeat) { |
| 34 | + sendGeneric(kBluestarHeavyHdrMark, kBluestarHeavyHdrSpace, |
| 35 | + kBluestarHeavyBitMark, kBluestarHeavyOneSpace, |
| 36 | + kBluestarHeavyBitMark, kBluestarHeavyZeroSpace, |
| 37 | + kBluestarHeavyHdrMark, kDefaultMessageGap, |
| 38 | + data, nbytes, // Bytes |
| 39 | + kBluestarHeavyFreq, true, repeat, kDutyDefault); |
| 40 | +} |
| 41 | +#endif // SEND_BLUESTARHEAVY |
| 42 | + |
| 43 | +#if DECODE_BLUESTARHEAVY |
| 44 | +/// Decode the supplied BluestarHeavy message. |
| 45 | +/// Status: BETA / Tested. |
| 46 | +/// @param[in,out] results Ptr to the data to decode & where to store the decode |
| 47 | +/// @param[in] offset The starting index to use when attempting to decode the |
| 48 | +/// raw data. Typically/Defaults to kStartOffset. |
| 49 | +/// @param[in] nbits The number of data bits to expect. |
| 50 | +/// @param[in] strict Flag indicating if we should perform strict matching. |
| 51 | +/// @return A boolean. True if it can decode it, false if it can't. |
| 52 | +bool IRrecv::decodeBluestarHeavy(decode_results *results, uint16_t offset, |
| 53 | + const uint16_t nbits, const bool strict) { |
| 54 | + if (strict && nbits != kBluestarHeavyBits) |
| 55 | + return false; |
| 56 | + |
| 57 | + uint16_t used = 0; |
| 58 | + |
| 59 | + used = matchGeneric(results->rawbuf + offset, results->state, |
| 60 | + results->rawlen - offset, nbits, |
| 61 | + kBluestarHeavyHdrMark, kBluestarHeavyHdrSpace, |
| 62 | + kBluestarHeavyBitMark, kBluestarHeavyOneSpace, |
| 63 | + kBluestarHeavyBitMark, kBluestarHeavyZeroSpace, |
| 64 | + kBluestarHeavyHdrMark, kDefaultMessageGap, true); |
| 65 | + if (used == 0) return false; // We failed to find any data. |
| 66 | + |
| 67 | + // Success |
| 68 | + results->decode_type = decode_type_t::BLUESTARHEAVY; |
| 69 | + results->bits = nbits; |
| 70 | + return true; |
| 71 | +} |
| 72 | +#endif // DECODE_BLUESTARHEAVY |
0 commit comments