-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for Lixil Inax Toilet protocol.
* Add send/decode routines & unit tests. * Update example code. Fixes #706
- Loading branch information
1 parent
7275d78
commit 8009d19
Showing
11 changed files
with
271 additions
and
4 deletions.
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
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,98 @@ | ||
// Copyright 2019 David Conran (crankyoldgit) | ||
|
||
#include <algorithm> | ||
#include "IRrecv.h" | ||
#include "IRsend.h" | ||
#include "IRutils.h" | ||
|
||
// Support for an IR controlled Robot Toilet | ||
// | ||
// Brand: Lixil | ||
// Model: Inax | ||
// Type: DT-BA283 | ||
|
||
// Documentation: | ||
// https://www.lixil-manual.com/GCW-1365-16050/GCW-1365-16050.pdf | ||
|
||
// Constants | ||
// Ref: | ||
// https://github.com/markszabo/IRremoteESP8266/issues/706 | ||
const uint16_t kInaxTick = 500; | ||
const uint16_t kInaxHdrMark = 9000; | ||
const uint16_t kInaxHdrSpace = 4500; | ||
const uint16_t kInaxBitMark = 560; | ||
const uint16_t kInaxOneSpace = 1675; | ||
const uint16_t kInaxZeroSpace = kInaxBitMark; | ||
const uint16_t kInaxMinGap = 40000; | ||
|
||
#if SEND_INAX | ||
// Send a Inax Toilet formatted message. | ||
// | ||
// Args: | ||
// data: The message to be sent. | ||
// nbits: The bit size of the message being sent. typically kInaxBits. | ||
// repeat: The number of times the message is to be repeated. | ||
// | ||
// Status: BETA / Should be working. | ||
// | ||
// Ref: https://github.com/markszabo/IRremoteESP8266/issues/706 | ||
void IRsend::sendInax(const uint64_t data, const uint16_t nbits, | ||
const uint16_t repeat) { | ||
sendGeneric(kInaxHdrMark, kInaxHdrSpace, | ||
kInaxBitMark, kInaxOneSpace, | ||
kInaxBitMark, kInaxZeroSpace, | ||
kInaxBitMark, kInaxMinGap, | ||
data, nbits, 38, true, repeat, kDutyDefault); | ||
} | ||
#endif | ||
|
||
#if DECODE_INAX | ||
// Decode the supplied Inax Toilet message. | ||
// | ||
// Args: | ||
// results: Ptr to the data to decode and where to store the decode result. | ||
// nbits: Nr. of bits to expect in the data portion. | ||
// Typically kInaxBits. | ||
// strict: Flag to indicate if we strictly adhere to the specification. | ||
// Returns: | ||
// boolean: True if it can decode it, false if it can't. | ||
// | ||
// Status: BETA / Should be Working. | ||
// | ||
bool IRrecv::decodeInax(decode_results *results, const uint16_t nbits, | ||
const bool strict) { | ||
if (results->rawlen < 2 * nbits + kHeader + kFooter - 1) | ||
return false; // Can't possibly be a valid Inax message. | ||
if (strict && nbits != kInaxBits) | ||
return false; // We expect Inax to be a certain sized message. | ||
|
||
uint64_t data = 0; | ||
uint16_t offset = kStartOffset; | ||
|
||
// Header | ||
if (!matchMark(results->rawbuf[offset++], kInaxHdrMark)) return false; | ||
if (!matchSpace(results->rawbuf[offset++], kInaxHdrSpace)) return false; | ||
// Data | ||
match_result_t data_result = | ||
matchData(&(results->rawbuf[offset]), nbits, kInaxBitMark, | ||
kInaxOneSpace, kInaxBitMark, kInaxZeroSpace); | ||
if (data_result.success == false) return false; | ||
data = data_result.data; | ||
offset += data_result.used; | ||
// Footer | ||
if (!matchMark(results->rawbuf[offset++], kInaxBitMark)) return false; | ||
if (offset < results->rawlen && | ||
!matchAtLeast(results->rawbuf[offset], kInaxMinGap)) | ||
return false; | ||
|
||
// Compliance | ||
|
||
// Success | ||
results->bits = nbits; | ||
results->value = data; | ||
results->decode_type = INAX; | ||
results->command = 0; | ||
results->address = 0; | ||
return true; | ||
} | ||
#endif |
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,119 @@ | ||
// Copyright 2019 crankyoldgit (David Conran) | ||
|
||
#include "IRsend.h" | ||
#include "IRsend_test.h" | ||
#include "IRutils.h" | ||
#include "gtest/gtest.h" | ||
|
||
|
||
// General housekeeping | ||
TEST(TestInax, Housekeeping) { | ||
ASSERT_EQ("INAX", typeToString(INAX)); | ||
ASSERT_FALSE(hasACState(INAX)); | ||
} | ||
|
||
// Tests for sendInax(). | ||
// Test sending typical data only. | ||
TEST(TestSendInax, SendDataOnly) { | ||
IRsendTest irsend(0); | ||
irsend.begin(); | ||
|
||
irsend.reset(); | ||
irsend.sendInax(0x5C32CD); // Small flush. | ||
EXPECT_EQ( | ||
"f38000d50" | ||
"m9000s4500" | ||
"m560s560m560s1675m560s560m560s1675m560s1675m560s1675m560s560m560s560" | ||
"m560s560m560s560m560s1675m560s1675m560s560m560s560m560s1675m560s560" | ||
"m560s1675m560s1675m560s560m560s560m560s1675m560s1675m560s560m560s1675" | ||
"m560s40000" | ||
"m9000s4500" | ||
"m560s560m560s1675m560s560m560s1675m560s1675m560s1675m560s560m560s560" | ||
"m560s560m560s560m560s1675m560s1675m560s560m560s560m560s1675m560s560" | ||
"m560s1675m560s1675m560s560m560s560m560s1675m560s1675m560s560m560s1675" | ||
"m560s40000", | ||
irsend.outputStr()); | ||
|
||
irsend.reset(); | ||
} | ||
|
||
// Test sending with different repeats. | ||
TEST(TestSendInax, SendWithRepeats) { | ||
IRsendTest irsend(0); | ||
irsend.begin(); | ||
|
||
irsend.reset(); | ||
irsend.sendInax(0x5C32CD, kInaxBits, 0); // 0 repeats. | ||
EXPECT_EQ( | ||
"f38000d50" | ||
"m9000s4500" | ||
"m560s560m560s1675m560s560m560s1675m560s1675m560s1675m560s560m560s560" | ||
"m560s560m560s560m560s1675m560s1675m560s560m560s560m560s1675m560s560" | ||
"m560s1675m560s1675m560s560m560s560m560s1675m560s1675m560s560m560s1675" | ||
"m560s40000", | ||
irsend.outputStr()); | ||
irsend.sendInax(0x5C32CD, kInaxBits, 2); // 2 repeats. | ||
EXPECT_EQ( | ||
"f38000d50" | ||
"m9000s4500" | ||
"m560s560m560s1675m560s560m560s1675m560s1675m560s1675m560s560m560s560" | ||
"m560s560m560s560m560s1675m560s1675m560s560m560s560m560s1675m560s560" | ||
"m560s1675m560s1675m560s560m560s560m560s1675m560s1675m560s560m560s1675" | ||
"m560s40000" | ||
"m9000s4500" | ||
"m560s560m560s1675m560s560m560s1675m560s1675m560s1675m560s560m560s560" | ||
"m560s560m560s560m560s1675m560s1675m560s560m560s560m560s1675m560s560" | ||
"m560s1675m560s1675m560s560m560s560m560s1675m560s1675m560s560m560s1675" | ||
"m560s40000" | ||
"m9000s4500" | ||
"m560s560m560s1675m560s560m560s1675m560s1675m560s1675m560s560m560s560" | ||
"m560s560m560s560m560s1675m560s1675m560s560m560s560m560s1675m560s560" | ||
"m560s1675m560s1675m560s560m560s560m560s1675m560s1675m560s560m560s1675" | ||
"m560s40000", | ||
irsend.outputStr()); | ||
} | ||
|
||
// Tests for decodeInax(). | ||
|
||
// Decode normal Inax messages. | ||
TEST(TestDecodeInax, SyntheticDecode) { | ||
IRsendTest irsend(0); | ||
IRrecv irrecv(0); | ||
irsend.begin(); | ||
|
||
// Normal Inax 24-bit message. | ||
irsend.reset(); | ||
irsend.sendInax(0x5C32CD); | ||
irsend.makeDecodeResult(); | ||
ASSERT_TRUE(irrecv.decode(&irsend.capture)); | ||
EXPECT_EQ(INAX, irsend.capture.decode_type); | ||
EXPECT_EQ(kInaxBits, irsend.capture.bits); | ||
EXPECT_EQ(0x5C32CD, irsend.capture.value); | ||
EXPECT_EQ(0, irsend.capture.address); | ||
EXPECT_EQ(0, irsend.capture.command); | ||
} | ||
|
||
// Decode real example via Issue #704 | ||
TEST(TestDecodeInax, DecodeExamples) { | ||
IRsendTest irsend(0); | ||
IRrecv irrecv(0); | ||
irsend.begin(); | ||
|
||
irsend.reset(); | ||
// Inax Small Flush from Issue #309 | ||
uint16_t smallFlushRawData[51] = { | ||
8996, 4474, 568, 556, 560, 1676, 568, 556, 562, 1676, 562, 1678, 566, | ||
1674, 566, 558, 560, 560, 566, 556, 566, 556, 560, 1678, 562, 1676, 566, | ||
556, 562, 560, 564, 1672, 566, 556, 562, 1676, 562, 1678, 562, 560, 564, | ||
558, 564, 1674, 560, 1678, 564, 560, 566, 1670, 562}; | ||
|
||
irsend.sendRaw(smallFlushRawData, 51, 38); | ||
irsend.makeDecodeResult(); | ||
|
||
ASSERT_TRUE(irrecv.decode(&irsend.capture)); | ||
EXPECT_EQ(INAX, irsend.capture.decode_type); | ||
EXPECT_EQ(kInaxBits, irsend.capture.bits); | ||
EXPECT_EQ(0x5C32CD, irsend.capture.value); | ||
EXPECT_EQ(0, irsend.capture.address); | ||
EXPECT_EQ(0, irsend.capture.command); | ||
} |
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