Force braces around multi-line statements (#3094)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Oxan van Leeuwen 2022-01-24 20:56:36 +01:00 committed by GitHub
parent 6b27f2d2cf
commit 80d03a631e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
125 changed files with 770 additions and 504 deletions

View file

@ -68,7 +68,6 @@ Checks: >-
-modernize-use-nodiscard, -modernize-use-nodiscard,
-mpi-*, -mpi-*,
-objc-*, -objc-*,
-readability-braces-around-statements,
-readability-convert-member-functions-to-static, -readability-convert-member-functions-to-static,
-readability-else-after-return, -readability-else-after-return,
-readability-function-cognitive-complexity, -readability-function-cognitive-complexity,
@ -109,6 +108,8 @@ CheckOptions:
value: 'make_unique' value: 'make_unique'
- key: modernize-make-unique.MakeSmartPtrFunctionHeader - key: modernize-make-unique.MakeSmartPtrFunctionHeader
value: 'esphome/core/helpers.h' value: 'esphome/core/helpers.h'
- key: readability-braces-around-statements.ShortStatementLines
value: 2
- key: readability-identifier-naming.LocalVariableCase - key: readability-identifier-naming.LocalVariableCase
value: 'lower_case' value: 'lower_case'
- key: readability-identifier-naming.ClassCase - key: readability-identifier-naming.ClassCase

View file

@ -52,10 +52,10 @@ uint32_t IRAM_ATTR HOT AcDimmerDataStore::timer_intr(uint32_t now) {
this->gate_pin.digital_write(false); 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 // Next event is enable, return time until that event
return this->enable_time_us - time_since_zc; 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 // Next event is disable, return time until that event
return this->disable_time_us - time_since_zc; 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 min_dt_us = 1000;
uint32_t now = micros(); uint32_t now = micros();
for (auto *dimmer : all_dimmers) { for (auto *dimmer : all_dimmers) {
if (dimmer == nullptr) if (dimmer == nullptr) {
// no more dimmers // no more dimmers
break; break;
}
uint32_t res = dimmer->timer_intr(now); uint32_t res = dimmer->timer_intr(now);
if (res != 0 && res < min_dt_us) if (res != 0 && res < min_dt_us)
min_dt_us = res; min_dt_us = res;
@ -212,12 +213,13 @@ void AcDimmer::dump_config() {
LOG_PIN(" Zero-Cross Pin: ", this->zero_cross_pin_); LOG_PIN(" Zero-Cross Pin: ", this->zero_cross_pin_);
ESP_LOGCONFIG(TAG, " Min Power: %.1f%%", this->store_.min_power / 10.0f); 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_)); 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"); ESP_LOGCONFIG(TAG, " Method: leading pulse");
else if (method_ == DIM_METHOD_LEADING) } else if (method_ == DIM_METHOD_LEADING) {
ESP_LOGCONFIG(TAG, " Method: leading"); ESP_LOGCONFIG(TAG, " Method: leading");
else } else {
ESP_LOGCONFIG(TAG, " Method: trailing"); ESP_LOGCONFIG(TAG, " Method: trailing");
}
LOG_FLOAT_OUTPUT(this); LOG_FLOAT_OUTPUT(this);
ESP_LOGV(TAG, " Estimated Frequency: %.3fHz", 1e6f / this->store_.cycle_time_us / 2); ESP_LOGV(TAG, " Estimated Frequency: %.3fHz", 1e6f / this->store_.cycle_time_us / 2);

View file

@ -65,9 +65,9 @@ void ADCSensor::dump_config() {
#ifdef USE_ESP32 #ifdef USE_ESP32
LOG_PIN(" Pin: ", pin_); LOG_PIN(" Pin: ", pin_);
if (autorange_) if (autorange_) {
ESP_LOGCONFIG(TAG, " Attenuation: auto"); ESP_LOGCONFIG(TAG, " Attenuation: auto");
else } else {
switch (this->attenuation_) { switch (this->attenuation_) {
case ADC_ATTEN_DB_0: case ADC_ATTEN_DB_0:
ESP_LOGCONFIG(TAG, " Attenuation: 0db (max 1.1V)"); 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 default: // This is to satisfy the unused ADC_ATTEN_MAX
break; break;
} }
}
#endif // USE_ESP32 #endif // USE_ESP32
LOG_UPDATE_INTERVAL(this); LOG_UPDATE_INTERVAL(this);
} }

View file

@ -19,13 +19,15 @@ uint16_t crc_16(uint8_t *ptr, uint8_t length) {
//------------------------------ //------------------------------
while (length--) { while (length--) {
crc ^= *ptr++; crc ^= *ptr++;
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++) {
if ((crc & 0x01) != 0) { if ((crc & 0x01) != 0) {
crc >>= 1; crc >>= 1;
crc ^= 0xA001; crc ^= 0xA001;
} else } else {
crc >>= 1; crc >>= 1;
} }
}
}
return crc; return crc;
} }

View file

@ -79,10 +79,11 @@ 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_, 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, packet->length, packet->data, ESP_GATT_WRITE_TYPE_NO_RSP,
ESP_GATT_AUTH_REQ_NONE); 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(), ESP_LOGW(TAG, "[%s] esp_ble_gattc_write_char failed, status=%d", this->parent_->address_str().c_str(),
status); status);
} }
}
this->current_sensor_ = 0; this->current_sensor_ = 0;
} }
break; break;

View file

@ -30,12 +30,13 @@ void Am43Component::loop() {
esp_ble_gattc_write_char(this->parent_->gattc_if, this->parent_->conn_id, this->char_handle_, packet->length, 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); 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()); 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); ESP_LOGW(TAG, "[%s] Error writing set_pin to device, error = %d", this->get_name().c_str(), status);
else } else {
this->logged_in_ = true; this->logged_in_ = true;
} }
} }
}
CoverTraits Am43Component::get_traits() { CoverTraits Am43Component::get_traits() {
auto traits = CoverTraits(); auto traits = CoverTraits();

View file

@ -114,11 +114,12 @@ void Anova::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_
auto status = auto status =
esp_ble_gattc_write_char(this->parent_->gattc_if, this->parent_->conn_id, this->char_handle_, pkt->length, 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); 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(), ESP_LOGW(TAG, "[%s] esp_ble_gattc_write_char failed, status=%d", this->parent_->address_str().c_str(),
status); status);
} }
} }
}
break; break;
} }
default: default:

View file

@ -225,9 +225,10 @@ void APDS9960::read_gesture_data_() {
uint8_t fifo_level; uint8_t fifo_level;
APDS9960_WARNING_CHECK(this->read_byte(0xAE, &fifo_level), "Reading FIFO level failed."); 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 // no data to process
return; return;
}
APDS9960_WARNING_CHECK(fifo_level <= 32, "FIFO level has invalid value.") APDS9960_WARNING_CHECK(fifo_level <= 32, "FIFO level has invalid value.")

View file

