Skip to content

Commit

Permalink
Add support for setting temperature with float value
Browse files Browse the repository at this point in the history
  • Loading branch information
zhixuan2333 committed Feb 19, 2024
1 parent f67948f commit e04a708
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 31 deletions.
12 changes: 12 additions & 0 deletions src/ir_Bosch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ void IRBosch144AC::setTemp(const uint8_t degrees) {
setTempRaw(kBosch144TempMap[temp - kBosch144TempMin]);
}

void IRBosch144AC::setTemp(const float degrees)
{
uint8_t temp = static_cast<uint8_t>(degrees);
setTemp(temp);

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

uint8_t IRBosch144AC::getTemp(void) const {
uint8_t temp = (_.TempS1 << 1) + _.TempS3;
uint8_t retemp = 25;
Expand All @@ -117,6 +125,10 @@ uint8_t IRBosch144AC::getTemp(void) const {
return retemp;
}

float IRBosch144AC::getTempFloat(void) const {
return getTemp() + (_.TempS3 ? 0.5 : 0);
}

/// Set the speed of the fan.
/// @param[in] speed The desired setting.
void IRBosch144AC::setFan(const uint16_t speed) {
Expand Down
66 changes: 35 additions & 31 deletions src/ir_Bosch.h
Original file line number Diff line number Diff line change
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 TempDecimals:1; // Desired temp. Bit in Section3 #
uint8_t :1; // 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 ###########
};
};

Expand All @@ -154,7 +156,9 @@ class IRBosch144AC {
void setPower(const bool state);
bool getPower(void) const;
void setTemp(const uint8_t temp);
void setTemp(const float temp);
uint8_t getTemp(void) const;
float getTempFloat(void) const;
void setFan(const uint16_t speed);
uint16_t getFan(void) const;
void setMode(const uint8_t mode);
Expand Down

0 comments on commit e04a708

Please sign in to comment.