1
- // Copyright 2020 David Conran (crankyoldgit )
1
+ // Copyright 2024 Harsh Bhosale (harshbhosale01 )
2
2
// / @file
3
3
// / @brief Support for BluestarHeavy protocol
4
4
5
5
// Supports:
6
- // Brand: Bluestar, Model: TODO add device and remote
6
+ // Brand: Bluestar, Model: TODO add device and remote
7
7
8
8
#include " IRrecv.h"
9
9
#include " IRsend.h"
10
10
#include " IRutils.h"
11
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
12
const uint16_t kBluestarHeavyHdrMark = 4912 ;
17
13
const uint16_t kBluestarHeavyBitMark = 465 ;
18
14
const uint16_t kBluestarHeavyHdrSpace = 5058 ;
19
15
const uint16_t kBluestarHeavyOneSpace = 1548 ;
20
16
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
17
+ const uint16_t kBluestarHeavyFreq = 38000 ;
24
18
const uint16_t kBluestarHeavyOverhead = 3 ;
25
- // DANGER: More than 64 bits detected. A uint64_t for 'data' won't work!
26
-
27
19
28
20
#if SEND_BLUESTARHEAVY
29
- // Alternative >64bit function to send BLUESTARHEAVY messages
30
- // Function should be safe over 64 bits.
31
21
// / Send a BluestarHeavy formatted message.
32
- // / Status: ALPHA / Untested .
22
+ // / Status: BETA / Tested .
33
23
// / @param[in] data An array of bytes containing the IR command.
34
24
// / It is assumed to be in MSB order for this code.
35
25
// / e.g.
@@ -39,108 +29,37 @@ const uint16_t kBluestarHeavyOverhead = 3;
39
29
// / @param[in] nbytes Nr. of bytes of data in the array. (>=kBluestarHeavyStateLength)
40
30
// / @param[in] repeat Nr. of times the message is to be repeated.
41
31
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 ,
32
+ sendGeneric (kBluestarHeavyHdrMark , kBluestarHeavyHdrSpace ,
49
33
kBluestarHeavyBitMark , kBluestarHeavyOneSpace ,
50
34
kBluestarHeavyBitMark , kBluestarHeavyZeroSpace ,
51
35
kBluestarHeavyHdrMark , kDefaultMessageGap ,
52
- data + pos, nbytes, // Bytes
53
- kBluestarHeavyFreq , true , kNoRepeat , kDutyDefault );
54
- pos += nbytes; // Adjust by how many bytes of data we sent
55
- }
36
+ data, nbytes, // Bytes
37
+ kBluestarHeavyFreq , true , repeat, kDutyDefault );
56
38
}
57
39
#endif // SEND_BLUESTARHEAVY
58
40
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
- // uint64_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
41
#if DECODE_BLUESTARHEAVY
113
- // Function should be safe over 64 bits.
114
42
// / Decode the supplied BluestarHeavy message.
115
- // / Status: ALPHA / Untested .
43
+ // / Status: BETA / Tested .
116
44
// / @param[in,out] results Ptr to the data to decode & where to store the decode
117
45
// / @param[in] offset The starting index to use when attempting to decode the
118
46
// / raw data. Typically/Defaults to kStartOffset.
119
47
// / @param[in] nbits The number of data bits to expect.
120
48
// / @param[in] strict Flag indicating if we should perform strict matching.
121
49
// / @return A boolean. True if it can decode it, false if it can't.
122
50
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
51
if (strict && nbits != kBluestarHeavyBits )
126
52
return false ;
127
53
128
- uint16_t pos = 0 ;
129
54
uint16_t used = 0 ;
130
55
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 ,
56
+ used = matchGeneric (results->rawbuf + offset, results->state ,
57
+ results->rawlen - offset, nbits,
137
58
kBluestarHeavyHdrMark , kBluestarHeavyHdrSpace ,
138
59
kBluestarHeavyBitMark , kBluestarHeavyOneSpace ,
139
60
kBluestarHeavyBitMark , kBluestarHeavyZeroSpace ,
140
61
kBluestarHeavyHdrMark , kDefaultMessageGap , true );
141
62
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
63
145
64
// Success
146
65
results->decode_type = decode_type_t ::BLUESTARHEAVY;
0 commit comments