From 97babdcc945baac0cc62fc1850f45381fcd09757 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 25 Jan 2026 22:05:19 -1000 Subject: [PATCH] [uln2003] Refactor step mode logging to use LogString --- esphome/components/uln2003/uln2003.cpp | 30 ++++++++++++-------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/esphome/components/uln2003/uln2003.cpp b/esphome/components/uln2003/uln2003.cpp index 11e1c3d4c0..d6d126e8e3 100644 --- a/esphome/components/uln2003/uln2003.cpp +++ b/esphome/components/uln2003/uln2003.cpp @@ -6,6 +6,19 @@ namespace uln2003 { static const char *const TAG = "uln2003.stepper"; +static const LogString *step_mode_to_log_string(ULN2003StepMode mode) { + switch (mode) { + case ULN2003_STEP_MODE_FULL_STEP: + return LOG_STR("FULL STEP"); + case ULN2003_STEP_MODE_HALF_STEP: + return LOG_STR("HALF STEP"); + case ULN2003_STEP_MODE_WAVE_DRIVE: + return LOG_STR("WAVE DRIVE"); + default: + return LOG_STR("UNKNOWN"); + } +} + void ULN2003::setup() { this->pin_a_->setup(); this->pin_b_->setup(); @@ -42,22 +55,7 @@ void ULN2003::dump_config() { LOG_PIN(" Pin B: ", this->pin_b_); LOG_PIN(" Pin C: ", this->pin_c_); LOG_PIN(" Pin D: ", this->pin_d_); - const char *step_mode_s; - switch (this->step_mode_) { - case ULN2003_STEP_MODE_FULL_STEP: - step_mode_s = "FULL STEP"; - break; - case ULN2003_STEP_MODE_HALF_STEP: - step_mode_s = "HALF STEP"; - break; - case ULN2003_STEP_MODE_WAVE_DRIVE: - step_mode_s = "WAVE DRIVE"; - break; - default: - step_mode_s = "UNKNOWN"; - break; - } - ESP_LOGCONFIG(TAG, " Step Mode: %s", step_mode_s); + ESP_LOGCONFIG(TAG, " Step Mode: %s", LOG_STR_ARG(step_mode_to_log_string(this->step_mode_))); } void ULN2003::write_step_(int32_t step) { int32_t n = this->step_mode_ == ULN2003_STEP_MODE_HALF_STEP ? 8 : 4;