1
+ // Copyright 2020 David Conran (crankyoldgit)
2
+ // / @file
3
+ // / @brief Support for BluestarHeavy protocol
4
+
5
+ // Supports:
6
+ // Brand: Bluestar, Model: TODO add device and remote
7
+
8
+ #include " IRrecv.h"
9
+ #include " IRsend.h"
10
+ #include " IRutils.h"
11
+
12
+ // WARNING: This probably isn't directly usable. It's a guide only.
13
+
14
+ // See https://github.com/crankyoldgit/IRremoteESP8266/wiki/Adding-support-for-a-new-IR-protocol
15
+ // for details of how to include this in the library.
16
+ const uint16_t kBluestarHeavyHdrMark = 4912 ;
17
+ const uint16_t kBluestarHeavyBitMark = 465 ;
18
+ const uint16_t kBluestarHeavyHdrSpace = 5058 ;
19
+ const uint16_t kBluestarHeavyOneSpace = 1548 ;
20
+ const uint16_t kBluestarHeavyZeroSpace = 572 ;
21
+ const uint16_t kBluestarHeavyFreq = 38000 ; // Hz. (Guessing the most common frequency.)
22
+ // const uint16_t kBluestarHeavyBits = 104; // Move to IRremoteESP8266.h
23
+ // const uint16_t kBluestarHeavyStateLength = 13; // Move to IRremoteESP8266.h
24
+ const uint16_t kBluestarHeavyOverhead = 3 ;
25
+ // DANGER: More than 64 bits detected. A uint64_t for 'data' won't work!
26
+
27
+
28
+ #if SEND_BLUESTARHEAVY
29
+ // Alternative >64bit function to send BLUESTARHEAVY messages
30
+ // Function should be safe over 64 bits.
31
+ // / Send a BluestarHeavy formatted message.
32
+ // / Status: ALPHA / Untested.
33
+ // / @param[in] data An array of bytes containing the IR command.
34
+ // / It is assumed to be in MSB order for this code.
35
+ // / e.g.
36
+ // / @code
37
+ // / uint8_t data[kBluestarHeavyStateLength] = {0xD5, 0xFE, 0xD7, 0x4F, 0xFA, 0x5F, 0xFA, 0x5F, 0xFF, 0x7F, 0x5C, 0xFD, 0xDC};
38
+ // / @endcode
39
+ // / @param[in] nbytes Nr. of bytes of data in the array. (>=kBluestarHeavyStateLength)
40
+ // / @param[in] repeat Nr. of times the message is to be repeated.
41
+ void IRsend::sendBluestarHeavy (const uint8_t data[], const uint16_t nbytes, const uint16_t repeat) {
42
+ for (uint16_t r = 0 ; r <= repeat; r++) {
43
+ uint16_t pos = 0 ;
44
+ // Data Section #2
45
+ // e.g.
46
+ // bits = 104; bytes = 13;
47
+ // *(data + pos) = {0xD5, 0xFE, 0xD7, 0x4F, 0xFA, 0x5F, 0xFA, 0x5F, 0xFF, 0x7F, 0x5C, 0xFD, 0xDC};
48
+ sendGeneric (kBluestarHeavyHdrMark , kBluestarHeavyHdrSpace ,
49
+ kBluestarHeavyBitMark , kBluestarHeavyOneSpace ,
50
+ kBluestarHeavyBitMark , kBluestarHeavyZeroSpace ,
51
+ kBluestarHeavyHdrMark , kDefaultMessageGap ,
52
+ data + pos, 13 , // Bytes
53
+ kBluestarHeavyFreq , true , kNoRepeat , kDutyDefault );
54
+ pos += 13 ; // Adjust by how many bytes of data we sent
55
+ }
56
+ }
57
+ #endif // SEND_BLUESTARHEAVY
58
+
59
+ /*
60
+ // DANGER: More than 64 bits detected. A uint64_t for 'data' won't work!
61
+ #if DECODE_BLUESTARHEAVY
62
+ // Function should be safe up to 64 bits.
63
+ /// Decode the supplied BluestarHeavy message.
64
+ /// Status: ALPHA / Untested.
65
+ /// @param[in,out] results Ptr to the data to decode & where to store the decode
66
+ /// @param[in] offset The starting index to use when attempting to decode the
67
+ /// raw data. Typically/Defaults to kStartOffset.
68
+ /// @param[in] nbits The number of data bits to expect.
69
+ /// @param[in] strict Flag indicating if we should perform strict matching.
70
+ /// @return A boolean. True if it can decode it, false if it can't.
71
+
72
+
73
+ bool IRrecv::decodeBluestarHeavy(decode_results *results, uint16_t offset, const uint16_t nbits, const bool strict) {
74
+ if (results->rawlen < 2 * nbits + kBluestarHeavyOverhead - offset)
75
+ return false; // Too short a message to match.
76
+ if (strict && nbits != kBluestarHeavyBits)
77
+ return false;
78
+
79
+ uint128_t data = 0;
80
+ match_result_t data_result;
81
+
82
+ // Header
83
+ if (!matchMark(results->rawbuf[offset++], kBluestarHeavyHdrMark))
84
+ return false;
85
+ if (!matchSpace(results->rawbuf[offset++], kBluestarHeavyHdrSpace))
86
+ return false;
87
+
88
+ // Data Section #1
89
+ // e.g. data_result.data = 0xD5FED74FFA5FFA5FFF7F5CFDDC, nbits = 104
90
+ data_result = matchData(&(results->rawbuf[offset]), 104,
91
+ kBluestarHeavyBitMark, kBluestarHeavyOneSpace,
92
+ kBluestarHeavyBitMark, kBluestarHeavyZeroSpace);
93
+ offset += data_result.used;
94
+ if (data_result.success == false) return false; // Fail
95
+ data <<= 104; // Make room for the new bits of data.
96
+ data |= data_result.data;
97
+
98
+ // Header
99
+ if (!matchMark(results->rawbuf[offset++], kBluestarHeavyHdrMark))
100
+ return false;
101
+
102
+ // Success
103
+ results->decode_type = decode_type_t::BLUESTARHEAVY;
104
+ results->bits = nbits;
105
+ results->value = data;
106
+ results->command = 0;
107
+ results->address = 0;
108
+ return true;
109
+ }
110
+ #endif // DECODE_BLUESTARHEAVY
111
+
112
+ #if DECODE_BLUESTARHEAVY
113
+ // Function should be safe over 64 bits.
114
+ /// Decode the supplied BluestarHeavy message.
115
+ /// Status: ALPHA / Untested.
116
+ /// @param[in,out] results Ptr to the data to decode & where to store the decode
117
+ /// @param[in] offset The starting index to use when attempting to decode the
118
+ /// raw data. Typically/Defaults to kStartOffset.
119
+ /// @param[in] nbits The number of data bits to expect.
120
+ /// @param[in] strict Flag indicating if we should perform strict matching.
121
+ /// @return A boolean. True if it can decode it, false if it can't.
122
+ bool IRrecv::decodeBluestarHeavy(decode_results *results, uint16_t offset, const uint16_t nbits, const bool strict) {
123
+ if (results->rawlen < 2 * nbits + kBluestarHeavyOverhead - offset)
124
+ return false; // Too short a message to match.
125
+ if (strict && nbits != kBluestarHeavyBits)
126
+ return false;
127
+
128
+ uint16_t pos = 0;
129
+ uint16_t used = 0;
130
+
131
+ // Data Section #2
132
+ // e.g.
133
+ // bits = 104; bytes = 13;
134
+ // *(results->state + pos) = {0xD5, 0xFE, 0xD7, 0x4F, 0xFA, 0x5F, 0xFA, 0x5F, 0xFF, 0x7F, 0x5C, 0xFD, 0xDC};
135
+ used = matchGeneric(results->rawbuf + offset, results->state + pos,
136
+ results->rawlen - offset, 104,
137
+ kBluestarHeavyHdrMark, kBluestarHeavyHdrSpace,
138
+ kBluestarHeavyBitMark, kBluestarHeavyOneSpace,
139
+ kBluestarHeavyBitMark, kBluestarHeavyZeroSpace,
140
+ kBluestarHeavyHdrMark, kDefaultMessageGap, true);
141
+ if (used == 0) return false; // We failed to find any data.
142
+ offset += used; // Adjust for how much of the message we read.
143
+ pos += 13; // Adjust by how many bytes of data we read
144
+
145
+ // Success
146
+ results->decode_type = decode_type_t::BLUESTARHEAVY;
147
+ results->bits = nbits;
148
+ return true;
149
+ }
150
+ #endif // DECODE_BLUESTARHEAVY
151
+ */
0 commit comments