mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Merge branch 'color_memory' into integration
This commit is contained in:
		| @@ -2,10 +2,8 @@ | ||||
|  | ||||
| namespace esphome { | ||||
|  | ||||
| const Color Color::BLACK(0, 0, 0, 0); | ||||
| const Color Color::WHITE(255, 255, 255, 255); | ||||
|  | ||||
| const Color COLOR_BLACK(0, 0, 0, 0); | ||||
| const Color COLOR_WHITE(255, 255, 255, 255); | ||||
| // C++20 constinit ensures compile-time initialization (stored in ROM) | ||||
| constinit const Color Color::BLACK(0, 0, 0, 0); | ||||
| constinit const Color Color::WHITE(255, 255, 255, 255); | ||||
|  | ||||
| }  // namespace esphome | ||||
|   | ||||
| @@ -5,7 +5,9 @@ | ||||
|  | ||||
| namespace esphome { | ||||
|  | ||||
| inline static uint8_t esp_scale8(uint8_t i, uint8_t scale) { return (uint16_t(i) * (1 + uint16_t(scale))) / 256; } | ||||
| inline static constexpr uint8_t esp_scale8(uint8_t i, uint8_t scale) { | ||||
|   return (uint16_t(i) * (1 + uint16_t(scale))) / 256; | ||||
| } | ||||
|  | ||||
| struct Color { | ||||
|   union { | ||||
| @@ -31,17 +33,20 @@ struct Color { | ||||
|     uint32_t raw_32; | ||||
|   }; | ||||
|  | ||||
|   inline Color() ESPHOME_ALWAYS_INLINE : r(0), g(0), b(0), w(0) {}  // NOLINT | ||||
|   inline Color(uint8_t red, uint8_t green, uint8_t blue) ESPHOME_ALWAYS_INLINE : r(red), g(green), b(blue), w(0) {} | ||||
|   inline constexpr Color() ESPHOME_ALWAYS_INLINE : raw_32(0) {}  // NOLINT | ||||
|   inline constexpr Color(uint8_t red, uint8_t green, uint8_t blue) ESPHOME_ALWAYS_INLINE : r(red), | ||||
|                                                                                            g(green), | ||||
|                                                                                            b(blue), | ||||
|                                                                                            w(0) {} | ||||
|  | ||||
|   inline Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) ESPHOME_ALWAYS_INLINE : r(red), | ||||
|                                                                                                 g(green), | ||||
|                                                                                                 b(blue), | ||||
|                                                                                                 w(white) {} | ||||
|   inline explicit Color(uint32_t colorcode) ESPHOME_ALWAYS_INLINE : r((colorcode >> 16) & 0xFF), | ||||
|                                                                     g((colorcode >> 8) & 0xFF), | ||||
|                                                                     b((colorcode >> 0) & 0xFF), | ||||
|                                                                     w((colorcode >> 24) & 0xFF) {} | ||||
|   inline constexpr Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) ESPHOME_ALWAYS_INLINE : r(red), | ||||
|                                                                                                           g(green), | ||||
|                                                                                                           b(blue), | ||||
|                                                                                                           w(white) {} | ||||
|   inline explicit constexpr Color(uint32_t colorcode) ESPHOME_ALWAYS_INLINE : r((colorcode >> 16) & 0xFF), | ||||
|                                                                               g((colorcode >> 8) & 0xFF), | ||||
|                                                                               b((colorcode >> 0) & 0xFF), | ||||
|                                                                               w((colorcode >> 24) & 0xFF) {} | ||||
|  | ||||
|   inline bool is_on() ESPHOME_ALWAYS_INLINE { return this->raw_32 != 0; } | ||||
|  | ||||
| @@ -169,9 +174,4 @@ struct Color { | ||||
|   static const Color WHITE; | ||||
| }; | ||||
|  | ||||
| ESPDEPRECATED("Use Color::BLACK instead of COLOR_BLACK", "v1.21") | ||||
| extern const Color COLOR_BLACK; | ||||
| ESPDEPRECATED("Use Color::WHITE instead of COLOR_WHITE", "v1.21") | ||||
| extern const Color COLOR_WHITE; | ||||
|  | ||||
| }  // namespace esphome | ||||
|   | ||||
| @@ -226,11 +226,11 @@ int32_t ESPTime::timezone_offset() { | ||||
|   return offset; | ||||
| } | ||||
|  | ||||
| bool ESPTime::operator<(ESPTime other) { return this->timestamp < other.timestamp; } | ||||
| bool ESPTime::operator<=(ESPTime other) { return this->timestamp <= other.timestamp; } | ||||
| bool ESPTime::operator==(ESPTime other) { return this->timestamp == other.timestamp; } | ||||
| bool ESPTime::operator>=(ESPTime other) { return this->timestamp >= other.timestamp; } | ||||
| bool ESPTime::operator>(ESPTime other) { return this->timestamp > other.timestamp; } | ||||
| bool ESPTime::operator<(const ESPTime &other) const { return this->timestamp < other.timestamp; } | ||||
| bool ESPTime::operator<=(const ESPTime &other) const { return this->timestamp <= other.timestamp; } | ||||
| bool ESPTime::operator==(const ESPTime &other) const { return this->timestamp == other.timestamp; } | ||||
| bool ESPTime::operator>=(const ESPTime &other) const { return this->timestamp >= other.timestamp; } | ||||
| bool ESPTime::operator>(const ESPTime &other) const { return this->timestamp > other.timestamp; } | ||||
|  | ||||
| template<typename T> bool increment_time_value(T ¤t, uint16_t begin, uint16_t end) { | ||||
|   current++; | ||||
|   | ||||
| @@ -109,10 +109,10 @@ struct ESPTime { | ||||
|   void increment_second(); | ||||
|   /// Increment this clock instance by one day. | ||||
|   void increment_day(); | ||||
|   bool operator<(ESPTime other); | ||||
|   bool operator<=(ESPTime other); | ||||
|   bool operator==(ESPTime other); | ||||
|   bool operator>=(ESPTime other); | ||||
|   bool operator>(ESPTime other); | ||||
|   bool operator<(const ESPTime &other) const; | ||||
|   bool operator<=(const ESPTime &other) const; | ||||
|   bool operator==(const ESPTime &other) const; | ||||
|   bool operator>=(const ESPTime &other) const; | ||||
|   bool operator>(const ESPTime &other) const; | ||||
| }; | ||||
| }  // namespace esphome | ||||
|   | ||||
		Reference in New Issue
	
	Block a user