From c3df520380925ae2459b4f5c09d3913227ab9cae Mon Sep 17 00:00:00 2001 From: Spencer Yan Date: Tue, 22 Oct 2024 15:46:36 +0800 Subject: [PATCH] chore(mr60fda2): utility functions to static methods --- esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp | 10 +++++----- esphome/components/seeed_mr60fda2/seeed_mr60fda2.h | 3 --- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp b/esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp index e6ac820119..5970ca7a94 100644 --- a/esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp +++ b/esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp @@ -73,7 +73,7 @@ void MR60FDA2Component::loop() { * @param len The length of the byte array. * @return The calculated checksum. */ -uint8_t MR60FDA2Component::calculate_checksum_(const uint8_t *data, size_t len) { +static uint8_t calculate_checksum_(const uint8_t *data, size_t len) { uint8_t checksum = 0; for (size_t i = 0; i < len; i++) { checksum ^= data[i]; @@ -93,11 +93,11 @@ uint8_t MR60FDA2Component::calculate_checksum_(const uint8_t *data, size_t len) * @param expected_checksum The expected checksum. * @return True if the checksum is valid, false otherwise. */ -bool MR60FDA2Component::validate_checksum_(const uint8_t *data, size_t len, uint8_t expected_checksum) { +static bool validate_checksum_(const uint8_t *data, size_t len, uint8_t expected_checksum) { return calculate_checksum_(data, len) == expected_checksum; } -uint8_t MR60FDA2Component::find_nearest_index_(float value, const float *arr, int size) { +static uint8_t find_nearest_index_(float value, const float *arr, int size) { int nearest_index = 0; float min_diff = std::abs(value - arr[0]); for (int i = 1; i < size; ++i) { @@ -183,7 +183,7 @@ void MR60FDA2Component::split_frame_(uint8_t buffer) { } break; case LOCATE_HEAD_CKSUM_FRAME: - if (this->validate_checksum_(this->current_frame_buf_, this->current_frame_len_, buffer)) { + if (validate_checksum_(this->current_frame_buf_, this->current_frame_len_, buffer)) { this->current_frame_len_++; this->current_frame_buf_[this->current_frame_len_ - 1] = buffer; this->current_frame_locate_++; @@ -207,7 +207,7 @@ void MR60FDA2Component::split_frame_(uint8_t buffer) { } break; case LOCATE_DATA_CKSUM_FRAME: - if (this->validate_checksum_(this->current_data_buf_, this->current_data_frame_len_, buffer)) { + if (validate_checksum_(this->current_data_buf_, this->current_data_frame_len_, buffer)) { this->current_frame_len_++; this->current_frame_buf_[this->current_frame_len_ - 1] = buffer; this->current_frame_locate_++; diff --git a/esphome/components/seeed_mr60fda2/seeed_mr60fda2.h b/esphome/components/seeed_mr60fda2/seeed_mr60fda2.h index e5fef35267..26004d8671 100644 --- a/esphome/components/seeed_mr60fda2/seeed_mr60fda2.h +++ b/esphome/components/seeed_mr60fda2/seeed_mr60fda2.h @@ -88,14 +88,11 @@ class MR60FDA2Component : public Component, uint8_t current_sensitivity_; uint8_t select_index_; - bool validate_checksum_(const uint8_t *data, size_t len, uint8_t expected_checksum); - uint8_t calculate_checksum_(const uint8_t *data, size_t len); void split_frame_(uint8_t buffer); void process_frame_(); void send_query_(uint8_t *query, size_t string_length); void float_to_bytes_(float value, unsigned char *bytes); void int_to_bytes_(uint32_t value, unsigned char *bytes); - uint8_t find_nearest_index_(float value, const float *arr, int size); public: float get_setup_priority() const override { return esphome::setup_priority::LATE; }