mirror of
https://github.com/esphome/esphome.git
synced 2025-02-15 09:28:16 +00:00
Improve code quality
This commit is contained in:
parent
227667fc5e
commit
b69a124780
@ -19,13 +19,13 @@ namespace climate_ir_samsung {
|
|||||||
setTemp(this->target_temperature);
|
setTemp(this->target_temperature);
|
||||||
setSwing(this->swing_mode);
|
setSwing(this->swing_mode);
|
||||||
setFan(this->fan_mode.has_value() ? this->fan_mode.value() : climate::CLIMATE_FAN_AUTO);
|
setFan(this->fan_mode.has_value() ? this->fan_mode.value() : climate::CLIMATE_FAN_AUTO);
|
||||||
|
|
||||||
send();
|
send();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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();
|
||||||
@ -139,7 +139,7 @@ namespace climate_ir_samsung {
|
|||||||
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};
|
||||||
|
|
||||||
std::memcpy(protocol.raw, on ? kOn : kOff, kSamsungAcExtendedStateLength);
|
std::memcpy(protocol.raw, on ? kOn : kOff, kSamsungAcExtendedStateLength);
|
||||||
|
|
||||||
send();
|
send();
|
||||||
@ -205,7 +205,7 @@ namespace climate_ir_samsung {
|
|||||||
/// @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++;
|
||||||
@ -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 SamsungClimateIR::countBits(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 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++;
|
||||||
|
|
||||||
|
@ -3,20 +3,22 @@
|
|||||||
#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"
|
||||||
|
|
||||||
#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 esphome {
|
||||||
namespace climate_ir_samsung {
|
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 char *const TAG = "samsung.climate";
|
||||||
static const uint32_t SAMSUNG_IR_FREQUENCY = 38000;
|
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 kSamsungAcExtendedStateLength = 21;
|
||||||
const uint16_t kSamsungAcSectionLength = 7;
|
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 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);
|
||||||
};
|
};
|
||||||
}}
|
}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user