Bring state_to_string_() in as a class member.

Under certain circumstances (eg: debug logging not enabled),
`ESP_LOGD` will be defined to be null. Consequently, the
`state_to_string` function will be defined but not used, causing
unused-function warnings.

Making it a class member removes these warnings; this is also
a more appropriate place for a class-specific conversion
function.
This commit is contained in:
Colm Buckley 2024-09-19 06:38:21 +01:00
parent 8e5d7337c8
commit c910009b5b
2 changed files with 10 additions and 10 deletions

View file

@ -364,28 +364,27 @@ void Rtttl::finish_() {
ESP_LOGD(TAG, "Playback finished");
}
static const LogString *state_to_string(State state) {
const char *Rtttl::state_to_string_(State state) {
switch (state) {
case STATE_STOPPED:
return LOG_STR("STATE_STOPPED");
return "STATE_STOPPED";
case STATE_STARTING:
return LOG_STR("STATE_STARTING");
return "STATE_STARTING";
case STATE_RUNNING:
return LOG_STR("STATE_RUNNING");
return "STATE_RUNNING";
case STATE_STOPPING:
return LOG_STR("STATE_STOPPING");
return "STATE_STOPPING";
case STATE_INIT:
return LOG_STR("STATE_INIT");
return "STATE_INIT";
default:
return LOG_STR("UNKNOWN");
return "UNKNOWN";
}
};
}
void Rtttl::set_state_(State state) {
State old_state = this->state_;
this->state_ = state;
ESP_LOGD(TAG, "State changed from %s to %s", LOG_STR_ARG(state_to_string(old_state)),
LOG_STR_ARG(state_to_string(state)));
ESP_LOGD(TAG, "State changed from %s to %s", this->state_to_string_(old_state), this->state_to_string_(state));
}
} // namespace rtttl

View file

@ -67,6 +67,7 @@ class Rtttl : public Component {
}
void finish_();
void set_state_(State state);
const char *state_to_string_(State state);
std::string rtttl_{""};
size_t position_{0};