Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add support for Bosch with temperature float value #2068

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/ir_Bosch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,28 @@ void IRBosch144AC::setTempRaw(const uint8_t code) {
_.TempS3 = code & 1; // save 1 bit in Section3
}

/// Set the temperature.
/// Set the temperature. Allow 0.5 degree steps.
/// @param[in] degrees The temperature in degrees celsius.
void IRBosch144AC::setTemp(const uint8_t degrees) {
uint8_t temp = max(kBosch144TempMin, degrees);
void IRBosch144AC::setTemp(const float degrees) {
zhixuan2333 marked this conversation as resolved.
Show resolved Hide resolved
uint8_t temp = static_cast<uint8_t>(degrees);
temp = max(kBosch144TempMin, temp);
temp = min(kBosch144TempMax, temp);
setTempRaw(kBosch144TempMap[temp - kBosch144TempMin]);

_.TempHalfDegree = (degrees - temp) >= 0.5;
}

uint8_t IRBosch144AC::getTemp(void) const {
/// Get the temperature with 0.5 degree steps.
/// @return The temperature in degrees celsius.
float IRBosch144AC::getTemp(void) const {
uint8_t temp = (_.TempS1 << 1) + _.TempS3;
uint8_t retemp = 25;
for (uint8_t i = 0; i < kBosch144TempRange; i++) {
if (temp == kBosch144TempMap[i]) {
retemp = kBosch144TempMin + i;
}
}
return retemp;
return static_cast<float>(retemp) + (_.TempHalfDegree ? 0.5f : 0.0f);
}

/// Set the speed of the fan.
Expand Down Expand Up @@ -260,7 +265,7 @@ String IRBosch144AC::toString(void) const {
static_cast<int>(stdAc::fanspeed_t::kAuto),
static_cast<int>(stdAc::fanspeed_t::kAuto),
static_cast<int>(stdAc::fanspeed_t::kMedium));
result += addTempToString(getTemp());
zhixuan2333 marked this conversation as resolved.
Show resolved Hide resolved
result += addTempFloatToString(getTemp());
result += addBoolToString(_.Quiet, kQuietStr);
return result;
}
Expand Down
70 changes: 36 additions & 34 deletions src/ir_Bosch.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const uint16_t kBosch144BytesPerSection = 6;
using irutils::addBoolToString;
using irutils::addModeToString;
using irutils::addFanToString;
using irutils::addTempToString;
using irutils::addTempFloatToString;
using std::min;
using std::max;
using std::memcpy;
Expand Down Expand Up @@ -100,37 +100,39 @@ const uint8_t kBosch144DefaultState[kBosch144StateLength] = {
union Bosch144Protocol {
uint8_t raw[kBosch144StateLength]; ///< The state in IR code form.
struct {
uint8_t :8; // Fixed value 0b10110010 / 0xB2. ############
uint8_t InnvertS1_1:8; // Invert byte 0b01001101 / 0x4D #
uint8_t :5; // not used (without timer use) #
uint8_t FanS1 :3; // Fan speed bits in Section 1 #
uint8_t InnvertS1_2:8; // Invert byte # Section 1 =
uint8_t :2; // not used (without timer use) # Sektion 2
uint8_t ModeS1 :2; // Operation mode bits S1 #
uint8_t TempS1 :4; // Desired temperature (Celsius) S2 #
uint8_t InnvertS1_3:8; // Invert byte (without timer use) ############

uint8_t :8; // Fixed value 0b10110010 / 0xB2. ############
uint8_t InnvertS2_1:8; // Invert byte 0b01001101 / 0x4D #
uint8_t :5; // not used (without timer use) #
uint8_t FanS2 :3; // Fan speed bits in Section 2 #
uint8_t InnvertS2_2:8; // Invert byte # Section 2 =
uint8_t :2; // not used (without timer use) # Sektion 1
uint8_t ModeS2 :2; // Operation mode bits S2 #
uint8_t TempS2 :4; // Desired temperature (Celsius) S2 #
uint8_t InnvertS2_3:8; // Invert byte (without timer use) ###########

uint8_t :8; // Fixed value 0b11010101 / 0xD5 ###########
uint8_t ModeS3 :1; // ModeBit in Section 3 #
uint8_t FanS3 :6; // Fan speed bits in Section 3 #
uint8_t :1; // Unknown #
uint8_t :7; // Unknown #
uint8_t Quiet :1; // Silent-Mode # Section 3
uint8_t :4; // Unknown #
uint8_t TempS3 :1; // Desired temp. Bit in Section3 #
uint8_t :3; // Unknown #
uint8_t :8; // Unknown #
uint8_t ChecksumS3 :8; // Checksum from byte 13-17 ###########
uint8_t :8; // Fixed value 0b10110010 / 0xB2. ##########
uint8_t InnvertS1_1 :8; // Invert byte 0b01001101 / 0x4D #
uint8_t :5; // not used (without timer use) #
uint8_t FanS1 :3; // Fan speed bits in Section 1 #
uint8_t InnvertS1_2 :8; // Invert byte # Section 1 =
uint8_t :2; // not used (without timer use) # Sektion 2
uint8_t ModeS1 :2; // Operation mode bits S1 #
uint8_t TempS1 :4; // Desired temperature (Celsius) S2 #
uint8_t InnvertS1_3 :8; // Invert byte (without timer use) ##########

uint8_t :8; // Fixed value 0b10110010 / 0xB2. ##########
uint8_t InnvertS2_1 :8; // Invert byte 0b01001101 / 0x4D #
uint8_t :5; // not used (without timer use) #
uint8_t FanS2 :3; // Fan speed bits in Section 2 #
uint8_t InnvertS2_2 :8; // Invert byte # Section 2 =
uint8_t :2; // not used (without timer use) # Sektion 1
uint8_t ModeS2 :2; // Operation mode bits S2 #
uint8_t TempS2 :4; // Desired temperature (Celsius) S2 #
uint8_t InnvertS2_3 :8; // Invert byte (without timer use) ##########

uint8_t :8; // Fixed value 0b11010101 / 0xD5 ##########
uint8_t ModeS3 :1; // ModeBit in Section 3 #
uint8_t FanS3 :6; // Fan speed bits in Section 3 #
uint8_t :1; // Unknown #
uint8_t :5; // Unknown #
uint8_t TempHalfDegree:1; // Desired temp. Half degree bit #
uint8_t :1; // Unknown # Section 3
uint8_t Quiet :1; // Silent-Mode #
uint8_t :4; // Unknown #
uint8_t TempS3 :1; // Desired temp. Bit in Section3 #
uint8_t :3; // Unknown #
uint8_t :8; // Unknown #
uint8_t ChecksumS3 :8; // Checksum from byte 13-17 ##########
};
};

Expand All @@ -153,8 +155,8 @@ class IRBosch144AC {
void begin();
void setPower(const bool state);
bool getPower(void) const;
void setTemp(const uint8_t temp);
uint8_t getTemp(void) const;
void setTemp(const float temp);
float getTemp(void) const;
void setFan(const uint16_t speed);
uint16_t getFan(void) const;
void setMode(const uint8_t mode);
Expand Down
Loading