-
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.
Basic support for Voltas A/C protocol (#1243)
* Basic send/decode for the Voltas A/C protocol. * Unit test coverage for above. These are all the changes I made on my end so far, to make the library capable of sending and recognizing the various states (as bytes) of the Voltas protocol. User-friendly functions for sending and decoding are yet to be implemented. Ref #1238 Co-authored-by: David <[email protected]>
- Loading branch information
1 parent
a6cd2ac
commit d64f07b
Showing
10 changed files
with
176 additions
and
2 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,69 @@ | ||
// Copyright 2020 David Conran (crankyoldgit) | ||
// Copyright 2020 manj9501 | ||
/// @file | ||
/// @brief Support for Voltas A/C protocol | ||
/// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1238 | ||
|
||
// Supports: | ||
// Brand: Voltas, Model: 122LZF 4011252 Window A/C | ||
|
||
#include "IRrecv.h" | ||
#include "IRsend.h" | ||
#include "IRutils.h" | ||
|
||
// Constants | ||
const uint16_t kVoltasBitMark = 1026; ///< uSeconds. | ||
const uint16_t kVoltasOneSpace = 2553; ///< uSeconds. | ||
const uint16_t kVoltasZeroSpace = 554; ///< uSeconds. | ||
const uint16_t kVoltasFreq = 38000; ///< Hz. | ||
|
||
#if SEND_VOLTAS | ||
/// Send a Voltas formatted message. | ||
/// Status: ALPHA / Untested. | ||
/// @param[in] data An array of bytes containing the IR command. | ||
/// It is assumed to be in MSB order for this code. | ||
/// e.g. | ||
/// @code | ||
/// uint8_t data[kVoltasStateLength] = {0x33, 0x28, 0x88, 0x1A, 0x3B, 0x3B, | ||
/// 0x3B, 0x11, 0x00, 0x40}; | ||
/// @endcode | ||
/// @param[in] nbytes Nr. of bytes of data in the array. (>=kVoltasStateLength) | ||
/// @param[in] repeat Nr. of times the message is to be repeated. | ||
void IRsend::sendVoltas(const uint8_t data[], const uint16_t nbytes, | ||
const uint16_t repeat) { | ||
sendGeneric(0, 0, | ||
kVoltasBitMark, kVoltasOneSpace, | ||
kVoltasBitMark, kVoltasZeroSpace, | ||
kVoltasBitMark, kDefaultMessageGap, | ||
data, nbytes, | ||
kVoltasFreq, true, repeat, kDutyDefault); | ||
} | ||
#endif // SEND_VOLTAS | ||
|
||
#if DECODE_VOLTAS | ||
/// Decode the supplied Voltas message. | ||
/// Status: ALPHA / Untested. | ||
/// @param[in,out] results Ptr to the data to decode & where to store the decode | ||
/// @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::decodeVoltas(decode_results *results, uint16_t offset, | ||
const uint16_t nbits, const bool strict) { | ||
if (strict && nbits != kVoltasBits) return false; | ||
|
||
// Data + Footer | ||
if (!matchGeneric(results->rawbuf + offset, results->state, | ||
results->rawlen - offset, nbits, | ||
0, 0, // No header | ||
kVoltasBitMark, kVoltasOneSpace, | ||
kVoltasBitMark, kVoltasZeroSpace, | ||
kVoltasBitMark, kDefaultMessageGap, true)) return false; | ||
|
||
// Success | ||
results->decode_type = decode_type_t::VOLTAS; | ||
results->bits = nbits; | ||
return true; | ||
} | ||
#endif // DECODE_VOLTAS |
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,67 @@ | ||
// Copyright 2020 crankyoldgit | ||
|
||
#include "IRac.h" | ||
#include "IRrecv.h" | ||
#include "IRrecv_test.h" | ||
#include "IRsend.h" | ||
#include "IRsend_test.h" | ||
#include "gtest/gtest.h" | ||
|
||
// Tests for decodeVoltas(). | ||
|
||
TEST(TestDecodeVoltas, RealExample) { | ||
IRsendTest irsend(kGpioUnused); | ||
IRrecv irrecv(kGpioUnused); | ||
const uint16_t rawData[161] = { | ||
1002, 584, 1000, 586, 1000, 2568, 1002, 2570, 1002, 586, 998, 588, 1000, | ||
2568, 1002, 2570, 1002, 2572, 1002, 584, 1002, 586, 1000, 584, 1000, 586, | ||
1002, 2568, 1004, 584, 1000, 586, 1002, 2568, 1002, 584, 1002, 584, 1004, | ||
584, 1000, 2568, 1002, 586, 1000, 586, 998, 590, 998, 584, 1002, 584, | ||
1000, 586, 1000, 2570, 1002, 2568, 1004, 584, 1000, 584, 1002, 584, 1002, | ||
582, 1004, 584, 1002, 2568, 1002, 2570, 1004, 2570, 1000, 586, 1002, 2568, | ||
1004, 2568, 1006, 584, 1000, 584, 1002, 2568, 1002, 2570, 1002, 2568, | ||
1002, 586, 1002, 2570, 1000, 2570, 1002, 588, 998, 586, 1000, 2568, 1004, | ||
2568, 1004, 2568, 1002, 588, 998, 2570, 1002, 2568, 1004, 586, 1002, 584, | ||
1000, 586, 1000, 2570, 1000, 586, 1000, 584, 1002, 586, 1000, 2568, 1004, | ||
584, 1000, 586, 1000, 586, 1002, 584, 1002, 586, 1000, 586, 1000, 586, | ||
1000, 586, 1000, 2568, 1002, 2568, 1002, 2568, 1004, 586, 1000, 584, | ||
1000, 2570, 1004, 2568, 1004, 584, 1002}; | ||
const uint8_t expected[kVoltasStateLength] = { | ||
0x33, 0x84, 0x88, 0x18, 0x3B, 0x3B, 0x3B, 0x11, 0x00, 0xE6}; | ||
|
||
irsend.begin(); | ||
irsend.reset(); | ||
irsend.sendRaw(rawData, 161, 38); | ||
irsend.makeDecodeResult(); | ||
|
||
ASSERT_TRUE(irrecv.decode(&irsend.capture)); | ||
ASSERT_EQ(decode_type_t::VOLTAS, irsend.capture.decode_type); | ||
ASSERT_EQ(kVoltasBits, irsend.capture.bits); | ||
EXPECT_STATE_EQ(expected, irsend.capture.state, irsend.capture.bits); | ||
} | ||
|
||
TEST(TestDecodeVoltas, SyntheticExample) { | ||
IRsendTest irsend(kGpioUnused); | ||
IRrecv irrecv(kGpioUnused); | ||
irsend.begin(); | ||
irsend.reset(); | ||
const uint8_t expected[kVoltasStateLength] = { | ||
0x33, 0x84, 0x88, 0x18, 0x3B, 0x3B, 0x3B, 0x11, 0x00, 0xE6}; | ||
// power | ||
irsend.sendVoltas(expected); | ||
irsend.makeDecodeResult(); | ||
|
||
ASSERT_TRUE(irrecv.decode(&irsend.capture)); | ||
EXPECT_EQ(decode_type_t::VOLTAS, irsend.capture.decode_type); | ||
EXPECT_EQ(kVoltasBits, irsend.capture.bits); | ||
EXPECT_STATE_EQ(expected, irsend.capture.state, irsend.capture.bits); | ||
} | ||
|
||
TEST(TestUtils, Housekeeping) { | ||
ASSERT_EQ("VOLTAS", typeToString(decode_type_t::VOLTAS)); | ||
ASSERT_EQ(decode_type_t::VOLTAS, strToDecodeType("VOLTAS")); | ||
ASSERT_TRUE(hasACState(decode_type_t::VOLTAS)); | ||
ASSERT_FALSE(IRac::isProtocolSupported(decode_type_t::VOLTAS)); | ||
ASSERT_EQ(kVoltasBits, IRsend::defaultBits(decode_type_t::VOLTAS)); | ||
ASSERT_EQ(kNoRepeat, IRsend::minRepeats(decode_type_t::VOLTAS)); | ||
} |