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

Improve code quality

This commit is contained in:
Georgi Filipov 2024-12-24 01:46:55 +02:00
parent 227667fc5e
commit b69a124780
2 changed files with 16 additions and 14 deletions

View File

@ -19,13 +19,13 @@ namespace climate_ir_samsung {
setTemp(this->target_temperature);
setSwing(this->swing_mode);
setFan(this->fan_mode.has_value() ? this->fan_mode.value() : climate::CLIMATE_FAN_AUTO);
send();
}
/// Send the current state of the climate object.
void SamsungClimateIR::send() {
checksum();
auto transmit = this->transmitter_->transmit();
@ -139,7 +139,7 @@ namespace climate_ir_samsung {
0x02, 0xB2, 0x0F, 0x00, 0x00, 0x00, 0xC0,
0x01, 0xD2, 0x0F, 0x00, 0x00, 0x00, 0x00,
0x01, 0x02, 0xFF, 0x71, 0x80, 0x11, 0xC0};
std::memcpy(protocol.raw, on ? kOn : kOff, kSamsungAcExtendedStateLength);
send();
@ -205,7 +205,7 @@ namespace climate_ir_samsung {
/// @return The nr. of bits found of the given type found in the array.
uint16_t SamsungClimateIR::countBits(const uint8_t * const start, const uint16_t length, const bool ones, const uint16_t init) {
uint16_t count = init;
for (uint16_t offset = 0; offset < length; offset++)
for (uint8_t currentbyte = *(start + offset); currentbyte; currentbyte >>= 1)
if (currentbyte & 1) count++;
@ -225,7 +225,7 @@ namespace climate_ir_samsung {
uint16_t SamsungClimateIR::countBits(const uint64_t data, const uint8_t length, const bool ones, const uint16_t init) {
uint16_t count = init;
uint8_t bitsSoFar = length;
for (uint64_t remainder = data; remainder && bitsSoFar; remainder >>= 1, bitsSoFar--)
if (remainder & 1) count++;

View File

@ -3,20 +3,22 @@
#include "esphome/components/climate/climate_mode.h"
#include "esphome/components/climate_ir/climate_ir.h"
#define SAMSUNG_AIRCON1_HDR_MARK 3000
#define SAMSUNG_AIRCON1_HDR_SPACE 9000
#define SAMSUNG_AIRCON1_BIT_MARK 500
#define SAMSUNG_AIRCON1_ONE_SPACE 1500
#define SAMSUNG_AIRCON1_ZERO_SPACE 500
#define SAMSUNG_AIRCON1_MSG_SPACE 2000
#define GETBITS8(data, offset, size) \
(((data) & (((uint8_t)UINT8_MAX >> (8 - (size))) << (offset))) >> (offset))
namespace esphome {
namespace climate_ir_samsung {
#define GETBITS8(data, offset, size) \
(((data) & (((uint8_t)UINT8_MAX >> (8 - (size))) << (offset))) >> (offset))
static const char *const TAG = "samsung.climate";
static const uint32_t SAMSUNG_IR_FREQUENCY = 38000;
static const int SAMSUNG_AIRCON1_HDR_MARK = 3000;
static const int SAMSUNG_AIRCON1_HDR_SPACE = 9000;
static const int SAMSUNG_AIRCON1_BIT_MARK = 500;
static const int SAMSUNG_AIRCON1_ONE_SPACE = 1500;
static const int SAMSUNG_AIRCON1_ZERO_SPACE = 500;
static const int SAMSUNG_AIRCON1_MSG_SPACE = 2000;
const uint16_t kSamsungAcExtendedStateLength = 21;
const uint16_t kSamsungAcSectionLength = 7;
@ -204,4 +206,4 @@ namespace climate_ir_samsung {
static uint16_t countBits(const uint8_t * const start, const uint16_t length, const bool ones = true, const uint16_t init = 0);
static uint16_t countBits(const uint64_t data, const uint8_t length, const bool ones = true, const uint16_t init = 0);
};
}}
}}