@ -469,11 +469,12 @@ void APIConnection::switch_command(const SwitchCommandRequest &msg) {
if (a_switch == nullptr) if (a_switch == nullptr)
return; return;
if (msg.state) if (msg.state) {
a_switch->turn_on(); a_switch->turn_on();
else } else {
a_switch->turn_off(); a_switch->turn_off();
} }
}
#endif #endif
#ifdef USE_TEXT_SENSOR #ifdef USE_TEXT_SENSOR
@ -810,11 +811,12 @@ DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) {
return resp; return resp;
} }
void APIConnection::on_home_assistant_state_response(const HomeAssistantStateResponse &msg) { 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) { if (it.entity_id == msg.entity_id && it.attribute.value() == msg.attribute) {
it.callback(msg.state); it.callback(msg.state);
} }
} }
}
void APIConnection::execute_service(const ExecuteServiceRequest &msg) { void APIConnection::execute_service(const ExecuteServiceRequest &msg) {
bool found = false; bool found = false;
for (auto *service : this->parent_->get_user_services()) { for (auto *service : this->parent_->get_user_services()) {

View file

@ -80,9 +80,10 @@ void APIServer::setup() {
if (esp32_camera::global_esp32_camera != nullptr && !esp32_camera::global_esp32_camera->is_internal()) { if (esp32_camera::global_esp32_camera != nullptr && !esp32_camera::global_esp32_camera->is_internal()) {
esp32_camera::global_esp32_camera->add_image_callback( esp32_camera::global_esp32_camera->add_image_callback(
[this](const std::shared_ptr<esp32_camera::CameraImage> &image) { [this](const std::shared_ptr<esp32_camera::CameraImage> &image) {
for (auto &c : this->clients_) for (auto &c : this->clients_) {
if (!c->remove_) if (!c->remove_)
c->send_camera_state(image); c->send_camera_state(image);
}
}); });
} }
#endif #endif

View file

@ -55,18 +55,20 @@ class ProtoVarInt {
} }
int32_t as_sint32() const { int32_t as_sint32() const {
// with ZigZag encoding // with ZigZag encoding
if (this->value_ & 1) if (this->value_ & 1) {
return static_cast<int32_t>(~(this->value_ >> 1)); return static_cast<int32_t>(~(this->value_ >> 1));
else } else {
return static_cast<int32_t>(this->value_ >> 1); return static_cast<int32_t>(this->value_ >> 1);
} }
}
int64_t as_sint64() const { int64_t as_sint64() const {
// with ZigZag encoding // with ZigZag encoding
if (this->value_ & 1) if (this->value_ & 1) {
return static_cast<int64_t>(~(this->value_ >> 1)); return static_cast<int64_t>(~(this->value_ >> 1));
else } else {
return static_cast<int64_t>(this->value_ >> 1); return static_cast<int64_t>(this->value_ >> 1);
} }
}
void encode(std::vector<uint8_t> &out) { void encode(std::vector<uint8_t> &out) {
uint32_t val = this->value_; uint32_t val = this->value_;
if (val <= 0x7F) { if (val <= 0x7F) {
@ -220,10 +222,11 @@ class ProtoWriteBuffer {
} }
void encode_sint32(uint32_t field_id, int32_t value, bool force = false) { void encode_sint32(uint32_t field_id, int32_t value, bool force = false) {
uint32_t uvalue; uint32_t uvalue;
if (value < 0) if (value < 0) {
uvalue = ~(value << 1); uvalue = ~(value << 1);
else } else {
uvalue = value << 1; uvalue = value << 1;
}
this->encode_uint32(field_id, uvalue, force); this->encode_uint32(field_id, uvalue, force);
} }
template<class C> void encode_message(uint32_t field_id, const C &value, bool force = false) { template<class C> void encode_message(uint32_t field_id, const C &value, bool force = false) {

View file

@ -58,11 +58,12 @@ void AS3935Component::loop() {
void AS3935Component::write_indoor(bool indoor) { void AS3935Component::write_indoor(bool indoor) {
ESP_LOGV(TAG, "Setting indoor to %d", indoor); ESP_LOGV(TAG, "Setting indoor to %d", indoor);
if (indoor) if (indoor) {
this->write_register(AFE_GAIN, GAIN_MASK, INDOOR, 1); this->write_register(AFE_GAIN, GAIN_MASK, INDOOR, 1);
else } else {
this->write_register(AFE_GAIN, GAIN_MASK, OUTDOOR, 1); this->write_register(AFE_GAIN, GAIN_MASK, OUTDOOR, 1);
} }
}
// REG0x01, bits[3:0], manufacturer default: 0010 (2). // REG0x01, bits[3:0], manufacturer default: 0010 (2).
// This setting determines the threshold for events that trigger the // This setting determines the threshold for events that trigger the
// IRQ Pin. // IRQ Pin.

View file

@ -130,10 +130,10 @@ bool BalluClimate::on_receive(remote_base::RemoteReceiveData data) {
for (int i = 0; i < BALLU_STATE_LENGTH; i++) { for (int i = 0; i < BALLU_STATE_LENGTH; i++) {
// Read bit // Read bit
for (int j = 0; j < 8; j++) { 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; 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); ESP_LOGV(TAG, "Byte %d bit %d fail", i, j);
return false; return false;
} }

View file

@ -21,12 +21,13 @@ void BangBangClimate::setup() {
restore->to_call(this).perform(); restore->to_call(this).perform();
} else { } else {
// restore from defaults, change_away handles those for us // 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; this->mode = climate::CLIMATE_MODE_HEAT_COOL;
else if (supports_cool_) } else if (supports_cool_) {
this->mode = climate::CLIMATE_MODE_COOL; this->mode = climate::CLIMATE_MODE_COOL;
else if (supports_heat_) } else if (supports_heat_) {
this->mode = climate::CLIMATE_MODE_HEAT; this->mode = climate::CLIMATE_MODE_HEAT;
}
this->change_away_(false); this->change_away_(false);
} }
} }
@ -56,11 +57,12 @@ climate::ClimateTraits BangBangClimate::traits() {
if (supports_cool_ && supports_heat_) if (supports_cool_ && supports_heat_)
traits.add_supported_mode(climate::CLIMATE_MODE_HEAT_COOL); traits.add_supported_mode(climate::CLIMATE_MODE_HEAT_COOL);
traits.set_supports_two_point_target_temperature(true); traits.set_supports_two_point_target_temperature(true);
if (supports_away_) if (supports_away_) {
traits.set_supported_presets({ traits.set_supported_presets({
climate::CLIMATE_PRESET_HOME, climate::CLIMATE_PRESET_HOME,
climate::CLIMATE_PRESET_AWAY, climate::CLIMATE_PRESET_AWAY,
}); });
}
traits.set_supports_action(true); traits.set_supports_action(true);
return traits; return traits;
} }
@ -82,17 +84,19 @@ void BangBangClimate::compute_state_() {
if (too_cold) { if (too_cold) {
// too cold -> enable heating if possible and enabled, else idle // too cold -> enable heating if possible and enabled, else idle
if (this->supports_heat_ && 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; target_action = climate::CLIMATE_ACTION_HEATING;
else } else {
target_action = climate::CLIMATE_ACTION_IDLE; target_action = climate::CLIMATE_ACTION_IDLE;
}
} else if (too_hot) { } else if (too_hot) {
// too hot -> enable cooling if possible and enabled, else idle // too hot -> enable cooling if possible and enabled, else idle
if (this->supports_cool_ && 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; target_action = climate::CLIMATE_ACTION_COOLING;
else } else {
target_action = climate::CLIMATE_ACTION_IDLE; target_action = climate::CLIMATE_ACTION_IDLE;
}
} else { } else {
// neither too hot nor too cold -> in range // neither too hot nor too cold -> in range
if (this->supports_cool_ && this->supports_heat_ && this->mode == climate::CLIMATE_MODE_HEAT_COOL) { 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); this->switch_to_action_(target_action);
} }
void BangBangClimate::switch_to_action_(climate::ClimateAction action) { void BangBangClimate::switch_to_action_(climate::ClimateAction action) {
if (action == this->action) if (action == this->action) {
// already in target mode // already in target mode
return; return;
}
if ((action == climate::CLIMATE_ACTION_OFF && this->action == climate::CLIMATE_ACTION_IDLE) || if ((action == climate::CLIMATE_ACTION_OFF && this->action == climate::CLIMATE_ACTION_IDLE) ||
(action == climate::CLIMATE_ACTION_IDLE && this->action == climate::CLIMATE_ACTION_OFF)) { (action == climate::CLIMATE_ACTION_IDLE && this->action == climate::CLIMATE_ACTION_OFF)) {

View file

@ -252,9 +252,10 @@ float BLEClient::parse_char_value(uint8_t *value, uint16_t length) {
} }
BLEService *BLEClient::get_service(espbt::ESPBTUUID uuid) { BLEService *BLEClient::get_service(espbt::ESPBTUUID uuid) {
for (auto *svc : this->services_) for (auto *svc : this->services_) {
if (svc->uuid == uuid) if (svc->uuid == uuid)
return svc; return svc;
}
return nullptr; return nullptr;
} }
@ -272,19 +273,24 @@ BLECharacteristic *BLEClient::get_characteristic(uint16_t service, uint16_t chr)
} }
BLEDescriptor *BLEClient::get_config_descriptor(uint16_t handle) { BLEDescriptor *BLEClient::get_config_descriptor(uint16_t handle) {
for (auto &svc : this->services_) for (auto &svc : this->services_) {
for (auto &chr : svc->characteristics) for (auto &chr : svc->characteristics) {
if (chr->handle == handle) if (chr->handle == handle) {
for (auto &desc : chr->descriptors) for (auto &desc : chr->descriptors) {
if (desc->uuid == espbt::ESPBTUUID::from_uint16(0x2902)) if (desc->uuid == espbt::ESPBTUUID::from_uint16(0x2902))
return desc; return desc;
}
}
}
}
return nullptr; return nullptr;
} }
BLECharacteristic *BLEService::get_characteristic(espbt::ESPBTUUID uuid) { BLECharacteristic *BLEService::get_characteristic(espbt::ESPBTUUID uuid) {
for (auto &chr : this->characteristics) for (auto &chr : this->characteristics) {
if (chr->uuid == uuid) if (chr->uuid == uuid)
return chr; return chr;
}
return nullptr; return nullptr;
} }
@ -379,9 +385,10 @@ void BLECharacteristic::parse_descriptors() {
} }
BLEDescriptor *BLECharacteristic::get_descriptor(espbt::ESPBTUUID uuid) { BLEDescriptor *BLECharacteristic::get_descriptor(espbt::ESPBTUUID uuid) {
for (auto &desc : this->descriptors) for (auto &desc : this->descriptors) {
if (desc->uuid == uuid) if (desc->uuid == uuid)
return desc; return desc;
}
return nullptr; return nullptr;
} }
BLEDescriptor *BLECharacteristic::get_descriptor(uint16_t uuid) { BLEDescriptor *BLECharacteristic::get_descriptor(uint16_t uuid) {

View file

@ -126,9 +126,10 @@ class BLEClient : public espbt::ESPBTClient, public Component {
bool all_nodes_established_() { bool all_nodes_established_() {
if (this->state() != espbt::ClientState::ESTABLISHED) if (this->state() != espbt::ClientState::ESTABLISHED)
return false; return false;
for (auto &node : nodes_) for (auto &node : nodes_) {
if (node->node_state != espbt::ClientState::ESTABLISHED) if (node->node_state != espbt::ClientState::ESTABLISHED)
return false; return false;
}
return true; return true;
} }

View file

@ -214,9 +214,10 @@ void BME280Component::update() {
float BME280Component::read_temperature_(const uint8_t *data, int32_t *t_fine) { 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); int32_t adc = ((data[3] & 0xFF) << 16) | ((data[4] & 0xFF) << 8) | (data[5] & 0xFF);
adc >>= 4; adc >>= 4;
if (adc == 0x80000) if (adc == 0x80000) {
// temperature was disabled // temperature was disabled
return NAN; return NAN;
}
const int32_t t1 = this->calibration_.t1; const int32_t t1 = this->calibration_.t1;
const int32_t t2 = this->calibration_.t2; 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) { 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); int32_t adc = ((data[0] & 0xFF) << 16) | ((data[1] & 0xFF) << 8) | (data[2] & 0xFF);
adc >>= 4; adc >>= 4;
if (adc == 0x80000) if (adc == 0x80000) {
// pressure was disabled // pressure was disabled
return NAN; return NAN;
}
const int64_t p1 = this->calibration_.p1; const int64_t p1 = this->calibration_.p1;
const int64_t p2 = this->calibration_.p2; const int64_t p2 = this->calibration_.p2;
const int64_t p3 = this->calibration_.p3; const int64_t p3 = this->calibration_.p3;

View file

@ -420,10 +420,11 @@ float BME680Component::calc_humidity_(uint16_t raw_humidity) {
calc_hum = var2 + (var3 + var4 * temp_comp) * var2 * var2; calc_hum = var2 + (var3 + var4 * temp_comp) * var2 * var2;
if (calc_hum > 100.0f) if (calc_hum > 100.0f) {
calc_hum = 100.0f; calc_hum = 100.0f;
else if (calc_hum < 0.0f) } else if (calc_hum < 0.0f) {
calc_hum = 0.0f; calc_hum = 0.0f;
}
return calc_hum; return calc_hum;
} }

View file

@ -161,9 +161,10 @@ float BMP280Component::read_temperature_(int32_t *t_fine) {
return NAN; return NAN;
int32_t adc = ((data[0] & 0xFF) << 16) | ((data[1] & 0xFF) << 8) | (data[2] & 0xFF); int32_t adc = ((data[0] & 0xFF) << 16) | ((data[1] & 0xFF) << 8) | (data[2] & 0xFF);
adc >>= 4; adc >>= 4;
if (adc == 0x80000) if (adc == 0x80000) {
// temperature was disabled // temperature was disabled
return NAN; return NAN;
}
const int32_t t1 = this->calibration_.t1; const int32_t t1 = this->calibration_.t1;
const int32_t t2 = this->calibration_.t2; const int32_t t2 = this->calibration_.t2;
@ -183,9 +184,10 @@ float BMP280Component::read_pressure_(int32_t t_fine) {
return NAN; return NAN;
int32_t adc = ((data[0] & 0xFF) << 16) | ((data[1] & 0xFF) << 8) | (data[2] & 0xFF); int32_t adc = ((data[0] & 0xFF) << 16) | ((data[1] & 0xFF) << 8) | (data[2] & 0xFF);
adc >>= 4; adc >>= 4;
if (adc == 0x80000) if (adc == 0x80000) {
// pressure was disabled // pressure was disabled
return NAN; return NAN;
}
const int64_t p1 = this->calibration_.p1; const int64_t p1 = this->calibration_.p1;
const int64_t p2 = this->calibration_.p2; const int64_t p2 = this->calibration_.p2;
const int64_t p3 = this->calibration_.p3; const int64_t p3 = this->calibration_.p3;

View file

@ -39,14 +39,15 @@ void CCS811Component::setup() {
// set MEAS_MODE (page 5) // set MEAS_MODE (page 5)
uint8_t meas_mode = 0; uint8_t meas_mode = 0;
uint32_t interval = this->get_update_interval(); 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 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 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 meas_mode = 1 << 4; // sensor takes a reading every second
else } else {
meas_mode = 4 << 4; // sensor takes a reading every 250ms meas_mode = 4 << 4; // sensor takes a reading every 250ms
}
CHECKED_IO(this->write_byte(0x01, meas_mode)) CHECKED_IO(this->write_byte(0x01, meas_mode))

View file

@ -137,11 +137,11 @@ bool LgIrClimate::on_receive(remote_base::RemoteReceiveData data) {
this->swing_mode = this->swing_mode =
this->swing_mode == climate::CLIMATE_SWING_OFF ? climate::CLIMATE_SWING_VERTICAL : climate::CLIMATE_SWING_OFF; this->swing_mode == climate::CLIMATE_SWING_OFF ? climate::CLIMATE_SWING_VERTICAL : climate::CLIMATE_SWING_OFF;
} else { } else {
if ((remote_state & COMMAND_MASK) == COMMAND_AUTO) if ((remote_state & COMMAND_MASK) == COMMAND_AUTO) {
this->mode = climate::CLIMATE_MODE_HEAT_COOL; 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; 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; this->mode = climate::CLIMATE_MODE_HEAT;
} else { } else {
this->mode = climate::CLIMATE_MODE_COOL; this->mode = climate::CLIMATE_MODE_COOL;
@ -156,16 +156,17 @@ bool LgIrClimate::on_receive(remote_base::RemoteReceiveData data) {
this->fan_mode = climate::CLIMATE_FAN_AUTO; this->fan_mode = climate::CLIMATE_FAN_AUTO;
} else if (this->mode == climate::CLIMATE_MODE_COOL || this->mode == climate::CLIMATE_MODE_HEAT || } else if (this->mode == climate::CLIMATE_MODE_COOL || this->mode == climate::CLIMATE_MODE_HEAT ||
this->mode == climate::CLIMATE_MODE_DRY) { 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; 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; 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; 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->fan_mode = climate::CLIMATE_FAN_HIGH;
} }
} }
}
this->publish_state(); this->publish_state();
return true; return true;

View file

@ -125,35 +125,38 @@ bool CoolixClimate::on_coolix(climate::Climate *parent, remote_base::RemoteRecei
parent->swing_mode = parent->swing_mode =
parent->swing_mode == climate::CLIMATE_SWING_OFF ? climate::CLIMATE_SWING_VERTICAL : climate::CLIMATE_SWING_OFF; parent->swing_mode == climate::CLIMATE_SWING_OFF ? climate::CLIMATE_SWING_VERTICAL : climate::CLIMATE_SWING_OFF;
} else { } else {
if ((remote_state & COOLIX_MODE_MASK) == COOLIX_HEAT) if ((remote_state & COOLIX_MODE_MASK) == COOLIX_HEAT) {
parent->mode = climate::CLIMATE_MODE_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; parent->mode = climate::CLIMATE_MODE_HEAT_COOL;
else if ((remote_state & COOLIX_MODE_MASK) == COOLIX_DRY_FAN) { } else if ((remote_state & COOLIX_MODE_MASK) == COOLIX_DRY_FAN) {
if ((remote_state & COOLIX_FAN_MASK) == COOLIX_FAN_MODE_AUTO_DRY) if ((remote_state & COOLIX_FAN_MASK) == COOLIX_FAN_MODE_AUTO_DRY) {
parent->mode = climate::CLIMATE_MODE_DRY; parent->mode = climate::CLIMATE_MODE_DRY;
else } else {
parent->mode = climate::CLIMATE_MODE_FAN_ONLY; parent->mode = climate::CLIMATE_MODE_FAN_ONLY;
}
} else } else
parent->mode = climate::CLIMATE_MODE_COOL; parent->mode = climate::CLIMATE_MODE_COOL;
// Fan Speed // Fan Speed
if ((remote_state & COOLIX_FAN_AUTO) == COOLIX_FAN_AUTO || parent->mode == climate::CLIMATE_MODE_HEAT_COOL || 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; 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; 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; 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; parent->fan_mode = climate::CLIMATE_FAN_HIGH;
}
// Temperature // Temperature
uint8_t temperature_code = remote_state & COOLIX_TEMP_MASK; 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) if (COOLIX_TEMP_MAP[i] == temperature_code)
parent->target_temperature = i + COOLIX_TEMP_MIN; parent->target_temperature = i + COOLIX_TEMP_MIN;
} }
}
parent->publish_state(); parent->publish_state();
return true; return true;

View file

@ -175,14 +175,15 @@ bool DaikinClimate::parse_state_frame_(const uint8_t frame[]) {
} }
uint8_t fan_mode = frame[8]; uint8_t fan_mode = frame[8];
uint8_t swing_mode = frame[9]; 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; this->swing_mode = climate::CLIMATE_SWING_BOTH;
else if (fan_mode & 0xF) } else if (fan_mode & 0xF) {
this->swing_mode = climate::CLIMATE_SWING_VERTICAL; this->swing_mode = climate::CLIMATE_SWING_VERTICAL;
else if (swing_mode & 0xF) } else if (swing_mode & 0xF) {
this->swing_mode = climate::CLIMATE_SWING_HORIZONTAL; this->swing_mode = climate::CLIMATE_SWING_HORIZONTAL;
else } else {
this->swing_mode = climate::CLIMATE_SWING_OFF; this->swing_mode = climate::CLIMATE_SWING_OFF;
}
switch (fan_mode & 0xF0) { switch (fan_mode & 0xF0) {
case DAIKIN_FAN_1: case DAIKIN_FAN_1:
case DAIKIN_FAN_2: 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++) { for (uint8_t pos = 0; pos < DAIKIN_STATE_FRAME_SIZE; pos++) {
uint8_t byte = 0; uint8_t byte = 0;
for (int8_t bit = 0; bit < 8; bit++) { 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; 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; return false;
} }
} }

View file

@ -145,9 +145,10 @@ uint64_t ESPOneWire::search() {
// read its complement // read its complement
bool cmp_id_bit = this->read_bit(); bool cmp_id_bit = this->read_bit();
if (id_bit && cmp_id_bit) if (id_bit && cmp_id_bit) {
// No devices participating in search // No devices participating in search
break; break;
}
bool branch; bool branch;
@ -170,12 +171,13 @@ uint64_t ESPOneWire::search() {
} }
} }
if (branch) if (branch) {
// set bit // set bit
this->rom_number8_()[rom_byte_number] |= rom_byte_mask; this->rom_number8_()[rom_byte_number] |= rom_byte_mask;
else } else {
// clear bit // clear bit
this->rom_number8_()[rom_byte_number] &= ~rom_byte_mask; this->rom_number8_()[rom_byte_number] &= ~rom_byte_mask;
}
// choose/announce branch // choose/announce branch
this->write_bit(branch); this->write_bit(branch);
@ -190,9 +192,10 @@ uint64_t ESPOneWire::search() {
if (id_bit_number >= 65) { if (id_bit_number >= 65) {
this->last_discrepancy_ = last_zero; 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. // we're at root and have no choices left, so this was the last one.
this->last_device_flag_ = true; this->last_device_flag_ = true;
}
search_result = true; search_result = true;
} }

View file

@ -114,10 +114,11 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r
// Wait for rising edge // Wait for rising edge
while (!this->pin_->digital_read()) { while (!this->pin_->digital_read()) {
if (micros() - start_time > 90) { if (micros() - start_time > 90) {
if (i < 0) if (i < 0) {
error_code = 1; error_code = 1;
else } else {
error_code = 2; error_code = 2;
}
break; break;
} }
} }
@ -130,10 +131,11 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r
// Wait for falling edge // Wait for falling edge
while (this->pin_->digital_read()) { while (this->pin_->digital_read()) {
if ((end_time = micros()) - start_time > 90) { if ((end_time = micros()) - start_time > 90) {
if (i < 0) if (i < 0) {
error_code = 3; error_code = 3;
else } else {
error_code = 4; error_code = 4;
}
break; break;
} }
} }

View file

@ -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]); ESP_LOGW(TAG, "Encountered character without representation in font: '%c'", text[i]);
if (!font->get_glyphs().empty()) { if (!font->get_glyphs().empty()) {
uint8_t glyph_width = font->get_glyphs()[0].glyph_data_->width; 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++) for (int glyph_y = 0; glyph_y < height; glyph_y++)
this->draw_pixel_at(glyph_x + x_at, glyph_y + y_start, color); this->draw_pixel_at(glyph_x + x_at, glyph_y + y_start, color);
}
x_at += glyph_width; x_at += glyph_width;
} }
@ -425,11 +426,12 @@ int Font::match_next_glyph(const char *str, int *match_length) {
int hi = this->glyphs_.size() - 1; int hi = this->glyphs_.size() - 1;
while (lo != hi) { while (lo != hi) {
int mid = (lo + hi + 1) / 2; int mid = (lo + hi + 1) / 2;
if (this->glyphs_[mid].compare_to(str)) if (this->glyphs_[mid].compare_to(str)) {
lo = mid; lo = mid;
else } else {
hi = mid - 1; hi = mid - 1;
} }
}
*match_length = this->glyphs_[lo].match_length(str); *match_length = this->glyphs_[lo].match_length(str);
if (*match_length <= 0) if (*match_length <= 0)
return -1; return -1;
@ -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]; const Glyph &glyph = this->glyphs_[glyph_n];
if (!has_char) if (!has_char) {
min_x = glyph.glyph_data_->offset_x; min_x = glyph.glyph_data_->offset_x;
else } else {
min_x = std::min(min_x, x + glyph.glyph_data_->offset_x); min_x = std::min(min_x, x + glyph.glyph_data_->offset_x);
}
x += glyph.glyph_data_->width + glyph.glyph_data_->offset_x; x += glyph.glyph_data_->width + glyph.glyph_data_->offset_x;
i += match_length; i += match_length;

