Merge remote-tracking branch 'upstream/dev' into integration

This commit is contained in:
J. Nick Koston
2026-02-25 13:10:41 -07:00
11 changed files with 31 additions and 31 deletions
+4 -4
View File
@@ -52,12 +52,12 @@ void BL0942::loop() {
return;
}
if (avail < sizeof(buffer)) {
if (!this->rx_start_) {
if (!this->rx_start_.has_value()) {
this->rx_start_ = millis();
} else if (millis() > this->rx_start_ + PKT_TIMEOUT_MS) {
} else if (millis() - *this->rx_start_ > PKT_TIMEOUT_MS) {
ESP_LOGW(TAG, "Junk on wire. Throwing away partial message (%zu bytes)", avail);
this->read_array((uint8_t *) &buffer, avail);
this->rx_start_ = 0;
this->rx_start_.reset();
}
return;
}
@@ -67,7 +67,7 @@ void BL0942::loop() {
this->received_package_(&buffer);
}
}
this->rx_start_ = 0;
this->rx_start_.reset();
}
bool BL0942::validate_checksum_(DataPacket *data) {
+1 -1
View File
@@ -140,7 +140,7 @@ class BL0942 : public PollingComponent, public uart::UARTDevice {
uint8_t address_ = 0;
bool reset_ = false;
LineFrequency line_freq_ = LINE_FREQUENCY_50HZ;
uint32_t rx_start_ = 0;
optional<uint32_t> rx_start_{};
uint32_t prev_cf_cnt_ = 0;
bool validate_checksum_(DataPacket *data);
@@ -101,7 +101,7 @@ class BLEPresenceDevice : public binary_sensor::BinarySensorInitiallyOff,
}
void loop() override {
if (this->found_ && this->last_seen_ + this->timeout_ < millis())
if (this->found_ && millis() - this->last_seen_ > this->timeout_)
this->set_found_(false);
}
void dump_config() override;
+1 -1
View File
@@ -95,7 +95,7 @@ void HMC5883LComponent::update() {
float mg_per_bit;
switch (this->range_) {
case HMC5883L_RANGE_88_UT:
mg_per_bit = 0.073f;
mg_per_bit = 0.73f;
break;
case HMC5883L_RANGE_130_UT:
mg_per_bit = 0.92f;
+1 -1
View File
@@ -45,7 +45,7 @@ void LCDDisplay::setup() {
// TODO dotsize
// Commands can only be sent 40ms after boot-up, so let's wait if we're close
const uint8_t now = millis();
const uint32_t now = millis();
if (now < 40)
delay(40u - now);
+3 -3
View File
@@ -590,7 +590,7 @@ void LD2420Component::handle_ack_data_(uint8_t *buffer, int len) {
for (uint16_t index = 0; index < (CMD_REG_DATA_REPLY_SIZE * // NOLINT
((buffer[CMD_FRAME_DATA_LENGTH] - 4) / CMD_REG_DATA_REPLY_SIZE));
index += CMD_REG_DATA_REPLY_SIZE) {
memcpy(&this->cmd_reply_.data[reg_element], &buffer[data_pos + index], sizeof(CMD_REG_DATA_REPLY_SIZE));
memcpy(&this->cmd_reply_.data[reg_element], &buffer[data_pos + index], CMD_REG_DATA_REPLY_SIZE);
byteswap(this->cmd_reply_.data[reg_element]);
reg_element++;
}
@@ -729,9 +729,9 @@ void LD2420Component::set_reg_value(uint16_t reg, uint16_t value) {
cmd_frame.data_length = 0;
cmd_frame.header = CMD_FRAME_HEADER;
cmd_frame.command = CMD_WRITE_REGISTER;
memcpy(&cmd_frame.data[cmd_frame.data_length], &reg, sizeof(CMD_REG_DATA_REPLY_SIZE));
memcpy(&cmd_frame.data[cmd_frame.data_length], &reg, CMD_REG_DATA_REPLY_SIZE);
cmd_frame.data_length += 2;
memcpy(&cmd_frame.data[cmd_frame.data_length], &value, sizeof(CMD_REG_DATA_REPLY_SIZE));
memcpy(&cmd_frame.data[cmd_frame.data_length], &value, CMD_REG_DATA_REPLY_SIZE);
cmd_frame.data_length += 2;
cmd_frame.footer = CMD_FRAME_FOOTER;
ESP_LOGV(TAG, "Sending write register %4X command: %2X data = %4X", reg, cmd_frame.command, value);
+3 -4
View File
@@ -44,12 +44,11 @@ class LightTransformer {
/// The progress of this transition, on a scale of 0 to 1.
float get_progress_() {
uint32_t now = esphome::millis();
if (now < this->start_time_)
return 0.0f;
if (now >= this->start_time_ + this->length_)
uint32_t elapsed = now - this->start_time_;
if (elapsed >= this->length_)
return 1.0f;
return clamp((now - this->start_time_) / float(this->length_), 0.0f, 1.0f);
return clamp(elapsed / float(this->length_), 0.0f, 1.0f);
}
uint32_t start_time_;
+1 -1
View File
@@ -78,7 +78,7 @@ class LightFlashTransformer : public LightTransformer {
optional<LightColorValues> apply() override {
optional<LightColorValues> result = {};
if (this->transformer_ == nullptr && millis() > this->start_time_ + this->length_ - this->transition_length_) {
if (this->transformer_ == nullptr && millis() - this->start_time_ > this->length_ - this->transition_length_) {
// second transition back to start value
this->transformer_ = this->state_.get_output()->create_default_transition();
this->transformer_->setup(this->state_.current_values, this->get_start_values(), this->transition_length_);
+11 -10
View File
@@ -139,9 +139,10 @@ void Rtttl::loop() {
x++;
}
if (x > 0) {
int send = this->speaker_->play((uint8_t *) (&sample), x * 2);
if (send != x * 4) {
this->samples_sent_ -= (x - (send / 2));
size_t bytes_to_send = x * sizeof(SpeakerSample);
size_t send = this->speaker_->play((uint8_t *) (&sample), bytes_to_send);
if (send != bytes_to_send) {
this->samples_sent_ -= (x - (send / sizeof(SpeakerSample)));
}
return;
}
@@ -201,9 +202,9 @@ void Rtttl::loop() {
bool need_note_gap = false;
if (note) {
auto note_index = (scale - 4) * 12 + note;
if (note_index < 0 || note_index >= (int) sizeof(NOTES)) {
if (note_index < 0 || note_index >= (int) (sizeof(NOTES) / sizeof(NOTES[0]))) {
ESP_LOGE(TAG, "Note out of range (note: %d, scale: %d, index: %d, max: %d)", note, scale, note_index,
(int) sizeof(NOTES));
(int) (sizeof(NOTES) / sizeof(NOTES[0])));
this->finish_();
return;
}
@@ -221,7 +222,7 @@ void Rtttl::loop() {
#ifdef USE_OUTPUT
if (this->output_ != nullptr) {
if (need_note_gap) {
if (need_note_gap && this->note_duration_ > DOUBLE_NOTE_GAP_MS) {
this->output_->set_level(0.0);
delay(DOUBLE_NOTE_GAP_MS);
this->note_duration_ -= DOUBLE_NOTE_GAP_MS;
@@ -240,9 +241,9 @@ void Rtttl::loop() {
this->samples_sent_ = 0;
this->samples_gap_ = 0;
this->samples_per_wave_ = 0;
this->samples_count_ = (this->sample_rate_ * this->note_duration_) / 1600; //(ms);
this->samples_count_ = (this->sample_rate_ * this->note_duration_) / 1000;
if (need_note_gap) {
this->samples_gap_ = (this->sample_rate_ * DOUBLE_NOTE_GAP_MS) / 1600; //(ms);
this->samples_gap_ = (this->sample_rate_ * DOUBLE_NOTE_GAP_MS) / 1000;
}
if (this->output_freq_ != 0) {
// make sure there is enough samples to add a full last sinus.
@@ -279,7 +280,7 @@ void Rtttl::play(std::string rtttl) {
this->note_duration_ = 0;
int bpm = 63;
uint8_t num;
uint16_t num;
// Get name
this->position_ = this->rtttl_.find(':');
@@ -395,7 +396,7 @@ void Rtttl::finish_() {
sample[0].right = 0;
sample[1].left = 0;
sample[1].right = 0;
this->speaker_->play((uint8_t *) (&sample), 8);
this->speaker_->play((uint8_t *) (&sample), sizeof(sample));
this->speaker_->finish();
this->set_state_(State::STOPPING);
}
+3 -3
View File
@@ -46,8 +46,8 @@ class Rtttl : public Component {
}
protected:
inline uint8_t get_integer_() {
uint8_t ret = 0;
inline uint16_t get_integer_() {
uint16_t ret = 0;
while (isdigit(this->rtttl_[this->position_])) {
ret = (ret * 10) + (this->rtttl_[this->position_++] - '0');
}
@@ -87,7 +87,7 @@ class Rtttl : public Component {
#ifdef USE_OUTPUT
/// The output to write the sound to.
output::FloatOutput *output_;
output::FloatOutput *output_{nullptr};
#endif // USE_OUTPUT
#ifdef USE_SPEAKER
@@ -149,7 +149,7 @@ stm32_err_t stm32_get_ack_timeout(const stm32_unique_ptr &stm, uint32_t timeout)
do {
yield();
if (!stream->available()) {
if (millis() < start_time + timeout)
if (millis() - start_time < timeout)
continue;
ESP_LOGD(TAG, "Failed to read ACK timeout=%i", timeout);
return STM32_ERR_UNKNOWN;
@@ -212,7 +212,7 @@ stm32_err_t stm32_resync(const stm32_unique_ptr &stm) {
static_assert(sizeof(buf) == BUFFER_SIZE, "Buf expected to be 2 bytes");
uint8_t ack;
while (t1 < t0 + STM32_RESYNC_TIMEOUT) {
while (t1 - t0 < STM32_RESYNC_TIMEOUT) {
stream->write_array(buf, BUFFER_SIZE);
stream->flush();
if (!stream->read_array(&ack, 1)) {