Skip to content

Commit

Permalink
Coolix: Increase Sensor Temp precission to 5 bits.
Browse files Browse the repository at this point in the history
* Allow 5 bits of Sensor Temp data. e.g. 0-30degC

For #1813
  • Loading branch information
crankyoldgit committed Nov 18, 2020
1 parent f5d8bf7 commit a2d18df
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
15 changes: 5 additions & 10 deletions src/ir_Coolix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,20 +239,15 @@ uint8_t IRCoolixAC::getTemp(void) const {
void IRCoolixAC::setSensorTempRaw(const uint8_t code) { _.SensorTemp = code; }

/// Set the sensor temperature.
/// @param[in] desired The temperature in degrees celsius.
void IRCoolixAC::setSensorTemp(const uint8_t desired) {
uint8_t temp = desired;
temp = std::min(temp, kCoolixSensorTempMax);
temp = std::max(temp, kCoolixSensorTempMin);
setSensorTempRaw(temp - kCoolixSensorTempMin);
/// @param[in] temp The temperature in degrees celsius.
void IRCoolixAC::setSensorTemp(const uint8_t temp) {
setSensorTempRaw(std::min(temp, kCoolixSensorTempMax));
setZoneFollow(true); // Setting a Sensor temp means you want to Zone Follow.
}

/// Get the sensor temperature setting.
/// @return The current setting for sensor temp. in degrees celsius.
uint8_t IRCoolixAC::getSensorTemp(void) const {
return _.SensorTemp + kCoolixSensorTempMin;
}
uint8_t IRCoolixAC::getSensorTemp(void) const { return _.SensorTemp; }

/// Get the value of the current power setting.
/// @return true, the setting is on. false, the setting is off.
Expand Down Expand Up @@ -608,7 +603,7 @@ String IRCoolixAC::toString(void) const {
if (getMode() != kCoolixFan) result += addTempToString(getTemp());
result += addBoolToString(getZoneFollow(), kZoneFollowStr);
result += addLabeledString(
(getSensorTemp() > kCoolixSensorTempMax)
(getSensorTemp() == kCoolixSensorTempIgnoreCode)
? kOffStr : uint64ToString(getSensorTemp()) + 'C', kSensorTempStr);
return result;
}
Expand Down
8 changes: 3 additions & 5 deletions src/ir_Coolix.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ const uint8_t kCoolixTempMap[kCoolixTempRange] = {
0b1010, // 29C
0b1011 // 30C
};
const uint8_t kCoolixSensorTempMin = 16; // Celsius
const uint8_t kCoolixSensorTempMax = 30; // Celsius
const uint8_t kCoolixSensorTempIgnoreCode = 0b1111;
const uint8_t kCoolixSensorTempIgnoreCode = 0b11111; // 0x1F / 31 (DEC)
// kCoolixSensorTempMask = 0b000000000000111100000000; // 0xF00
// Fixed states/messages.
const uint32_t kCoolixOff = 0b101100100111101111100000; // 0xB27BE0
Expand All @@ -97,8 +96,7 @@ union CoolixProtocol {
uint32_t Mode :2; ///< Operation mode.
uint32_t Temp :4; ///< Desired temperature (Celsius)
// Byte
uint32_t SensorTemp :4; ///< The temperature sensor in the IR remote.
uint32_t :1; // Probably part of Sensor Temp.
uint32_t SensorTemp :5; ///< The temperature sensor in the IR remote.
uint32_t Fan :3; ///< Fan speed
// Byte
uint32_t :3; // Unknown
Expand Down Expand Up @@ -131,7 +129,7 @@ class IRCoolixAC {
bool getPower(void) const;
void setTemp(const uint8_t temp);
uint8_t getTemp(void) const;
void setSensorTemp(const uint8_t desired);
void setSensorTemp(const uint8_t temp);
uint8_t getSensorTemp(void) const;
void clearSensorTemp(void);
void setFan(const uint8_t speed, const bool modecheck = true);
Expand Down
10 changes: 4 additions & 6 deletions test/ir_Coolix_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,19 +444,17 @@ TEST(TestCoolixACClass, SetGetClearSensorTempAndZoneFollow) {

ircoolix.setRaw(kCoolixDefaultState);
EXPECT_FALSE(ircoolix.getZoneFollow());
EXPECT_LT(kCoolixSensorTempMax, ircoolix.getSensorTemp());
EXPECT_LE(kCoolixSensorTempMax, ircoolix.getSensorTemp());

ircoolix.setSensorTemp(25);
EXPECT_TRUE(ircoolix.getZoneFollow());
EXPECT_EQ(25, ircoolix.getSensorTemp());

// Lower bounds
ircoolix.setSensorTemp(kCoolixSensorTempMin);
EXPECT_TRUE(ircoolix.getZoneFollow());
EXPECT_EQ(kCoolixSensorTempMin, ircoolix.getSensorTemp());
ircoolix.setSensorTemp(kCoolixSensorTempMin - 1);
ircoolix.setSensorTemp(0);
EXPECT_TRUE(ircoolix.getZoneFollow());
EXPECT_EQ(kCoolixSensorTempMin, ircoolix.getSensorTemp());
EXPECT_EQ(0, ircoolix.getSensorTemp());

// Upper bounds
ircoolix.setSensorTemp(kCoolixSensorTempMax);
EXPECT_TRUE(ircoolix.getZoneFollow());
Expand Down

0 comments on commit a2d18df

Please sign in to comment.