Skip to content

Commit

Permalink
Add support for Elite Screens protocol. (#1310)
Browse files Browse the repository at this point in the history
* Add support for Elite Screens protocol.
* A constant bit time 32-bit protocol with a single repeat.
* Add `sendElitescreens()` & `decodeElitescreens()`
* Unit test coverage including real & synthetic examples.
* decoding confirmed to be working.
See #1306 (comment)

Fixes #1306
  • Loading branch information
crankyoldgit authored Oct 26, 2020
1 parent 5e82c21 commit b77b0e1
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/IRrecv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,10 @@ bool IRrecv::decode(decode_results *results, irparams_t *save,
DPRINTLN("Attempting Mirage decode");
if (decodeMirage(results, offset)) return true;
#endif // DECODE_MIRAGE
#if DECODE_ELITESCREENS
DPRINTLN("Attempting EliteScreens decode");
if (decodeElitescreens(results, offset)) return true;
#endif // DECODE_ELITESCREENS
// Typically new protocols are added above this line.
}
#if DECODE_HASH
Expand Down
6 changes: 6 additions & 0 deletions src/IRrecv.h
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,12 @@ class IRrecv {
const uint16_t nbits = kMirageBits,
const bool strict = true);
#endif // DECODE_MIRAGE
#if DECODE_ELITESCREENS
bool decodeElitescreens(decode_results *results,
uint16_t offset = kStartOffset,
const uint16_t nbits = kEliteScreensBits,
const bool strict = true);
#endif // DECODE_ELITESCREENS
};

#endif // IRRECV_H_
12 changes: 11 additions & 1 deletion src/IRremoteESP8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,13 @@
#define SEND_MIRAGE _IR_ENABLE_DEFAULT_
#endif // SEND_MIRAGE

#ifndef DECODE_ELITESCREENS
#define DECODE_ELITESCREENS _IR_ENABLE_DEFAULT_
#endif // DECODE_ELITESCREENS
#ifndef SEND_ELITESCREENS
#define SEND_ELITESCREENS _IR_ENABLE_DEFAULT_
#endif // SEND_ELITESCREENS

#if (DECODE_ARGO || DECODE_DAIKIN || DECODE_FUJITSU_AC || DECODE_GREE || \
DECODE_KELVINATOR || DECODE_MITSUBISHI_AC || DECODE_TOSHIBA_AC || \
DECODE_TROTEC || DECODE_HAIER_AC || DECODE_HITACHI_AC || \
Expand Down Expand Up @@ -851,8 +858,9 @@ enum decode_type_t {
TRANSCOLD,
TECHNIBEL_AC,
MIRAGE,
ELITESCREENS, // 95
// Add new entries before this one, and update it to point to the last entry.
kLastDecodeType = MIRAGE,
kLastDecodeType = ELITESCREENS,
};

