mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 06:33:51 +00:00 
			
		
		
		
	[button] Convert LOG_BUTTON macro to function to reduce flash usage (#10295)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
		| @@ -6,6 +6,19 @@ namespace button { | |||||||
|  |  | ||||||
| static const char *const TAG = "button"; | static const char *const TAG = "button"; | ||||||
|  |  | ||||||
|  | // Function implementation of LOG_BUTTON macro to reduce code size | ||||||
|  | void log_button(const char *tag, const char *prefix, const char *type, Button *obj) { | ||||||
|  |   if (obj == nullptr) { | ||||||
|  |     return; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str()); | ||||||
|  |  | ||||||
|  |   if (!obj->get_icon().empty()) { | ||||||
|  |     ESP_LOGCONFIG(tag, "%s  Icon: '%s'", prefix, obj->get_icon().c_str()); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
| void Button::press() { | void Button::press() { | ||||||
|   ESP_LOGD(TAG, "'%s' Pressed.", this->get_name().c_str()); |   ESP_LOGD(TAG, "'%s' Pressed.", this->get_name().c_str()); | ||||||
|   this->press_action(); |   this->press_action(); | ||||||
|   | |||||||
| @@ -7,13 +7,10 @@ | |||||||
| namespace esphome { | namespace esphome { | ||||||
| namespace button { | namespace button { | ||||||
|  |  | ||||||
| #define LOG_BUTTON(prefix, type, obj) \ | class Button; | ||||||
|   if ((obj) != nullptr) { \ | void log_button(const char *tag, const char *prefix, const char *type, Button *obj); | ||||||
|     ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \ |  | ||||||
|     if (!(obj)->get_icon().empty()) { \ | #define LOG_BUTTON(prefix, type, obj) log_button(TAG, prefix, LOG_STR_LITERAL(type), obj) | ||||||
|       ESP_LOGCONFIG(TAG, "%s  Icon: '%s'", prefix, (obj)->get_icon().c_str()); \ |  | ||||||
|     } \ |  | ||||||
|   } |  | ||||||
|  |  | ||||||
| #define SUB_BUTTON(name) \ | #define SUB_BUTTON(name) \ | ||||||
|  protected: \ |  protected: \ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user