Skip to content

Commit

Permalink
Samsung36: Adjust timings & update unit tests.
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.

For #1220
  • Loading branch information
crankyoldgit committed Jul 20, 2020
1 parent b2c36ca commit de71200
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 76 deletions.
36 changes: 22 additions & 14 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 @@ -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 Down Expand Up @@ -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
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 de71200

Please sign in to comment.