mirror of
https://github.com/esphome/esphome.git
synced 2024-12-21 16:27:44 +01:00
Force braces around multi-line statements (#3094)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
6b27f2d2cf
commit
80d03a631e
@ -68,7 +68,6 @@ Checks: >-
|
||||
-modernize-use-nodiscard,
|
||||
-mpi-*,
|
||||
-objc-*,
|
||||
-readability-braces-around-statements,
|
||||
-readability-convert-member-functions-to-static,
|
||||
-readability-else-after-return,
|
||||
-readability-function-cognitive-complexity,
|
||||
@ -109,6 +108,8 @@ CheckOptions:
|
||||
value: 'make_unique'
|
||||
- key: modernize-make-unique.MakeSmartPtrFunctionHeader
|
||||
value: 'esphome/core/helpers.h'
|
||||
- key: readability-braces-around-statements.ShortStatementLines
|
||||
value: 2
|
||||
- key: readability-identifier-naming.LocalVariableCase
|
||||
value: 'lower_case'
|
||||
- key: readability-identifier-naming.ClassCase
|
||||
|
@ -52,10 +52,10 @@ uint32_t IRAM_ATTR HOT AcDimmerDataStore::timer_intr(uint32_t now) {
|
||||
this->gate_pin.digital_write(false);
|
||||
}
|
||||
|
||||
if (time_since_zc < this->enable_time_us)
|
||||
if (time_since_zc < this->enable_time_us) {
|
||||
// Next event is enable, return time until that event
|
||||
return this->enable_time_us - time_since_zc;
|
||||
else if (time_since_zc < disable_time_us) {
|
||||
} else if (time_since_zc < disable_time_us) {
|
||||
// Next event is disable, return time until that event
|
||||
return this->disable_time_us - time_since_zc;
|
||||
}
|
||||
@ -74,9 +74,10 @@ uint32_t IRAM_ATTR HOT timer_interrupt() {
|
||||
uint32_t min_dt_us = 1000;
|
||||
uint32_t now = micros();
|
||||
for (auto *dimmer : all_dimmers) {
|
||||
if (dimmer == nullptr)
|
||||
if (dimmer == nullptr) {
|
||||
// no more dimmers
|
||||
break;
|
||||
}
|
||||
uint32_t res = dimmer->timer_intr(now);
|
||||
if (res != 0 && res < min_dt_us)
|
||||
min_dt_us = res;
|
||||
@ -212,12 +213,13 @@ void AcDimmer::dump_config() {
|
||||
LOG_PIN(" Zero-Cross Pin: ", this->zero_cross_pin_);
|
||||
ESP_LOGCONFIG(TAG, " Min Power: %.1f%%", this->store_.min_power / 10.0f);
|
||||
ESP_LOGCONFIG(TAG, " Init with half cycle: %s", YESNO(this->init_with_half_cycle_));
|
||||
if (method_ == DIM_METHOD_LEADING_PULSE)
|
||||
if (method_ == DIM_METHOD_LEADING_PULSE) {
|
||||
ESP_LOGCONFIG(TAG, " Method: leading pulse");
|
||||
else if (method_ == DIM_METHOD_LEADING)
|
||||
} else if (method_ == DIM_METHOD_LEADING) {
|
||||
ESP_LOGCONFIG(TAG, " Method: leading");
|
||||
else
|
||||
} else {
|
||||
ESP_LOGCONFIG(TAG, " Method: trailing");
|
||||
}
|
||||
|
||||
LOG_FLOAT_OUTPUT(this);
|
||||
ESP_LOGV(TAG, " Estimated Frequency: %.3fHz", 1e6f / this->store_.cycle_time_us / 2);
|
||||
|
@ -65,9 +65,9 @@ void ADCSensor::dump_config() {
|
||||
|
||||
#ifdef USE_ESP32
|
||||
LOG_PIN(" Pin: ", pin_);
|
||||
if (autorange_)
|
||||
if (autorange_) {
|
||||
ESP_LOGCONFIG(TAG, " Attenuation: auto");
|
||||
else
|
||||
} else {
|
||||
switch (this->attenuation_) {
|
||||
case ADC_ATTEN_DB_0:
|
||||
ESP_LOGCONFIG(TAG, " Attenuation: 0db (max 1.1V)");
|
||||
@ -84,6 +84,7 @@ void ADCSensor::dump_config() {
|
||||
default: // This is to satisfy the unused ADC_ATTEN_MAX
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif // USE_ESP32
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
}
|
||||
|
@ -19,12 +19,14 @@ uint16_t crc_16(uint8_t *ptr, uint8_t length) {
|
||||
//------------------------------
|
||||
while (length--) {
|
||||
crc ^= *ptr++;
|
||||
for (i = 0; i < 8; i++)
|
||||
for (i = 0; i < 8; i++) {
|
||||
if ((crc & 0x01) != 0) {
|
||||
crc >>= 1;
|
||||
crc ^= 0xA001;
|
||||
} else
|
||||
} else {
|
||||
crc >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
@ -79,9 +79,10 @@ void Am43::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_i
|
||||
auto status = esp_ble_gattc_write_char(this->parent_->gattc_if, this->parent_->conn_id, this->char_handle_,
|
||||
packet->length, packet->data, ESP_GATT_WRITE_TYPE_NO_RSP,
|
||||
ESP_GATT_AUTH_REQ_NONE);
|
||||
if (status)
|
||||
if (status) {
|
||||
ESP_LOGW(TAG, "[%s] esp_ble_gattc_write_char failed, status=%d", this->parent_->address_str().c_str(),
|
||||
status);
|
||||
}
|
||||
}
|
||||
this->current_sensor_ = 0;
|
||||
}
|
||||
|
@ -30,10 +30,11 @@ void Am43Component::loop() {
|
||||
esp_ble_gattc_write_char(this->parent_->gattc_if, this->parent_->conn_id, this->char_handle_, packet->length,
|
||||
packet->data, ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE);
|
||||
ESP_LOGI(TAG, "[%s] Logging into AM43", this->get_name().c_str());
|
||||
if (status)
|
||||
if (status) {
|
||||
ESP_LOGW(TAG, "[%s] Error writing set_pin to device, error = %d", this->get_name().c_str(), status);
|
||||
else
|
||||
} else {
|
||||
this->logged_in_ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,9 +114,10 @@ void Anova::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_
|
||||
auto status =
|
||||
esp_ble_gattc_write_char(this->parent_->gattc_if, this->parent_->conn_id, this->char_handle_, pkt->length,
|
||||
pkt->data, ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE);
|
||||
if (status)
|
||||
if (status) {
|
||||
ESP_LOGW(TAG, "[%s] esp_ble_gattc_write_char failed, status=%d", this->parent_->address_str().c_str(),
|
||||
status);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -225,9 +225,10 @@ void APDS9960::read_gesture_data_() {
|
||||
|
||||
uint8_t fifo_level;
|
||||
APDS9960_WARNING_CHECK(this->read_byte(0xAE, &fifo_level), "Reading FIFO level failed.");
|
||||
if (fifo_level == 0)
|
||||
if (fifo_level == 0) {
|
||||
// no data to process
|
||||
return;
|
||||
}
|
||||
|
||||
APDS9960_WARNING_CHECK(fifo_level <= 32, "FIFO level has invalid value.")
|
||||
|
||||
|
@ -469,10 +469,11 @@ void APIConnection::switch_command(const SwitchCommandRequest &msg) {
|
||||
if (a_switch == nullptr)
|
||||
return;
|
||||
|
||||
if (msg.state)
|
||||
if (msg.state) {
|
||||
a_switch->turn_on();
|
||||
else
|
||||
} else {
|
||||
a_switch->turn_off();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -810,10 +811,11 @@ DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) {
|
||||
return resp;
|
||||
}
|
||||
void APIConnection::on_home_assistant_state_response(const HomeAssistantStateResponse &msg) {
|
||||
for (auto &it : this->parent_->get_state_subs())
|
||||
for (auto &it : this->parent_->get_state_subs()) {
|
||||
if (it.entity_id == msg.entity_id && it.attribute.value() == msg.attribute) {
|
||||
it.callback(msg.state);
|
||||
}
|
||||
}
|
||||
}
|
||||
void APIConnection::execute_service(const ExecuteServiceRequest &msg) {
|
||||
bool found = false;
|
||||
|
@ -80,9 +80,10 @@ void APIServer::setup() {
|
||||
if (esp32_camera::global_esp32_camera != nullptr && !esp32_camera::global_esp32_camera->is_internal()) {
|
||||
esp32_camera::global_esp32_camera->add_image_callback(
|
||||
[this](const std::shared_ptr<esp32_camera::CameraImage> &image) {
|
||||
for (auto &c : this->clients_)
|
||||
for (auto &c : this->clients_) {
|
||||
if (!c->remove_)
|
||||
c->send_camera_state(image);
|
||||
}
|
||||
});
|
||||
}
|
||||
#endif
|
||||
|
@ -55,17 +55,19 @@ class ProtoVarInt {
|
||||
}
|
||||
int32_t as_sint32() const {
|
||||
// with ZigZag encoding
|
||||
if (this->value_ & 1)
|
||||
if (this->value_ & 1) {
|
||||
return static_cast<int32_t>(~(this->value_ >> 1));
|
||||
else
|
||||
} else {
|
||||
return static_cast<int32_t>(this->value_ >> 1);
|
||||
}
|
||||
}
|
||||
int64_t as_sint64() const {
|
||||
// with ZigZag encoding
|
||||
if (this->value_ & 1)
|
||||
if (this->value_ & 1) {
|
||||
return static_cast<int64_t>(~(this->value_ >> 1));
|
||||
else
|
||||
} else {
|
||||
return static_cast<int64_t>(this->value_ >> 1);
|
||||
}
|
||||
}
|
||||
void encode(std::vector<uint8_t> &out) {
|
||||
uint32_t val = this->value_;
|
||||
@ -220,10 +222,11 @@ class ProtoWriteBuffer {
|
||||
}
|
||||
void encode_sint32(uint32_t field_id, int32_t value, bool force = false) {
|
||||
uint32_t uvalue;
|
||||
if (value < 0)
|
||||
if (value < 0) {
|
||||
uvalue = ~(value << 1);
|
||||
else
|
||||
} else {
|
||||
uvalue = value << 1;
|
||||
}
|
||||
this->encode_uint32(field_id, uvalue, force);
|
||||
}
|
||||
template<class C> void encode_message(uint32_t field_id, const C &value, bool force = false) {
|
||||
|
@ -58,10 +58,11 @@ void AS3935Component::loop() {
|
||||
|
||||
void AS3935Component::write_indoor(bool indoor) {
|
||||
ESP_LOGV(TAG, "Setting indoor to %d", indoor);
|
||||
if (indoor)
|
||||
if (indoor) {
|
||||
this->write_register(AFE_GAIN, GAIN_MASK, INDOOR, 1);
|
||||
else
|
||||
} else {
|
||||
this->write_register(AFE_GAIN, GAIN_MASK, OUTDOOR, 1);
|
||||
}
|
||||
}
|
||||
// REG0x01, bits[3:0], manufacturer default: 0010 (2).
|
||||
// This setting determines the threshold for events that trigger the
|
||||
|
@ -130,10 +130,10 @@ bool BalluClimate::on_receive(remote_base::RemoteReceiveData data) {
|
||||
for (int i = 0; i < BALLU_STATE_LENGTH; i++) {
|
||||
// Read bit
|
||||
for (int j = 0; j < 8; j++) {
|
||||
if (data.expect_item(BALLU_BIT_MARK, BALLU_ONE_SPACE))
|
||||
if (data.expect_item(BALLU_BIT_MARK, BALLU_ONE_SPACE)) {
|
||||
remote_state[i] |= 1 << j;
|
||||
|
||||
else if (!data.expect_item(BALLU_BIT_MARK, BALLU_ZERO_SPACE)) {
|
||||
} else if (!data.expect_item(BALLU_BIT_MARK, BALLU_ZERO_SPACE)) {
|
||||
ESP_LOGV(TAG, "Byte %d bit %d fail", i, j);
|
||||
return false;
|
||||
}
|
||||
|
@ -21,12 +21,13 @@ void BangBangClimate::setup() {
|
||||
restore->to_call(this).perform();
|
||||
} else {
|
||||
// restore from defaults, change_away handles those for us
|
||||
if (supports_cool_ && supports_heat_)
|
||||
if (supports_cool_ && supports_heat_) {
|
||||
this->mode = climate::CLIMATE_MODE_HEAT_COOL;
|
||||
else if (supports_cool_)
|
||||
} else if (supports_cool_) {
|
||||
this->mode = climate::CLIMATE_MODE_COOL;
|
||||
else if (supports_heat_)
|
||||
} else if (supports_heat_) {
|
||||
this->mode = climate::CLIMATE_MODE_HEAT;
|
||||
}
|
||||
this->change_away_(false);
|
||||
}
|
||||
}
|
||||
@ -56,11 +57,12 @@ climate::ClimateTraits BangBangClimate::traits() {
|
||||
if (supports_cool_ && supports_heat_)
|
||||
traits.add_supported_mode(climate::CLIMATE_MODE_HEAT_COOL);
|
||||
traits.set_supports_two_point_target_temperature(true);
|
||||
if (supports_away_)
|
||||
if (supports_away_) {
|
||||
traits.set_supported_presets({
|
||||
climate::CLIMATE_PRESET_HOME,
|
||||
climate::CLIMATE_PRESET_AWAY,
|
||||
});
|
||||
}
|
||||
traits.set_supports_action(true);
|
||||
return traits;
|
||||
}
|
||||
@ -82,17 +84,19 @@ void BangBangClimate::compute_state_() {
|
||||
if (too_cold) {
|
||||
// too cold -> enable heating if possible and enabled, else idle
|
||||
if (this->supports_heat_ &&
|
||||
(this->mode == climate::CLIMATE_MODE_HEAT_COOL || this->mode == climate::CLIMATE_MODE_HEAT))
|
||||
(this->mode == climate::CLIMATE_MODE_HEAT_COOL || this->mode == climate::CLIMATE_MODE_HEAT)) {
|
||||
target_action = climate::CLIMATE_ACTION_HEATING;
|
||||
else
|
||||
} else {
|
||||
target_action = climate::CLIMATE_ACTION_IDLE;
|
||||
}
|
||||
} else if (too_hot) {
|
||||
// too hot -> enable cooling if possible and enabled, else idle
|
||||
if (this->supports_cool_ &&
|
||||
(this->mode == climate::CLIMATE_MODE_HEAT_COOL || this->mode == climate::CLIMATE_MODE_COOL))
|
||||
(this->mode == climate::CLIMATE_MODE_HEAT_COOL || this->mode == climate::CLIMATE_MODE_COOL)) {
|
||||
target_action = climate::CLIMATE_ACTION_COOLING;
|
||||
else
|
||||
} else {
|
||||
target_action = climate::CLIMATE_ACTION_IDLE;
|
||||
}
|
||||
} else {
|
||||
// neither too hot nor too cold -> in range
|
||||
if (this->supports_cool_ && this->supports_heat_ && this->mode == climate::CLIMATE_MODE_HEAT_COOL) {
|
||||
@ -107,9 +111,10 @@ void BangBangClimate::compute_state_() {
|
||||
this->switch_to_action_(target_action);
|
||||
}
|
||||
void BangBangClimate::switch_to_action_(climate::ClimateAction action) {
|
||||
if (action == this->action)
|
||||
if (action == this->action) {
|
||||
// already in target mode
|
||||
return;
|
||||
}
|
||||
|
||||
if ((action == climate::CLIMATE_ACTION_OFF && this->action == climate::CLIMATE_ACTION_IDLE) ||
|
||||
(action == climate::CLIMATE_ACTION_IDLE && this->action == climate::CLIMATE_ACTION_OFF)) {
|
||||
|
@ -252,9 +252,10 @@ float BLEClient::parse_char_value(uint8_t *value, uint16_t length) {
|
||||
}
|
||||
|
||||
BLEService *BLEClient::get_service(espbt::ESPBTUUID uuid) {
|
||||
for (auto *svc : this->services_)
|
||||
for (auto *svc : this->services_) {
|
||||
if (svc->uuid == uuid)
|
||||
return svc;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -272,19 +273,24 @@ BLECharacteristic *BLEClient::get_characteristic(uint16_t service, uint16_t chr)
|
||||
}
|
||||
|
||||
BLEDescriptor *BLEClient::get_config_descriptor(uint16_t handle) {
|
||||
for (auto &svc : this->services_)
|
||||
for (auto &chr : svc->characteristics)
|
||||
if (chr->handle == handle)
|
||||
for (auto &desc : chr->descriptors)
|
||||
for (auto &svc : this->services_) {
|
||||
for (auto &chr : svc->characteristics) {
|
||||
if (chr->handle == handle) {
|
||||
for (auto &desc : chr->descriptors) {
|
||||
if (desc->uuid == espbt::ESPBTUUID::from_uint16(0x2902))
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BLECharacteristic *BLEService::get_characteristic(espbt::ESPBTUUID uuid) {
|
||||
for (auto &chr : this->characteristics)
|
||||
for (auto &chr : this->characteristics) {
|
||||
if (chr->uuid == uuid)
|
||||
return chr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -379,9 +385,10 @@ void BLECharacteristic::parse_descriptors() {
|
||||
}
|
||||
|
||||
BLEDescriptor *BLECharacteristic::get_descriptor(espbt::ESPBTUUID uuid) {
|
||||
for (auto &desc : this->descriptors)
|
||||
for (auto &desc : this->descriptors) {
|
||||
if (desc->uuid == uuid)
|
||||
return desc;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
BLEDescriptor *BLECharacteristic::get_descriptor(uint16_t uuid) {
|
||||
|
@ -126,9 +126,10 @@ class BLEClient : public espbt::ESPBTClient, public Component {
|
||||
bool all_nodes_established_() {
|
||||
if (this->state() != espbt::ClientState::ESTABLISHED)
|
||||
return false;
|
||||
for (auto &node : nodes_)
|
||||
for (auto &node : nodes_) {
|
||||
if (node->node_state != espbt::ClientState::ESTABLISHED)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -214,9 +214,10 @@ void BME280Component::update() {
|
||||
float BME280Component::read_temperature_(const uint8_t *data, int32_t *t_fine) {
|
||||
int32_t adc = ((data[3] & 0xFF) << 16) | ((data[4] & 0xFF) << 8) | (data[5] & 0xFF);
|
||||
adc >>= 4;
|
||||
if (adc == 0x80000)
|
||||
if (adc == 0x80000) {
|
||||
// temperature was disabled
|
||||
return NAN;
|
||||
}
|
||||
|
||||
const int32_t t1 = this->calibration_.t1;
|
||||
const int32_t t2 = this->calibration_.t2;
|
||||
@ -233,9 +234,10 @@ float BME280Component::read_temperature_(const uint8_t *data, int32_t *t_fine) {
|
||||
float BME280Component::read_pressure_(const uint8_t *data, int32_t t_fine) {
|
||||
int32_t adc = ((data[0] & 0xFF) << 16) | ((data[1] & 0xFF) << 8) | (data[2] & 0xFF);
|
||||
adc >>= 4;
|
||||
if (adc == 0x80000)
|
||||
if (adc == 0x80000) {
|
||||
// pressure was disabled
|
||||
return NAN;
|
||||
}
|
||||
const int64_t p1 = this->calibration_.p1;
|
||||
const int64_t p2 = this->calibration_.p2;
|
||||
const int64_t p3 = this->calibration_.p3;
|
||||
|
@ -420,10 +420,11 @@ float BME680Component::calc_humidity_(uint16_t raw_humidity) {
|
||||
|
||||
calc_hum = var2 + (var3 + var4 * temp_comp) * var2 * var2;
|
||||
|
||||
if (calc_hum > 100.0f)
|
||||
if (calc_hum > 100.0f) {
|
||||
calc_hum = 100.0f;
|
||||
else if (calc_hum < 0.0f)
|
||||
} else if (calc_hum < 0.0f) {
|
||||
calc_hum = 0.0f;
|
||||
}
|
||||
|
||||
return calc_hum;
|
||||
}
|
||||
|
@ -161,9 +161,10 @@ float BMP280Component::read_temperature_(int32_t *t_fine) {
|
||||
return NAN;
|
||||
int32_t adc = ((data[0] & 0xFF) << 16) | ((data[1] & 0xFF) << 8) | (data[2] & 0xFF);
|
||||
adc >>= 4;
|
||||
if (adc == 0x80000)
|
||||
if (adc == 0x80000) {
|
||||
// temperature was disabled
|
||||
return NAN;
|
||||
}
|
||||
|
||||
const int32_t t1 = this->calibration_.t1;
|
||||
const int32_t t2 = this->calibration_.t2;
|
||||
@ -183,9 +184,10 @@ float BMP280Component::read_pressure_(int32_t t_fine) {
|
||||
return NAN;
|
||||
int32_t adc = ((data[0] & 0xFF) << 16) | ((data[1] & 0xFF) << 8) | (data[2] & 0xFF);
|
||||
adc >>= 4;
|
||||
if (adc == 0x80000)
|
||||
if (adc == 0x80000) {
|
||||
// pressure was disabled
|
||||
return NAN;
|
||||
}
|
||||
const int64_t p1 = this->calibration_.p1;
|
||||
const int64_t p2 = this->calibration_.p2;
|
||||
const int64_t p3 = this->calibration_.p3;
|
||||
|
@ -39,14 +39,15 @@ void CCS811Component::setup() {
|
||||
// set MEAS_MODE (page 5)
|
||||
uint8_t meas_mode = 0;
|
||||
uint32_t interval = this->get_update_interval();
|
||||
if (interval >= 60 * 1000)
|
||||
if (interval >= 60 * 1000) {
|
||||
meas_mode = 3 << 4; // sensor takes a reading every 60 seconds
|
||||
else if (interval >= 10 * 1000)
|
||||
} else if (interval >= 10 * 1000) {
|
||||
meas_mode = 2 << 4; // sensor takes a reading every 10 seconds
|
||||
else if (interval >= 1 * 1000)
|
||||
} else if (interval >= 1 * 1000) {
|
||||
meas_mode = 1 << 4; // sensor takes a reading every second
|
||||
else
|
||||
} else {
|
||||
meas_mode = 4 << 4; // sensor takes a reading every 250ms
|
||||
}
|
||||
|
||||
CHECKED_IO(this->write_byte(0x01, meas_mode))
|
||||
|
||||
|
@ -137,11 +137,11 @@ bool LgIrClimate::on_receive(remote_base::RemoteReceiveData data) {
|
||||
this->swing_mode =
|
||||
this->swing_mode == climate::CLIMATE_SWING_OFF ? climate::CLIMATE_SWING_VERTICAL : climate::CLIMATE_SWING_OFF;
|
||||
} else {
|
||||
if ((remote_state & COMMAND_MASK) == COMMAND_AUTO)
|
||||
if ((remote_state & COMMAND_MASK) == COMMAND_AUTO) {
|
||||
this->mode = climate::CLIMATE_MODE_HEAT_COOL;
|
||||
else if ((remote_state & COMMAND_MASK) == COMMAND_DRY_FAN)
|
||||
} else if ((remote_state & COMMAND_MASK) == COMMAND_DRY_FAN) {
|
||||
this->mode = climate::CLIMATE_MODE_DRY;
|
||||
else if ((remote_state & COMMAND_MASK) == COMMAND_HEAT) {
|
||||
} else if ((remote_state & COMMAND_MASK) == COMMAND_HEAT) {
|
||||
this->mode = climate::CLIMATE_MODE_HEAT;
|
||||
} else {
|
||||
this->mode = climate::CLIMATE_MODE_COOL;
|
||||
@ -156,14 +156,15 @@ bool LgIrClimate::on_receive(remote_base::RemoteReceiveData data) {
|
||||
this->fan_mode = climate::CLIMATE_FAN_AUTO;
|
||||
} else if (this->mode == climate::CLIMATE_MODE_COOL || this->mode == climate::CLIMATE_MODE_HEAT ||
|
||||
this->mode == climate::CLIMATE_MODE_DRY) {
|
||||
if ((remote_state & FAN_MASK) == FAN_AUTO)
|
||||
if ((remote_state & FAN_MASK) == FAN_AUTO) {
|
||||
this->fan_mode = climate::CLIMATE_FAN_AUTO;
|
||||
else if ((remote_state & FAN_MASK) == FAN_MIN)
|
||||
} else if ((remote_state & FAN_MASK) == FAN_MIN) {
|
||||
this->fan_mode = climate::CLIMATE_FAN_LOW;
|
||||
else if ((remote_state & FAN_MASK) == FAN_MED)
|
||||
} else if ((remote_state & FAN_MASK) == FAN_MED) {
|
||||
this->fan_mode = climate::CLIMATE_FAN_MEDIUM;
|
||||
else if ((remote_state & FAN_MASK) == FAN_MAX)
|
||||
} else if ((remote_state & FAN_MASK) == FAN_MAX) {
|
||||
this->fan_mode = climate::CLIMATE_FAN_HIGH;
|
||||
}
|
||||
}
|
||||
}
|
||||
this->publish_state();
|
||||
|
@ -125,34 +125,37 @@ bool CoolixClimate::on_coolix(climate::Climate *parent, remote_base::RemoteRecei
|
||||
parent->swing_mode =
|
||||
parent->swing_mode == climate::CLIMATE_SWING_OFF ? climate::CLIMATE_SWING_VERTICAL : climate::CLIMATE_SWING_OFF;
|
||||
} else {
|
||||
if ((remote_state & COOLIX_MODE_MASK) == COOLIX_HEAT)
|
||||
if ((remote_state & COOLIX_MODE_MASK) == COOLIX_HEAT) {
|
||||
parent->mode = climate::CLIMATE_MODE_HEAT;
|
||||
else if ((remote_state & COOLIX_MODE_MASK) == COOLIX_AUTO)
|
||||
} else if ((remote_state & COOLIX_MODE_MASK) == COOLIX_AUTO) {
|
||||
parent->mode = climate::CLIMATE_MODE_HEAT_COOL;
|
||||
else if ((remote_state & COOLIX_MODE_MASK) == COOLIX_DRY_FAN) {
|
||||
if ((remote_state & COOLIX_FAN_MASK) == COOLIX_FAN_MODE_AUTO_DRY)
|
||||
} else if ((remote_state & COOLIX_MODE_MASK) == COOLIX_DRY_FAN) {
|
||||
if ((remote_state & COOLIX_FAN_MASK) == COOLIX_FAN_MODE_AUTO_DRY) {
|
||||
parent->mode = climate::CLIMATE_MODE_DRY;
|
||||
else
|
||||
} else {
|
||||
parent->mode = climate::CLIMATE_MODE_FAN_ONLY;
|
||||
}
|
||||
} else
|
||||
parent->mode = climate::CLIMATE_MODE_COOL;
|
||||
|
||||
// Fan Speed
|
||||
if ((remote_state & COOLIX_FAN_AUTO) == COOLIX_FAN_AUTO || parent->mode == climate::CLIMATE_MODE_HEAT_COOL ||
|
||||
parent->mode == climate::CLIMATE_MODE_DRY)
|
||||
parent->mode == climate::CLIMATE_MODE_DRY) {
|
||||
parent->fan_mode = climate::CLIMATE_FAN_AUTO;
|
||||
else if ((remote_state & COOLIX_FAN_MIN) == COOLIX_FAN_MIN)
|
||||
} else if ((remote_state & COOLIX_FAN_MIN) == COOLIX_FAN_MIN) {
|
||||
parent->fan_mode = climate::CLIMATE_FAN_LOW;
|
||||
else if ((remote_state & COOLIX_FAN_MED) == COOLIX_FAN_MED)
|
||||
} else if ((remote_state & COOLIX_FAN_MED) == COOLIX_FAN_MED) {
|
||||
parent->fan_mode = climate::CLIMATE_FAN_MEDIUM;
|
||||
else if ((remote_state & COOLIX_FAN_MAX) == COOLIX_FAN_MAX)
|
||||
} else if ((remote_state & COOLIX_FAN_MAX) == COOLIX_FAN_MAX) {
|
||||
parent->fan_mode = climate::CLIMATE_FAN_HIGH;
|
||||
}
|
||||
|
||||
// Temperature
|
||||
uint8_t temperature_code = remote_state & COOLIX_TEMP_MASK;
|
||||
for (uint8_t i = 0; i < COOLIX_TEMP_RANGE; i++)
|
||||
for (uint8_t i = 0; i < COOLIX_TEMP_RANGE; i++) {
|
||||
if (COOLIX_TEMP_MAP[i] == temperature_code)
|
||||
parent->target_temperature = i + COOLIX_TEMP_MIN;
|
||||
}
|
||||
}
|
||||
parent->publish_state();
|
||||
|
||||
|
@ -175,14 +175,15 @@ bool DaikinClimate::parse_state_frame_(const uint8_t frame[]) {
|
||||
}
|
||||
uint8_t fan_mode = frame[8];
|
||||
uint8_t swing_mode = frame[9];
|
||||
if (fan_mode & 0xF && swing_mode & 0xF)
|
||||
if (fan_mode & 0xF && swing_mode & 0xF) {
|
||||
this->swing_mode = climate::CLIMATE_SWING_BOTH;
|
||||
else if (fan_mode & 0xF)
|
||||
} else if (fan_mode & 0xF) {
|
||||
this->swing_mode = climate::CLIMATE_SWING_VERTICAL;
|
||||
else if (swing_mode & 0xF)
|
||||
} else if (swing_mode & 0xF) {
|
||||
this->swing_mode = climate::CLIMATE_SWING_HORIZONTAL;
|
||||
else
|
||||
} else {
|
||||
this->swing_mode = climate::CLIMATE_SWING_OFF;
|
||||
}
|
||||
switch (fan_mode & 0xF0) {
|
||||
case DAIKIN_FAN_1:
|
||||
case DAIKIN_FAN_2:
|
||||
@ -212,9 +213,9 @@ bool DaikinClimate::on_receive(remote_base::RemoteReceiveData data) {
|
||||
for (uint8_t pos = 0; pos < DAIKIN_STATE_FRAME_SIZE; pos++) {
|
||||
uint8_t byte = 0;
|
||||
for (int8_t bit = 0; bit < 8; bit++) {
|
||||
if (data.expect_item(DAIKIN_BIT_MARK, DAIKIN_ONE_SPACE))
|
||||
if (data.expect_item(DAIKIN_BIT_MARK, DAIKIN_ONE_SPACE)) {
|
||||
byte |= 1 << bit;
|
||||
else if (!data.expect_item(DAIKIN_BIT_MARK, DAIKIN_ZERO_SPACE)) {
|
||||
} else if (!data.expect_item(DAIKIN_BIT_MARK, DAIKIN_ZERO_SPACE)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -145,9 +145,10 @@ uint64_t ESPOneWire::search() {
|
||||
// read its complement
|
||||
bool cmp_id_bit = this->read_bit();
|
||||
|
||||
if (id_bit && cmp_id_bit)
|
||||
if (id_bit && cmp_id_bit) {
|
||||
// No devices participating in search
|
||||
break;
|
||||
}
|
||||
|
||||
bool branch;
|
||||
|
||||
@ -170,12 +171,13 @@ uint64_t ESPOneWire::search() {
|
||||
}
|
||||
}
|
||||
|
||||
if (branch)
|
||||
if (branch) {
|
||||
// set bit
|
||||
this->rom_number8_()[rom_byte_number] |= rom_byte_mask;
|
||||
else
|
||||
} else {
|
||||
// clear bit
|
||||
this->rom_number8_()[rom_byte_number] &= ~rom_byte_mask;
|
||||
}
|
||||
|
||||
// choose/announce branch
|
||||
this->write_bit(branch);
|
||||
@ -190,9 +192,10 @@ uint64_t ESPOneWire::search() {
|
||||
|
||||
if (id_bit_number >= 65) {
|
||||
this->last_discrepancy_ = last_zero;
|
||||
if (this->last_discrepancy_ == 0)
|
||||
if (this->last_discrepancy_ == 0) {
|
||||
// we're at root and have no choices left, so this was the last one.
|
||||
this->last_device_flag_ = true;
|
||||
}
|
||||
search_result = true;
|
||||
}
|
||||
|
||||
|
@ -114,10 +114,11 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r
|
||||
// Wait for rising edge
|
||||
while (!this->pin_->digital_read()) {
|
||||
if (micros() - start_time > 90) {
|
||||
if (i < 0)
|
||||
if (i < 0) {
|
||||
error_code = 1;
|
||||
else
|
||||
} else {
|
||||
error_code = 2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -130,10 +131,11 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r
|
||||
// Wait for falling edge
|
||||
while (this->pin_->digital_read()) {
|
||||
if ((end_time = micros()) - start_time > 90) {
|
||||
if (i < 0)
|
||||
if (i < 0) {
|
||||
error_code = 3;
|
||||
else
|
||||
} else {
|
||||
error_code = 4;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -176,9 +176,10 @@ void DisplayBuffer::print(int x, int y, Font *font, Color color, TextAlign align
|
||||
ESP_LOGW(TAG, "Encountered character without representation in font: '%c'", text[i]);
|
||||
if (!font->get_glyphs().empty()) {
|
||||
uint8_t glyph_width = font->get_glyphs()[0].glyph_data_->width;
|
||||
for (int glyph_x = 0; glyph_x < glyph_width; glyph_x++)
|
||||
for (int glyph_x = 0; glyph_x < glyph_width; glyph_x++) {
|
||||
for (int glyph_y = 0; glyph_y < height; glyph_y++)
|
||||
this->draw_pixel_at(glyph_x + x_at, glyph_y + y_start, color);
|
||||
}
|
||||
x_at += glyph_width;
|
||||
}
|
||||
|
||||
@ -425,10 +426,11 @@ int Font::match_next_glyph(const char *str, int *match_length) {
|
||||
int hi = this->glyphs_.size() - 1;
|
||||
while (lo != hi) {
|
||||
int mid = (lo + hi + 1) / 2;
|
||||
if (this->glyphs_[mid].compare_to(str))
|
||||
if (this->glyphs_[mid].compare_to(str)) {
|
||||
lo = mid;
|
||||
else
|
||||
} else {
|
||||
hi = mid - 1;
|
||||
}
|
||||
}
|
||||
*match_length = this->glyphs_[lo].match_length(str);
|
||||
if (*match_length <= 0)
|
||||
@ -454,10 +456,11 @@ void Font::measure(const char *str, int *width, int *x_offset, int *baseline, in
|
||||
}
|
||||
|
||||
const Glyph &glyph = this->glyphs_[glyph_n];
|
||||
if (!has_char)
|
||||
if (!has_char) {
|
||||
min_x = glyph.glyph_data_->offset_x;
|
||||
else
|
||||
} else {
|
||||
min_x = std::min(min_x, x + glyph.glyph_data_->offset_x);
|
||||
}
|
||||
x += glyph.glyph_data_->width + glyph.glyph_data_->offset_x;
|
||||
|
||||
i += match_length;
|
||||
|
@ -68,9 +68,10 @@ void EKTF2232Touchscreen::loop() {
|
||||
|
||||
uint8_t raw[8];
|
||||
this->read(raw, 8);
|
||||
for (int i = 0; i < 8; i++)
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (raw[7] & (1 << i))
|
||||
touch_count++;
|
||||
}
|
||||
|
||||
if (touch_count == 0) {
|
||||
for (auto *listener : this->touch_listeners_)
|
||||
|
@ -147,40 +147,46 @@ bool BLECharacteristic::is_failed() {
|
||||
}
|
||||
|
||||
void BLECharacteristic::set_broadcast_property(bool value) {
|
||||
if (value)
|
||||
if (value) {
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_BROADCAST);
|
||||
else
|
||||
} else {
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_BROADCAST);
|
||||
}
|
||||
}
|
||||
void BLECharacteristic::set_indicate_property(bool value) {
|
||||
if (value)
|
||||
if (value) {
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_INDICATE);
|
||||
else
|
||||
} else {
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_INDICATE);
|
||||
}
|
||||
}
|
||||
void BLECharacteristic::set_notify_property(bool value) {
|
||||
if (value)
|
||||
if (value) {
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_NOTIFY);
|
||||
else
|
||||
} else {
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_NOTIFY);
|
||||
}
|
||||
}
|
||||
void BLECharacteristic::set_read_property(bool value) {
|
||||
if (value)
|
||||
if (value) {
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_READ);
|
||||
else
|
||||
} else {
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_READ);
|
||||
}
|
||||
}
|
||||
void BLECharacteristic::set_write_property(bool value) {
|
||||
if (value)
|
||||
if (value) {
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_WRITE);
|
||||
else
|
||||
} else {
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_WRITE);
|
||||
}
|
||||
}
|
||||
void BLECharacteristic::set_write_no_response_property(bool value) {
|
||||
if (value)
|
||||
if (value) {
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ | ESP_GATT_CHAR_PROP_BIT_WRITE_NR);
|
||||
else
|
||||
} else {
|
||||
this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_WRITE_NR);
|
||||
}
|
||||
}
|
||||
|
||||
void BLECharacteristic::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if,
|
||||
|
@ -18,9 +18,10 @@ BLEService::~BLEService() {
|
||||
}
|
||||
|
||||
BLECharacteristic *BLEService::get_characteristic(ESPBTUUID uuid) {
|
||||
for (auto *chr : this->characteristics_)
|
||||
for (auto *chr : this->characteristics_) {
|
||||
if (chr->get_uuid() == uuid)
|
||||
return chr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -58,11 +58,12 @@ void ESP32BLETracker::setup() {
|
||||
void ESP32BLETracker::loop() {
|
||||
BLEEvent *ble_event = this->ble_events_.pop();
|
||||
while (ble_event != nullptr) {
|
||||
if (ble_event->type_)
|
||||
if (ble_event->type_) {
|
||||
this->real_gattc_event_handler_(ble_event->event_.gattc.gattc_event, ble_event->event_.gattc.gattc_if,
|
||||
&ble_event->event_.gattc.gattc_param);
|
||||
else
|
||||
} else {
|
||||
this->real_gap_event_handler_(ble_event->event_.gap.gap_event, &ble_event->event_.gap.gap_param);
|
||||
}
|
||||
delete ble_event; // NOLINT(cppcoreguidelines-owning-memory)
|
||||
ble_event = this->ble_events_.pop();
|
||||
}
|
||||
@ -89,11 +90,12 @@ void ESP32BLETracker::loop() {
|
||||
device.parse_scan_rst(this->scan_result_buffer_[i]);
|
||||
|
||||
bool found = false;
|
||||
for (auto *listener : this->listeners_)
|
||||
for (auto *listener : this->listeners_) {
|
||||
if (listener->parse_device(device))
|
||||
found = true;
|
||||
}
|
||||
|
||||
for (auto *client : this->clients_)
|
||||
for (auto *client : this->clients_) {
|
||||
if (client->parse_device(device)) {
|
||||
found = true;
|
||||
if (client->state() == ClientState::DISCOVERED) {
|
||||
@ -103,6 +105,7 @@ void ESP32BLETracker::loop() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
this->print_bt_device_info(device);
|
||||
|
@ -87,10 +87,11 @@ void CameraWebServer::on_shutdown() {
|
||||
void CameraWebServer::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "ESP32 Camera Web Server:");
|
||||
ESP_LOGCONFIG(TAG, " Port: %d", this->port_);
|
||||
if (this->mode_ == STREAM)
|
||||
if (this->mode_ == STREAM) {
|
||||
ESP_LOGCONFIG(TAG, " Mode: stream");
|
||||
else
|
||||
} else {
|
||||
ESP_LOGCONFIG(TAG, " Mode: snapshot");
|
||||
}
|
||||
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, " Setup Failed");
|
||||
|
@ -98,16 +98,18 @@ static bool load_from_flash(size_t offset, uint32_t *data, size_t len) {
|
||||
}
|
||||
|
||||
static bool save_to_rtc(size_t offset, const uint32_t *data, size_t len) {
|
||||
for (uint32_t i = 0; i < len; i++)
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
if (!esp_rtc_user_mem_write(offset + i, data[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool load_from_rtc(size_t offset, uint32_t *data, size_t len) {
|
||||
for (uint32_t i = 0; i < len; i++)
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
if (!esp_rtc_user_mem_read(offset + i, &data[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -75,9 +75,10 @@ void EZOSensor::loop() {
|
||||
return;
|
||||
|
||||
// some sensors return multiple comma-separated values, terminate string after first one
|
||||
for (size_t i = 1; i < sizeof(buf) - 1; i++)
|
||||
for (size_t i = 1; i < sizeof(buf) - 1; i++) {
|
||||
if (buf[i] == ',')
|
||||
buf[i] = '\0';
|
||||
}
|
||||
|
||||
float val = parse_number<float>((char *) &buf[1]).value_or(0);
|
||||
this->publish_state(val);
|
||||
|
@ -278,10 +278,11 @@ void FingerprintGrowComponent::delete_all_fingerprints() {
|
||||
|
||||
void FingerprintGrowComponent::led_control(bool state) {
|
||||
ESP_LOGD(TAG, "Setting LED");
|
||||
if (state)
|
||||
if (state) {
|
||||
this->data_ = {LED_ON};
|
||||
else
|
||||
} else {
|
||||
this->data_ = {LED_OFF};
|
||||
}
|
||||
switch (this->send_command_()) {
|
||||
case OK:
|
||||
ESP_LOGD(TAG, "LED set");
|
||||
|
@ -33,16 +33,18 @@ void GPIOSwitch::setup() {
|
||||
}
|
||||
|
||||
// write state before setup
|
||||
if (initial_state)
|
||||
if (initial_state) {
|
||||
this->turn_on();
|
||||
else
|
||||
} else {
|
||||
this->turn_off();
|
||||
}
|
||||
this->pin_->setup();
|
||||
// write after setup again for other IOs
|
||||
if (initial_state)
|
||||
if (initial_state) {
|
||||
this->turn_on();
|
||||
else
|
||||
} else {
|
||||
this->turn_off();
|
||||
}
|
||||
}
|
||||
void GPIOSwitch::dump_config() {
|
||||
LOG_SWITCH("", "GPIO Switch", this);
|
||||
|
@ -19,10 +19,11 @@ void set_bits(uint8_t *const dst, const uint8_t offset, const uint8_t nbits, con
|
||||
|
||||
void set_bit(uint8_t *const data, const uint8_t position, const bool on) {
|
||||
uint8_t mask = 1 << position;
|
||||
if (on)
|
||||
if (on) {
|
||||
*data |= mask;
|
||||
else
|
||||
} else {
|
||||
*data &= ~mask;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t *invert_byte_pairs(uint8_t *ptr, const uint16_t length) {
|
||||
@ -69,10 +70,11 @@ void HitachiClimate::set_temp_(uint8_t celsius, bool set_previous) {
|
||||
temp = std::min(celsius, HITACHI_AC344_TEMP_MAX);
|
||||
temp = std::max(temp, HITACHI_AC344_TEMP_MIN);
|
||||
set_bits(&remote_state_[HITACHI_AC344_TEMP_BYTE], HITACHI_AC344_TEMP_OFFSET, HITACHI_AC344_TEMP_SIZE, temp);
|
||||
if (previous_temp_ > temp)
|
||||
if (previous_temp_ > temp) {
|
||||
set_button_(HITACHI_AC344_BUTTON_TEMP_DOWN);
|
||||
else if (previous_temp_ < temp)
|
||||
} else if (previous_temp_ < temp) {
|
||||
set_button_(HITACHI_AC344_BUTTON_TEMP_UP);
|
||||
}
|
||||
if (set_previous)
|
||||
previous_temp_ = temp;
|
||||
}
|
||||
@ -110,11 +112,12 @@ void HitachiClimate::set_fan_(uint8_t speed) {
|
||||
|
||||
void HitachiClimate::set_swing_v_toggle_(bool on) {
|
||||
uint8_t button = get_button_(); // Get the current button value.
|
||||
if (on)
|
||||
button = HITACHI_AC344_BUTTON_SWINGV; // Set the button to SwingV.
|
||||
else if (button == HITACHI_AC344_BUTTON_SWINGV) // Asked to unset it
|
||||
if (on) {
|
||||
button = HITACHI_AC344_BUTTON_SWINGV; // Set the button to SwingV.
|
||||
} else if (button == HITACHI_AC344_BUTTON_SWINGV) { // Asked to unset it
|
||||
// It was set previous, so use Power as a default
|
||||
button = HITACHI_AC344_BUTTON_POWER;
|
||||
}
|
||||
set_button_(button);
|
||||
}
|
||||
|
||||
@ -320,9 +323,9 @@ bool HitachiClimate::on_receive(remote_base::RemoteReceiveData data) {
|
||||
for (uint8_t pos = 0; pos < HITACHI_AC344_STATE_LENGTH; pos++) {
|
||||
// Read bit
|
||||
for (int8_t bit = 0; bit < 8; bit++) {
|
||||
if (data.expect_item(HITACHI_AC344_BIT_MARK, HITACHI_AC344_ONE_SPACE))
|
||||
if (data.expect_item(HITACHI_AC344_BIT_MARK, HITACHI_AC344_ONE_SPACE)) {
|
||||
recv_state[pos] |= 1 << bit;
|
||||
else if (!data.expect_item(HITACHI_AC344_BIT_MARK, HITACHI_AC344_ZERO_SPACE)) {
|
||||
} else if (!data.expect_item(HITACHI_AC344_BIT_MARK, HITACHI_AC344_ZERO_SPACE)) {
|
||||
ESP_LOGVV(TAG, "Byte %d bit %d fail", pos, bit);
|
||||
return false;
|
||||
}
|
||||
|
@ -19,10 +19,11 @@ void set_bits(uint8_t *const dst, const uint8_t offset, const uint8_t nbits, con
|
||||
|
||||
void set_bit(uint8_t *const data, const uint8_t position, const bool on) {
|
||||
uint8_t mask = 1 << position;
|
||||
if (on)
|
||||
if (on) {
|
||||
*data |= mask;
|
||||
else
|
||||
} else {
|
||||
*data &= ~mask;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t *invert_byte_pairs(uint8_t *ptr, const uint16_t length) {
|
||||
@ -69,10 +70,11 @@ void HitachiClimate::set_temp_(uint8_t celsius, bool set_previous) {
|
||||
temp = std::min(celsius, HITACHI_AC424_TEMP_MAX);
|
||||
temp = std::max(temp, HITACHI_AC424_TEMP_MIN);
|
||||
set_bits(&remote_state_[HITACHI_AC424_TEMP_BYTE], HITACHI_AC424_TEMP_OFFSET, HITACHI_AC424_TEMP_SIZE, temp);
|
||||
if (previous_temp_ > temp)
|
||||
if (previous_temp_ > temp) {
|
||||
set_button_(HITACHI_AC424_BUTTON_TEMP_DOWN);
|
||||
else if (previous_temp_ < temp)
|
||||
} else if (previous_temp_ < temp) {
|
||||
set_button_(HITACHI_AC424_BUTTON_TEMP_UP);
|
||||
}
|
||||
if (set_previous)
|
||||
previous_temp_ = temp;
|
||||
}
|
||||
@ -110,11 +112,12 @@ void HitachiClimate::set_fan_(uint8_t speed) {
|
||||
|
||||
void HitachiClimate::set_swing_v_toggle_(bool on) {
|
||||
uint8_t button = get_button_(); // Get the current button value.
|
||||
if (on)
|
||||
button = HITACHI_AC424_BUTTON_SWINGV; // Set the button to SwingV.
|
||||
else if (button == HITACHI_AC424_BUTTON_SWINGV) // Asked to unset it
|
||||
if (on) {
|
||||
button = HITACHI_AC424_BUTTON_SWINGV; // Set the button to SwingV.
|
||||
} else if (button == HITACHI_AC424_BUTTON_SWINGV) { // Asked to unset it
|
||||
// It was set previous, so use Power as a default
|
||||
button = HITACHI_AC424_BUTTON_POWER;
|
||||
}
|
||||
set_button_(button);
|
||||
}
|
||||
|
||||
@ -321,9 +324,9 @@ bool HitachiClimate::on_receive(remote_base::RemoteReceiveData data) {
|
||||
for (uint8_t pos = 0; pos < HITACHI_AC424_STATE_LENGTH; pos++) {
|
||||
// Read bit
|
||||
for (int8_t bit = 0; bit < 8; bit++) {
|
||||
if (data.expect_item(HITACHI_AC424_BIT_MARK, HITACHI_AC424_ONE_SPACE))
|
||||
if (data.expect_item(HITACHI_AC424_BIT_MARK, HITACHI_AC424_ONE_SPACE)) {
|
||||
recv_state[pos] |= 1 << bit;
|
||||
else if (!data.expect_item(HITACHI_AC424_BIT_MARK, HITACHI_AC424_ZERO_SPACE)) {
|
||||
} else if (!data.expect_item(HITACHI_AC424_BIT_MARK, HITACHI_AC424_ZERO_SPACE)) {
|
||||
ESP_LOGVV(TAG, "Byte %d bit %d fail", pos, bit);
|
||||
return false;
|
||||
}
|
||||
|
@ -25,10 +25,11 @@ void HomeassistantBinarySensor::setup() {
|
||||
} else {
|
||||
ESP_LOGD(TAG, "'%s': Got state %s", this->entity_id_.c_str(), ONOFF(new_state));
|
||||
}
|
||||
if (this->initial_)
|
||||
if (this->initial_) {
|
||||
this->publish_initial_state(new_state);
|
||||
else
|
||||
} else {
|
||||
this->publish_state(new_state);
|
||||
}
|
||||
break;
|
||||
}
|
||||
this->initial_ = false;
|
||||
|
@ -16,10 +16,11 @@ void ArduinoI2CBus::setup() {
|
||||
|
||||
#ifdef USE_ESP32
|
||||
static uint8_t next_bus_num = 0;
|
||||
if (next_bus_num == 0)
|
||||
if (next_bus_num == 0) {
|
||||
wire_ = &Wire;
|
||||
else
|
||||
} else {
|
||||
wire_ = new TwoWire(next_bus_num); // NOLINT(cppcoreguidelines-owning-memory)
|
||||
}
|
||||
next_bus_num++;
|
||||
#else
|
||||
wire_ = &Wire; // NOLINT(cppcoreguidelines-prefer-member-initializer)
|
||||
@ -55,10 +56,11 @@ void ArduinoI2CBus::dump_config() {
|
||||
ESP_LOGI(TAG, "Found no i2c devices!");
|
||||
} else {
|
||||
for (const auto &s : scan_results_) {
|
||||
if (s.second)
|
||||
if (s.second) {
|
||||
ESP_LOGI(TAG, "Found i2c device at address 0x%02X", s.first);
|
||||
else
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Unknown error at address 0x%02X", s.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,10 +65,11 @@ void IDFI2CBus::dump_config() {
|
||||
ESP_LOGI(TAG, "Found no i2c devices!");
|
||||
} else {
|
||||
for (const auto &s : scan_results_) {
|
||||
if (s.second)
|
||||
if (s.second) {
|
||||
ESP_LOGI(TAG, "Found i2c device at address 0x%02X", s.first);
|
||||
else
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Unknown error at address 0x%02X", s.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -548,14 +548,15 @@ void Inkplate6::clean_fast_(uint8_t c, uint8_t rep) {
|
||||
|
||||
eink_on_();
|
||||
uint8_t data = 0;
|
||||
if (c == 0) // White
|
||||
if (c == 0) { // White
|
||||
data = 0b10101010;
|
||||
else if (c == 1) // Black
|
||||
} else if (c == 1) { // Black
|
||||
data = 0b01010101;
|
||||
else if (c == 2) // Discharge
|
||||
} else if (c == 2) { // Discharge
|
||||
data = 0b00000000;
|
||||
else if (c == 3) // Skip
|
||||
} else if (c == 3) { // Skip
|
||||
data = 0b11111111;
|
||||
}
|
||||
|
||||
uint32_t send = ((data & 0b00000011) << 4) | (((data & 0b00001100) >> 2) << 18) | (((data & 0b00010000) >> 4) << 23) |
|
||||
(((data & 0b11100000) >> 5) << 25);
|
||||
|
@ -109,18 +109,20 @@ class Inkplate6 : public PollingComponent, public display::DisplayBuffer, public
|
||||
void pins_as_outputs_();
|
||||
|
||||
int get_width_internal() override {
|
||||
if (this->model_ == INKPLATE_6)
|
||||
if (this->model_ == INKPLATE_6) {
|
||||
return 800;
|
||||
else if (this->model_ == INKPLATE_10)
|
||||
} else if (this->model_ == INKPLATE_10) {
|
||||
return 1200;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_height_internal() override {
|
||||
if (this->model_ == INKPLATE_6)
|
||||
if (this->model_ == INKPLATE_6) {
|
||||
return 600;
|
||||
else if (this->model_ == INKPLATE_10)
|
||||
} else if (this->model_ == INKPLATE_10) {
|
||||
return 825;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -98,10 +98,11 @@ void LightCall::perform() {
|
||||
// EFFECT
|
||||
auto effect = this->effect_;
|
||||
const char *effect_s;
|
||||
if (effect == 0u)
|
||||
if (effect == 0u) {
|
||||
effect_s = "None";
|
||||
else
|
||||
} else {
|
||||
effect_s = this->parent_->effects_[*this->effect_ - 1]->get_name().c_str();
|
||||
}
|
||||
|
||||
if (this->publish_) {
|
||||
ESP_LOGD(TAG, " Effect: '%s'", effect_s);
|
||||
@ -445,9 +446,10 @@ std::set<ColorMode> LightCall::get_suitable_color_modes_() {
|
||||
};
|
||||
|
||||
auto key = KEY(has_white, has_ct, has_cwww, has_rgb);
|
||||
for (auto &item : lookup_table)
|
||||
for (auto &item : lookup_table) {
|
||||
if (std::get<0>(item) == key)
|
||||
return std::get<1>(item);
|
||||
}
|
||||
|
||||
// This happens if there are conflicting flags given.
|
||||
return {};
|
||||
|
@ -145,10 +145,11 @@ void LightState::publish_state() { this->remote_values_callback_.call(); }
|
||||
|
||||
LightOutput *LightState::get_output() const { return this->output_; }
|
||||
std::string LightState::get_effect_name() {
|
||||
if (this->active_effect_index_ > 0)
|
||||
if (this->active_effect_index_ > 0) {
|
||||
return this->effects_[this->active_effect_index_ - 1]->get_name();
|
||||
else
|
||||
} else {
|
||||
return "None";
|
||||
}
|
||||
}
|
||||
|
||||
void LightState::add_new_remote_values_callback(std::function<void()> &&send_callback) {
|
||||
@ -219,10 +220,11 @@ void LightState::start_effect_(uint32_t effect_index) {
|
||||
effect->start_internal();
|
||||
}
|
||||
LightEffect *LightState::get_active_effect_() {
|
||||
if (this->active_effect_index_ == 0)
|
||||
if (this->active_effect_index_ == 0) {
|
||||
return nullptr;
|
||||
else
|
||||
} else {
|
||||
return this->effects_[this->active_effect_index_ - 1];
|
||||
}
|
||||
}
|
||||
void LightState::stop_effect_() {
|
||||
auto *effect = this->get_active_effect_();
|
||||
|
@ -143,11 +143,13 @@ void MAX7219Component::dump_config() {
|
||||
void MAX7219Component::display() {
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
this->enable();
|
||||
for (uint8_t j = 0; j < this->num_chips_; j++)
|
||||
if (reverse_)
|
||||
for (uint8_t j = 0; j < this->num_chips_; j++) {
|
||||
if (reverse_) {
|
||||
this->send_byte_(8 - i, buffer_[(num_chips_ - j - 1) * 8 + i]);
|
||||
else
|
||||
} else {
|
||||
this->send_byte_(8 - i, buffer_[j * 8 + i]);
|
||||
}
|
||||
}
|
||||
this->disable();
|
||||
}
|
||||
}
|
||||
|
@ -253,10 +253,11 @@ void MAX7219Component::send_char(uint8_t chip, uint8_t data) {
|
||||
void MAX7219Component::send64pixels(uint8_t chip, const uint8_t pixels[8]) {
|
||||
for (uint8_t col = 0; col < 8; col++) { // RUN THIS LOOP 8 times until column is 7
|
||||
this->enable(); // start sending by enabling SPI
|
||||
for (uint8_t i = 0; i < chip; i++) // send extra NOPs to push the pixels out to extra displays
|
||||
for (uint8_t i = 0; i < chip; i++) { // send extra NOPs to push the pixels out to extra displays
|
||||
this->send_byte_(MAX7219_REGISTER_NOOP,
|
||||
MAX7219_REGISTER_NOOP); // run this loop unit the matching chip is reached
|
||||
uint8_t b = 0; // rotate pixels 90 degrees -- set byte to 0
|
||||
}
|
||||
uint8_t b = 0; // rotate pixels 90 degrees -- set byte to 0
|
||||
if (this->orientation_ == 0) {
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
// run this loop 8 times for all the pixels[8] received
|
||||
|
@ -62,10 +62,11 @@ void MCP23016::update_reg_(uint8_t pin, bool pin_value, uint8_t reg_addr) {
|
||||
this->read_reg_(reg_addr, ®_value);
|
||||
}
|
||||
|
||||
if (pin_value)
|
||||
if (pin_value) {
|
||||
reg_value |= 1 << bit;
|
||||
else
|
||||
} else {
|
||||
reg_value &= ~(1 << bit);
|
||||
}
|
||||
|
||||
this->write_reg_(reg_addr, reg_value);
|
||||
|
||||
|
@ -67,10 +67,11 @@ void MCP23X08Base::update_reg(uint8_t pin, bool pin_value, uint8_t reg_addr) {
|
||||
this->read_reg(reg_addr, ®_value);
|
||||
}
|
||||
|
||||
if (pin_value)
|
||||
if (pin_value) {
|
||||
reg_value |= 1 << bit;
|
||||
else
|
||||
} else {
|
||||
reg_value &= ~(1 << bit);
|
||||
}
|
||||
|
||||
this->write_reg(reg_addr, reg_value);
|
||||
|
||||
|
@ -70,10 +70,11 @@ void MCP23X17Base::update_reg(uint8_t pin, bool pin_value, uint8_t reg_addr) {
|
||||
this->read_reg(reg_addr, ®_value);
|
||||
}
|
||||
|
||||
if (pin_value)
|
||||
if (pin_value) {
|
||||
reg_value |= 1 << bit;
|
||||
else
|
||||
} else {
|
||||
reg_value &= ~(1 << bit);
|
||||
}
|
||||
|
||||
this->write_reg(reg_addr, reg_value);
|
||||
|
||||
|
@ -59,14 +59,16 @@ void AirConditioner::control(const ClimateCall &call) {
|
||||
ctrl.swingMode = Converters::to_midea_swing_mode(call.get_swing_mode().value());
|
||||
if (call.get_mode().has_value())
|
||||
ctrl.mode = Converters::to_midea_mode(call.get_mode().value());
|
||||
if (call.get_preset().has_value())
|
||||
if (call.get_preset().has_value()) {
|
||||
ctrl.preset = Converters::to_midea_preset(call.get_preset().value());
|
||||
else if (call.get_custom_preset().has_value())
|
||||
} else if (call.get_custom_preset().has_value()) {
|
||||
ctrl.preset = Converters::to_midea_preset(call.get_custom_preset().value());
|
||||
if (call.get_fan_mode().has_value())
|
||||
}
|
||||
if (call.get_fan_mode().has_value()) {
|
||||
ctrl.fanMode = Converters::to_midea_fan_mode(call.get_fan_mode().value());
|
||||
else if (call.get_custom_fan_mode().has_value())
|
||||
} else if (call.get_custom_fan_mode().has_value()) {
|
||||
ctrl.fanMode = Converters::to_midea_fan_mode(call.get_custom_fan_mode().value());
|
||||
}
|
||||
this->base_.control(ctrl);
|
||||
}
|
||||
|
||||
|
@ -172,10 +172,11 @@ bool MideaIR::on_midea_(const MideaData &data) {
|
||||
this->target_temperature = status.get_temp();
|
||||
this->mode = status.get_mode();
|
||||
this->fan_mode = status.get_fan_mode();
|
||||
if (status.get_sleep_preset())
|
||||
if (status.get_sleep_preset()) {
|
||||
this->preset = climate::CLIMATE_PRESET_SLEEP;
|
||||
else if (this->preset == climate::CLIMATE_PRESET_SLEEP)
|
||||
} else if (this->preset == climate::CLIMATE_PRESET_SLEEP) {
|
||||
this->preset = climate::CLIMATE_PRESET_NONE;
|
||||
}
|
||||
this->publish_state();
|
||||
return true;
|
||||
}
|
||||
|
@ -63,12 +63,13 @@ void MitsubishiClimate::transmit_state() {
|
||||
data->mark(MITSUBISHI_HEADER_MARK);
|
||||
data->space(MITSUBISHI_HEADER_SPACE);
|
||||
// Data
|
||||
for (uint8_t i : remote_state)
|
||||
for (uint8_t i : remote_state) {
|
||||
for (uint8_t j = 0; j < 8; j++) {
|
||||
data->mark(MITSUBISHI_BIT_MARK);
|
||||
bool bit = i & (1 << j);
|
||||
data->space(bit ? MITSUBISHI_ONE_SPACE : MITSUBISHI_ZERO_SPACE);
|
||||
}
|
||||
}
|
||||
// Footer
|
||||
if (r == 0) {
|
||||
data->mark(MITSUBISHI_BIT_MARK);
|
||||
|
@ -19,10 +19,11 @@ class ModbusBinarySensor : public Component, public binary_sensor::BinarySensor,
|
||||
this->skip_updates = skip_updates;
|
||||
this->force_new_range = force_new_range;
|
||||
|
||||
if (register_type == ModbusRegisterType::COIL || register_type == ModbusRegisterType::DISCRETE_INPUT)
|
||||
if (register_type == ModbusRegisterType::COIL || register_type == ModbusRegisterType::DISCRETE_INPUT) {
|
||||
this->register_count = offset + 1;
|
||||
else
|
||||
} else {
|
||||
this->register_count = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void parse_and_publish(const std::vector<uint8_t> &data) override;
|
||||
|
@ -230,10 +230,11 @@ class SensorItem {
|
||||
|
||||
void set_custom_data(const std::vector<uint8_t> &data) { custom_data = data; }
|
||||
size_t virtual get_register_size() const {
|
||||
if (register_type == ModbusRegisterType::COIL || register_type == ModbusRegisterType::DISCRETE_INPUT)
|
||||
if (register_type == ModbusRegisterType::COIL || register_type == ModbusRegisterType::DISCRETE_INPUT) {
|
||||
return 1;
|
||||
else // if CONF_RESPONSE_BYTES is used override the default
|
||||
} else { // if CONF_RESPONSE_BYTES is used override the default
|
||||
return response_bytes > 0 ? response_bytes : register_count * 2;
|
||||
}
|
||||
}
|
||||
// Override register size for modbus devices not using 1 register for one dword
|
||||
void set_register_size(uint8_t register_size) { response_bytes = register_size; }
|
||||
|
@ -373,10 +373,11 @@ void MQTTClientComponent::unsubscribe(const std::string &topic) {
|
||||
|
||||
auto it = subscriptions_.begin();
|
||||
while (it != subscriptions_.end()) {
|
||||
if (it->topic == topic)
|
||||
if (it->topic == topic) {
|
||||
it = subscriptions_.erase(it);
|
||||
else
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -484,9 +485,10 @@ void MQTTClientComponent::on_message(const std::string &topic, const std::string
|
||||
// in an ISR.
|
||||
this->defer([this, topic, payload]() {
|
||||
#endif
|
||||
for (auto &subscription : this->subscriptions_)
|
||||
for (auto &subscription : this->subscriptions_) {
|
||||
if (topic_match(topic.c_str(), subscription.topic.c_str()))
|
||||
subscription.callback(topic, payload);
|
||||
}
|
||||
#ifdef USE_ESP8266
|
||||
});
|
||||
#endif
|
||||
|
@ -299,7 +299,7 @@ bool MQTTClimateComponent::publish_state_() {
|
||||
|
||||
if (traits.get_supports_fan_modes()) {
|
||||
std::string payload;
|
||||
if (this->device_->fan_mode.has_value())
|
||||
if (this->device_->fan_mode.has_value()) {
|
||||
switch (this->device_->fan_mode.value()) {
|
||||
case CLIMATE_FAN_ON:
|
||||
payload = "on";
|
||||
@ -329,6 +329,7 @@ bool MQTTClimateComponent::publish_state_() {
|
||||
payload = "diffuse";
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (this->device_->custom_fan_mode.has_value())
|
||||
payload = this->device_->custom_fan_mode.value();
|
||||
if (!this->publish(this->get_fan_mode_state_topic(), payload))
|
||||
|
@ -737,9 +737,10 @@ void Nextion::process_nextion_commands_() {
|
||||
for (size_t i = 0; i < this->nextion_queue_.size(); i++) {
|
||||
NextionComponentBase *component = this->nextion_queue_[i]->component;
|
||||
if (this->nextion_queue_[i]->queue_time + this->max_q_age_ms_ < ms) {
|
||||
if (this->nextion_queue_[i]->queue_time == 0)
|
||||
if (this->nextion_queue_[i]->queue_time == 0) {
|
||||
ESP_LOGD(TAG, "Removing old queue type \"%s\" name \"%s\" queue_time 0",
|
||||
component->get_queue_type_string().c_str(), component->get_variable_name().c_str());
|
||||
}
|
||||
|
||||
if (component->get_variable_name() == "sleep_wake") {
|
||||
this->is_sleeping_ = false;
|
||||
@ -873,9 +874,9 @@ uint16_t Nextion::recv_ret_string_(std::string &response, uint32_t timeout, bool
|
||||
|
||||
while ((timeout == 0 && this->available()) || millis() - start <= timeout) {
|
||||
this->read_byte(&c);
|
||||
if (c == 0xFF)
|
||||
if (c == 0xFF) {
|
||||
nr_of_ff_bytes++;
|
||||
else {
|
||||
} else {
|
||||
nr_of_ff_bytes = 0;
|
||||
ff_flag = false;
|
||||
}
|
||||
|
@ -452,10 +452,11 @@ bool OTAComponent::should_enter_safe_mode(uint8_t num_attempts, uint32_t enable_
|
||||
|
||||
bool is_manual_safe_mode = this->safe_mode_rtc_value_ == esphome::ota::OTAComponent::ENTER_SAFE_MODE_MAGIC;
|
||||
|
||||
if (is_manual_safe_mode)
|
||||
if (is_manual_safe_mode) {
|
||||
ESP_LOGI(TAG, "Safe mode has been entered manually");
|
||||
else
|
||||
} else {
|
||||
ESP_LOGCONFIG(TAG, "There have been %u suspected unsuccessful boot attempts.", this->safe_mode_rtc_value_);
|
||||
}
|
||||
|
||||
if (this->safe_mode_rtc_value_ >= num_attempts || is_manual_safe_mode) {
|
||||
this->clean_rtc();
|
||||
|
@ -32,10 +32,11 @@ class BinaryOutput {
|
||||
|
||||
/// Enable or disable this binary output.
|
||||
virtual void set_state(bool state) {
|
||||
if (state)
|
||||
if (state) {
|
||||
this->turn_on();
|
||||
else
|
||||
} else {
|
||||
this->turn_off();
|
||||
}
|
||||
}
|
||||
|
||||
/// Enable this binary output.
|
||||
|
@ -30,10 +30,11 @@ void OutputSwitch::setup() {
|
||||
break;
|
||||
}
|
||||
|
||||
if (initial_state)
|
||||
if (initial_state) {
|
||||
this->turn_on();
|
||||
else
|
||||
} else {
|
||||
this->turn_off();
|
||||
}
|
||||
}
|
||||
void OutputSwitch::write_state(bool state) {
|
||||
if (state) {
|
||||
|
@ -78,10 +78,11 @@ class PartitionLightOutput : public light::AddressableLight {
|
||||
int32_t seg_off = index - seg.get_dst_offset();
|
||||
// offset within the src
|
||||
int32_t src_off;
|
||||
if (seg.is_reversed())
|
||||
if (seg.is_reversed()) {
|
||||
src_off = seg.get_src_offset() + seg.get_size() - seg_off - 1;
|
||||
else
|
||||
} else {
|
||||
src_off = seg.get_src_offset() + seg_off;
|
||||
}
|
||||
|
||||
auto view = (*seg.get_src())[src_off];
|
||||
view.raw_set_color_correction(&this->correction_);
|
||||
|
@ -20,12 +20,13 @@ void PIDClimate::setup() {
|
||||
restore->to_call(this).perform();
|
||||
} else {
|
||||
// restore from defaults, change_away handles those for us
|
||||
if (supports_heat_() && supports_cool_())
|
||||
if (supports_heat_() && supports_cool_()) {
|
||||
this->mode = climate::CLIMATE_MODE_HEAT_COOL;
|
||||
else if (supports_cool_())
|
||||
} else if (supports_cool_()) {
|
||||
this->mode = climate::CLIMATE_MODE_COOL;
|
||||
else if (supports_heat_())
|
||||
} else if (supports_heat_()) {
|
||||
this->mode = climate::CLIMATE_MODE_HEAT;
|
||||
}
|
||||
this->target_temperature = this->default_target_temperature_;
|
||||
}
|
||||
}
|
||||
@ -83,14 +84,15 @@ void PIDClimate::write_output_(float value) {
|
||||
|
||||
// Update action variable for user feedback what's happening
|
||||
climate::ClimateAction new_action;
|
||||
if (this->supports_cool_() && value < 0)
|
||||
if (this->supports_cool_() && value < 0) {
|
||||
new_action = climate::CLIMATE_ACTION_COOLING;
|
||||
else if (this->supports_heat_() && value > 0)
|
||||
} else if (this->supports_heat_() && value > 0) {
|
||||
new_action = climate::CLIMATE_ACTION_HEATING;
|
||||
else if (this->mode == climate::CLIMATE_MODE_OFF)
|
||||
} else if (this->mode == climate::CLIMATE_MODE_OFF) {
|
||||
new_action = climate::CLIMATE_ACTION_OFF;
|
||||
else
|
||||
} else {
|
||||
new_action = climate::CLIMATE_ACTION_IDLE;
|
||||
}
|
||||
|
||||
if (new_action != this->action) {
|
||||
this->action = new_action;
|
||||
|
@ -908,10 +908,11 @@ uint16_t Pipsolar::crc_xmodem_update_(uint16_t crc, uint8_t data) {
|
||||
int i;
|
||||
crc = crc ^ ((uint16_t) data << 8);
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (crc & 0x8000)
|
||||
if (crc & 0x8000) {
|
||||
crc = (crc << 1) ^ 0x1021; //(polynomial = 0x1021)
|
||||
else
|
||||
} else {
|
||||
crc <<= 1;
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
@ -139,10 +139,11 @@ void RC522::loop() {
|
||||
|
||||
StatusCode status = STATUS_ERROR; // For lint passing. TODO: refactor this
|
||||
if (awaiting_comm_) {
|
||||
if (state_ == STATE_SELECT_SERIAL_DONE)
|
||||
if (state_ == STATE_SELECT_SERIAL_DONE) {
|
||||
status = await_crc_();
|
||||
else
|
||||
} else {
|
||||
status = await_transceive_();
|
||||
}
|
||||
|
||||
if (status == STATUS_WAITING) {
|
||||
return;
|
||||
@ -210,11 +211,12 @@ void RC522::loop() {
|
||||
}
|
||||
case STATE_READ_SERIAL_DONE: {
|
||||
if (status != STATUS_OK || back_length_ != 3) {
|
||||
if (status == STATUS_TIMEOUT)
|
||||
if (status == STATUS_TIMEOUT) {
|
||||
ESP_LOGV(TAG, "STATE_READ_SERIAL_DONE -> TIMEOUT (no tag present) %d", status);
|
||||
else
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Unexpected response. Read status is %d. Read bytes: %d (%s)", status, back_length_,
|
||||
format_buffer(buffer_, 9).c_str());
|
||||
}
|
||||
|
||||
state_ = STATE_DONE;
|
||||
uid_idx_ = 0;
|
||||
@ -476,9 +478,9 @@ RC522::StatusCode RC522::await_crc_() {
|
||||
|
||||
bool RC522BinarySensor::process(std::vector<uint8_t> &data) {
|
||||
bool result = true;
|
||||
if (data.size() != this->uid_.size())
|
||||
if (data.size() != this->uid_.size()) {
|
||||
result = false;
|
||||
else {
|
||||
} else {
|
||||
for (size_t i = 0; i < data.size(); i++) {
|
||||
if (data[i] != this->uid_[i]) {
|
||||
result = false;
|
||||
|
@ -51,10 +51,11 @@ static bool decode_data(RemoteReceiveData &src, CoolixData &dst) {
|
||||
for (uint32_t mask = 1 << 7; mask; mask >>= 1) {
|
||||
if (!src.expect_mark(BIT_MARK_US))
|
||||
return false;
|
||||
if (src.expect_space(BIT_ONE_SPACE_US))
|
||||
if (src.expect_space(BIT_ONE_SPACE_US)) {
|
||||
data |= mask;
|
||||
else if (!src.expect_space(BIT_ZERO_SPACE_US))
|
||||
} else if (!src.expect_space(BIT_ZERO_SPACE_US)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Check for inverse byte
|
||||
for (uint32_t mask = 1 << 7; mask; mask >>= 1) {
|
||||
|
@ -24,18 +24,20 @@ void DishProtocol::encode(RemoteTransmitData *dst, const DishData &data) {
|
||||
for (uint i = 0; i < 4; i++) {
|
||||
// COMMAND (function, in MSB)
|
||||
for (uint8_t mask = 1UL << 5; mask; mask >>= 1) {
|
||||
if (data.command & mask)
|
||||
if (data.command & mask) {
|
||||
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
|
||||
else
|
||||
} else {
|
||||
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
|
||||
}
|
||||
}
|
||||
|
||||
// ADDRESS (unit code, in LSB)
|
||||
for (uint8_t mask = 1UL; mask < 1UL << 4; mask <<= 1) {
|
||||
if ((data.address - 1) & mask)
|
||||
if ((data.address - 1) & mask) {
|
||||
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
|
||||
else
|
||||
} else {
|
||||
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
|
||||
}
|
||||
}
|
||||
// PADDING
|
||||
for (uint j = 0; j < 6; j++)
|
||||
|
@ -20,10 +20,11 @@ void JVCProtocol::encode(RemoteTransmitData *dst, const JVCData &data) {
|
||||
dst->item(HEADER_HIGH_US, HEADER_LOW_US);
|
||||
|
||||
for (uint32_t mask = 1UL << (NBITS - 1); mask != 0; mask >>= 1) {
|
||||
if (data.data & mask)
|
||||
if (data.data & mask) {
|
||||
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
|
||||
else
|
||||
} else {
|
||||
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
|
||||
}
|
||||
}
|
||||
|
||||
dst->mark(BIT_HIGH_US);
|
||||
|
@ -19,10 +19,11 @@ void LGProtocol::encode(RemoteTransmitData *dst, const LGData &data) {
|
||||
dst->item(HEADER_HIGH_US, HEADER_LOW_US);
|
||||
|
||||
for (uint32_t mask = 1UL << (data.nbits - 1); mask != 0; mask >>= 1) {
|
||||
if (data.data & mask)
|
||||
if (data.data & mask) {
|
||||
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
|
||||
else
|
||||
} else {
|
||||
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
|
||||
}
|
||||
}
|
||||
|
||||
dst->mark(BIT_HIGH_US);
|
||||
|
@ -31,14 +31,16 @@ void MideaProtocol::encode(RemoteTransmitData *dst, const MideaData &src) {
|
||||
dst->set_carrier_frequency(38000);
|
||||
dst->reserve(2 + 48 * 2 + 2 + 2 + 48 * 2 + 1);
|
||||
dst->item(HEADER_MARK_US, HEADER_SPACE_US);
|
||||
for (unsigned idx = 0; idx < 6; idx++)
|
||||
for (unsigned idx = 0; idx < 6; idx++) {
|
||||
for (uint8_t mask = 1 << 7; mask; mask >>= 1)
|
||||
dst->item(BIT_MARK_US, (src[idx] & mask) ? BIT_ONE_SPACE_US : BIT_ZERO_SPACE_US);
|
||||
}
|
||||
dst->item(FOOTER_MARK_US, FOOTER_SPACE_US);
|
||||
dst->item(HEADER_MARK_US, HEADER_SPACE_US);
|
||||
for (unsigned idx = 0; idx < 6; idx++)
|
||||
for (unsigned idx = 0; idx < 6; idx++) {
|
||||
for (uint8_t mask = 1 << 7; mask; mask >>= 1)
|
||||
dst->item(BIT_MARK_US, (src[idx] & mask) ? BIT_ZERO_SPACE_US : BIT_ONE_SPACE_US);
|
||||
}
|
||||
dst->mark(FOOTER_MARK_US);
|
||||
}
|
||||
|
||||
@ -48,10 +50,11 @@ static bool decode_data(RemoteReceiveData &src, MideaData &dst) {
|
||||
for (uint8_t mask = 1 << 7; mask; mask >>= 1) {
|
||||
if (!src.expect_mark(BIT_MARK_US))
|
||||
return false;
|
||||
if (src.expect_space(BIT_ONE_SPACE_US))
|
||||
if (src.expect_space(BIT_ONE_SPACE_US)) {
|
||||
data |= mask;
|
||||
else if (!src.expect_space(BIT_ZERO_SPACE_US))
|
||||
} else if (!src.expect_space(BIT_ZERO_SPACE_US)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
dst[idx] = data;
|
||||
}
|
||||
|
@ -18,17 +18,19 @@ void NECProtocol::encode(RemoteTransmitData *dst, const NECData &data) {
|
||||
|
||||
dst->item(HEADER_HIGH_US, HEADER_LOW_US);
|
||||
for (uint16_t mask = 1; mask; mask <<= 1) {
|
||||
if (data.address & mask)
|
||||
if (data.address & mask) {
|
||||
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
|
||||
else
|
||||
} else {
|
||||
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
|
||||
}
|
||||
}
|
||||
|
||||
for (uint16_t mask = 1; mask; mask <<= 1) {
|
||||
if (data.command & mask)
|
||||
if (data.command & mask) {
|
||||
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
|
||||
else
|
||||
} else {
|
||||
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
|
||||
}
|
||||
}
|
||||
|
||||
dst->mark(BIT_HIGH_US);
|
||||
|
@ -41,43 +41,48 @@ void NexaProtocol::encode(RemoteTransmitData *dst, const NexaData &data) {
|
||||
|
||||
// Device (26 bits)
|
||||
for (int16_t i = 26 - 1; i >= 0; i--) {
|
||||
if (data.device & (1 << i))
|
||||
if (data.device & (1 << i)) {
|
||||
this->one(dst);
|
||||
else
|
||||
} else {
|
||||
this->zero(dst);
|
||||
}
|
||||
}
|
||||
|
||||
// Group (1 bit)
|
||||
if (data.group != 0)
|
||||
if (data.group != 0) {
|
||||
this->one(dst);
|
||||
else
|
||||
} else {
|
||||
this->zero(dst);
|
||||
}
|
||||
|
||||
// State (1 bit)
|
||||
if (data.state == 2) {
|
||||
// Special case for dimmers...send 00 as state
|
||||
dst->item(TX_BIT_HIGH_US, TX_BIT_ZERO_LOW_US);
|
||||
dst->item(TX_BIT_HIGH_US, TX_BIT_ZERO_LOW_US);
|
||||
} else if (data.state == 1)
|
||||
} else if (data.state == 1) {
|
||||
this->one(dst);
|
||||
else
|
||||
} else {
|
||||
this->zero(dst);
|
||||
}
|
||||
|
||||
// Channel (4 bits)
|
||||
for (int16_t i = 4 - 1; i >= 0; i--) {
|
||||
if (data.channel & (1 << i))
|
||||
if (data.channel & (1 << i)) {
|
||||
this->one(dst);
|
||||
else
|
||||
} else {
|
||||
this->zero(dst);
|
||||
}
|
||||
}
|
||||
|
||||
// Level (4 bits)
|
||||
if (data.state == 2) {
|
||||
for (int16_t i = 4 - 1; i >= 0; i--) {
|
||||
if (data.level & (1 << i))
|
||||
if (data.level & (1 << i)) {
|
||||
this->one(dst);
|
||||
else
|
||||
} else {
|
||||
this->zero(dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,17 +19,19 @@ void PanasonicProtocol::encode(RemoteTransmitData *dst, const PanasonicData &dat
|
||||
|
||||
uint32_t mask;
|
||||
for (mask = 1UL << 15; mask != 0; mask >>= 1) {
|
||||
if (data.address & mask)
|
||||
if (data.address & mask) {
|
||||
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
|
||||
else
|
||||
} else {
|
||||
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
|
||||
}
|
||||
}
|
||||
|
||||
for (mask = 1UL << 31; mask != 0; mask >>= 1) {
|
||||
if (data.command & mask)
|
||||
if (data.command & mask) {
|
||||
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
|
||||
else
|
||||
} else {
|
||||
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
|
||||
}
|
||||
}
|
||||
dst->mark(BIT_HIGH_US);
|
||||
}
|
||||
|
@ -42,26 +42,29 @@ void PioneerProtocol::encode(RemoteTransmitData *dst, const PioneerData &data) {
|
||||
command1 = (command1 << 8) | ((~command1) & 0xff);
|
||||
command2 = (command2 << 8) | ((~command2) & 0xff);
|
||||
|
||||
if (data.rc_code_2 == 0)
|
||||
if (data.rc_code_2 == 0) {
|
||||
dst->reserve(68);
|
||||
else
|
||||
} else {
|
||||
dst->reserve((68 * 2) + 1);
|
||||
}
|
||||
|
||||
dst->set_carrier_frequency(40000);
|
||||
|
||||
dst->item(HEADER_HIGH_US, HEADER_LOW_US);
|
||||
for (uint32_t mask = 1UL << 15; mask; mask >>= 1) {
|
||||
if (address1 & mask)
|
||||
if (address1 & mask) {
|
||||
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
|
||||
else
|
||||
} else {
|
||||
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t mask = 1UL << 15; mask; mask >>= 1) {
|
||||
if (command1 & mask)
|
||||
if (command1 & mask) {
|
||||
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
|
||||
else
|
||||
} else {
|
||||
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
|
||||
}
|
||||
}
|
||||
|
||||
dst->mark(BIT_HIGH_US);
|
||||
@ -70,17 +73,19 @@ void PioneerProtocol::encode(RemoteTransmitData *dst, const PioneerData &data) {
|
||||
dst->space(TRAILER_SPACE_US);
|
||||
dst->item(HEADER_HIGH_US, HEADER_LOW_US);
|
||||
for (uint32_t mask = 1UL << 15; mask; mask >>= 1) {
|
||||
if (address2 & mask)
|
||||
if (address2 & mask) {
|
||||
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
|
||||
else
|
||||
} else {
|
||||
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t mask = 1UL << 15; mask; mask >>= 1) {
|
||||
if (command2 & mask)
|
||||
if (command2 & mask) {
|
||||
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
|
||||
else
|
||||
} else {
|
||||
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
|
||||
}
|
||||
}
|
||||
|
||||
dst->mark(BIT_HIGH_US);
|
||||
@ -140,10 +145,11 @@ optional<PioneerData> PioneerProtocol::decode(RemoteReceiveData src) {
|
||||
return data;
|
||||
}
|
||||
void PioneerProtocol::dump(const PioneerData &data) {
|
||||
if (data.rc_code_2 == 0)
|
||||
if (data.rc_code_2 == 0) {
|
||||
ESP_LOGD(TAG, "Received Pioneer: rc_code_X=0x%04X", data.rc_code_1);
|
||||
else
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Received Pioneer: rc_code_1=0x%04X, rc_code_2=0x%04X", data.rc_code_1, data.rc_code_2);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace remote_base
|
||||
|
@ -50,10 +50,11 @@ template<typename... Ts> class RawAction : public RemoteTransmitterActionBase<Ts
|
||||
if (this->code_static_ != nullptr) {
|
||||
for (size_t i = 0; i < this->code_static_len_; i++) {
|
||||
auto val = this->code_static_[i];
|
||||
if (val < 0)
|
||||
if (val < 0) {
|
||||
dst->space(static_cast<uint32_t>(-val));
|
||||
else
|
||||
} else {
|
||||
dst->mark(static_cast<uint32_t>(val));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dst->set_data(this->code_func_(x...));
|
||||
|
@ -57,10 +57,11 @@ void RCSwitchBase::transmit(RemoteTransmitData *dst, uint64_t code, uint8_t len)
|
||||
dst->set_carrier_frequency(0);
|
||||
this->sync(dst);
|
||||
for (int16_t i = len - 1; i >= 0; i--) {
|
||||
if (code & ((uint64_t) 1 << i))
|
||||
if (code & ((uint64_t) 1 << i)) {
|
||||
this->one(dst);
|
||||
else
|
||||
} else {
|
||||
this->zero(dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,10 +149,11 @@ void RCSwitchBase::simple_code_to_tristate(uint16_t code, uint8_t nbits, uint64_
|
||||
*out_code = 0;
|
||||
for (int8_t i = nbits - 1; i >= 0; i--) {
|
||||
*out_code <<= 2;
|
||||
if (code & (1 << i))
|
||||
if (code & (1 << i)) {
|
||||
*out_code |= 0b01;
|
||||
else
|
||||
} else {
|
||||
*out_code |= 0b00;
|
||||
}
|
||||
}
|
||||
}
|
||||
void RCSwitchBase::type_a_code(uint8_t switch_group, uint8_t switch_device, bool state, uint64_t *out_code,
|
||||
|
@ -22,10 +22,11 @@ void SamsungProtocol::encode(RemoteTransmitData *dst, const SamsungData &data) {
|
||||
dst->item(HEADER_HIGH_US, HEADER_LOW_US);
|
||||
|
||||
for (uint8_t bit = data.nbits; bit > 0; bit--) {
|
||||
if ((data.data >> (bit - 1)) & 1)
|
||||
if ((data.data >> (bit - 1)) & 1) {
|
||||
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
|
||||
else
|
||||
} else {
|
||||
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
|
||||
}
|
||||
}
|
||||
|
||||
dst->item(FOOTER_HIGH_US, FOOTER_LOW_US);
|
||||
|
@ -19,10 +19,11 @@ void SonyProtocol::encode(RemoteTransmitData *dst, const SonyData &data) {
|
||||
dst->item(HEADER_HIGH_US, HEADER_LOW_US);
|
||||
|
||||
for (uint32_t mask = 1UL << (data.nbits - 1); mask != 0; mask >>= 1) {
|
||||
if (data.data & mask)
|
||||
if (data.data & mask) {
|
||||
dst->item(BIT_ONE_HIGH_US, BIT_LOW_US);
|
||||
else
|
||||
} else {
|
||||
dst->item(BIT_ZERO_HIGH_US, BIT_LOW_US);
|
||||
}
|
||||
}
|
||||
}
|
||||
optional<SonyData> SonyProtocol::decode(RemoteReceiveData src) {
|
||||
|
@ -24,10 +24,11 @@ void ToshibaAcProtocol::encode(RemoteTransmitData *dst, const ToshibaAcData &dat
|
||||
dst->item(HEADER_HIGH_US, HEADER_LOW_US);
|
||||
for (uint8_t bit = 48; bit > 0; bit--) {
|
||||
dst->mark(BIT_HIGH_US);
|
||||
if ((data.rc_code_1 >> (bit - 1)) & 1)
|
||||
if ((data.rc_code_1 >> (bit - 1)) & 1) {
|
||||
dst->space(BIT_ONE_LOW_US);
|
||||
else
|
||||
} else {
|
||||
dst->space(BIT_ZERO_LOW_US);
|
||||
}
|
||||
}
|
||||
dst->item(FOOTER_HIGH_US, FOOTER_LOW_US);
|
||||
}
|
||||
@ -36,10 +37,11 @@ void ToshibaAcProtocol::encode(RemoteTransmitData *dst, const ToshibaAcData &dat
|
||||
dst->item(HEADER_HIGH_US, HEADER_LOW_US);
|
||||
for (uint8_t bit = 48; bit > 0; bit--) {
|
||||
dst->mark(BIT_HIGH_US);
|
||||
if ((data.rc_code_2 >> (bit - 1)) & 1)
|
||||
if ((data.rc_code_2 >> (bit - 1)) & 1) {
|
||||
dst->space(BIT_ONE_LOW_US);
|
||||
else
|
||||
} else {
|
||||
dst->space(BIT_ZERO_LOW_US);
|
||||
}
|
||||
}
|
||||
dst->item(FOOTER_HIGH_US, FOOTER_LOW_US);
|
||||
}
|
||||
@ -102,10 +104,11 @@ optional<ToshibaAcData> ToshibaAcProtocol::decode(RemoteReceiveData src) {
|
||||
}
|
||||
|
||||
void ToshibaAcProtocol::dump(const ToshibaAcData &data) {
|
||||
if (data.rc_code_2 != 0)
|
||||
if (data.rc_code_2 != 0) {
|
||||
ESP_LOGD(TAG, "Received Toshiba AC: rc_code_1=0x%" PRIX64 ", rc_code_2=0x%" PRIX64, data.rc_code_1, data.rc_code_2);
|
||||
else
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Received Toshiba AC: rc_code_1=0x%" PRIX64, data.rc_code_1);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace remote_base
|
||||
|
@ -79,9 +79,10 @@ void RemoteReceiverComponent::loop() {
|
||||
if (dist <= 1)
|
||||
return;
|
||||
const uint32_t now = micros();
|
||||
if (now - s.buffer[write_at] < this->idle_us_)
|
||||
if (now - s.buffer[write_at] < this->idle_us_) {
|
||||
// The last change was fewer than the configured idle time ago.
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGVV(TAG, "read_at=%u write_at=%u dist=%u now=%u end=%u", s.buffer_read_at, write_at, dist, now,
|
||||
s.buffer[write_at]);
|
||||
|
@ -35,10 +35,11 @@ void RemoteTransmitterComponent::calculate_on_off_time_(uint32_t carrier_frequen
|
||||
|
||||
void RemoteTransmitterComponent::await_target_time_() {
|
||||
const uint32_t current_time = micros();
|
||||
if (this->target_time_ == 0)
|
||||
if (this->target_time_ == 0) {
|
||||
this->target_time_ = current_time;
|
||||
else if (this->target_time_ > current_time)
|
||||
} else if (this->target_time_ > current_time) {
|
||||
delayMicroseconds(this->target_time_ - current_time);
|
||||
}
|
||||
}
|
||||
|
||||
void RemoteTransmitterComponent::mark_(uint32_t on_time, uint32_t off_time, uint32_t usec) {
|
||||
|
@ -20,16 +20,18 @@ void ResistanceSensor::process_(float value) {
|
||||
float res = 0;
|
||||
switch (this->configuration_) {
|
||||
case UPSTREAM:
|
||||
if (value == 0.0f)
|
||||
if (value == 0.0f) {
|
||||
res = NAN;
|
||||
else
|
||||
} else {
|
||||
res = (this->reference_voltage_ - value) / value;
|
||||
}
|
||||
break;
|
||||
case DOWNSTREAM:
|
||||
if (value == this->reference_voltage_)
|
||||
if (value == this->reference_voltage_) {
|
||||
res = NAN;
|
||||
else
|
||||
} else {
|
||||
res = value / (this->reference_voltage_ - value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -104,10 +104,11 @@ void Rtttl::loop() {
|
||||
// first, get note duration, if available
|
||||
uint8_t num = this->get_integer_();
|
||||
|
||||
if (num)
|
||||
if (num) {
|
||||
note_duration_ = wholenote_ / num;
|
||||
else
|
||||
} else {
|
||||
note_duration_ = wholenote_ / default_duration_; // we will need to check if we are a dotted note after
|
||||
}
|
||||
|
||||
uint8_t note;
|
||||
|
||||
|
@ -229,18 +229,20 @@ uint8_t SCD30Component::sht_crc_(uint8_t data1, uint8_t data2) {
|
||||
|
||||
crc ^= data1;
|
||||
for (bit = 8; bit > 0; --bit) {
|
||||
if (crc & 0x80)
|
||||
if (crc & 0x80) {
|
||||
crc = (crc << 1) ^ 0x131;
|
||||
else
|
||||
} else {
|
||||
crc = (crc << 1);
|
||||
}
|
||||
}
|
||||
|
||||
crc ^= data2;
|
||||
for (bit = 8; bit > 0; --bit) {
|
||||
if (crc & 0x80)
|
||||
if (crc & 0x80) {
|
||||
crc = (crc << 1) ^ 0x131;
|
||||
else
|
||||
} else {
|
||||
crc = (crc << 1);
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
|
@ -233,18 +233,20 @@ uint8_t SCD4XComponent::sht_crc_(uint8_t data1, uint8_t data2) {
|
||||
|
||||
crc ^= data1;
|
||||
for (bit = 8; bit > 0; --bit) {
|
||||
if (crc & 0x80)
|
||||
if (crc & 0x80) {
|
||||
crc = (crc << 1) ^ 0x131;
|
||||
else
|
||||
} else {
|
||||
crc = (crc << 1);
|
||||
}
|
||||
}
|
||||
|
||||
crc ^= data2;
|
||||
for (bit = 8; bit > 0; --bit) {
|
||||
if (crc & 0x80)
|
||||
if (crc & 0x80) {
|
||||
crc = (crc << 1) ^ 0x131;
|
||||
else
|
||||
} else {
|
||||
crc = (crc << 1);
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
|
@ -138,10 +138,11 @@ bool SDP3XComponent::check_crc_(const uint8_t data[], uint8_t size, uint8_t chec
|
||||
for (int i = 0; i < size; i++) {
|
||||
crc ^= (data[i]);
|
||||
for (uint8_t bit = 8; bit > 0; --bit) {
|
||||
if (crc & 0x80)
|
||||
if (crc & 0x80) {
|
||||
crc = (crc << 1) ^ 0x31;
|
||||
else
|
||||
} else {
|
||||
crc = (crc << 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -176,10 +176,11 @@ optional<float> SlidingWindowMovingAverageFilter::new_value(float value) {
|
||||
this->sum_ += value;
|
||||
}
|
||||
float average;
|
||||
if (this->queue_.empty())
|
||||
if (this->queue_.empty()) {
|
||||
average = 0.0f;
|
||||
else
|
||||
} else {
|
||||
average = this->sum_ / this->queue_.size();
|
||||
}
|
||||
ESP_LOGVV(TAG, "SlidingWindowMovingAverageFilter(%p)::new_value(%f) -> %f", this, value, average);
|
||||
|
||||
if (++this->send_at_ % this->send_every_ == 0) {
|
||||
@ -203,10 +204,11 @@ ExponentialMovingAverageFilter::ExponentialMovingAverageFilter(float alpha, size
|
||||
: send_every_(send_every), send_at_(send_every - 1), alpha_(alpha) {}
|
||||
optional<float> ExponentialMovingAverageFilter::new_value(float value) {
|
||||
if (!std::isnan(value)) {
|
||||
if (this->first_value_)
|
||||
if (this->first_value_) {
|
||||
this->accumulator_ = value;
|
||||
else
|
||||
} else {
|
||||
this->accumulator_ = (this->alpha_ * value) + (1.0f - this->alpha_) * this->accumulator_;
|
||||
}
|
||||
this->first_value_ = false;
|
||||
}
|
||||
|
||||
@ -274,19 +276,21 @@ FilterOutValueFilter::FilterOutValueFilter(float value_to_filter_out) : value_to
|
||||
|
||||
optional<float> FilterOutValueFilter::new_value(float value) {
|
||||
if (std::isnan(this->value_to_filter_out_)) {
|
||||
if (std::isnan(value))
|
||||
if (std::isnan(value)) {
|
||||
return {};
|
||||
else
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
} else {
|
||||
int8_t accuracy = this->parent_->get_accuracy_decimals();
|
||||
float accuracy_mult = powf(10.0f, accuracy);
|
||||
float rounded_filter_out = roundf(accuracy_mult * this->value_to_filter_out_);
|
||||
float rounded_value = roundf(accuracy_mult * value);
|
||||
if (rounded_filter_out == rounded_value)
|
||||
if (rounded_filter_out == rounded_value) {
|
||||
return {};
|
||||
else
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,10 +65,11 @@ void Servo::write(float value) {
|
||||
void Servo::internal_write(float value) {
|
||||
value = clamp(value, -1.0f, 1.0f);
|
||||
float level;
|
||||
if (value < 0.0)
|
||||
if (value < 0.0) {
|
||||
level = lerp(-value, this->idle_level_, this->min_level_);
|
||||
else
|
||||
} else {
|
||||
level = lerp(value, this->idle_level_, this->max_level_);
|
||||
}
|
||||
this->output_->set_level(level);
|
||||
if (this->target_value_ == this->current_value_) {
|
||||
this->save_level_(level);
|
||||
|
@ -220,9 +220,10 @@ void SGP30Component::write_iaq_baseline_(uint16_t eco2_baseline, uint16_t tvoc_b
|
||||
data[6] = sht_crc_(data[4], data[5]);
|
||||
if (!this->write_bytes(SGP30_CMD_SET_IAQ_BASELINE >> 8, data, 7)) {
|
||||
ESP_LOGE(TAG, "Error applying eCO2 baseline: 0x%04X, TVOC baseline: 0x%04X", eco2_baseline, tvoc_baseline);
|
||||
} else
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Initial baselines applied successfully! eCO2 baseline: 0x%04X, TVOC baseline: 0x%04X", eco2_baseline,
|
||||
tvoc_baseline);
|
||||
}
|
||||
}
|
||||
|
||||
void SGP30Component::dump_config() {
|
||||
@ -315,18 +316,20 @@ uint8_t SGP30Component::sht_crc_(uint8_t data1, uint8_t data2) {
|
||||
|
||||
crc ^= data1;
|
||||
for (bit = 8; bit > 0; --bit) {
|
||||
if (crc & 0x80)
|
||||
if (crc & 0x80) {
|
||||
crc = (crc << 1) ^ 0x131;
|
||||
else
|
||||
} else {
|
||||
crc = (crc << 1);
|
||||
}
|
||||
}
|
||||
|
||||
crc ^= data2;
|
||||
for (bit = 8; bit > 0; --bit) {
|
||||
if (crc & 0x80)
|
||||
if (crc & 0x80) {
|
||||
crc = (crc << 1) ^ 0x131;
|
||||
else
|
||||
} else {
|
||||
crc = (crc << 1);
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
|
@ -229,10 +229,11 @@ uint8_t SGP40Component::generate_crc_(const uint8_t *data, uint8_t datalen) {
|
||||
for (uint8_t i = 0; i < datalen; i++) {
|
||||
crc ^= data[i];
|
||||
for (uint8_t b = 0; b < 8; b++) {
|
||||
if (crc & 0x80)
|
||||
if (crc & 0x80) {
|
||||
crc = (crc << 1) ^ SGP40_CRC8_POLYNOMIAL;
|
||||
else
|
||||
} else {
|
||||
crc <<= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
@ -303,18 +304,20 @@ uint8_t SGP40Component::sht_crc_(uint8_t data1, uint8_t data2) {
|
||||
|
||||
crc ^= data1;
|
||||
for (bit = 8; bit > 0; --bit) {
|
||||
if (crc & 0x80)
|
||||
if (crc & 0x80) {
|
||||
crc = (crc << 1) ^ 0x131;
|
||||
else
|
||||
} else {
|
||||
crc = (crc << 1);
|
||||
}
|
||||
}
|
||||
|
||||
crc ^= data2;
|
||||
for (bit = 8; bit > 0; --bit) {
|
||||
if (crc & 0x80)
|
||||
if (crc & 0x80) {
|
||||
crc = (crc << 1) ^ 0x131;
|
||||
else
|
||||
} else {
|
||||
crc = (crc << 1);
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
|
@ -82,18 +82,20 @@ uint8_t sht_crc(uint8_t data1, uint8_t data2) {
|
||||
|
||||
crc ^= data1;
|
||||
for (bit = 8; bit > 0; --bit) {
|
||||
if (crc & 0x80)
|
||||
if (crc & 0x80) {
|
||||
crc = (crc << 1) ^ 0x131;
|
||||
else
|
||||
} else {
|
||||
crc = (crc << 1);
|
||||
}
|
||||
}
|
||||
|
||||
crc ^= data2;
|
||||
for (bit = 8; bit > 0; --bit) {
|
||||
if (crc & 0x80)
|
||||
if (crc & 0x80) {
|
||||
crc = (crc << 1) ^ 0x131;
|
||||
else
|
||||
} else {
|
||||
crc = (crc << 1);
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
|
@ -112,18 +112,20 @@ uint8_t sht_crc(uint8_t data1, uint8_t data2) {
|
||||
|
||||
crc ^= data1;
|
||||
for (bit = 8; bit > 0; --bit) {
|
||||
if (crc & 0x80)
|
||||
if (crc & 0x80) {
|
||||
crc = (crc << 1) ^ 0x131;
|
||||
else
|
||||
} else {
|
||||
crc = (crc << 1);
|
||||
}
|
||||
}
|
||||
|
||||
crc ^= data2;
|
||||
for (bit = 8; bit > 0; --bit) {
|
||||
if (crc & 0x80)
|
||||
if (crc & 0x80) {
|
||||
crc = (crc << 1) ^ 0x131;
|
||||
else
|
||||
} else {
|
||||
crc = (crc << 1);
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
|
@ -88,9 +88,10 @@ class BSDSocketImpl : public Socket {
|
||||
for (int i = 0; i < iovcnt; i++) {
|
||||
ssize_t err = this->read(reinterpret_cast<uint8_t *>(iov[i].iov_base), iov[i].iov_len);
|
||||
if (err == -1) {
|
||||
if (ret != 0)
|
||||
if (ret != 0) {
|
||||
// if we already read some don't return an error
|
||||
break;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
ret += err;
|
||||
@ -115,9 +116,10 @@ class BSDSocketImpl : public Socket {
|
||||
ssize_t err =
|
||||
this->send(reinterpret_cast<uint8_t *>(iov[i].iov_base), iov[i].iov_len, i == iovcnt - 1 ? 0 : MSG_MORE);
|
||||
if (err == -1) {
|
||||
if (ret != 0)
|
||||
if (ret != 0) {
|
||||
// if we already wrote some don't return an error
|
||||
break;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
ret += err;
|
||||
|
@ -129,10 +129,11 @@ uint8_t HOT SPIComponent::transfer_(uint8_t data) {
|
||||
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
uint8_t shift;
|
||||
if (BIT_ORDER == BIT_ORDER_MSB_FIRST)
|
||||
if (BIT_ORDER == BIT_ORDER_MSB_FIRST) {
|
||||
shift = 7 - i;
|
||||
else
|
||||
} else {
|
||||
shift = i;
|
||||
}
|
||||
|
||||
if (CLOCK_PHASE == CLOCK_PHASE_LEADING) {
|
||||
// sampling on leading edge
|
||||
|
@ -216,18 +216,20 @@ uint8_t SPS30Component::sht_crc_(uint8_t data1, uint8_t data2) {
|
||||
|
||||
crc ^= data1;
|
||||
for (bit = 8; bit > 0; --bit) {
|
||||
if (crc & 0x80)
|
||||
if (crc & 0x80) {
|
||||
crc = (crc << 1) ^ 0x131;
|
||||
else
|
||||
} else {
|
||||
crc = (crc << 1);
|
||||
}
|
||||
}
|
||||
|
||||
crc ^= data2;
|
||||
for (bit = 8; bit > 0; --bit) {
|
||||
if (crc & 0x80)
|
||||
if (crc & 0x80) {
|
||||
crc = (crc << 1) ^ 0x131;
|
||||
else
|
||||
} else {
|
||||
crc = (crc << 1);
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
|
@ -66,10 +66,11 @@ void SSD1306::setup() {
|
||||
if (!this->is_ssd1305_()) {
|
||||
// Enable charge pump (0x8D)
|
||||
this->command(SSD1306_COMMAND_CHARGE_PUMP);
|
||||
if (this->external_vcc_)
|
||||
if (this->external_vcc_) {
|
||||
this->command(0x10);
|
||||
else
|
||||
} else {
|
||||
this->command(0x14);
|
||||
}
|
||||
}
|
||||
|
||||
// Set addressing mode to horizontal (0x20)
|
||||
@ -105,10 +106,11 @@ void SSD1306::setup() {
|
||||
|
||||
// Pre-charge period (0xD9)
|
||||
this->command(SSD1306_COMMAND_SET_PRE_CHARGE);
|
||||
if (this->external_vcc_)
|
||||
if (this->external_vcc_) {
|
||||
this->command(0x22);
|
||||
else
|
||||
} else {
|
||||
this->command(0xF1);
|
||||
}
|
||||
|
||||
// Set V_COM (0xDB)
|
||||
this->command(SSD1306_COMMAND_SET_VCOM_DETECT);
|
||||
|
@ -51,24 +51,27 @@ void SSD1325::setup() {
|
||||
this->command(SSD1325_SETCLOCK); // set osc division
|
||||
this->command(0xF1); // 145
|
||||
this->command(SSD1325_SETMULTIPLEX); // multiplex ratio
|
||||
if (this->model_ == SSD1327_MODEL_128_128)
|
||||
if (this->model_ == SSD1327_MODEL_128_128) {
|
||||
this->command(0x7f); // duty = height - 1
|
||||
else
|
||||
this->command(0x3f); // duty = 1/64
|
||||
} else {
|
||||
this->command(0x3f); // duty = 1/64
|
||||
}
|
||||
this->command(SSD1325_SETOFFSET); // set display offset
|
||||
if (this->model_ == SSD1327_MODEL_128_128)
|
||||
if (this->model_ == SSD1327_MODEL_128_128) {
|
||||
this->command(0x00); // 0
|
||||
else
|
||||
this->command(0x4C); // 76
|
||||
} else {
|
||||
this->command(0x4C); // 76
|
||||
}
|
||||
this->command(SSD1325_SETSTARTLINE); // set start line
|
||||
this->command(0x00); // ...
|
||||
this->command(SSD1325_MASTERCONFIG); // Set Master Config DC/DC Converter
|
||||
this->command(0x02);
|
||||
this->command(SSD1325_SETREMAP); // set segment remapping
|
||||
if (this->model_ == SSD1327_MODEL_128_128)
|
||||
if (this->model_ == SSD1327_MODEL_128_128) {
|
||||
this->command(0x53); // COM bottom-up, split odd/even, enable column and nibble remapping
|
||||
else
|
||||
this->command(0x50); // COM bottom-up, split odd/even
|
||||
} else {
|
||||
this->command(0x50); // COM bottom-up, split odd/even
|
||||
}
|
||||
this->command(SSD1325_SETCURRENT + 0x2); // Set Full Current Range
|
||||
this->command(SSD1325_SETGRAYTABLE);
|
||||
// gamma ~2.2
|
||||
@ -122,10 +125,11 @@ void SSD1325::display() {
|
||||
this->command(0x3F); // set column end address
|
||||
this->command(SSD1325_SETROWADDR); // set row address
|
||||
this->command(0x00); // set row start address
|
||||
if (this->model_ == SSD1327_MODEL_128_128)
|
||||
if (this->model_ == SSD1327_MODEL_128_128) {
|
||||
this->command(127); // set last row
|
||||
else
|
||||
} else {
|
||||
this->command(63); // set last row
|
||||
}
|
||||
|
||||
this->write_display_data();
|
||||
}
|
||||
@ -135,12 +139,13 @@ void SSD1325::update() {
|
||||
}
|
||||
void SSD1325::set_brightness(float brightness) {
|
||||
// validation
|
||||
if (brightness > 1)
|
||||
if (brightness > 1) {
|
||||
this->brightness_ = 1.0;
|
||||
else if (brightness < 0)
|
||||
} else if (brightness < 0) {
|
||||
this->brightness_ = 0;
|
||||
else
|
||||
} else {
|
||||
this->brightness_ = brightness;
|
||||
}
|
||||
// now write the new brightness level to the display
|
||||
this->command(SSD1325_SETCONTRAST);
|
||||
this->command(int(SSD1325_MAX_CONTRAST * (this->brightness_)));
|
||||
|
@ -129,12 +129,13 @@ void HOT SSD1331::draw_absolute_pixel_internal(int x, int y, Color color) {
|
||||
}
|
||||
void SSD1331::fill(Color color) {
|
||||
const uint32_t color565 = display::ColorUtil::color_to_565(color);
|
||||
for (uint32_t i = 0; i < this->get_buffer_length_(); i++)
|
||||
for (uint32_t i = 0; i < this->get_buffer_length_(); i++) {
|
||||
if (i & 1) {
|
||||
this->buffer_[i] = color565 & 0xff;
|
||||
} else {
|
||||
this->buffer_[i] = (color565 >> 8) & 0xff;
|
||||
}
|
||||
}
|
||||
}
|
||||
void SSD1331::init_reset_() {
|
||||
if (this->reset_pin_ != nullptr) {
|
||||
|
@ -105,12 +105,13 @@ void SSD1351::update() {
|
||||
}
|
||||
void SSD1351::set_brightness(float brightness) {
|
||||
// validation
|
||||
if (brightness > 1)
|
||||
if (brightness > 1) {
|
||||
this->brightness_ = 1.0;
|
||||
else if (brightness < 0)
|
||||
} else if (brightness < 0) {
|
||||
this->brightness_ = 0;
|
||||
else
|
||||
} else {
|
||||
this->brightness_ = brightness;
|
||||
}
|
||||
// now write the new brightness level to the display
|
||||
this->command(SSD1351_CONTRASTMASTER);
|
||||
this->data(int(SSD1351_MAX_CONTRAST * (this->brightness_)));
|
||||
@ -157,12 +158,13 @@ void HOT SSD1351::draw_absolute_pixel_internal(int x, int y, Color color) {
|
||||
}
|
||||
void SSD1351::fill(Color color) {
|
||||
const uint32_t color565 = display::ColorUtil::color_to_565(color);
|
||||
for (uint32_t i = 0; i < this->get_buffer_length_(); i++)
|
||||
for (uint32_t i = 0; i < this->get_buffer_length_(); i++) {
|
||||
if (i & 1) {
|
||||
this->buffer_[i] = color565 & 0xff;
|
||||
} else {
|
||||
this->buffer_[i] = (color565 >> 8) & 0xff;
|
||||
}
|
||||
}
|
||||
}
|
||||
void SSD1351::init_reset_() {
|
||||
if (this->reset_pin_ != nullptr) {
|
||||
|
@ -78,18 +78,20 @@ uint8_t sts3x_crc(uint8_t data1, uint8_t data2) {
|
||||
|
||||
crc ^= data1;
|
||||
for (bit = 8; bit > 0; --bit) {
|
||||
if (crc & 0x80)
|
||||
if (crc & 0x80) {
|
||||
crc = (crc << 1) ^ 0x131;
|
||||
else
|
||||
} else {
|
||||
crc = (crc << 1);
|
||||
}
|
||||
}
|
||||
|
||||
crc ^= data2;
|
||||
for (bit = 8; bit > 0; --bit) {
|
||||
if (crc & 0x80)
|
||||
if (crc & 0x80) {
|
||||
crc = (crc << 1) ^ 0x131;
|
||||
else
|
||||
} else {
|
||||
crc = (crc << 1);
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
|
@ -110,10 +110,11 @@ template<typename... Ts> class SunCondition : public Condition<Ts...>, public Pa
|
||||
bool check(Ts... x) override {
|
||||
double elevation = this->elevation_.value(x...);
|
||||
double current = this->parent_->elevation();
|
||||
if (this->above_)
|
||||
if (this->above_) {
|
||||
return current > elevation;
|
||||
else
|
||||
} else {
|
||||
return current < elevation;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user