View file

@ -68,9 +68,10 @@ void EKTF2232Touchscreen::loop() {
uint8_t raw[8]; uint8_t raw[8];
this->read(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)) if (raw[7] & (1 << i))
touch_count++; touch_count++;
}
if (touch_count == 0) { if (touch_count == 0) {
for (auto *listener : this->touch_listeners_) for (auto *listener : this->touch_listeners_)

View file

@ -147,41 +147,47 @@ bool BLECharacteristic::is_failed() {
} }
void BLECharacteristic::set_broadcast_property(bool value) { 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); 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); this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_BROADCAST);
} }
}
void BLECharacteristic::set_indicate_property(bool value) { 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); 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); this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_INDICATE);
} }
}
void BLECharacteristic::set_notify_property(bool value) { 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); 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); this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_NOTIFY);
} }
}
void BLECharacteristic::set_read_property(bool value) { 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); 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); this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_READ);
} }
}
void BLECharacteristic::set_write_property(bool value) { 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); 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); this->properties_ = (esp_gatt_char_prop_t)(this->properties_ & ~ESP_GATT_CHAR_PROP_BIT_WRITE);
} }
}
void BLECharacteristic::set_write_no_response_property(bool value) { 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); 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); 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, void BLECharacteristic::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if,
esp_ble_gatts_cb_param_t *param) { esp_ble_gatts_cb_param_t *param) {

View file

@ -18,9 +18,10 @@ BLEService::~BLEService() {
} }
BLECharacteristic *BLEService::get_characteristic(ESPBTUUID uuid) { BLECharacteristic *BLEService::get_characteristic(ESPBTUUID uuid) {
for (auto *chr : this->characteristics_) for (auto *chr : this->characteristics_) {
if (chr->get_uuid() == uuid) if (chr->get_uuid() == uuid)
return chr; return chr;
}
return nullptr; return nullptr;
} }

View file

@ -58,11 +58,12 @@ void ESP32BLETracker::setup() {
void ESP32BLETracker::loop() { void ESP32BLETracker::loop() {
BLEEvent *ble_event = this->ble_events_.pop(); BLEEvent *ble_event = this->ble_events_.pop();
while (ble_event != nullptr) { 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, this->real_gattc_event_handler_(ble_event->event_.gattc.gattc_event, ble_event->event_.gattc.gattc_if,
&ble_event->event_.gattc.gattc_param); &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); this->real_gap_event_handler_(ble_event->event_.gap.gap_event, &ble_event->event_.gap.gap_param);
}
delete ble_event; // NOLINT(cppcoreguidelines-owning-memory) delete ble_event; // NOLINT(cppcoreguidelines-owning-memory)
ble_event = this->ble_events_.pop(); ble_event = this->ble_events_.pop();
} }
@ -89,11 +90,12 @@ void ESP32BLETracker::loop() {
device.parse_scan_rst(this->scan_result_buffer_[i]); device.parse_scan_rst(this->scan_result_buffer_[i]);
bool found = false; bool found = false;
for (auto *listener : this->listeners_) for (auto *listener : this->listeners_) {
if (listener->parse_device(device)) if (listener->parse_device(device))
found = true; found = true;
}
for (auto *client : this->clients_) for (auto *client : this->clients_) {
if (client->parse_device(device)) { if (client->parse_device(device)) {
found = true; found = true;
if (client->state() == ClientState::DISCOVERED) { if (client->state() == ClientState::DISCOVERED) {
@ -103,6 +105,7 @@ void ESP32BLETracker::loop() {
} }
} }
} }
}
if (!found) { if (!found) {
this->print_bt_device_info(device); this->print_bt_device_info(device);

View file

@ -87,10 +87,11 @@ void CameraWebServer::on_shutdown() {
void CameraWebServer::dump_config() { void CameraWebServer::dump_config() {
ESP_LOGCONFIG(TAG, "ESP32 Camera Web Server:"); ESP_LOGCONFIG(TAG, "ESP32 Camera Web Server:");
ESP_LOGCONFIG(TAG, " Port: %d", this->port_); ESP_LOGCONFIG(TAG, " Port: %d", this->port_);
if (this->mode_ == STREAM) if (this->mode_ == STREAM) {
ESP_LOGCONFIG(TAG, " Mode: stream"); ESP_LOGCONFIG(TAG, " Mode: stream");
else } else {
ESP_LOGCONFIG(TAG, " Mode: snapshot"); ESP_LOGCONFIG(TAG, " Mode: snapshot");
}
if (this->is_failed()) { if (this->is_failed()) {
ESP_LOGE(TAG, " Setup Failed"); ESP_LOGE(TAG, " Setup Failed");

View file

@ -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) { 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])) if (!esp_rtc_user_mem_write(offset + i, data[i]))
return false; return false;
}
return true; return true;
} }
static bool load_from_rtc(size_t offset, uint32_t *data, size_t len) { 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])) if (!esp_rtc_user_mem_read(offset + i, &data[i]))
return false; return false;
}
return true; return true;
} }

View file

@ -75,9 +75,10 @@ void EZOSensor::loop() {
return; return;
// some sensors return multiple comma-separated values, terminate string after first one // 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] == ',') if (buf[i] == ',')
buf[i] = '\0'; buf[i] = '\0';
}
float val = parse_number<float>((char *) &buf[1]).value_or(0); float val = parse_number<float>((char *) &buf[1]).value_or(0);
this->publish_state(val); this->publish_state(val);

View file

