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

Fixed typos

This commit is contained in:
Georgi Filipov 2024-12-24 01:10:27 +02:00
parent e3e0f6f5cb
commit 227667fc5e
3 changed files with 45 additions and 49 deletions

View File

@ -7,12 +7,12 @@ CODEOWNERS = ["@jorofi"]
AUTO_LOAD = ["climate_ir"]
samsung_ns = cg.esphome_ns.namespace("samsung")
SamsungClimate = samsung_ns.class_("SamsungClimate", climate_ir.ClimateIR)
samsung_ns = cg.esphome_ns.namespace("climate_ir_samsung")
SamsungClimateIR = samsung_ns.class_("SamsungClimateIR", climate_ir.ClimateIR)
CONFIG_SCHEMA = climate_ir.CLIMATE_IR_WITH_RECEIVER_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(SamsungClimate)
cv.GenerateID(): cv.declare_id(SamsungClimateIR)
}
)

View File

@ -1,44 +1,4 @@
#include "climate_ir_samsung.h"
#include <thread>
#include <chrono>
/// 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 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++;
if (ones || length == 0)
return count;
else
return (length * 8) - count;
}
/// 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 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++;
if (ones || length == 0)
return count;
else
return length - count;
}
namespace esphome {
namespace climate_ir_samsung {
@ -51,7 +11,6 @@ namespace climate_ir_samsung {
if(current_climate_mode == climate::ClimateMode::CLIMATE_MODE_OFF && this->mode != climate::ClimateMode::CLIMATE_MODE_OFF) {
setAndSendPowerState(true);
std::this_thread::sleep_for(std::chrono::seconds(2));
}
current_climate_mode = this->mode;
@ -237,4 +196,42 @@ namespace climate_ir_samsung {
protocol.Sum3Upper = GETBITS8(sectionsum, kHighNibble, kNibbleSize);
protocol.Sum3Lower = GETBITS8(sectionsum, kLowNibble, kNibbleSize);
}
/// 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 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++;
if (ones || length == 0)
return count;
else
return (length * 8) - count;
}
/// 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 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++;
if (ones || length == 0)
return count;
else
return length - count;
}
}}

View File

@ -12,9 +12,6 @@
#define GETBITS8(data, offset, size) \
(((data) & (((uint8_t)UINT8_MAX >> (8 - (size))) << (offset))) >> (offset))
uint16_t countBits(const uint8_t * const start, const uint16_t length, const bool ones = true, const uint16_t init = 0);
uint16_t countBits(const uint64_t data, const uint8_t length, const bool ones = true, const uint16_t init = 0);
namespace esphome {
namespace climate_ir_samsung {
@ -181,12 +178,12 @@ namespace climate_ir_samsung {
};
};
class SamsungClimate : public climate_ir::ClimateIR {
class SamsungClimateIR : public climate_ir::ClimateIR {
SamsungProtocol protocol;
climate::ClimateMode current_climate_mode;
public: SamsungClimate() :
public: SamsungClimateIR() :
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},
@ -204,5 +201,7 @@ namespace climate_ir_samsung {
void checksum(void);
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 uint64_t data, const uint8_t length, const bool ones = true, const uint16_t init = 0);
};
}}