-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental Bose remote support (#1579)
* Experimental Bose remote support * Unit tests. Co-authored-by: crankyoldgit <[email protected]>
- Loading branch information
1 parent
f026c5c
commit b1b9277
Showing
9 changed files
with
209 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2021 parsnip42 | ||
// Copyright 2021 David Conran | ||
|
||
/// @file | ||
/// @brief Support for Bose protocols. | ||
/// @note Currently only tested against Bose TV Speaker. | ||
/// @see https://github.com/crankyoldgit/IRremoteESP8266/pull/1579 | ||
|
||
// Supports: | ||
// Brand: Bose, Model: Bose TV Speaker | ||
|
||
#include "IRrecv.h" | ||
#include "IRsend.h" | ||
|
||
const uint16_t kBoseHdrMark = 1100; | ||
const uint16_t kBoseHdrSpace = 1350; | ||
const uint16_t kBoseBitMark = 555; | ||
const uint16_t kBoseOneSpace = 1435; | ||
const uint16_t kBoseZeroSpace = 500; | ||
const uint32_t kBoseGap = kDefaultMessageGap; | ||
const uint16_t kBoseFreq = 38; | ||
|
||
#if SEND_BOSE | ||
/// Send a Bose formatted message. | ||
/// Status: STABLE / Known working. | ||
/// @param[in] data The message to be sent. | ||
/// @param[in] nbits The number of bits of message to be sent. | ||
/// @param[in] repeat The number of times the command is to be repeated. | ||
void IRsend::sendBose(const uint64_t data, const uint16_t nbits, | ||
const uint16_t repeat) { | ||
sendGeneric(kBoseHdrMark, kBoseHdrSpace, | ||
kBoseBitMark, kBoseOneSpace, | ||
kBoseBitMark, kBoseZeroSpace, | ||
kBoseBitMark, kBoseGap, | ||
data, nbits, kBoseFreq, false, | ||
repeat, kDutyDefault); | ||
} | ||
#endif // SEND_BOSE | ||
|
||
#if DECODE_BOSE | ||
/// Decode the supplied Bose formatted message. | ||
/// Status: STABLE / Known working. | ||
/// @param[in,out] results Ptr to the data to decode & where to store the result | ||
/// @param[in] offset The starting index to use when attempting to decode the | ||
/// raw data. Typically/Defaults to kStartOffset. | ||
/// @param[in] nbits The number of data bits to expect. | ||
/// @param[in] strict Flag indicating if we should perform strict matching. | ||
bool IRrecv::decodeBose(decode_results *results, uint16_t offset, | ||
const uint16_t nbits, const bool strict) { | ||
if (strict && nbits != kBoseBits) return false; | ||
|
||
if (!matchGeneric(results->rawbuf + offset, &(results->value), | ||
results->rawlen - offset, nbits, | ||
kBoseHdrMark, kBoseHdrSpace, | ||
kBoseBitMark, kBoseOneSpace, | ||
kBoseBitMark, kBoseZeroSpace, | ||
kBoseBitMark, kBoseGap, true, | ||
kUseDefTol, 0, false)) { | ||
return false; | ||
} | ||
|
||
// | ||
results->decode_type = decode_type_t::BOSE; | ||
results->bits = nbits; | ||
results->address = 0; | ||
results->command = 0; | ||
return true; | ||
} | ||
#endif // DECODE_BOSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright 2021 parsnip42 | ||
// Copyright 2021 David Conran | ||
|
||
#include "IRac.h" | ||
#include "IRrecv.h" | ||
#include "IRrecv_test.h" | ||
#include "IRsend.h" | ||
#include "IRsend_test.h" | ||
#include "gtest/gtest.h" | ||
|
||
|
||
TEST(TestUtils, Housekeeping) { | ||
ASSERT_EQ("BOSE", typeToString(decode_type_t::BOSE)); | ||
ASSERT_EQ(decode_type_t::BOSE, strToDecodeType("BOSE")); | ||
ASSERT_FALSE(hasACState(decode_type_t::BOSE)); | ||
ASSERT_FALSE(IRac::isProtocolSupported(decode_type_t::BOSE)); | ||
ASSERT_EQ(kBoseBits, IRsend::defaultBits(decode_type_t::BOSE)); | ||
ASSERT_EQ(kNoRepeat, IRsend::minRepeats(decode_type_t::BOSE)); | ||
} | ||
|
||
// Tests for sendBose(). | ||
|
||
// Test sending typical data only. | ||
TEST(TestSendBose, SendDataOnly) { | ||
IRsendTest irsend(kGpioUnused); | ||
irsend.begin(); | ||
irsend.sendBose(0xCD32); | ||
EXPECT_EQ("f38000d50" | ||
"m1100s1350m555s500m555s1435m555s500m555s500m555s1435m555s1435" | ||
"m555s500m555s500m555s1435m555s500m555s1435m555s1435m555s500" | ||
"m555s500m555s1435m555s1435m555s100000", | ||
irsend.outputStr()); | ||
} | ||
|
||
// Decode normal Bose messages. | ||
TEST(TestDecodeBose, SyntheticSelfDecode) { | ||
IRsendTest irsend(kGpioUnused); | ||
IRrecv irrecv(kGpioUnused); | ||
irsend.begin(); | ||
|
||
// Synthesised 16-bit Bose message (TV Speaker Power On). | ||
irsend.reset(); | ||
irsend.sendBose(0xCD32); | ||
irsend.makeDecodeResult(); | ||
|
||
EXPECT_TRUE(irrecv.decode(&irsend.capture)); | ||
EXPECT_EQ(BOSE, irsend.capture.decode_type); | ||
EXPECT_EQ(kBoseBits, irsend.capture.bits); | ||
EXPECT_EQ(0xCD32, irsend.capture.value); | ||
EXPECT_EQ(0x0, irsend.capture.address); | ||
EXPECT_EQ(0x0, irsend.capture.command); | ||
} | ||
|
||
// Decode normal Bose messages. | ||
TEST(TestDecodeBose, RealMessageDecode1) { | ||
IRsendTest irsend(kGpioUnused); | ||
IRrecv irrecv(kGpioUnused); | ||
|
||
irsend.begin(); | ||
|
||
// Real-life Bose code from an actual capture/decode (TV Speaker Power On). | ||
irsend.reset(); | ||
|
||
const uint16_t rawData_0[35] = { | ||
942, 1558, | ||
442, 558, 442, 1502, 494, 534, 466, 560, 440, 1530, 468, 1532, 466, | ||
558, 440, 504, 496, 1558, 440, 534, 466, 1556, 442, 1558, 440, 558, | ||
440, 534, 466, 1556, 442, 1558, 440 | ||
}; | ||
|
||
irsend.sendRaw(rawData_0, 35, 38000); | ||
irsend.makeDecodeResult(); | ||
|
||
EXPECT_TRUE(irrecv.decode(&irsend.capture)); | ||
EXPECT_EQ(BOSE, irsend.capture.decode_type); | ||
EXPECT_EQ(kBoseBits, irsend.capture.bits); | ||
EXPECT_EQ(0xCD32, irsend.capture.value); | ||
EXPECT_EQ(0x0, irsend.capture.address); | ||
EXPECT_EQ(0x0, irsend.capture.command); | ||
} | ||
|
||
// Decode normal Bose messages. | ||
TEST(TestDecodeBose, RealMessageDecode2) { | ||
IRsendTest irsend(kGpioUnused); | ||
IRrecv irrecv(kGpioUnused); | ||
|
||
irsend.begin(); | ||
|
||
// Real-life Bose code from an actual capture/decode (TV Speaker Mute). | ||
irsend.reset(); | ||
|
||
const uint16_t rawData_0[35] = { | ||
1024, 1504, | ||
496, 528, 472, 480, 520, 502, 496, 506, 494, 502, 496, 502, 498, | ||
502, 498, 1500, 498, 1502, 496, 1504, 496, 1502, 496, 1504, 494, | ||
1472, 524, 1504, 468, 1556, 442, 532, 468, | ||
}; | ||
|
||
irsend.sendRaw(rawData_0, 35, 38000); | ||
irsend.makeDecodeResult(); | ||
|
||
EXPECT_TRUE(irrecv.decode(&irsend.capture)); | ||
EXPECT_EQ(BOSE, irsend.capture.decode_type); | ||
EXPECT_EQ(kBoseBits, irsend.capture.bits); | ||
EXPECT_EQ(0x7F80, irsend.capture.value); | ||
EXPECT_EQ(0x0, irsend.capture.address); | ||
EXPECT_EQ(0x0, irsend.capture.command); | ||
} |