@ -278,10 +278,11 @@ void FingerprintGrowComponent::delete_all_fingerprints() {
void FingerprintGrowComponent::led_control(bool state) { void FingerprintGrowComponent::led_control(bool state) {
ESP_LOGD(TAG, "Setting LED"); ESP_LOGD(TAG, "Setting LED");
if (state) if (state) {
this->data_ = {LED_ON}; this->data_ = {LED_ON};
else } else {
this->data_ = {LED_OFF}; this->data_ = {LED_OFF};
}
switch (this->send_command_()) { switch (this->send_command_()) {
case OK: case OK:
ESP_LOGD(TAG, "LED set"); ESP_LOGD(TAG, "LED set");

View file

@ -33,17 +33,19 @@ void GPIOSwitch::setup() {
} }
// write state before setup // write state before setup
if (initial_state) if (initial_state) {
this->turn_on(); this->turn_on();
else } else {
this->turn_off(); this->turn_off();
}
this->pin_->setup(); this->pin_->setup();
// write after setup again for other IOs // write after setup again for other IOs
if (initial_state) if (initial_state) {
this->turn_on(); this->turn_on();
else } else {
this->turn_off(); this->turn_off();
} }
}
void GPIOSwitch::dump_config() { void GPIOSwitch::dump_config() {
LOG_SWITCH("", "GPIO Switch", this); LOG_SWITCH("", "GPIO Switch", this);
LOG_PIN(" Pin: ", this->pin_); LOG_PIN(" Pin: ", this->pin_);

View file

@ -19,11 +19,12 @@ 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) { void set_bit(uint8_t *const data, const uint8_t position, const bool on) {
uint8_t mask = 1 << position; uint8_t mask = 1 << position;
if (on) if (on) {
*data |= mask; *data |= mask;
else } else {
*data &= ~mask; *data &= ~mask;
} }
}
uint8_t *invert_byte_pairs(uint8_t *ptr, const uint16_t length) { uint8_t *invert_byte_pairs(uint8_t *ptr, const uint16_t length) {
for (uint16_t i = 1; i < length; i += 2) { for (uint16_t i = 1; i < length; i += 2) {
@ -69,10 +70,11 @@ void HitachiClimate::set_temp_(uint8_t celsius, bool set_previous) {
temp = std::min(celsius, HITACHI_AC344_TEMP_MAX); temp = std::min(celsius, HITACHI_AC344_TEMP_MAX);
temp = std::max(temp, HITACHI_AC344_TEMP_MIN); 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); 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); set_button_(HITACHI_AC344_BUTTON_TEMP_DOWN);
else if (previous_temp_ < temp) } else if (previous_temp_ < temp) {
set_button_(HITACHI_AC344_BUTTON_TEMP_UP); set_button_(HITACHI_AC344_BUTTON_TEMP_UP);
}
if (set_previous) if (set_previous)
previous_temp_ = temp; previous_temp_ = temp;
} }
@ -110,11 +112,12 @@ void HitachiClimate::set_fan_(uint8_t speed) {
void HitachiClimate::set_swing_v_toggle_(bool on) { void HitachiClimate::set_swing_v_toggle_(bool on) {
uint8_t button = get_button_(); // Get the current button value. uint8_t button = get_button_(); // Get the current button value.
if (on) if (on) {
button = HITACHI_AC344_BUTTON_SWINGV; // Set the button to SwingV. button = HITACHI_AC344_BUTTON_SWINGV; // Set the button to SwingV.
else if (button == HITACHI_AC344_BUTTON_SWINGV) // Asked to unset it } else if (button == HITACHI_AC344_BUTTON_SWINGV) { // Asked to unset it
// It was set previous, so use Power as a default // It was set previous, so use Power as a default
button = HITACHI_AC344_BUTTON_POWER; button = HITACHI_AC344_BUTTON_POWER;
}
set_button_(button); 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++) { for (uint8_t pos = 0; pos < HITACHI_AC344_STATE_LENGTH; pos++) {
// Read bit // Read bit
for (int8_t bit = 0; bit < 8; 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; 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); ESP_LOGVV(TAG, "Byte %d bit %d fail", pos, bit);
return false; return false;
} }

View file

@ -19,11 +19,12 @@ 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) { void set_bit(uint8_t *const data, const uint8_t position, const bool on) {
uint8_t mask = 1 << position; uint8_t mask = 1 << position;
if (on) if (on) {
*data |= mask; *data |= mask;
else } else {
*data &= ~mask; *data &= ~mask;
} }
}
uint8_t *invert_byte_pairs(uint8_t *ptr, const uint16_t length) { uint8_t *invert_byte_pairs(uint8_t *ptr, const uint16_t length) {
for (uint16_t i = 1; i < length; i += 2) { for (uint16_t i = 1; i < length; i += 2) {
@ -69,10 +70,11 @@ void HitachiClimate::set_temp_(uint8_t celsius, bool set_previous) {
temp = std::min(celsius, HITACHI_AC424_TEMP_MAX); temp = std::min(celsius, HITACHI_AC424_TEMP_MAX);
temp = std::max(temp, HITACHI_AC424_TEMP_MIN); 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); 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); set_button_(HITACHI_AC424_BUTTON_TEMP_DOWN);
else if (previous_temp_ < temp) } else if (previous_temp_ < temp) {
set_button_(HITACHI_AC424_BUTTON_TEMP_UP); set_button_(HITACHI_AC424_BUTTON_TEMP_UP);
}
if (set_previous) if (set_previous)
previous_temp_ = temp; previous_temp_ = temp;
} }
@ -110,11 +112,12 @@ void HitachiClimate::set_fan_(uint8_t speed) {
void HitachiClimate::set_swing_v_toggle_(bool on) { void HitachiClimate::set_swing_v_toggle_(bool on) {
uint8_t button = get_button_(); // Get the current button value. uint8_t button = get_button_(); // Get the current button value.
if (on) if (on) {
button = HITACHI_AC424_BUTTON_SWINGV; // Set the button to SwingV. button = HITACHI_AC424_BUTTON_SWINGV; // Set the button to SwingV.
else if (button == HITACHI_AC424_BUTTON_SWINGV) // Asked to unset it } else if (button == HITACHI_AC424_BUTTON_SWINGV) { // Asked to unset it
// It was set previous, so use Power as a default // It was set previous, so use Power as a default
button = HITACHI_AC424_BUTTON_POWER; button = HITACHI_AC424_BUTTON_POWER;
}
set_button_(button); 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++) { for (uint8_t pos = 0; pos < HITACHI_AC424_STATE_LENGTH; pos++) {
// Read bit // Read bit
for (int8_t bit = 0; bit < 8; 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; 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); ESP_LOGVV(TAG, "Byte %d bit %d fail", pos, bit);
return false; return false;
} }

View file

@ -25,10 +25,11 @@ void HomeassistantBinarySensor::setup() {
} else { } else {
ESP_LOGD(TAG, "'%s': Got state %s", this->entity_id_.c_str(), ONOFF(new_state)); 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); this->publish_initial_state(new_state);
else } else {
this->publish_state(new_state); this->publish_state(new_state);
}
break; break;
} }
this->initial_ = false; this->initial_ = false;

View file

@ -16,10 +16,11 @@ void ArduinoI2CBus::setup() {
#ifdef USE_ESP32 #ifdef USE_ESP32
static uint8_t next_bus_num = 0; static uint8_t next_bus_num = 0;
if (next_bus_num == 0) if (next_bus_num == 0) {
wire_ = &Wire; wire_ = &Wire;
else } else {
wire_ = new TwoWire(next_bus_num); // NOLINT(cppcoreguidelines-owning-memory) wire_ = new TwoWire(next_bus_num); // NOLINT(cppcoreguidelines-owning-memory)
}
next_bus_num++; next_bus_num++;
#else #else
wire_ = &Wire; // NOLINT(cppcoreguidelines-prefer-member-initializer) wire_ = &Wire; // NOLINT(cppcoreguidelines-prefer-member-initializer)
@ -55,14 +56,15 @@ void ArduinoI2CBus::dump_config() {
ESP_LOGI(TAG, "Found no i2c devices!"); ESP_LOGI(TAG, "Found no i2c devices!");
} else { } else {
for (const auto &s : scan_results_) { for (const auto &s : scan_results_) {
if (s.second) if (s.second) {
ESP_LOGI(TAG, "Found i2c device at address 0x%02X", s.first); 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); ESP_LOGE(TAG, "Unknown error at address 0x%02X", s.first);
} }
} }
} }
} }
}
ErrorCode ArduinoI2CBus::readv(uint8_t address, ReadBuffer *buffers, size_t cnt) { ErrorCode ArduinoI2CBus::readv(uint8_t address, ReadBuffer *buffers, size_t cnt) {
// logging is only enabled with vv level, if warnings are shown the caller // logging is only enabled with vv level, if warnings are shown the caller

View file

@ -65,14 +65,15 @@ void IDFI2CBus::dump_config() {
ESP_LOGI(TAG, "Found no i2c devices!"); ESP_LOGI(TAG, "Found no i2c devices!");
} else { } else {
for (const auto &s : scan_results_) { for (const auto &s : scan_results_) {
if (s.second) if (s.second) {
ESP_LOGI(TAG, "Found i2c device at address 0x%02X", s.first); 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); ESP_LOGE(TAG, "Unknown error at address 0x%02X", s.first);
} }
} }
} }
} }
}
ErrorCode IDFI2CBus::readv(uint8_t address, ReadBuffer *buffers, size_t cnt) { ErrorCode IDFI2CBus::readv(uint8_t address, ReadBuffer *buffers, size_t cnt) {
// logging is only enabled with vv level, if warnings are shown the caller // logging is only enabled with vv level, if warnings are shown the caller

View file

@ -548,14 +548,15 @@ void Inkplate6::clean_fast_(uint8_t c, uint8_t rep) {
eink_on_(); eink_on_();
uint8_t data = 0; uint8_t data = 0;
if (c == 0) // White if (c == 0) { // White
data = 0b10101010; data = 0b10101010;
else if (c == 1) // Black } else if (c == 1) { // Black
data = 0b01010101; data = 0b01010101;
else if (c == 2) // Discharge } else if (c == 2) { // Discharge
data = 0b00000000; data = 0b00000000;
else if (c == 3) // Skip } else if (c == 3) { // Skip
data = 0b11111111; data = 0b11111111;
}
uint32_t send = ((data & 0b00000011) << 4) | (((data & 0b00001100) >> 2) << 18) | (((data & 0b00010000) >> 4) << 23) | uint32_t send = ((data & 0b00000011) << 4) | (((data & 0b00001100) >> 2) << 18) | (((data & 0b00010000) >> 4) << 23) |
(((data & 0b11100000) >> 5) << 25); (((data & 0b11100000) >> 5) << 25);

View file

@ -109,18 +109,20 @@ class Inkplate6 : public PollingComponent, public display::DisplayBuffer, public
void pins_as_outputs_(); void pins_as_outputs_();
int get_width_internal() override { int get_width_internal() override {
if (this->model_ == INKPLATE_6) if (this->model_ == INKPLATE_6) {
return 800; return 800;
else if (this->model_ == INKPLATE_10) } else if (this->model_ == INKPLATE_10) {
return 1200; return 1200;
}
return 0; return 0;
} }
int get_height_internal() override { int get_height_internal() override {
if (this->model_ == INKPLATE_6) if (this->model_ == INKPLATE_6) {
return 600; return 600;
else if (this->model_ == INKPLATE_10) } else if (this->model_ == INKPLATE_10) {
return 825; return 825;
}
return 0; return 0;
} }

View file

@ -98,10 +98,11 @@ void LightCall::perform() {
// EFFECT // EFFECT
auto effect = this->effect_; auto effect = this->effect_;
const char *effect_s; const char *effect_s;
if (effect == 0u) if (effect == 0u) {
effect_s = "None"; effect_s = "None";
else } else {
effect_s = this->parent_->effects_[*this->effect_ - 1]->get_name().c_str(); effect_s = this->parent_->effects_[*this->effect_ - 1]->get_name().c_str();
}
if (this->publish_) { if (this->publish_) {
ESP_LOGD(TAG, " Effect: '%s'", effect_s); 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); 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) if (std::get<0>(item) == key)
return std::get<1>(item); return std::get<1>(item);
}
// This happens if there are conflicting flags given. // This happens if there are conflicting flags given.
return {}; return {};

View file

@ -145,11 +145,12 @@ void LightState::publish_state() { this->remote_values_callback_.call(); }
LightOutput *LightState::get_output() const { return this->output_; } LightOutput *LightState::get_output() const { return this->output_; }
std::string LightState::get_effect_name() { 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(); return this->effects_[this->active_effect_index_ - 1]->get_name();
else } else {
return "None"; return "None";
} }
}
void LightState::add_new_remote_values_callback(std::function<void()> &&send_callback) { void LightState::add_new_remote_values_callback(std::function<void()> &&send_callback) {
this->remote_values_callback_.add(std::move(send_callback)); this->remote_values_callback_.add(std::move(send_callback));
@ -219,11 +220,12 @@ void LightState::start_effect_(uint32_t effect_index) {
effect->start_internal(); effect->start_internal();
} }
LightEffect *LightState::get_active_effect_() { LightEffect *LightState::get_active_effect_() {
if (this->active_effect_index_ == 0) if (this->active_effect_index_ == 0) {
return nullptr; return nullptr;
else } else {
return this->effects_[this->active_effect_index_ - 1]; return this->effects_[this->active_effect_index_ - 1];
} }
}
void LightState::stop_effect_() { void LightState::stop_effect_() {
auto *effect = this->get_active_effect_(); auto *effect = this->get_active_effect_();
if (effect != nullptr) { if (effect != nullptr) {

View file

@ -143,11 +143,13 @@ void MAX7219Component::dump_config() {
void MAX7219Component::display() { void MAX7219Component::display() {
for (uint8_t i = 0; i < 8; i++) { for (uint8_t i = 0; i < 8; i++) {
this->enable(); this->enable();
for (uint8_t j = 0; j < this->num_chips_; j++) for (uint8_t j = 0; j < this->num_chips_; j++) {
if (reverse_) if (reverse_) {
this->send_byte_(8 - i, buffer_[(num_chips_ - j - 1) * 8 + i]); this->send_byte_(8 - i, buffer_[(num_chips_ - j - 1) * 8 + i]);
else } else {
this->send_byte_(8 - i, buffer_[j * 8 + i]); this->send_byte_(8 - i, buffer_[j * 8 + i]);
}
}
this->disable(); this->disable();
} }
} }

View file

@ -253,9 +253,10 @@ void MAX7219Component::send_char(uint8_t chip, uint8_t data) {
void MAX7219Component::send64pixels(uint8_t chip, const uint8_t pixels[8]) { 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 for (uint8_t col = 0; col < 8; col++) { // RUN THIS LOOP 8 times until column is 7
this->enable(); // start sending by enabling SPI 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, this->send_byte_(MAX7219_REGISTER_NOOP,
MAX7219_REGISTER_NOOP); // run this loop unit the matching chip is reached 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) { if (this->orientation_ == 0) {
for (uint8_t i = 0; i < 8; i++) { for (uint8_t i = 0; i < 8; i++) {

View file

@ -62,10 +62,11 @@ void MCP23016::update_reg_(uint8_t pin, bool pin_value, uint8_t reg_addr) {
this->read_reg_(reg_addr, &reg_value); this->read_reg_(reg_addr, &reg_value);
} }
if (pin_value) if (pin_value) {
reg_value |= 1 << bit; reg_value |= 1 << bit;
else } else {
reg_value &= ~(1 << bit); reg_value &= ~(1 << bit);
}
this->write_reg_(reg_addr, reg_value); this->write_reg_(reg_addr, reg_value);

View file

@ -67,10 +67,11 @@ void MCP23X08Base::update_reg(uint8_t pin, bool pin_value, uint8_t reg_addr) {
this->read_reg(reg_addr, &reg_value); this->read_reg(reg_addr, &reg_value);
} }
if (pin_value) if (pin_value) {
reg_value |= 1 << bit; reg_value |= 1 << bit;
else } else {
reg_value &= ~(1 << bit); reg_value &= ~(1 << bit);
}
this->write_reg(reg_addr, reg_value); this->write_reg(reg_addr, reg_value);

View file

@ -70,10 +70,11 @@ void MCP23X17Base::update_reg(uint8_t pin, bool pin_value, uint8_t reg_addr) {
this->read_reg(reg_addr, &reg_value); this->read_reg(reg_addr, &reg_value);
} }
if (pin_value) if (pin_value) {
reg_value |= 1 << bit; reg_value |= 1 << bit;
else } else {
reg_value &= ~(1 << bit); reg_value &= ~(1 << bit);
}
this->write_reg(reg_addr, reg_value); this->write_reg(reg_addr, reg_value);

View file

@ -59,14 +59,16 @@ void AirConditioner::control(const ClimateCall &call) {
ctrl.swingMode = Converters::to_midea_swing_mode(call.get_swing_mode().value()); ctrl.swingMode = Converters::to_midea_swing_mode(call.get_swing_mode().value());
if (call.get_mode().has_value()) if (call.get_mode().has_value())
ctrl.mode = Converters::to_midea_mode(call.get_mode().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()); 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()); 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()); 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()); ctrl.fanMode = Converters::to_midea_fan_mode(call.get_custom_fan_mode().value());
}
this->base_.control(ctrl); this->base_.control(ctrl);
} }

View file

@ -172,10 +172,11 @@ bool MideaIR::on_midea_(const MideaData &data) {
this->target_temperature = status.get_temp(); this->target_temperature = status.get_temp();
this->mode = status.get_mode(); this->mode = status.get_mode();
this->fan_mode = status.get_fan_mode(); this->fan_mode = status.get_fan_mode();
if (status.get_sleep_preset()) if (status.get_sleep_preset()) {
this->preset = climate::CLIMATE_PRESET_SLEEP; 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->preset = climate::CLIMATE_PRESET_NONE;
}
this->publish_state(); this->publish_state();
return true; return true;
} }

View file

@ -63,12 +63,13 @@ void MitsubishiClimate::transmit_state() {
data->mark(MITSUBISHI_HEADER_MARK); data->mark(MITSUBISHI_HEADER_MARK);
data->space(MITSUBISHI_HEADER_SPACE); data->space(MITSUBISHI_HEADER_SPACE);
// Data // Data
for (uint8_t i : remote_state) for (uint8_t i : remote_state) {
for (uint8_t j = 0; j < 8; j++) { for (uint8_t j = 0; j < 8; j++) {
data->mark(MITSUBISHI_BIT_MARK); data->mark(MITSUBISHI_BIT_MARK);
bool bit = i & (1 << j); bool bit = i & (1 << j);
data->space(bit ? MITSUBISHI_ONE_SPACE : MITSUBISHI_ZERO_SPACE); data->space(bit ? MITSUBISHI_ONE_SPACE : MITSUBISHI_ZERO_SPACE);
} }
}
// Footer // Footer
if (r == 0) { if (r == 0) {
data->mark(MITSUBISHI_BIT_MARK); data->mark(MITSUBISHI_BIT_MARK);

View file

@ -19,11 +19,12 @@ class ModbusBinarySensor : public Component, public binary_sensor::BinarySensor,
this->skip_updates = skip_updates; this->skip_updates = skip_updates;
this->force_new_range = force_new_range; 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; this->register_count = offset + 1;
else } else {
this->register_count = 1; this->register_count = 1;
} }
}
void parse_and_publish(const std::vector<uint8_t> &data) override; void parse_and_publish(const std::vector<uint8_t> &data) override;
void set_state(bool state) { this->state = state; } void set_state(bool state) { this->state = state; }

View file

@ -230,11 +230,12 @@ class SensorItem {
void set_custom_data(const std::vector<uint8_t> &data) { custom_data = data; } void set_custom_data(const std::vector<uint8_t> &data) { custom_data = data; }
size_t virtual get_register_size() const { 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; 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; return response_bytes > 0 ? response_bytes : register_count * 2;
} }
}
// Override register size for modbus devices not using 1 register for one dword // 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; } void set_register_size(uint8_t register_size) { response_bytes = register_size; }
ModbusRegisterType register_type; ModbusRegisterType register_type;

