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

Format files with clang-format

This commit is contained in:
Georgi Filipov 2024-12-24 02:12:12 +02:00
parent ccb754c56a
commit 534d4822a0
3 changed files with 390 additions and 393 deletions

View File

@ -11,9 +11,7 @@ samsung_ns = cg.esphome_ns.namespace("climate_ir_samsung")
SamsungClimateIR = samsung_ns.class_("SamsungClimateIR", climate_ir.ClimateIR) SamsungClimateIR = samsung_ns.class_("SamsungClimateIR", climate_ir.ClimateIR)
CONFIG_SCHEMA = climate_ir.CLIMATE_IR_WITH_RECEIVER_SCHEMA.extend( CONFIG_SCHEMA = climate_ir.CLIMATE_IR_WITH_RECEIVER_SCHEMA.extend(
{ {cv.GenerateID(): cv.declare_id(SamsungClimateIR)}
cv.GenerateID(): cv.declare_id(SamsungClimateIR)
}
) )

View File

@ -4,12 +4,14 @@ namespace esphome {
namespace climate_ir_samsung { namespace climate_ir_samsung {
void SamsungClimateIR::transmit_state() { void SamsungClimateIR::transmit_state() {
if(current_climate_mode != climate::ClimateMode::CLIMATE_MODE_OFF && this->mode == climate::ClimateMode::CLIMATE_MODE_OFF) { if (current_climate_mode != climate::ClimateMode::CLIMATE_MODE_OFF &&
this->mode == climate::ClimateMode::CLIMATE_MODE_OFF) {
setAndSendPowerState(false); setAndSendPowerState(false);
return; return;
} }
if(current_climate_mode == climate::ClimateMode::CLIMATE_MODE_OFF && this->mode != climate::ClimateMode::CLIMATE_MODE_OFF) { if (current_climate_mode == climate::ClimateMode::CLIMATE_MODE_OFF &&
this->mode != climate::ClimateMode::CLIMATE_MODE_OFF) {
setAndSendPowerState(true); setAndSendPowerState(true);
} }
@ -25,7 +27,6 @@ namespace climate_ir_samsung {
/// Send the current state of the climate object. /// Send the current state of the climate object.
void SamsungClimateIR::send() { void SamsungClimateIR::send() {
checksum(); checksum();
auto transmit = this->transmitter_->transmit(); auto transmit = this->transmitter_->transmit();
@ -36,11 +37,8 @@ namespace climate_ir_samsung {
data->mark(SAMSUNG_AIRCON1_HDR_MARK); data->mark(SAMSUNG_AIRCON1_HDR_MARK);
data->space(SAMSUNG_AIRCON1_HDR_SPACE); data->space(SAMSUNG_AIRCON1_HDR_SPACE);
for (int i = 0; i < 21; i++) for (int i = 0; i < 21; i++) {
{ if (i == 7 || i == 14) {
if (i == 7 || i == 14)
{
data->mark(SAMSUNG_AIRCON1_BIT_MARK); data->mark(SAMSUNG_AIRCON1_BIT_MARK);
data->space(SAMSUNG_AIRCON1_MSG_SPACE); data->space(SAMSUNG_AIRCON1_MSG_SPACE);
@ -50,16 +48,12 @@ namespace climate_ir_samsung {
uint8_t sendByte = protocol.raw[i]; uint8_t sendByte = protocol.raw[i];
for (int y = 0; y < 8; y++) for (int y = 0; y < 8; y++) {
{ if (sendByte & 0x01) {
if (sendByte & 0x01)
{
// ESP_LOGI(TAG, "For Y %d 1", y); // ESP_LOGI(TAG, "For Y %d 1", y);
data->mark(SAMSUNG_AIRCON1_BIT_MARK); data->mark(SAMSUNG_AIRCON1_BIT_MARK);
data->space(SAMSUNG_AIRCON1_ONE_SPACE); data->space(SAMSUNG_AIRCON1_ONE_SPACE);
} } else {
else
{
// ESP_LOGI(TAG, "For Y %d 0", y); // ESP_LOGI(TAG, "For Y %d 0", y);
data->mark(SAMSUNG_AIRCON1_BIT_MARK); data->mark(SAMSUNG_AIRCON1_BIT_MARK);
data->space(SAMSUNG_AIRCON1_ZERO_SPACE); data->space(SAMSUNG_AIRCON1_ZERO_SPACE);
@ -82,14 +76,17 @@ namespace climate_ir_samsung {
protocol.Swing = kSamsungAcSwingBoth; protocol.Swing = kSamsungAcSwingBoth;
break; break;
case climate::ClimateSwingMode::CLIMATE_SWING_HORIZONTAL: case climate::ClimateSwingMode::CLIMATE_SWING_HORIZONTAL:
protocol.Swing = kSamsungAcSwingH;; protocol.Swing = kSamsungAcSwingH;
;
break; break;
case climate::ClimateSwingMode::CLIMATE_SWING_VERTICAL: case climate::ClimateSwingMode::CLIMATE_SWING_VERTICAL:
protocol.Swing = kSamsungAcSwingV;; protocol.Swing = kSamsungAcSwingV;
;
break; break;
case climate::ClimateSwingMode::CLIMATE_SWING_OFF: case climate::ClimateSwingMode::CLIMATE_SWING_OFF:
default: default:
protocol.Swing = kSamsungAcSwingOff;; protocol.Swing = kSamsungAcSwingOff;
;
break; break;
} }
} }
@ -129,14 +126,11 @@ namespace climate_ir_samsung {
/// Change the AC power state. /// Change the AC power state.
/// @param[in] on true, the AC is on. false, the AC is off. /// @param[in] on true, the AC is on. false, the AC is off.
void SamsungClimateIR::setAndSendPowerState(const bool on) { void SamsungClimateIR::setAndSendPowerState(const bool on) {
static const uint8_t kOn[kSamsungAcExtendedStateLength] = {0x02, 0x92, 0x0F, 0x00, 0x00, 0x00, 0xF0,
static const uint8_t kOn[kSamsungAcExtendedStateLength] = {
0x02, 0x92, 0x0F, 0x00, 0x00, 0x00, 0xF0,
0x01, 0xD2, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0xD2, 0x0F, 0x00, 0x00, 0x00, 0x00,
0x01, 0xE2, 0xFE, 0x71, 0x80, 0x11, 0xF0}; 0x01, 0xE2, 0xFE, 0x71, 0x80, 0x11, 0xF0};
static const uint8_t kOff[kSamsungAcExtendedStateLength] = { static const uint8_t kOff[kSamsungAcExtendedStateLength] = {0x02, 0xB2, 0x0F, 0x00, 0x00, 0x00, 0xC0,
0x02, 0xB2, 0x0F, 0x00, 0x00, 0x00, 0xC0,
0x01, 0xD2, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0xD2, 0x0F, 0x00, 0x00, 0x00, 0x00,
0x01, 0x02, 0xFF, 0x71, 0x80, 0x11, 0xC0}; 0x01, 0x02, 0xFF, 0x71, 0x80, 0x11, 0xC0};
@ -203,12 +197,14 @@ namespace climate_ir_samsung {
/// @param[in] ones Count the binary nr of `1` bits. False is count the `0`s. /// @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) /// @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. /// @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 SamsungClimateIR::countBits(const uint8_t *const start, const uint16_t length, const bool ones,
const uint16_t init) {
uint16_t count = init; uint16_t count = init;
for (uint16_t offset = 0; offset < length; offset++) for (uint16_t offset = 0; offset < length; offset++)
for (uint8_t currentbyte = *(start + offset); currentbyte; currentbyte >>= 1) for (uint8_t currentbyte = *(start + offset); currentbyte; currentbyte >>= 1)
if (currentbyte & 1) count++; if (currentbyte & 1)
count++;
if (ones || length == 0) if (ones || length == 0)
return count; return count;
@ -227,11 +223,13 @@ namespace climate_ir_samsung {
uint8_t bitsSoFar = length; uint8_t bitsSoFar = length;
for (uint64_t remainder = data; remainder && bitsSoFar; remainder >>= 1, bitsSoFar--) for (uint64_t remainder = data; remainder && bitsSoFar; remainder >>= 1, bitsSoFar--)
if (remainder & 1) count++; if (remainder & 1)
count++;
if (ones || length == 0) if (ones || length == 0)
return count; return count;
else else
return length - count; return length - count;
} }
}} } // namespace climate_ir_samsung
} // namespace esphome

View File

@ -3,12 +3,10 @@
#include "esphome/components/climate/climate_mode.h" #include "esphome/components/climate/climate_mode.h"
#include "esphome/components/climate_ir/climate_ir.h" #include "esphome/components/climate_ir/climate_ir.h"
namespace esphome { namespace esphome {
namespace climate_ir_samsung { namespace climate_ir_samsung {
#define GETBITS8(data, offset, size) \ #define GETBITS8(data, offset, size) (((data) & (((uint8_t) UINT8_MAX >> (8 - (size))) << (offset))) >> (offset))
(((data) & (((uint8_t)UINT8_MAX >> (8 - (size))) << (offset))) >> (offset))
static const char *const TAG = "samsung.climate"; static const char *const TAG = "samsung.climate";
static const uint32_t SAMSUNG_IR_FREQUENCY = 38000; static const uint32_t SAMSUNG_IR_FREQUENCY = 38000;
@ -54,9 +52,9 @@ namespace climate_ir_samsung {
const uint8_t kHighNibble = 4; const uint8_t kHighNibble = 4;
const uint8_t kModeBitsSize = 3; const uint8_t kModeBitsSize = 3;
// static const uint8_t kReset[kSamsungAcExtendedStateLength] = {0x02, 0x92, 0x0F, 0x00, 0x00, 0x00, 0xF0, 0x01, 0x02, 0xAE, 0x71, 0x00, 0x15, 0xF0}; // static const uint8_t kReset[kSamsungAcExtendedStateLength] = {0x02, 0x92, 0x0F, 0x00, 0x00, 0x00, 0xF0, 0x01, 0x02,
static const uint8_t kReset[kSamsungAcExtendedStateLength] = { // 0xAE, 0x71, 0x00, 0x15, 0xF0};
0x02, 0x92, 0x0F, 0x00, 0x00, 0x00, 0xF0, static const uint8_t kReset[kSamsungAcExtendedStateLength] = {0x02, 0x92, 0x0F, 0x00, 0x00, 0x00, 0xF0,
0x01, 0x02, 0xAE, 0x71, 0x00, 0x15, 0xF0}; 0x01, 0x02, 0xAE, 0x71, 0x00, 0x15, 0xF0};
/// Native representation of a Samsung A/C message. /// Native representation of a Samsung A/C message.
@ -181,15 +179,16 @@ namespace climate_ir_samsung {
}; };
class SamsungClimateIR : public climate_ir::ClimateIR { class SamsungClimateIR : public climate_ir::ClimateIR {
SamsungProtocol protocol; SamsungProtocol protocol;
climate::ClimateMode current_climate_mode; climate::ClimateMode current_climate_mode;
public: SamsungClimateIR() : public:
climate_ir::ClimateIR( SamsungClimateIR()
kSamsungAcMinTemp, kSamsungAcMaxTemp, 1.0f, true, true, : climate_ir::ClimateIR(kSamsungAcMinTemp, kSamsungAcMaxTemp, 1.0f, true, true,
{climate::CLIMATE_FAN_AUTO, climate::CLIMATE_FAN_LOW, climate::CLIMATE_FAN_MEDIUM, climate::CLIMATE_FAN_HIGH}, {climate::CLIMATE_FAN_AUTO, climate::CLIMATE_FAN_LOW, climate::CLIMATE_FAN_MEDIUM,
{climate::CLIMATE_SWING_OFF, climate::CLIMATE_SWING_VERTICAL, climate::CLIMATE_SWING_HORIZONTAL, climate::CLIMATE_SWING_BOTH}) { } climate::CLIMATE_FAN_HIGH},
{climate::CLIMATE_SWING_OFF, climate::CLIMATE_SWING_VERTICAL,
climate::CLIMATE_SWING_HORIZONTAL, climate::CLIMATE_SWING_BOTH}) {}
protected: protected:
void transmit_state() override; void transmit_state() override;
@ -203,7 +202,9 @@ namespace climate_ir_samsung {
void checksum(void); void checksum(void);
static uint8_t calcSectionChecksum(const uint8_t *section); static uint8_t calcSectionChecksum(const uint8_t *section);
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 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); static uint16_t countBits(const uint64_t data, const uint8_t length, const bool ones = true, const uint16_t init = 0);
}; };
}} } // namespace climate_ir_samsung
} // namespace esphome