Skip to content

Commit

Permalink
Samsung36: Adjust timings & update unit tests. (#1221)
Browse files Browse the repository at this point in the history
* Adjust protocol timings based on more real-world/capture data.
* Improve Samsung housekeeping tests.
* Update timings accordingly in Unit tests.
* Update supported Samsung36 devices.

For #1220
  • Loading branch information
crankyoldgit authored Jul 21, 2020
1 parent b2c36ca commit ad436f7
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 78 deletions.
40 changes: 24 additions & 16 deletions src/ir_Samsung.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ const uint16_t kSamsungAcBitMark = 586;
const uint16_t kSamsungAcOneSpace = 1432;
const uint16_t kSamsungAcZeroSpace = 436;

// Data from https://github.com/crankyoldgit/IRremoteESP8266/issues/1220
// Values calculated based on the average of ten messages.
const uint16_t kSamsung36HdrMark = 4515; /// < uSeconds
const uint16_t kSamsung36HdrSpace = 4438; /// < uSeconds
const uint16_t kSamsung36BitMark = 512; /// < uSeconds
const uint16_t kSamsung36OneSpace = 1468; /// < uSeconds
const uint16_t kSamsung36ZeroSpace = 490; /// < uSeconds

using irutils::addBoolToString;
using irutils::addFanToString;
using irutils::addIntToString;
Expand Down Expand Up @@ -146,7 +154,7 @@ bool IRrecv::decodeSAMSUNG(decode_results *results, uint16_t offset,

#if SEND_SAMSUNG36
/// Send a Samsung 36-bit formatted message.
/// Status: Alpha / Experimental.
/// Status: STABLE / Works on real devices.
/// @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.
Expand All @@ -156,16 +164,16 @@ void IRsend::sendSamsung36(const uint64_t data, const uint16_t nbits,
if (nbits < 16) return; // To small to send.
for (uint16_t r = 0; r <= repeat; r++) {
// Block #1 (16 bits)
sendGeneric(kSamsungHdrMark, kSamsungHdrSpace,
kSamsungBitMark, kSamsungOneSpace,
kSamsungBitMark, kSamsungZeroSpace,
kSamsungBitMark, kSamsungHdrSpace,
sendGeneric(kSamsung36HdrMark, kSamsung36HdrSpace,
kSamsung36BitMark, kSamsung36OneSpace,
kSamsung36BitMark, kSamsung36ZeroSpace,
kSamsung36BitMark, kSamsung36HdrSpace,
data >> (nbits - 16), 16, 38, true, 0, kDutyDefault);
// Block #2 (The rest, typically 20 bits)
sendGeneric(0, 0, // No header
kSamsungBitMark, kSamsungOneSpace,
kSamsungBitMark, kSamsungZeroSpace,
kSamsungBitMark, kSamsungMinGap, // Gap is just a guess.
kSamsung36BitMark, kSamsung36OneSpace,
kSamsung36BitMark, kSamsung36ZeroSpace,
kSamsung36BitMark, kSamsungMinGap, // Gap is just a guess.
// Mask off the rest of the bits.
data & ((1ULL << (nbits - 16)) - 1),
nbits - 16, 38, true, 0, kDutyDefault);
Expand All @@ -175,7 +183,7 @@ void IRsend::sendSamsung36(const uint64_t data, const uint16_t nbits,

#if DECODE_SAMSUNG36
/// Decode the supplied Samsung36 message.
/// Status: Alpha / Experimental
/// Status: STABLE / Expected to work.
/// @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.
Expand All @@ -198,20 +206,20 @@ bool IRrecv::decodeSamsung36(decode_results *results, uint16_t offset,
uint16_t used;
used = matchGeneric(results->rawbuf + offset, &data,
results->rawlen - offset, 16,
kSamsungHdrMark, kSamsungHdrSpace,
kSamsungBitMark, kSamsungOneSpace,
kSamsungBitMark, kSamsungZeroSpace,
kSamsungBitMark, kSamsungHdrSpace, false);
kSamsung36HdrMark, kSamsung36HdrSpace,
kSamsung36BitMark, kSamsung36OneSpace,
kSamsung36BitMark, kSamsung36ZeroSpace,
kSamsung36BitMark, kSamsung36HdrSpace, false);
if (!used) return false;
offset += used;
// Data (Block #2)
uint64_t data2 = 0;
if (!matchGeneric(results->rawbuf + offset, &data2,
results->rawlen - offset, nbits - 16,
0, 0,
kSamsungBitMark, kSamsungOneSpace,
kSamsungBitMark, kSamsungZeroSpace,
kSamsungBitMark, kSamsungMinGap, true)) return false;
kSamsung36BitMark, kSamsung36OneSpace,
kSamsung36BitMark, kSamsung36ZeroSpace,
kSamsung36BitMark, kSamsungMinGap, true)) return false;
data <<= (nbits - 16);
data += data2;

Expand Down
2 changes: 2 additions & 0 deletions src/ir_Samsung.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// Brand: Samsung, Model: DB93-16761C remote
// Brand: Samsung, Model: IEC-R03 remote
// Brand: Samsung, Model: AK59-00167A Bluray remote (SAMSUNG36)
// Brand: Samsung, Model: AH59-02692E Soundbar remote (SAMSUNG36)
// Brand: Samsung, Model: HW-J551 Soundbar (SAMSUNG36)
// Brand: Samsung, Model: AR09FSSDAWKNFA A/C (SAMSUNG_AC)
// Brand: Samsung, Model: AR12KSFPEWQNET A/C (SAMSUNG_AC)
// Brand: Samsung, Model: AR12HSSDBWKNEU A/C (SAMSUNG_AC)
Expand Down
132 changes: 70 additions & 62 deletions test/ir_Samsung_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

// General housekeeping
TEST(TestSamsung, Housekeeping) {
ASSERT_EQ("SAMSUNG", typeToString(SAMSUNG));
ASSERT_FALSE(hasACState(SAMSUNG));
ASSERT_EQ("SAMSUNG", typeToString(decode_type_t::SAMSUNG));
ASSERT_EQ(decode_type_t::SAMSUNG, strToDecodeType("SAMSUNG"));
ASSERT_FALSE(hasACState(decode_type_t::SAMSUNG));
ASSERT_EQ(kSamsungBits, IRsend::defaultBits(decode_type_t::SAMSUNG));
}

// Tests for sendSAMSUNG().
Expand Down Expand Up @@ -307,8 +309,12 @@ TEST(TestDecodeSamsung, FailToDecodeNonSamsungExample) {

// General housekeeping
TEST(TestSamsungAC, Housekeeping) {
ASSERT_EQ("SAMSUNG_AC", typeToString(SAMSUNG_AC));
ASSERT_TRUE(hasACState(SAMSUNG_AC));
ASSERT_EQ("SAMSUNG_AC", typeToString(decode_type_t::SAMSUNG_AC));
ASSERT_EQ(decode_type_t::SAMSUNG_AC, strToDecodeType("SAMSUNG_AC"));
ASSERT_TRUE(hasACState(decode_type_t::SAMSUNG_AC));
ASSERT_TRUE(IRac::isProtocolSupported(decode_type_t::SAMSUNG_AC));
ASSERT_EQ(kSamsungAcBits, IRsend::defaultBits(decode_type_t::SAMSUNG_AC));
ASSERT_EQ(kNoRepeat, IRsend::minRepeats(decode_type_t::SAMSUNG_AC));
}

// Tests for sendSamsungAC().
Expand Down Expand Up @@ -1143,34 +1149,36 @@ TEST(TestSendSamsung36, SendDataOnly) {
irsend.sendSamsung36(0);
EXPECT_EQ(
"f38000d50"
"m4480s4480"
"m560s560m560s560m560s560m560s560m560s560m560s560m560s560m560s560"
"m560s560m560s560m560s560m560s560m560s560m560s560m560s560m560s560"
"m560s4480"
"m560s560m560s560m560s560m560s560m560s560m560s560m560s560m560s560"
"m560s560m560s560m560s560m560s560m560s560m560s560m560s560m560s560"
"m560s560m560s560m560s560m560s560"
"m560s26880",
"m4515s4438"
"m512s490m512s490m512s490m512s490m512s490m512s490m512s490m512s490"
"m512s490m512s490m512s490m512s490m512s490m512s490m512s490m512s490"
"m512s4438"
"m512s490m512s490m512s490m512s490m512s490m512s490m512s490m512s490"
"m512s490m512s490m512s490m512s490m512s490m512s490m512s490m512s490"
"m512s490m512s490m512s490m512s490"
"m512s26880",
irsend.outputStr());
irsend.sendSamsung36(0x400E00FF);
EXPECT_EQ(
"f38000d50"
"m4480s4480"
"m560s560m560s560m560s560m560s560m560s560m560s1680m560s560m560s560"
"m560s560m560s560m560s560m560s560m560s560m560s560m560s560m560s560"
"m560s4480"
"m560s1680m560s1680m560s1680m560s560m560s560m560s560m560s560m560s560"
"m560s560m560s560m560s560m560s560m560s1680m560s1680m560s1680m560s1680"
"m560s1680m560s1680m560s1680m560s1680"
"m560s26880",
"m4515s4438"
"m512s490m512s490m512s490m512s490m512s490m512s1468m512s490m512s490"
"m512s490m512s490m512s490m512s490m512s490m512s490m512s490m512s490"
"m512s4438"
"m512s1468m512s1468m512s1468m512s490m512s490m512s490m512s490m512s490"
"m512s490m512s490m512s490m512s490m512s1468m512s1468m512s1468m512s1468"
"m512s1468m512s1468m512s1468m512s1468"
"m512s26880",
irsend.outputStr());
irsend.reset();
}

// General housekeeping
TEST(TestSamsung36, Housekeeping) {
ASSERT_EQ("SAMSUNG36", typeToString(SAMSUNG36));
ASSERT_FALSE(hasACState(SAMSUNG36));
ASSERT_EQ("SAMSUNG36", typeToString(decode_type_t::SAMSUNG36));
ASSERT_EQ(decode_type_t::SAMSUNG36, strToDecodeType("SAMSUNG36"));
ASSERT_FALSE(hasACState(decode_type_t::SAMSUNG36));
ASSERT_EQ(kSamsung36Bits, IRsend::defaultBits(decode_type_t::SAMSUNG36));
}

// Test sending with different repeats.
Expand All @@ -1182,50 +1190,50 @@ TEST(TestSendSamsung36, SendWithRepeats) {
irsend.sendSamsung36(0x400E00FF, kSamsung36Bits, 1); // 1 repeat.
EXPECT_EQ(
"f38000d50"
"m4480s4480"
"m560s560m560s560m560s560m560s560m560s560m560s1680m560s560m560s560"
"m560s560m560s560m560s560m560s560m560s560m560s560m560s560m560s560"
"m560s4480"
"m560s1680m560s1680m560s1680m560s560m560s560m560s560m560s560m560s560"
"m560s560m560s560m560s560m560s560m560s1680m560s1680m560s1680m560s1680"
"m560s1680m560s1680m560s1680m560s1680"
"m560s26880"
"m4480s4480"
"m560s560m560s560m560s560m560s560m560s560m560s1680m560s560m560s560"
"m560s560m560s560m560s560m560s560m560s560m560s560m560s560m560s560"
"m560s4480"
"m560s1680m560s1680m560s1680m560s560m560s560m560s560m560s560m560s560"
"m560s560m560s560m560s560m560s560m560s1680m560s1680m560s1680m560s1680"
"m560s1680m560s1680m560s1680m560s1680"
"m560s26880",
"m4515s4438"
"m512s490m512s490m512s490m512s490m512s490m512s1468m512s490m512s490"
"m512s490m512s490m512s490m512s490m512s490m512s490m512s490m512s490"
"m512s4438"
"m512s1468m512s1468m512s1468m512s490m512s490m512s490m512s490m512s490"
"m512s490m512s490m512s490m512s490m512s1468m512s1468m512s1468m512s1468"
"m512s1468m512s1468m512s1468m512s1468"
"m512s26880"
"m4515s4438"
"m512s490m512s490m512s490m512s490m512s490m512s1468m512s490m512s490"
"m512s490m512s490m512s490m512s490m512s490m512s490m512s490m512s490"
"m512s4438"
"m512s1468m512s1468m512s1468m512s490m512s490m512s490m512s490m512s490"
"m512s490m512s490m512s490m512s490m512s1468m512s1468m512s1468m512s1468"
"m512s1468m512s1468m512s1468m512s1468"
"m512s26880",
irsend.outputStr());
irsend.sendSamsung36(0x400E00FF, kSamsung36Bits, 2); // 2 repeats.
EXPECT_EQ(
"f38000d50"
"m4480s4480"
"m560s560m560s560m560s560m560s560m560s560m560s1680m560s560m560s560"
"m560s560m560s560m560s560m560s560m560s560m560s560m560s560m560s560"
"m560s4480"
"m560s1680m560s1680m560s1680m560s560m560s560m560s560m560s560m560s560"
"m560s560m560s560m560s560m560s560m560s1680m560s1680m560s1680m560s1680"
"m560s1680m560s1680m560s1680m560s1680"
"m560s26880"
"m4480s4480"
"m560s560m560s560m560s560m560s560m560s560m560s1680m560s560m560s560"
"m560s560m560s560m560s560m560s560m560s560m560s560m560s560m560s560"
"m560s4480"
"m560s1680m560s1680m560s1680m560s560m560s560m560s560m560s560m560s560"
"m560s560m560s560m560s560m560s560m560s1680m560s1680m560s1680m560s1680"
"m560s1680m560s1680m560s1680m560s1680"
"m560s26880"
"m4480s4480"
"m560s560m560s560m560s560m560s560m560s560m560s1680m560s560m560s560"
"m560s560m560s560m560s560m560s560m560s560m560s560m560s560m560s560"
"m560s4480"
"m560s1680m560s1680m560s1680m560s560m560s560m560s560m560s560m560s560"
"m560s560m560s560m560s560m560s560m560s1680m560s1680m560s1680m560s1680"
"m560s1680m560s1680m560s1680m560s1680"
"m560s26880",
"m4515s4438"
"m512s490m512s490m512s490m512s490m512s490m512s1468m512s490m512s490"
"m512s490m512s490m512s490m512s490m512s490m512s490m512s490m512s490"
"m512s4438"
"m512s1468m512s1468m512s1468m512s490m512s490m512s490m512s490m512s490"
"m512s490m512s490m512s490m512s490m512s1468m512s1468m512s1468m512s1468"
"m512s1468m512s1468m512s1468m512s1468"
"m512s26880"
"m4515s4438"
"m512s490m512s490m512s490m512s490m512s490m512s1468m512s490m512s490"
"m512s490m512s490m512s490m512s490m512s490m512s490m512s490m512s490"
"m512s4438"
"m512s1468m512s1468m512s1468m512s490m512s490m512s490m512s490m512s490"
"m512s490m512s490m512s490m512s490m512s1468m512s1468m512s1468m512s1468"
"m512s1468m512s1468m512s1468m512s1468"
"m512s26880"
"m4515s4438"
"m512s490m512s490m512s490m512s490m512s490m512s1468m512s490m512s490"
"m512s490m512s490m512s490m512s490m512s490m512s490m512s490m512s490"
"m512s4438"
"m512s1468m512s1468m512s1468m512s490m512s490m512s490m512s490m512s490"
"m512s490m512s490m512s490m512s490m512s1468m512s1468m512s1468m512s1468"
"m512s1468m512s1468m512s1468m512s1468"
"m512s26880",
irsend.outputStr());
}

Expand Down

0 comments on commit ad436f7

Please sign in to comment.