View file

@ -373,12 +373,13 @@ void MQTTClientComponent::unsubscribe(const std::string &topic) {
auto it = subscriptions_.begin(); auto it = subscriptions_.begin();
while (it != subscriptions_.end()) { while (it != subscriptions_.end()) {
if (it->topic == topic) if (it->topic == topic) {
it = subscriptions_.erase(it); it = subscriptions_.erase(it);
else } else {
++it; ++it;
} }
} }
}
// Publish // Publish
bool MQTTClientComponent::publish(const std::string &topic, const std::string &payload, uint8_t qos, bool retain) { bool MQTTClientComponent::publish(const std::string &topic, const std::string &payload, uint8_t qos, bool retain) {
@ -484,9 +485,10 @@ void MQTTClientComponent::on_message(const std::string &topic, const std::string
// in an ISR. // in an ISR.
this->defer([this, topic, payload]() { this->defer([this, topic, payload]() {
#endif #endif
for (auto &subscription : this->subscriptions_) for (auto &subscription : this->subscriptions_) {
if (topic_match(topic.c_str(), subscription.topic.c_str())) if (topic_match(topic.c_str(), subscription.topic.c_str()))
subscription.callback(topic, payload); subscription.callback(topic, payload);
}
#ifdef USE_ESP8266 #ifdef USE_ESP8266
}); });
#endif #endif

View file

@ -299,7 +299,7 @@ bool MQTTClimateComponent::publish_state_() {
if (traits.get_supports_fan_modes()) { if (traits.get_supports_fan_modes()) {
std::string payload; std::string payload;
if (this->device_->fan_mode.has_value()) if (this->device_->fan_mode.has_value()) {
switch (this->device_->fan_mode.value()) { switch (this->device_->fan_mode.value()) {
case CLIMATE_FAN_ON: case CLIMATE_FAN_ON:
payload = "on"; payload = "on";
@ -329,6 +329,7 @@ bool MQTTClimateComponent::publish_state_() {
payload = "diffuse"; payload = "diffuse";
break; break;
} }
}
if (this->device_->custom_fan_mode.has_value()) if (this->device_->custom_fan_mode.has_value())
payload = this->device_->custom_fan_mode.value(); payload = this->device_->custom_fan_mode.value();
if (!this->publish(this->get_fan_mode_state_topic(), payload)) if (!this->publish(this->get_fan_mode_state_topic(), payload))

View file

@ -737,9 +737,10 @@ void Nextion::process_nextion_commands_() {
for (size_t i = 0; i < this->nextion_queue_.size(); i++) { for (size_t i = 0; i < this->nextion_queue_.size(); i++) {
NextionComponentBase *component = this->nextion_queue_[i]->component; 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 + 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", 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()); component->get_queue_type_string().c_str(), component->get_variable_name().c_str());
}
if (component->get_variable_name() == "sleep_wake") { if (component->get_variable_name() == "sleep_wake") {
this->is_sleeping_ = false; 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) { while ((timeout == 0 && this->available()) || millis() - start <= timeout) {
this->read_byte(&c); this->read_byte(&c);
if (c == 0xFF) if (c == 0xFF) {
nr_of_ff_bytes++; nr_of_ff_bytes++;
else { } else {
nr_of_ff_bytes = 0; nr_of_ff_bytes = 0;
ff_flag = false; ff_flag = false;
} }

View file

@ -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; 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"); 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_); 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) { if (this->safe_mode_rtc_value_ >= num_attempts || is_manual_safe_mode) {
this->clean_rtc(); this->clean_rtc();

View file

@ -32,11 +32,12 @@ class BinaryOutput {
/// Enable or disable this binary output. /// Enable or disable this binary output.
virtual void set_state(bool state) { virtual void set_state(bool state) {
if (state) if (state) {
this->turn_on(); this->turn_on();
else } else {
this->turn_off(); this->turn_off();
} }
}
/// Enable this binary output. /// Enable this binary output.
virtual void turn_on() { virtual void turn_on() {

View file

@ -30,11 +30,12 @@ void OutputSwitch::setup() {
break; break;
} }
if (initial_state) if (initial_state) {
this->turn_on(); this->turn_on();
else } else {
this->turn_off(); this->turn_off();
} }
}
void OutputSwitch::write_state(bool state) { void OutputSwitch::write_state(bool state) {
if (state) { if (state) {
this->output_->turn_on(); this->output_->turn_on();

View file

@ -78,10 +78,11 @@ class PartitionLightOutput : public light::AddressableLight {
int32_t seg_off = index - seg.get_dst_offset(); int32_t seg_off = index - seg.get_dst_offset();
// offset within the src // offset within the src
int32_t src_off; int32_t src_off;
if (seg.is_reversed()) if (seg.is_reversed()) {
src_off = seg.get_src_offset() + seg.get_size() - seg_off - 1; src_off = seg.get_src_offset() + seg.get_size() - seg_off - 1;
else } else {
src_off = seg.get_src_offset() + seg_off; src_off = seg.get_src_offset() + seg_off;
}
auto view = (*seg.get_src())[src_off]; auto view = (*seg.get_src())[src_off];
view.raw_set_color_correction(&this->correction_); view.raw_set_color_correction(&this->correction_);

View file

@ -20,12 +20,13 @@ void PIDClimate::setup() {
restore->to_call(this).perform(); restore->to_call(this).perform();
} else { } else {
// restore from defaults, change_away handles those for us // 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; this->mode = climate::CLIMATE_MODE_HEAT_COOL;
else if (supports_cool_()) } else if (supports_cool_()) {
this->mode = climate::CLIMATE_MODE_COOL; this->mode = climate::CLIMATE_MODE_COOL;
else if (supports_heat_()) } else if (supports_heat_()) {
this->mode = climate::CLIMATE_MODE_HEAT; this->mode = climate::CLIMATE_MODE_HEAT;
}
this->target_temperature = this->default_target_temperature_; 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 // Update action variable for user feedback what's happening
climate::ClimateAction new_action; climate::ClimateAction new_action;
if (this->supports_cool_() && value < 0) if (this->supports_cool_() && value < 0) {
new_action = climate::CLIMATE_ACTION_COOLING; 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; 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; new_action = climate::CLIMATE_ACTION_OFF;
else } else {
new_action = climate::CLIMATE_ACTION_IDLE; new_action = climate::CLIMATE_ACTION_IDLE;
}
if (new_action != this->action) { if (new_action != this->action) {
this->action = new_action; this->action = new_action;

View file

@ -908,11 +908,12 @@ uint16_t Pipsolar::crc_xmodem_update_(uint16_t crc, uint8_t data) {
int i; int i;
crc = crc ^ ((uint16_t) data << 8); crc = crc ^ ((uint16_t) data << 8);
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
if (crc & 0x8000) if (crc & 0x8000) {
crc = (crc << 1) ^ 0x1021; //(polynomial = 0x1021) crc = (crc << 1) ^ 0x1021; //(polynomial = 0x1021)
else } else {
crc <<= 1; crc <<= 1;
} }
}
return crc; return crc;
} }

View file

@ -139,10 +139,11 @@ void RC522::loop() {
StatusCode status = STATUS_ERROR; // For lint passing. TODO: refactor this StatusCode status = STATUS_ERROR; // For lint passing. TODO: refactor this
if (awaiting_comm_) { if (awaiting_comm_) {
if (state_ == STATE_SELECT_SERIAL_DONE) if (state_ == STATE_SELECT_SERIAL_DONE) {
status = await_crc_(); status = await_crc_();
else } else {
status = await_transceive_(); status = await_transceive_();
}
if (status == STATUS_WAITING) { if (status == STATUS_WAITING) {
return; return;
@ -210,11 +211,12 @@ void RC522::loop() {
} }
case STATE_READ_SERIAL_DONE: { case STATE_READ_SERIAL_DONE: {
if (status != STATUS_OK || back_length_ != 3) { 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); 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_, ESP_LOGW(TAG, "Unexpected response. Read status is %d. Read bytes: %d (%s)", status, back_length_,
format_buffer(buffer_, 9).c_str()); format_buffer(buffer_, 9).c_str());
}
state_ = STATE_DONE; state_ = STATE_DONE;
uid_idx_ = 0; uid_idx_ = 0;
@ -476,9 +478,9 @@ RC522::StatusCode RC522::await_crc_() {
bool RC522BinarySensor::process(std::vector<uint8_t> &data) { bool RC522BinarySensor::process(std::vector<uint8_t> &data) {
bool result = true; bool result = true;
if (data.size() != this->uid_.size()) if (data.size() != this->uid_.size()) {
result = false; result = false;
else { } else {
for (size_t i = 0; i < data.size(); i++) { for (size_t i = 0; i < data.size(); i++) {
if (data[i] != this->uid_[i]) { if (data[i] != this->uid_[i]) {
result = false; result = false;

View file

@ -51,11 +51,12 @@ static bool decode_data(RemoteReceiveData &src, CoolixData &dst) {
for (uint32_t mask = 1 << 7; mask; mask >>= 1) { for (uint32_t mask = 1 << 7; mask; mask >>= 1) {
if (!src.expect_mark(BIT_MARK_US)) if (!src.expect_mark(BIT_MARK_US))
return false; return false;
if (src.expect_space(BIT_ONE_SPACE_US)) if (src.expect_space(BIT_ONE_SPACE_US)) {
data |= mask; data |= mask;
else if (!src.expect_space(BIT_ZERO_SPACE_US)) } else if (!src.expect_space(BIT_ZERO_SPACE_US)) {
return false; return false;
} }
}
// Check for inverse byte // Check for inverse byte
for (uint32_t mask = 1 << 7; mask; mask >>= 1) { for (uint32_t mask = 1 << 7; mask; mask >>= 1) {
if (!src.expect_item(BIT_MARK_US, (data & mask) ? BIT_ZERO_SPACE_US : BIT_ONE_SPACE_US)) if (!src.expect_item(BIT_MARK_US, (data & mask) ? BIT_ZERO_SPACE_US : BIT_ONE_SPACE_US))

View file

@ -24,19 +24,21 @@ void DishProtocol::encode(RemoteTransmitData *dst, const DishData &data) {
for (uint i = 0; i < 4; i++) { for (uint i = 0; i < 4; i++) {
// COMMAND (function, in MSB) // COMMAND (function, in MSB)
for (uint8_t mask = 1UL << 5; mask; mask >>= 1) { 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); dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
else } else {
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
} }
}
// ADDRESS (unit code, in LSB) // ADDRESS (unit code, in LSB)
for (uint8_t mask = 1UL; mask < 1UL << 4; mask <<= 1) { 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); dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
else } else {
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
} }
}
// PADDING // PADDING
for (uint j = 0; j < 6; j++) for (uint j = 0; j < 6; j++)
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);

View file

@ -20,11 +20,12 @@ void JVCProtocol::encode(RemoteTransmitData *dst, const JVCData &data) {
dst->item(HEADER_HIGH_US, HEADER_LOW_US); dst->item(HEADER_HIGH_US, HEADER_LOW_US);
for (uint32_t mask = 1UL << (NBITS - 1); mask != 0; mask >>= 1) { 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); dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
else } else {
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
} }
}
dst->mark(BIT_HIGH_US); dst->mark(BIT_HIGH_US);
} }

View file

@ -19,11 +19,12 @@ void LGProtocol::encode(RemoteTransmitData *dst, const LGData &data) {
dst->item(HEADER_HIGH_US, HEADER_LOW_US); dst->item(HEADER_HIGH_US, HEADER_LOW_US);
for (uint32_t mask = 1UL << (data.nbits - 1); mask != 0; mask >>= 1) { 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); dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
else } else {
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
} }
}
dst->mark(BIT_HIGH_US); dst->mark(BIT_HIGH_US);
} }

View file

@ -31,14 +31,16 @@ void MideaProtocol::encode(RemoteTransmitData *dst, const MideaData &src) {
dst->set_carrier_frequency(38000); dst->set_carrier_frequency(38000);
dst->reserve(2 + 48 * 2 + 2 + 2 + 48 * 2 + 1); dst->reserve(2 + 48 * 2 + 2 + 2 + 48 * 2 + 1);
dst->item(HEADER_MARK_US, HEADER_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) 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(BIT_MARK_US, (src[idx] & mask) ? BIT_ONE_SPACE_US : BIT_ZERO_SPACE_US);
}
dst->item(FOOTER_MARK_US, FOOTER_SPACE_US); dst->item(FOOTER_MARK_US, FOOTER_SPACE_US);
dst->item(HEADER_MARK_US, HEADER_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) 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->item(BIT_MARK_US, (src[idx] & mask) ? BIT_ZERO_SPACE_US : BIT_ONE_SPACE_US);
}
dst->mark(FOOTER_MARK_US); dst->mark(FOOTER_MARK_US);
} }
@ -48,11 +50,12 @@ static bool decode_data(RemoteReceiveData &src, MideaData &dst) {
for (uint8_t mask = 1 << 7; mask; mask >>= 1) { for (uint8_t mask = 1 << 7; mask; mask >>= 1) {
if (!src.expect_mark(BIT_MARK_US)) if (!src.expect_mark(BIT_MARK_US))
return false; return false;
if (src.expect_space(BIT_ONE_SPACE_US)) if (src.expect_space(BIT_ONE_SPACE_US)) {
data |= mask; data |= mask;
else if (!src.expect_space(BIT_ZERO_SPACE_US)) } else if (!src.expect_space(BIT_ZERO_SPACE_US)) {
return false; return false;
} }
}
dst[idx] = data; dst[idx] = data;
} }
return true; return true;

View file

@ -18,18 +18,20 @@ void NECProtocol::encode(RemoteTransmitData *dst, const NECData &data) {
dst->item(HEADER_HIGH_US, HEADER_LOW_US); dst->item(HEADER_HIGH_US, HEADER_LOW_US);
for (uint16_t mask = 1; mask; mask <<= 1) { 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); dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
else } else {
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
} }
}
for (uint16_t mask = 1; mask; mask <<= 1) { 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); dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
else } else {
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
} }
}
dst->mark(BIT_HIGH_US); dst->mark(BIT_HIGH_US);
} }

View file

@ -41,45 +41,50 @@ void NexaProtocol::encode(RemoteTransmitData *dst, const NexaData &data) {
// Device (26 bits) // Device (26 bits)
for (int16_t i = 26 - 1; i >= 0; i--) { for (int16_t i = 26 - 1; i >= 0; i--) {
if (data.device & (1 << i)) if (data.device & (1 << i)) {
this->one(dst); this->one(dst);
else } else {
this->zero(dst); this->zero(dst);
} }
}
// Group (1 bit) // Group (1 bit)
if (data.group != 0) if (data.group != 0) {
this->one(dst); this->one(dst);
else } else {
this->zero(dst); this->zero(dst);
}
// State (1 bit) // State (1 bit)
if (data.state == 2) { if (data.state == 2) {
// Special case for dimmers...send 00 as state // 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);
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); this->one(dst);
else } else {
this->zero(dst); this->zero(dst);
}
// Channel (4 bits) // Channel (4 bits)
for (int16_t i = 4 - 1; i >= 0; i--) { for (int16_t i = 4 - 1; i >= 0; i--) {
if (data.channel & (1 << i)) if (data.channel & (1 << i)) {
this->one(dst); this->one(dst);
else } else {
this->zero(dst); this->zero(dst);
} }
}
// Level (4 bits) // Level (4 bits)
if (data.state == 2) { if (data.state == 2) {
for (int16_t i = 4 - 1; i >= 0; i--) { for (int16_t i = 4 - 1; i >= 0; i--) {
if (data.level & (1 << i)) if (data.level & (1 << i)) {
this->one(dst); this->one(dst);
else } else {
this->zero(dst); this->zero(dst);
} }
} }
}
// Send finishing Zero // Send finishing Zero
dst->item(TX_BIT_HIGH_US, TX_BIT_ZERO_LOW_US); dst->item(TX_BIT_HIGH_US, TX_BIT_ZERO_LOW_US);

View file

@ -19,18 +19,20 @@ void PanasonicProtocol::encode(RemoteTransmitData *dst, const PanasonicData &dat
uint32_t mask; uint32_t mask;
for (mask = 1UL << 15; mask != 0; mask >>= 1) { 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); dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
else } else {
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
} }
}
for (mask = 1UL << 31; mask != 0; mask >>= 1) { 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); dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
else } else {
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
} }
}
dst->mark(BIT_HIGH_US); dst->mark(BIT_HIGH_US);
} }
optional<PanasonicData> PanasonicProtocol::decode(RemoteReceiveData src) { optional<PanasonicData> PanasonicProtocol::decode(RemoteReceiveData src) {

View file

@ -42,27 +42,30 @@ void PioneerProtocol::encode(RemoteTransmitData *dst, const PioneerData &data) {
command1 = (command1 << 8) | ((~command1) & 0xff); command1 = (command1 << 8) | ((~command1) & 0xff);
command2 = (command2 << 8) | ((~command2) & 0xff); command2 = (command2 << 8) | ((~command2) & 0xff);
if (data.rc_code_2 == 0) if (data.rc_code_2 == 0) {
dst->reserve(68); dst->reserve(68);
else } else {
dst->reserve((68 * 2) + 1); dst->reserve((68 * 2) + 1);
}
dst->set_carrier_frequency(40000); dst->set_carrier_frequency(40000);
dst->item(HEADER_HIGH_US, HEADER_LOW_US); dst->item(HEADER_HIGH_US, HEADER_LOW_US);
for (uint32_t mask = 1UL << 15; mask; mask >>= 1) { for (uint32_t mask = 1UL << 15; mask; mask >>= 1) {
if (address1 & mask) if (address1 & mask) {
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US); dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
else } else {
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
} }
}
for (uint32_t mask = 1UL << 15; mask; mask >>= 1) { for (uint32_t mask = 1UL << 15; mask; mask >>= 1) {
if (command1 & mask) if (command1 & mask) {
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US); dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
else } else {
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
} }
}
dst->mark(BIT_HIGH_US); dst->mark(BIT_HIGH_US);
@ -70,18 +73,20 @@ void PioneerProtocol::encode(RemoteTransmitData *dst, const PioneerData &data) {
dst->space(TRAILER_SPACE_US); dst->space(TRAILER_SPACE_US);
dst->item(HEADER_HIGH_US, HEADER_LOW_US); dst->item(HEADER_HIGH_US, HEADER_LOW_US);
for (uint32_t mask = 1UL << 15; mask; mask >>= 1) { for (uint32_t mask = 1UL << 15; mask; mask >>= 1) {
if (address2 & mask) if (address2 & mask) {
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US); dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
else } else {
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
} }
}
for (uint32_t mask = 1UL << 15; mask; mask >>= 1) { for (uint32_t mask = 1UL << 15; mask; mask >>= 1) {
if (command2 & mask) if (command2 & mask) {
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US); dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
else } else {
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
} }
}
dst->mark(BIT_HIGH_US); dst->mark(BIT_HIGH_US);
} }
@ -140,11 +145,12 @@ optional<PioneerData> PioneerProtocol::decode(RemoteReceiveData src) {
return data; return data;
} }
void PioneerProtocol::dump(const PioneerData &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); 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); 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 } // namespace remote_base
} // namespace esphome } // namespace esphome