// Message lengths & required repeat values
Expand Down Expand Up @@ -922,6 +930,8 @@ const uint16_t kEpsonMinRepeat = 2;
const uint16_t kElectraAcStateLength = 13;
const uint16_t kElectraAcBits = kElectraAcStateLength * 8;
const uint16_t kElectraAcMinRepeat = kNoRepeat;
const uint16_t kEliteScreensBits = 32;
const uint16_t kEliteScreensDefaultRepeat = kSingleRepeat;
const uint16_t kFujitsuAcMinRepeat = kNoRepeat;
const uint16_t kFujitsuAcStateLength = 16;
const uint16_t kFujitsuAcStateLengthShort = 7;
Expand Down
7 changes: 7 additions & 0 deletions src/IRsend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ uint16_t IRsend::minRepeats(const decode_type_t protocol) {
case AIWA_RC_T501:
case AMCOR:
case COOLIX:
case ELITESCREENS:
case GICABLE:
case INAX:
case MIDEA24:
Expand Down Expand Up @@ -634,6 +635,7 @@ uint16_t IRsend::defaultBits(const decode_type_t protocol) {
case LG2:
return 28;
case CARRIER_AC:
case ELITESCREENS:
case EPSON:
case NEC:
case NEC_LIKE:
Expand Down Expand Up @@ -816,6 +818,11 @@ bool IRsend::send(const decode_type_t type, const uint64_t data,
sendDoshisha(data, nbits, min_repeat);
break;
#endif
#if SEND_ELITESCREENS
case ELITESCREENS:
sendElitescreens(data, nbits, min_repeat);
break;
#endif // SEND_ELITESCREENS
#if SEND_EPSON
case EPSON:
sendEpson(data, nbits, min_repeat);
Expand Down
5 changes: 5 additions & 0 deletions src/IRsend.h
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,11 @@ class IRsend {
void sendTranscold(const uint64_t data, const uint16_t nbits = kTranscoldBits,
const uint16_t repeat = kTranscoldDefaultRepeat);
#endif // SEND_TRANSCOLD
#if SEND_ELITESCREENS
void sendElitescreens(const uint64_t data,
const uint16_t nbits = kEliteScreensBits,
const uint16_t repeat = kEliteScreensDefaultRepeat);
#endif // SEND_ELITESCREENS

protected:
#ifdef UNIT_TEST
Expand Down
1 change: 1 addition & 0 deletions src/IRtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,6 @@ const PROGMEM char *kAllProtocolNamesStr =
D_STR_TRANSCOLD "\x0"
D_STR_TECHNIBEL_AC "\x0"
D_STR_MIRAGE "\x0"
D_STR_ELITESCREENS "\x0"
///< New protocol strings should be added just above this line.
"\x0"; ///< This string requires double null termination.
81 changes: 81 additions & 0 deletions src/ir_EliteScreens.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2020 David Conran
/// @file
/// @brief Elite Screens protocol support
/// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1306
/// @see https://elitescreens.com/kcfinder/upload/files/FAQ/ir_commands.pdf

// Supports:
// Brand: Elite Screens, Model: Spectrum series
// Brand: Elite Screens, Model: VMAX2 / VMAX2 Plus series
// Brand: Elite Screens, Model: VMAX Plus4 series
// Brand: Elite Screens, Model: Home2 / Home3 series
// Brand: Elite Screens, Model: CineTension2 / CineTension3 series
// Brand: Elite Screens, Model: ZSP-IR-B / ZSP-IR-W remote

// Known Elite Screens commands:
// 0xFEA3387 (STOP)
// 0xFDA2256 (UP)
// 0xFBA1136 (DOWN)

#include "IRrecv.h"
#include "IRsend.h"
#include "IRutils.h"


// Constants
const uint16_t kEliteScreensOne = 470;
const uint16_t kEliteScreensZero = 1214;
const uint16_t kEliteScreensGap = 29200;

#if SEND_ELITESCREENS
/// Send an Elite Screens formatted message.
/// Status: BETA / Probably 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::sendElitescreens(uint64_t data, uint16_t nbits, uint16_t repeat) {
// Protocol uses a constant bit time encoding.
sendGeneric(0, 0, // No header.
kEliteScreensOne, kEliteScreensZero,
kEliteScreensZero, kEliteScreensOne,
0, kEliteScreensGap, data, nbits, 38000, true, repeat, 50);
}
#endif

#if DECODE_ELITESCREENS
/// Decode the supplied Elite Screens message.
/// Status: STABLE / Confirmed working.
/// @param[in,out] results Ptr to the data to decode & where to store the decode
/// 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.
/// @return A boolean. True if it can decode it, false if it can't.
bool IRrecv::decodeElitescreens(decode_results *results, uint16_t offset,
const uint16_t nbits, const bool strict) {
// Compliance check.
if (strict && nbits != kEliteScreensBits) return false;

uint64_t data = 0;

// Data + Footer
if (!matchGenericConstBitTime(results->rawbuf + offset, &data,
results->rawlen - offset, nbits,
// Header (None)
0, 0,
// Data
kEliteScreensOne, kEliteScreensZero,
// Footer (None)
0, kEliteScreensGap, true)) return false;

// Success
results->decode_type = decode_type_t::ELITESCREENS;
results->bits = nbits;
results->value = data;
results->address = 0;
results->command = 0;
results->repeat = false;
return true;
}
#endif
3 changes: 3 additions & 0 deletions src/locale/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,9 @@
#ifndef D_STR_ELECTRA_AC
#define D_STR_ELECTRA_AC "ELECTRA_AC"
#endif // D_STR_ELECTRA_AC
#ifndef D_STR_ELITESCREENS
#define D_STR_ELITESCREENS "ELITESCREENS"
#endif // D_STR_ELITESCREENS
#ifndef D_STR_EPSON
#define D_STR_EPSON "EPSON"
#endif // D_STR_EPSON
Expand Down
140 changes: 140 additions & 0 deletions test/ir_EliteScreens_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Copyright 2017 David Conran

#include "IRac.h"
#include "IRsend.h"
#include "IRsend_test.h"
#include "gtest/gtest.h"

// Housekeeping tests

TEST(TestUtils, Housekeeping) {
ASSERT_EQ("ELITESCREENS", typeToString(decode_type_t::ELITESCREENS));
ASSERT_EQ(decode_type_t::ELITESCREENS, strToDecodeType("ELITESCREENS"));
ASSERT_FALSE(hasACState(decode_type_t::ELITESCREENS));
ASSERT_FALSE(IRac::isProtocolSupported(decode_type_t::ELITESCREENS));
ASSERT_EQ(kEliteScreensBits,
IRsendTest::defaultBits(decode_type_t::ELITESCREENS));
ASSERT_EQ(kEliteScreensDefaultRepeat,
IRsendTest::minRepeats(decode_type_t::ELITESCREENS));
}

// Tests for sendElitescreens().

// Test sending typical data only.
TEST(TestSendElitescreens, SendDataOnly) {
IRsendTest irsend(kGpioUnused);
irsend.begin();

irsend.reset();
irsend.sendElitescreens(0xFEA3387); // STOP command
EXPECT_EQ(
"f38000d50"
"m1214s470m1214s470m1214s470m1214s470"
"m470s1214m470s1214m470s1214m470s1214"
"m470s1214m470s1214m470s1214m1214s470"
"m470s1214m1214s470m470s1214m1214s470"
"m1214s470m1214s470m470s1214m470s1214"
"m1214s470m1214s470m470s1214m470s1214"
"m470s1214m1214s470m1214s470m1214s470"
"m1214s470m470s1214m470s1214m470"
"s30414"
"m1214s470m1214s470m1214s470m1214s470"
"m470s1214m470s1214m470s1214m470s1214"
"m470s1214m470s1214m470s1214m1214s470"
"m470s1214m1214s470m470s1214m1214s470"
"m1214s470m1214s470m470s1214m470s1214"
"m1214s470m1214s470m470s1214m470s1214"
"m470s1214m1214s470m1214s470m1214s470"
"m1214s470m470s1214m470s1214m470"
"s30414",
irsend.outputStr());
}

// Tests for decodeElitescreens().

// Decode a 'real' example
TEST(TestDecodeElitescreens, RealExample) {
IRsendTest irsend(kGpioUnused);
IRrecv irrecv(kGpioUnused);
irsend.begin();

// From https://github.com/crankyoldgit/IRremoteESP8266/issues/1306#issuecomment-715913084
// STOP (111100000010 0xF02)
const uint16_t rawData[127] = {
1278, 456, 1248, 486, 1226, 452, 1252, 454, // 0 0 0 0 0x0
474, 1220, 474, 1222, 480, 1214, 476, 1222, // 1 1 1 1 0xF
472, 1224, 478, 1216, 476, 1220, 1256, 480, // 1 1 1 0 0xE
450, 1216, 1248, 488, 442, 1222, 1252, 486, // 1 0 1 0 0xA
1226, 478, 1224, 482, 448, 1220, 472, 1222, // 0 0 1 1 0x3
1254, 482, 1220, 486, 444, 1222, 480, 1218, // 0 0 1 1 0x3
474, 1220, 1254, 482, 1222, 484, 1218, 488, // 1 0 0 0 0x8
1224, 482, 450, 1218, 474, 1220, 470, // 0 1 1 1 0x7
30482,
1246, 460, 1274, 460, 1220, 456, 1246, 488,
452, 1214, 478, 1218, 474, 1220, 470, 1228,
476, 1220, 472, 1222, 480, 1214, 1248, 486,
476, 1190, 1274, 460, 480, 1186, 1278, 460,
1252, 426, 1276, 456, 474, 1194, 478, 1216,
1280, 456, 1246, 460, 482, 1186, 474, 1224,
478, 1216, 1282, 454, 1248, 458, 1244, 462,
1252, 456, 474, 1192, 480, 1216, 476}; // UNKNOWN 148A4DFF

irsend.reset();
irsend.sendRaw(rawData, 127, 38000);
irsend.makeDecodeResult();

ASSERT_TRUE(irrecv.decode(&irsend.capture));
EXPECT_EQ(ELITESCREENS, irsend.capture.decode_type);
EXPECT_EQ(kEliteScreensBits, irsend.capture.bits);
EXPECT_EQ(0xFEA3387, irsend.capture.value);
EXPECT_EQ(0x0, irsend.capture.address);
EXPECT_EQ(0x0, irsend.capture.command);
EXPECT_FALSE(irsend.capture.repeat);
}

// Decode a Synthetic example
TEST(TestDecodeElitescreens, SyntheticExample) {
IRsendTest irsend(kGpioUnused);
IRrecv irrecv(kGpioUnused);
irsend.begin();

irsend.reset();
irsend.sendElitescreens(0xFEA3387);
irsend.makeDecodeResult();

ASSERT_TRUE(irrecv.decode(&irsend.capture));
EXPECT_EQ(ELITESCREENS, irsend.capture.decode_type);
EXPECT_EQ(kEliteScreensBits, irsend.capture.bits);
EXPECT_EQ(0xFEA3387, irsend.capture.value);
EXPECT_EQ(0x0, irsend.capture.address);
EXPECT_EQ(0x0, irsend.capture.command);
EXPECT_FALSE(irsend.capture.repeat);
}

// Decode a 'real' example with no repeat.
TEST(TestDecodeElitescreens, RealExampleNoRepeat) {
IRsendTest irsend(kGpioUnused);
IRrecv irrecv(kGpioUnused);
irsend.begin();

// From https://github.com/crankyoldgit/IRremoteESP8266/issues/1306#issuecomment-715901468
// UP
const uint16_t rawData[63] = {
1250, 450, 1250, 450, 1250, 500, 1200, 500, 450, 1250, 450, 1200, 500, 1200,
500, 1200, 500, 1200, 500, 1200, 1250, 450, 500, 1200, 450, 1250, 1250, 450,
450, 1250, 1250, 450, 1250, 450, 1250, 450, 500, 1200, 1250, 450, 1250, 450,
1250, 450, 500, 1200, 1250, 450, 1250, 450, 500, 1200, 1250, 450, 500, 1200,
1250, 450, 500, 1200, 500, 1200, 1250}; // Protocol=UNKNOWN Data=0x2D8CB141

irsend.reset();
irsend.sendRaw(rawData, 63, 38000);
irsend.makeDecodeResult();

ASSERT_TRUE(irrecv.decode(&irsend.capture));
EXPECT_EQ(ELITESCREENS, irsend.capture.decode_type);
EXPECT_EQ(kEliteScreensBits, irsend.capture.bits);
EXPECT_EQ(0xFDA2256, irsend.capture.value);
EXPECT_EQ(0x0, irsend.capture.address);
EXPECT_EQ(0x0, irsend.capture.command);
EXPECT_FALSE(irsend.capture.repeat);
}

0 comments on commit b77b0e1

Please sign in to comment.