1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-01 08:18:16 +00:00

Move comments into the header

This commit is contained in:
Georgi Filipov 2025-01-02 22:23:54 +02:00
parent 859e80e864
commit dc9e4638dc
2 changed files with 27 additions and 29 deletions

View File

@ -26,7 +26,6 @@ void SamsungClimate::transmit_state() {
send_(); send_();
} }
/// Send the current state of the climate object.
void SamsungClimate::send_() { void SamsungClimate::send_() {
checksum_(); checksum_();
@ -64,7 +63,6 @@ void SamsungClimate::send_() {
transmit.perform(); transmit.perform();
} }
/// Set the vertical swing setting of the A/C.
void SamsungClimate::set_swing_(const climate::ClimateSwingMode swing_mode) { void SamsungClimate::set_swing_(const climate::ClimateSwingMode swing_mode) {
switch (swing_mode) { switch (swing_mode) {
case climate::ClimateSwingMode::CLIMATE_SWING_BOTH: case climate::ClimateSwingMode::CLIMATE_SWING_BOTH:
@ -83,8 +81,6 @@ void SamsungClimate::set_swing_(const climate::ClimateSwingMode swing_mode) {
} }
} }
/// Set the operating mode of the A/C.
/// @param[in] climateMode The desired operating mode.
void SamsungClimate::set_mode_(const climate::ClimateMode climate_mode) { void SamsungClimate::set_mode_(const climate::ClimateMode climate_mode) {
switch (climate_mode) { switch (climate_mode) {
case climate::ClimateMode::CLIMATE_MODE_HEAT: case climate::ClimateMode::CLIMATE_MODE_HEAT:
@ -107,14 +103,10 @@ void SamsungClimate::set_mode_(const climate::ClimateMode climate_mode) {
} }
} }
/// Set the temperature.
/// @param[in] temp The temperature in degrees celsius.
void SamsungClimate::set_temp_(const uint8_t temp) { void SamsungClimate::set_temp_(const uint8_t temp) {
protocol_.Temp = esphome::clamp<uint8_t>(temp, K_SAMSUNG_AC_MIN_TEMP, K_SAMSUNG_AC_MAX_TEMP); protocol_.Temp = esphome::clamp<uint8_t>(temp, K_SAMSUNG_AC_MIN_TEMP, K_SAMSUNG_AC_MAX_TEMP);
} }
/// Change the AC power state.
/// @param[in] on true, the AC is on. false, the AC is off.
void SamsungClimate::send_power_state_(const bool on) { void SamsungClimate::send_power_state_(const bool on) {
static const uint8_t K_ON[K_SAMSUNG_AC_EXTENDED_STATE_LENGTH] = {0x02, 0x92, 0x0F, 0x00, 0x00, 0x00, 0xF0, static const uint8_t K_ON[K_SAMSUNG_AC_EXTENDED_STATE_LENGTH] = {0x02, 0x92, 0x0F, 0x00, 0x00, 0x00, 0xF0,
0x01, 0xD2, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0xD2, 0x0F, 0x00, 0x00, 0x00, 0x00,
@ -131,7 +123,6 @@ void SamsungClimate::send_power_state_(const bool on) {
std::memcpy(protocol_.raw, K_RESET, K_SAMSUNG_AC_EXTENDED_STATE_LENGTH); std::memcpy(protocol_.raw, K_RESET, K_SAMSUNG_AC_EXTENDED_STATE_LENGTH);
} }
/// Set the fan speed.
void SamsungClimate::set_fan_(const climate::ClimateFanMode fan_mode) { void SamsungClimate::set_fan_(const climate::ClimateFanMode fan_mode) {
switch (fan_mode) { switch (fan_mode) {
case climate::ClimateFanMode::CLIMATE_FAN_LOW: case climate::ClimateFanMode::CLIMATE_FAN_LOW:
@ -150,10 +141,6 @@ void SamsungClimate::set_fan_(const climate::ClimateFanMode fan_mode) {
} }
} }
/// Calculate the checksum_ for a given state section.
/// @param[in] section The array to calc the checksum_ of.
/// @return The calculated checksum_ value.
/// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1538#issuecomment-894645947
uint8_t SamsungClimate::calc_section_checksum(const uint8_t *section) { uint8_t SamsungClimate::calc_section_checksum(const uint8_t *section) {
uint8_t sum = 0; uint8_t sum = 0;
@ -168,7 +155,6 @@ uint8_t SamsungClimate::calc_section_checksum(const uint8_t *section) {
return sum ^ UINT8_MAX; return sum ^ UINT8_MAX;
} }
/// Update the checksum_ for the internal state.
void SamsungClimate::checksum_() { void SamsungClimate::checksum_() {
uint8_t sectionsum = calc_section_checksum(protocol_.raw); uint8_t sectionsum = calc_section_checksum(protocol_.raw);
protocol_.Sum1Upper = GETBITS8(sectionsum, K_HIGH_NIBBLE, K_NIBBLE_SIZE); protocol_.Sum1Upper = GETBITS8(sectionsum, K_HIGH_NIBBLE, K_NIBBLE_SIZE);
@ -181,12 +167,6 @@ void SamsungClimate::checksum_() {
protocol_.Sum3Lower = GETBITS8(sectionsum, K_LOW_NIBBLE, K_NIBBLE_SIZE); protocol_.Sum3Lower = GETBITS8(sectionsum, K_LOW_NIBBLE, K_NIBBLE_SIZE);
} }
/// Count the number of bits of a certain type in an array.
/// @param[in] start A ptr to the start of the byte array to calculate over.
/// @param[in] length How many bytes to use in the calculation.
/// @param[in] ones Count the binary nr of `1` bits. False is count the `0`s.
/// @param[in] init Starting value of the calculation to use. (Default is 0)
/// @return The nr. of bits found of the given type found in the array.
uint16_t SamsungClimate::count_bits(const uint8_t *const start, const uint16_t length, const bool ones, uint16_t SamsungClimate::count_bits(const uint8_t *const start, const uint16_t length, const bool ones,
const uint16_t init) { const uint16_t init) {
uint16_t count = init; uint16_t count = init;
@ -205,12 +185,6 @@ uint16_t SamsungClimate::count_bits(const uint8_t *const start, const uint16_t l
} }
} }
/// Count the number of bits of a certain type in an Integer.
/// @param[in] data The value you want bits counted for. Starting from the LSB.
/// @param[in] length How many bits to use in the calculation? Starts at the LSB
/// @param[in] ones Count the binary nr of `1` bits. False is count the `0`s.
/// @param[in] init Starting value of the calculation to use. (Default is 0)
/// @return The nr. of bits found of the given type found in the Integer.
uint16_t SamsungClimate::count_bits(const uint64_t data, const uint8_t length, const bool ones, const uint16_t init) { uint16_t SamsungClimate::count_bits(const uint64_t data, const uint8_t length, const bool ones, const uint16_t init) {
uint16_t count = init; uint16_t count = init;
uint8_t bits_so_far = length; uint8_t bits_so_far = length;

View File

@ -184,21 +184,45 @@ class SamsungClimate : public climate_ir::ClimateIR {
climate::CLIMATE_SWING_HORIZONTAL, climate::CLIMATE_SWING_BOTH}) {} climate::CLIMATE_SWING_HORIZONTAL, climate::CLIMATE_SWING_BOTH}) {}
protected: protected:
// Transmit via IR the state of this climate controller /// Transmit via IR the state of this climate controller
void transmit_state() override; void transmit_state() override;
/// Send the current state of the climate object.
void send_(); void send_();
/// Change the AC power state.
/// @param[in] on true, the AC is on. false, the AC is off.
void send_power_state_(bool on); void send_power_state_(bool on);
/// Set the swing setting of the A/C.
void set_swing_(climate::ClimateSwingMode swing_mode); void set_swing_(climate::ClimateSwingMode swing_mode);
/// Set the operating mode of the A/C.
/// @param[in] climate_mode The desired operating mode.
void set_mode_(climate::ClimateMode climate_mode); void set_mode_(climate::ClimateMode climate_mode);
/// Set the temperature.
/// @param[in] temp The temperature in degrees celsius.
void set_temp_(uint8_t temp); void set_temp_(uint8_t temp);
/// Set the fan speed.
void set_fan_(climate::ClimateFanMode fan_mode); void set_fan_(climate::ClimateFanMode fan_mode);
/// Update the checksum_ for the internal state.
void checksum_(); void checksum_();
/// Calculate the checksum_ for a given state section.
/// @param[in] section The array to calc the checksum_ of.
/// @return The calculated checksum_ value.
/// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1538#issuecomment-894645947
static uint8_t calc_section_checksum(const uint8_t *section); static uint8_t calc_section_checksum(const uint8_t *section);
/// Count the number of bits of a certain type in an array.
/// @param[in] start A ptr to the start of the byte array to calculate over.
/// @param[in] length How many bytes to use in the calculation.
/// @param[in] ones Count the binary nr of `1` bits. False is count the `0`s.
/// @param[in] init Starting value of the calculation to use. (Default is 0)
/// @return The nr. of bits found of the given type found in the array.
static uint16_t count_bits(const uint8_t *start, uint16_t length, bool ones = true, uint16_t init = 0); static uint16_t count_bits(const uint8_t *start, uint16_t length, bool ones = true, uint16_t init = 0);
/// Count the number of bits of a certain type in an Integer.
/// @param[in] data The value you want bits counted for. Starting from the LSB.
/// @param[in] length How many bits to use in the calculation? Starts at the LSB
/// @param[in] ones Count the binary nr of `1` bits. False is count the `0`s.
/// @param[in] init Starting value of the calculation to use. (Default is 0)
/// @return The nr. of bits found of the given type found in the Integer.
static uint16_t count_bits(uint64_t data, uint8_t length, bool ones = true, uint16_t init = 0); static uint16_t count_bits(uint64_t data, uint8_t length, bool ones = true, uint16_t init = 0);
}; };
;
} // namespace samsung } // namespace samsung
} // namespace esphome } // namespace esphome