View file

@ -50,11 +50,12 @@ template<typename... Ts> class RawAction : public RemoteTransmitterActionBase<Ts
if (this->code_static_ != nullptr) { if (this->code_static_ != nullptr) {
for (size_t i = 0; i < this->code_static_len_; i++) { for (size_t i = 0; i < this->code_static_len_; i++) {
auto val = this->code_static_[i]; auto val = this->code_static_[i];
if (val < 0) if (val < 0) {
dst->space(static_cast<uint32_t>(-val)); dst->space(static_cast<uint32_t>(-val));
else } else {
dst->mark(static_cast<uint32_t>(val)); dst->mark(static_cast<uint32_t>(val));
} }
}
} else { } else {
dst->set_data(this->code_func_(x...)); dst->set_data(this->code_func_(x...));
} }

View file

@ -57,12 +57,13 @@ void RCSwitchBase::transmit(RemoteTransmitData *dst, uint64_t code, uint8_t len)
dst->set_carrier_frequency(0); dst->set_carrier_frequency(0);
this->sync(dst); this->sync(dst);
for (int16_t i = len - 1; i >= 0; i--) { for (int16_t i = len - 1; i >= 0; i--) {
if (code & ((uint64_t) 1 << i)) if (code & ((uint64_t) 1 << i)) {
this->one(dst); this->one(dst);
else } else {
this->zero(dst); this->zero(dst);
} }
} }
}
bool RCSwitchBase::expect_one(RemoteReceiveData &src) const { bool RCSwitchBase::expect_one(RemoteReceiveData &src) const {
if (!this->inverted_) { if (!this->inverted_) {
@ -148,12 +149,13 @@ void RCSwitchBase::simple_code_to_tristate(uint16_t code, uint8_t nbits, uint64_
*out_code = 0; *out_code = 0;
for (int8_t i = nbits - 1; i >= 0; i--) { for (int8_t i = nbits - 1; i >= 0; i--) {
*out_code <<= 2; *out_code <<= 2;
if (code & (1 << i)) if (code & (1 << i)) {
*out_code |= 0b01; *out_code |= 0b01;
else } else {
*out_code |= 0b00; *out_code |= 0b00;
} }
} }
}
void RCSwitchBase::type_a_code(uint8_t switch_group, uint8_t switch_device, bool state, uint64_t *out_code, void RCSwitchBase::type_a_code(uint8_t switch_group, uint8_t switch_device, bool state, uint64_t *out_code,
uint8_t *out_nbits) { uint8_t *out_nbits) {
uint16_t code = 0; uint16_t code = 0;

View file

@ -22,11 +22,12 @@ void SamsungProtocol::encode(RemoteTransmitData *dst, const SamsungData &data) {
dst->item(HEADER_HIGH_US, HEADER_LOW_US); dst->item(HEADER_HIGH_US, HEADER_LOW_US);
for (uint8_t bit = data.nbits; bit > 0; bit--) { 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); dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
else } else {
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
} }
}
dst->item(FOOTER_HIGH_US, FOOTER_LOW_US); dst->item(FOOTER_HIGH_US, FOOTER_LOW_US);
} }

View file

@ -19,12 +19,13 @@ void SonyProtocol::encode(RemoteTransmitData *dst, const SonyData &data) {
dst->item(HEADER_HIGH_US, HEADER_LOW_US); dst->item(HEADER_HIGH_US, HEADER_LOW_US);
for (uint32_t mask = 1UL << (data.nbits - 1); mask != 0; mask >>= 1) { 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); dst->item(BIT_ONE_HIGH_US, BIT_LOW_US);
else } else {
dst->item(BIT_ZERO_HIGH_US, BIT_LOW_US); dst->item(BIT_ZERO_HIGH_US, BIT_LOW_US);
} }
} }
}
optional<SonyData> SonyProtocol::decode(RemoteReceiveData src) { optional<SonyData> SonyProtocol::decode(RemoteReceiveData src) {
SonyData out{ SonyData out{
.data = 0, .data = 0,

View file

@ -24,11 +24,12 @@ void ToshibaAcProtocol::encode(RemoteTransmitData *dst, const ToshibaAcData &dat
dst->item(HEADER_HIGH_US, HEADER_LOW_US); dst->item(HEADER_HIGH_US, HEADER_LOW_US);
for (uint8_t bit = 48; bit > 0; bit--) { for (uint8_t bit = 48; bit > 0; bit--) {
dst->mark(BIT_HIGH_US); 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); dst->space(BIT_ONE_LOW_US);
else } else {
dst->space(BIT_ZERO_LOW_US); dst->space(BIT_ZERO_LOW_US);
} }
}
dst->item(FOOTER_HIGH_US, FOOTER_LOW_US); dst->item(FOOTER_HIGH_US, FOOTER_LOW_US);
} }
@ -36,11 +37,12 @@ void ToshibaAcProtocol::encode(RemoteTransmitData *dst, const ToshibaAcData &dat
dst->item(HEADER_HIGH_US, HEADER_LOW_US); dst->item(HEADER_HIGH_US, HEADER_LOW_US);
for (uint8_t bit = 48; bit > 0; bit--) { for (uint8_t bit = 48; bit > 0; bit--) {
dst->mark(BIT_HIGH_US); 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); dst->space(BIT_ONE_LOW_US);
else } else {
dst->space(BIT_ZERO_LOW_US); dst->space(BIT_ZERO_LOW_US);
} }
}
dst->item(FOOTER_HIGH_US, FOOTER_LOW_US); dst->item(FOOTER_HIGH_US, FOOTER_LOW_US);
} }
} }
@ -102,11 +104,12 @@ optional<ToshibaAcData> ToshibaAcProtocol::decode(RemoteReceiveData src) {
} }
void ToshibaAcProtocol::dump(const ToshibaAcData &data) { 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); 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); ESP_LOGD(TAG, "Received Toshiba AC: rc_code_1=0x%" PRIX64, data.rc_code_1);
} }
}
} // namespace remote_base } // namespace remote_base
} // namespace esphome } // namespace esphome

