Skip to content

Commit

Permalink
Trotec3550: Add Fahrenheit support
Browse files Browse the repository at this point in the history
* Add proper support for DegC and DegF
* Update `sendTrotec3550()` to STABLE.

For #1536
  • Loading branch information
crankyoldgit committed Aug 14, 2021
1 parent 104cbbe commit 59ef809
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
23 changes: 17 additions & 6 deletions src/ir_Trotec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ bool IRrecv::decodeTrotec(decode_results *results, uint16_t offset,

#if SEND_TROTEC_3550
/// Send a Trotec 3550 message.
/// Status: BETA / Probably works. Untested on real device.
/// Status: STABLE / Known to be working.
/// @param[in] data The message to be sent.
/// @param[in] nbytes The number of bytes of message to be sent.
/// @param[in] repeat The number of times the command is to be repeated.
Expand Down Expand Up @@ -491,21 +491,32 @@ uint8_t IRTrotec3550::getMode(void) const { return _.Mode; }
/// Set the temperature.
/// @param[in] degrees The temperature in degrees.
/// @param[in] celsius Use celsius units. True, Celsius; False Fahrenheit.
/// @note Fahrenheit is not yet supported. Waiting on data analysis.
void IRTrotec3550::setTemp(const uint8_t degrees, const bool celsius) {
setTempUnit(celsius);
uint8_t minTemp = kTrotec3550MinTempC;
uint8_t maxTemp = kTrotec3550MaxTempC;
if (!celsius) { // Fahrenheit?
minTemp = kTrotec3550MinTempF;
maxTemp = kTrotec3550MaxTempF;
}
uint8_t temp = std::max(degrees, minTemp);
temp = std::min(temp, maxTemp);
_.Temp = _.Temp2 = temp - minTemp;
if (celsius) {
_.TempC = temp - minTemp;
_.TempF = celsiusToFahrenheit(temp) - kTrotec3550MinTempF;
} else {
_.TempF = temp - minTemp;
_.TempC = fahrenheitToCelsius(temp) - kTrotec3550MinTempC;
}
}

/// Get the current temperature setting.
/// @return The current setting for temp. in degrees.
/// @note Fahrenheit is not yet supported. Waiting on data analysis.
uint8_t IRTrotec3550::getTemp(void) const {
return _.Temp + kTrotec3550MinTempC;
if (getTempUnit()) // Is Celsius?
return _.TempC + kTrotec3550MinTempC;
else
return _.TempF + kTrotec3550MinTempF;
}

/// Set the temperature unit that the A/C will use..
Expand Down Expand Up @@ -582,7 +593,7 @@ stdAc::state_t IRTrotec3550::toCommon(void) const {
result.protocol = decode_type_t::TROTEC_3550;
result.power = _.Power;
result.mode = toCommonMode(_.Mode);
result.celsius = _.Celsius;
result.celsius = getTempUnit();
result.degrees = getTemp();
result.fanspeed = toCommonFanSpeed(_.Fan);
result.swingv = _.SwingV ? stdAc::swingv_t::kAuto : stdAc::swingv_t::kOff;
Expand Down
8 changes: 4 additions & 4 deletions src/ir_Trotec.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ union Trotec3550Protocol{
uint8_t Power :1;
uint8_t :1; // Unknown
uint8_t TimerSet :1;
uint8_t Temp :4; // Temp +16 for degC)
uint8_t TempC :4; // Temp + kTrotec3550MinTempC for degC)
// Byte 2
uint8_t :8; // Unknown
// Byte 3
uint8_t :1; // Unknown
uint8_t Temp2 :4; // Temp +16 for degC)
uint8_t TempF :5; // Temp + kTrotec3550MinTempF for degF)
uint8_t :3; // Unknown
// Byte 4
uint8_t :8; // Unknown
Expand All @@ -111,8 +110,9 @@ union Trotec3550Protocol{
};

const uint8_t kTrotec3550MinTempC = 16;
const uint8_t kTrotec3550DefTempC = 25;
const uint8_t kTrotec3550MaxTempC = 30;
const uint8_t kTrotec3550MinTempF = 59;
const uint8_t kTrotec3550MaxTempF = 86;

// Legacy defines. (Deprecated)
#define TROTEC_AUTO kTrotecAuto
Expand Down
22 changes: 22 additions & 0 deletions test/ir_Trotec_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,10 @@ TEST(TestTrotec3550Class, SetAndGetFan) {
TEST(TestTrotec3550Class, SetAndGetTemp) {
IRTrotec3550 ac(kGpioUnused);

// Celsius
ac.setTemp(25);
EXPECT_EQ(25, ac.getTemp());
EXPECT_TRUE(ac.getTempUnit());
ac.setTemp(kTrotec3550MinTempC);
EXPECT_EQ(kTrotec3550MinTempC, ac.getTemp());
ac.setTemp(kTrotec3550MaxTempC);
Expand All @@ -290,6 +292,26 @@ TEST(TestTrotec3550Class, SetAndGetTemp) {
EXPECT_EQ(kTrotec3550MinTempC, ac.getTemp());
ac.setTemp(kTrotec3550MaxTempC + 1);
EXPECT_EQ(kTrotec3550MaxTempC, ac.getTemp());
// Fahrenheit
ac.setTemp(72, false);
EXPECT_EQ(72, ac.getTemp());
EXPECT_FALSE(ac.getTempUnit());
ac.setTemp(kTrotec3550MinTempF, false);
EXPECT_EQ(kTrotec3550MinTempF, ac.getTemp());
ac.setTemp(kTrotec3550MaxTempF, false);
EXPECT_EQ(kTrotec3550MaxTempF, ac.getTemp());
ac.setTemp(kTrotec3550MinTempF - 1, false);
EXPECT_EQ(kTrotec3550MinTempF, ac.getTemp());
ac.setTemp(kTrotec3550MaxTempF + 1, false);
EXPECT_EQ(kTrotec3550MaxTempF, ac.getTemp());
// Celsius
ac.setTemp(25, true);
EXPECT_EQ(25, ac.getTemp());
EXPECT_TRUE(ac.getTempUnit());
uint8_t deg79F[9] = {0x55, 0xA3, 0x00, 0x14, 0x00, 0x00, 0x31, 0x40, 0x7D};
ac.setRaw(deg79F);
EXPECT_FALSE(ac.getTempUnit()); // Fahrenheit
EXPECT_EQ(79, ac.getTemp());
}

TEST(TestTrotec3550Class, SwingV) {
Expand Down

0 comments on commit 59ef809

Please sign in to comment.