View file

@ -79,9 +79,10 @@ void RemoteReceiverComponent::loop() {
if (dist <= 1) if (dist <= 1)
return; return;
const uint32_t now = micros(); 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. // The last change was fewer than the configured idle time ago.
return; return;
}
ESP_LOGVV(TAG, "read_at=%u write_at=%u dist=%u now=%u end=%u", s.buffer_read_at, write_at, dist, now, 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]); s.buffer[write_at]);

View file

@ -35,11 +35,12 @@ void RemoteTransmitterComponent::calculate_on_off_time_(uint32_t carrier_frequen
void RemoteTransmitterComponent::await_target_time_() { void RemoteTransmitterComponent::await_target_time_() {
const uint32_t current_time = micros(); const uint32_t current_time = micros();
if (this->target_time_ == 0) if (this->target_time_ == 0) {
this->target_time_ = current_time; 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); delayMicroseconds(this->target_time_ - current_time);
} }
}
void RemoteTransmitterComponent::mark_(uint32_t on_time, uint32_t off_time, uint32_t usec) { void RemoteTransmitterComponent::mark_(uint32_t on_time, uint32_t off_time, uint32_t usec) {
this->await_target_time_(); this->await_target_time_();

View file

@ -20,16 +20,18 @@ void ResistanceSensor::process_(float value) {
float res = 0; float res = 0;
switch (this->configuration_) { switch (this->configuration_) {
case UPSTREAM: case UPSTREAM:
if (value == 0.0f) if (value == 0.0f) {
res = NAN; res = NAN;
else } else {
res = (this->reference_voltage_ - value) / value; res = (this->reference_voltage_ - value) / value;
}
break; break;
case DOWNSTREAM: case DOWNSTREAM:
if (value == this->reference_voltage_) if (value == this->reference_voltage_) {
res = NAN; res = NAN;
else } else {
res = value / (this->reference_voltage_ - value); res = value / (this->reference_voltage_ - value);
}
break; break;
} }

View file

@ -104,10 +104,11 @@ void Rtttl::loop() {
// first, get note duration, if available // first, get note duration, if available
uint8_t num = this->get_integer_(); uint8_t num = this->get_integer_();
if (num) if (num) {
note_duration_ = wholenote_ / num; note_duration_ = wholenote_ / num;
else } else {
note_duration_ = wholenote_ / default_duration_; // we will need to check if we are a dotted note after note_duration_ = wholenote_ / default_duration_; // we will need to check if we are a dotted note after
}
uint8_t note; uint8_t note;

View file

@ -229,19 +229,21 @@ uint8_t SCD30Component::sht_crc_(uint8_t data1, uint8_t data2) {
crc ^= data1; crc ^= data1;
for (bit = 8; bit > 0; --bit) { for (bit = 8; bit > 0; --bit) {
if (crc & 0x80) if (crc & 0x80) {
crc = (crc << 1) ^ 0x131; crc = (crc << 1) ^ 0x131;
else } else {
crc = (crc << 1); crc = (crc << 1);
} }
}
crc ^= data2; crc ^= data2;
for (bit = 8; bit > 0; --bit) { for (bit = 8; bit > 0; --bit) {
if (crc & 0x80) if (crc & 0x80) {
crc = (crc << 1) ^ 0x131; crc = (crc << 1) ^ 0x131;
else } else {
crc = (crc << 1); crc = (crc << 1);
} }
}
return crc; return crc;
} }

View file

@ -233,19 +233,21 @@ uint8_t SCD4XComponent::sht_crc_(uint8_t data1, uint8_t data2) {
crc ^= data1; crc ^= data1;
for (bit = 8; bit > 0; --bit) { for (bit = 8; bit > 0; --bit) {
if (crc & 0x80) if (crc & 0x80) {
crc = (crc << 1) ^ 0x131; crc = (crc << 1) ^ 0x131;
else } else {
crc = (crc << 1); crc = (crc << 1);
} }
}
crc ^= data2; crc ^= data2;
for (bit = 8; bit > 0; --bit) { for (bit = 8; bit > 0; --bit) {
if (crc & 0x80) if (crc & 0x80) {
crc = (crc << 1) ^ 0x131; crc = (crc << 1) ^ 0x131;
else } else {
crc = (crc << 1); crc = (crc << 1);
} }
}
return crc; return crc;
} }

View file

@ -138,12 +138,13 @@ bool SDP3XComponent::check_crc_(const uint8_t data[], uint8_t size, uint8_t chec
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
crc ^= (data[i]); crc ^= (data[i]);
for (uint8_t bit = 8; bit > 0; --bit) { for (uint8_t bit = 8; bit > 0; --bit) {
if (crc & 0x80) if (crc & 0x80) {
crc = (crc << 1) ^ 0x31; crc = (crc << 1) ^ 0x31;
else } else {
crc = (crc << 1); crc = (crc << 1);
} }
} }
}
// verify checksum // verify checksum
return (crc == checksum); return (crc == checksum);

View file

@ -176,10 +176,11 @@ optional<float> SlidingWindowMovingAverageFilter::new_value(float value) {
this->sum_ += value; this->sum_ += value;
} }
float average; float average;
if (this->queue_.empty()) if (this->queue_.empty()) {
average = 0.0f; average = 0.0f;
else } else {
average = this->sum_ / this->queue_.size(); average = this->sum_ / this->queue_.size();
}
ESP_LOGVV(TAG, "SlidingWindowMovingAverageFilter(%p)::new_value(%f) -> %f", this, value, average); ESP_LOGVV(TAG, "SlidingWindowMovingAverageFilter(%p)::new_value(%f) -> %f", this, value, average);
if (++this->send_at_ % this->send_every_ == 0) { 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) {} : send_every_(send_every), send_at_(send_every - 1), alpha_(alpha) {}
optional<float> ExponentialMovingAverageFilter::new_value(float value) { optional<float> ExponentialMovingAverageFilter::new_value(float value) {
if (!std::isnan(value)) { if (!std::isnan(value)) {
if (this->first_value_) if (this->first_value_) {
this->accumulator_ = value; this->accumulator_ = value;
else } else {
this->accumulator_ = (this->alpha_ * value) + (1.0f - this->alpha_) * this->accumulator_; this->accumulator_ = (this->alpha_ * value) + (1.0f - this->alpha_) * this->accumulator_;
}
this->first_value_ = false; this->first_value_ = false;
} }
@ -274,21 +276,23 @@ FilterOutValueFilter::FilterOutValueFilter(float value_to_filter_out) : value_to
optional<float> FilterOutValueFilter::new_value(float value) { optional<float> FilterOutValueFilter::new_value(float value) {
if (std::isnan(this->value_to_filter_out_)) { if (std::isnan(this->value_to_filter_out_)) {
if (std::isnan(value)) if (std::isnan(value)) {
return {}; return {};
else } else {
return value; return value;
}
} else { } else {
int8_t accuracy = this->parent_->get_accuracy_decimals(); int8_t accuracy = this->parent_->get_accuracy_decimals();
float accuracy_mult = powf(10.0f, accuracy); float accuracy_mult = powf(10.0f, accuracy);
float rounded_filter_out = roundf(accuracy_mult * this->value_to_filter_out_); float rounded_filter_out = roundf(accuracy_mult * this->value_to_filter_out_);
float rounded_value = roundf(accuracy_mult * value); float rounded_value = roundf(accuracy_mult * value);
if (rounded_filter_out == rounded_value) if (rounded_filter_out == rounded_value) {
return {}; return {};
else } else {
return value; return value;
} }
} }
}
// ThrottleFilter // ThrottleFilter
ThrottleFilter::ThrottleFilter(uint32_t min_time_between_inputs) : min_time_between_inputs_(min_time_between_inputs) {} ThrottleFilter::ThrottleFilter(uint32_t min_time_between_inputs) : min_time_between_inputs_(min_time_between_inputs) {}

View file

@ -65,10 +65,11 @@ void Servo::write(float value) {
void Servo::internal_write(float value) { void Servo::internal_write(float value) {
value = clamp(value, -1.0f, 1.0f); value = clamp(value, -1.0f, 1.0f);
float level; float level;
if (value < 0.0) if (value < 0.0) {
level = lerp(-value, this->idle_level_, this->min_level_); level = lerp(-value, this->idle_level_, this->min_level_);
else } else {
level = lerp(value, this->idle_level_, this->max_level_); level = lerp(value, this->idle_level_, this->max_level_);
}
this->output_->set_level(level); this->output_->set_level(level);
if (this->target_value_ == this->current_value_) { if (this->target_value_ == this->current_value_) {
this->save_level_(level); this->save_level_(level);

View file

@ -220,10 +220,11 @@ void SGP30Component::write_iaq_baseline_(uint16_t eco2_baseline, uint16_t tvoc_b
data[6] = sht_crc_(data[4], data[5]); data[6] = sht_crc_(data[4], data[5]);
if (!this->write_bytes(SGP30_CMD_SET_IAQ_BASELINE >> 8, data, 7)) { 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); 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, ESP_LOGI(TAG, "Initial baselines applied successfully! eCO2 baseline: 0x%04X, TVOC baseline: 0x%04X", eco2_baseline,
tvoc_baseline); tvoc_baseline);
} }
}
void SGP30Component::dump_config() { void SGP30Component::dump_config() {
ESP_LOGCONFIG(TAG, "SGP30:"); ESP_LOGCONFIG(TAG, "SGP30:");
@ -315,19 +316,21 @@ uint8_t SGP30Component::sht_crc_(uint8_t data1, uint8_t data2) {
crc ^= data1; crc ^= data1;
for (bit = 8; bit > 0; --bit) { for (bit = 8; bit > 0; --bit) {
if (crc & 0x80) if (crc & 0x80) {
crc = (crc << 1) ^ 0x131; crc = (crc << 1) ^ 0x131;
else } else {
crc = (crc << 1); crc = (crc << 1);
} }
}
crc ^= data2; crc ^= data2;
for (bit = 8; bit > 0; --bit) { for (bit = 8; bit > 0; --bit) {
if (crc & 0x80) if (crc & 0x80) {
crc = (crc << 1) ^ 0x131; crc = (crc << 1) ^ 0x131;
else } else {
crc = (crc << 1); crc = (crc << 1);
} }
}
return crc; return crc;
} }

View file

@ -229,12 +229,13 @@ uint8_t SGP40Component::generate_crc_(const uint8_t *data, uint8_t datalen) {
for (uint8_t i = 0; i < datalen; i++) { for (uint8_t i = 0; i < datalen; i++) {
crc ^= data[i]; crc ^= data[i];
for (uint8_t b = 0; b < 8; b++) { for (uint8_t b = 0; b < 8; b++) {
if (crc & 0x80) if (crc & 0x80) {
crc = (crc << 1) ^ SGP40_CRC8_POLYNOMIAL; crc = (crc << 1) ^ SGP40_CRC8_POLYNOMIAL;
else } else {
crc <<= 1; crc <<= 1;
} }
} }
}
return crc; return crc;
} }
@ -303,19 +304,21 @@ uint8_t SGP40Component::sht_crc_(uint8_t data1, uint8_t data2) {
crc ^= data1; crc ^= data1;
for (bit = 8; bit > 0; --bit) { for (bit = 8; bit > 0; --bit) {
if (crc & 0x80) if (crc & 0x80) {
crc = (crc << 1) ^ 0x131; crc = (crc << 1) ^ 0x131;
else } else {
crc = (crc << 1); crc = (crc << 1);
} }
}
crc ^= data2; crc ^= data2;
for (bit = 8; bit > 0; --bit) { for (bit = 8; bit > 0; --bit) {
if (crc & 0x80) if (crc & 0x80) {
crc = (crc << 1) ^ 0x131; crc = (crc << 1) ^ 0x131;
else } else {
crc = (crc << 1); crc = (crc << 1);
} }
}
return crc; return crc;
} }

View file

@ -82,19 +82,21 @@ uint8_t sht_crc(uint8_t data1, uint8_t data2) {
crc ^= data1; crc ^= data1;
for (bit = 8; bit > 0; --bit) { for (bit = 8; bit > 0; --bit) {
if (crc & 0x80) if (crc & 0x80) {
crc = (crc << 1) ^ 0x131; crc = (crc << 1) ^ 0x131;
else } else {
crc = (crc << 1); crc = (crc << 1);
} }
}
crc ^= data2; crc ^= data2;
for (bit = 8; bit > 0; --bit) { for (bit = 8; bit > 0; --bit) {
if (crc & 0x80) if (crc & 0x80) {
crc = (crc << 1) ^ 0x131; crc = (crc << 1) ^ 0x131;
else } else {
crc = (crc << 1); crc = (crc << 1);
} }
}
return crc; return crc;
} }

View file

@ -112,19 +112,21 @@ uint8_t sht_crc(uint8_t data1, uint8_t data2) {
crc ^= data1; crc ^= data1;
for (bit = 8; bit > 0; --bit) { for (bit = 8; bit > 0; --bit) {
if (crc & 0x80) if (crc & 0x80) {
crc = (crc << 1) ^ 0x131; crc = (crc << 1) ^ 0x131;
else } else {
crc = (crc << 1); crc = (crc << 1);
} }
}
crc ^= data2; crc ^= data2;
for (bit = 8; bit > 0; --bit) { for (bit = 8; bit > 0; --bit) {
if (crc & 0x80) if (crc & 0x80) {
crc = (crc << 1) ^ 0x131; crc = (crc << 1) ^ 0x131;
else } else {
crc = (crc << 1); crc = (crc << 1);
} }
}
return crc; return crc;
} }

View file

@ -88,9 +88,10 @@ class BSDSocketImpl : public Socket {
for (int i = 0; i < iovcnt; i++) { for (int i = 0; i < iovcnt; i++) {
ssize_t err = this->read(reinterpret_cast<uint8_t *>(iov[i].iov_base), iov[i].iov_len); ssize_t err = this->read(reinterpret_cast<uint8_t *>(iov[i].iov_base), iov[i].iov_len);
if (err == -1) { if (err == -1) {
if (ret != 0) if (ret != 0) {
// if we already read some don't return an error // if we already read some don't return an error
break; break;
}
return err; return err;
} }
ret += err; ret += err;
@ -115,9 +116,10 @@ class BSDSocketImpl : public Socket {
ssize_t err = ssize_t err =
this->send(reinterpret_cast<uint8_t *>(iov[i].iov_base), iov[i].iov_len, i == iovcnt - 1 ? 0 : MSG_MORE); this->send(reinterpret_cast<uint8_t *>(iov[i].iov_base), iov[i].iov_len, i == iovcnt - 1 ? 0 : MSG_MORE);
if (err == -1) { if (err == -1) {
if (ret != 0) if (ret != 0) {
// if we already wrote some don't return an error // if we already wrote some don't return an error
break; break;
}
return err; return err;
} }
ret += err; ret += err;

View file

@ -129,10 +129,11 @@ uint8_t HOT SPIComponent::transfer_(uint8_t data) {
for (uint8_t i = 0; i < 8; i++) { for (uint8_t i = 0; i < 8; i++) {
uint8_t shift; uint8_t shift;
if (BIT_ORDER == BIT_ORDER_MSB_FIRST) if (BIT_ORDER == BIT_ORDER_MSB_FIRST) {
shift = 7 - i; shift = 7 - i;
else } else {
shift = i; shift = i;
}
if (CLOCK_PHASE == CLOCK_PHASE_LEADING) { if (CLOCK_PHASE == CLOCK_PHASE_LEADING) {
// sampling on leading edge // sampling on leading edge

View file

@ -216,19 +216,21 @@ uint8_t SPS30Component::sht_crc_(uint8_t data1, uint8_t data2) {
crc ^= data1; crc ^= data1;
for (bit = 8; bit > 0; --bit) { for (bit = 8; bit > 0; --bit) {
if (crc & 0x80) if (crc & 0x80) {
crc = (crc << 1) ^ 0x131; crc = (crc << 1) ^ 0x131;
else } else {
crc = (crc << 1); crc = (crc << 1);
} }
}
crc ^= data2; crc ^= data2;
for (bit = 8; bit > 0; --bit) { for (bit = 8; bit > 0; --bit) {
if (crc & 0x80) if (crc & 0x80) {
crc = (crc << 1) ^ 0x131; crc = (crc << 1) ^ 0x131;
else } else {
crc = (crc << 1); crc = (crc << 1);
} }
}
return crc; return crc;
} }

View file

@ -66,11 +66,12 @@ void SSD1306::setup() {
if (!this->is_ssd1305_()) { if (!this->is_ssd1305_()) {
// Enable charge pump (0x8D) // Enable charge pump (0x8D)
this->command(SSD1306_COMMAND_CHARGE_PUMP); this->command(SSD1306_COMMAND_CHARGE_PUMP);
if (this->external_vcc_) if (this->external_vcc_) {
this->command(0x10); this->command(0x10);
else } else {
this->command(0x14); this->command(0x14);
} }
}
// Set addressing mode to horizontal (0x20) // Set addressing mode to horizontal (0x20)
this->command(SSD1306_COMMAND_MEMORY_MODE); this->command(SSD1306_COMMAND_MEMORY_MODE);
@ -105,10 +106,11 @@ void SSD1306::setup() {
// Pre-charge period (0xD9) // Pre-charge period (0xD9)
this->command(SSD1306_COMMAND_SET_PRE_CHARGE); this->command(SSD1306_COMMAND_SET_PRE_CHARGE);
if (this->external_vcc_) if (this->external_vcc_) {
this->command(0x22); this->command(0x22);
else } else {
this->command(0xF1); this->command(0xF1);
}
// Set V_COM (0xDB) // Set V_COM (0xDB)
this->command(SSD1306_COMMAND_SET_VCOM_DETECT); this->command(SSD1306_COMMAND_SET_VCOM_DETECT);

View file

@ -51,24 +51,27 @@ void SSD1325::setup() {
this->command(SSD1325_SETCLOCK); // set osc division this->command(SSD1325_SETCLOCK); // set osc division
this->command(0xF1); // 145 this->command(0xF1); // 145
this->command(SSD1325_SETMULTIPLEX); // multiplex ratio 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 this->command(0x7f); // duty = height - 1
else } else {
this->command(0x3f); // duty = 1/64 this->command(0x3f); // duty = 1/64
}
this->command(SSD1325_SETOFFSET); // set display offset 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 this->command(0x00); // 0
else } else {
this->command(0x4C); // 76 this->command(0x4C); // 76
}
this->command(SSD1325_SETSTARTLINE); // set start line this->command(SSD1325_SETSTARTLINE); // set start line
this->command(0x00); // ... this->command(0x00); // ...
this->command(SSD1325_MASTERCONFIG); // Set Master Config DC/DC Converter this->command(SSD1325_MASTERCONFIG); // Set Master Config DC/DC Converter
this->command(0x02); this->command(0x02);
this->command(SSD1325_SETREMAP); // set segment remapping 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 this->command(0x53); // COM bottom-up, split odd/even, enable column and nibble remapping
else } else {
this->command(0x50); // COM bottom-up, split odd/even this->command(0x50); // COM bottom-up, split odd/even
}
this->command(SSD1325_SETCURRENT + 0x2); // Set Full Current Range this->command(SSD1325_SETCURRENT + 0x2); // Set Full Current Range
this->command(SSD1325_SETGRAYTABLE); this->command(SSD1325_SETGRAYTABLE);
// gamma ~2.2 // gamma ~2.2
@ -122,10 +125,11 @@ void SSD1325::display() {
this->command(0x3F); // set column end address this->command(0x3F); // set column end address
this->command(SSD1325_SETROWADDR); // set row address this->command(SSD1325_SETROWADDR); // set row address
this->command(0x00); // set row start 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 this->command(127); // set last row
else } else {
this->command(63); // set last row this->command(63); // set last row
}
this->write_display_data(); this->write_display_data();
} }
@ -135,12 +139,13 @@ void SSD1325::update() {
} }
void SSD1325::set_brightness(float brightness) { void SSD1325::set_brightness(float brightness) {
// validation // validation
if (brightness > 1) if (brightness > 1) {
this->brightness_ = 1.0; this->brightness_ = 1.0;
else if (brightness < 0) } else if (brightness < 0) {
this->brightness_ = 0; this->brightness_ = 0;
else } else {
this->brightness_ = brightness; this->brightness_ = brightness;
}
// now write the new brightness level to the display // now write the new brightness level to the display
this->command(SSD1325_SETCONTRAST); this->command(SSD1325_SETCONTRAST);
this->command(int(SSD1325_MAX_CONTRAST * (this->brightness_))); this->command(int(SSD1325_MAX_CONTRAST * (this->brightness_)));

View file

@ -129,13 +129,14 @@ void HOT SSD1331::draw_absolute_pixel_internal(int x, int y, Color color) {
} }
void SSD1331::fill(Color color) { void SSD1331::fill(Color color) {
const uint32_t color565 = display::ColorUtil::color_to_565(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) { if (i & 1) {
this->buffer_[i] = color565 & 0xff; this->buffer_[i] = color565 & 0xff;
} else { } else {
this->buffer_[i] = (color565 >> 8) & 0xff; this->buffer_[i] = (color565 >> 8) & 0xff;
} }
} }
}
void SSD1331::init_reset_() { void SSD1331::init_reset_() {
if (this->reset_pin_ != nullptr) { if (this->reset_pin_ != nullptr) {
this->reset_pin_->setup(); this->reset_pin_->setup();

View file

@ -105,12 +105,13 @@ void SSD1351::update() {
} }
void SSD1351::set_brightness(float brightness) { void SSD1351::set_brightness(float brightness) {
// validation // validation
if (brightness > 1) if (brightness > 1) {
this->brightness_ = 1.0; this->brightness_ = 1.0;
else if (brightness < 0) } else if (brightness < 0) {
this->brightness_ = 0; this->brightness_ = 0;
else } else {
this->brightness_ = brightness; this->brightness_ = brightness;
}
// now write the new brightness level to the display // now write the new brightness level to the display
this->command(SSD1351_CONTRASTMASTER); this->command(SSD1351_CONTRASTMASTER);
this->data(int(SSD1351_MAX_CONTRAST * (this->brightness_))); this->data(int(SSD1351_MAX_CONTRAST * (this->brightness_)));
@ -157,13 +158,14 @@ void HOT SSD1351::draw_absolute_pixel_internal(int x, int y, Color color) {
} }
void SSD1351::fill(Color color) { void SSD1351::fill(Color color) {
const uint32_t color565 = display::ColorUtil::color_to_565(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) { if (i & 1) {
this->buffer_[i] = color565 & 0xff; this->buffer_[i] = color565 & 0xff;
} else { } else {
this->buffer_[i] = (color565 >> 8) & 0xff; this->buffer_[i] = (color565 >> 8) & 0xff;
} }
} }
}
void SSD1351::init_reset_() { void SSD1351::init_reset_() {
if (this->reset_pin_ != nullptr) { if (this->reset_pin_ != nullptr) {
this->reset_pin_->setup(); this->reset_pin_->setup();

View file

@ -78,19 +78,21 @@ uint8_t sts3x_crc(uint8_t data1, uint8_t data2) {
crc ^= data1; crc ^= data1;
for (bit = 8; bit > 0; --bit) { for (bit = 8; bit > 0; --bit) {
if (crc & 0x80) if (crc & 0x80) {
crc = (crc << 1) ^ 0x131; crc = (crc << 1) ^ 0x131;
else } else {
crc = (crc << 1); crc = (crc << 1);
} }
}
crc ^= data2; crc ^= data2;
for (bit = 8; bit > 0; --bit) { for (bit = 8; bit > 0; --bit) {
if (crc & 0x80) if (crc & 0x80) {
crc = (crc << 1) ^ 0x131; crc = (crc << 1) ^ 0x131;
else } else {
crc = (crc << 1); crc = (crc << 1);
} }
}
return crc; return crc;
} }

View file

@ -110,11 +110,12 @@ template<typename... Ts> class SunCondition : public Condition<Ts...>, public Pa
bool check(Ts... x) override { bool check(Ts... x) override {
double elevation = this->elevation_.value(x...); double elevation = this->elevation_.value(x...);
double current = this->parent_->elevation(); double current = this->parent_->elevation();
if (this->above_) if (this->above_) {
return current > elevation; return current > elevation;
else } else {
return current < elevation; return current < elevation;
} }
}
protected: protected:
bool above_; bool above_;

Some files were not shown because too many files have changed in this diff Show more