From ac689a9a2e62d6e5453ec4ab85ee6c5d15b48eef Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Fri, 6 Sep 2024 12:19:04 +0200 Subject: [PATCH] Remove array, un-inline calculateCCT --- wled00/bus_manager.cpp | 21 +++++++++++++++++++++ wled00/bus_manager.h | 29 ++++------------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/wled00/bus_manager.cpp b/wled00/bus_manager.cpp index e214604fc..c6c54885c 100644 --- a/wled00/bus_manager.cpp +++ b/wled00/bus_manager.cpp @@ -78,6 +78,27 @@ uint8_t IRAM_ATTR ColorOrderMap::getPixelColorOrder(uint16_t pix, uint8_t defaul } +void Bus::calculateCCT(uint32_t c, uint8_t &ww, uint8_t &cw) { + unsigned cct = 0; //0 - full warm white, 255 - full cold white + unsigned w = W(c); + + if (_cct > -1) { // using RGB? + if (_cct >= 1900) cct = (_cct - 1900) >> 5; // convert K in relative format + else if (_cct < 256) cct = _cct; // already relative + } else { + cct = (approximateKelvinFromRGB(c) - 1900) >> 5; // convert K (from RGB value) to relative format + } + + //0 - linear (CCT 127 = 50% warm, 50% cold), 127 - additive CCT blending (CCT 127 = 100% warm, 100% cold) + if (cct < _cctBlend) ww = 255; + else ww = ((255-cct) * 255) / (255 - _cctBlend); + if ((255-cct) < _cctBlend) cw = 255; + else cw = (cct * 255) / (255 - _cctBlend); + + ww = (w * ww) / 255; //brightness scaling + cw = (w * cw) / 255; +} + uint32_t Bus::autoWhiteCalc(uint32_t c) const { unsigned aWM = _autoWhiteMode; if (_gAWM < AW_GLOBAL_DISABLED) aWM = _gAWM; diff --git a/wled00/bus_manager.h b/wled00/bus_manager.h index f6bbf5f97..3411f4e62 100644 --- a/wled00/bus_manager.h +++ b/wled00/bus_manager.h @@ -6,7 +6,6 @@ */ #include "const.h" -#include #include //colors.cpp @@ -116,7 +115,7 @@ class Bus { inline bool isOffRefreshRequired(void) const { return _needsRefresh; } inline bool containsPixel(uint16_t pix) const { return pix >= _start && pix < _start + _len; } - static std::vector getLEDTypes(void) { return {{TYPE_NONE, "", PSTR("None")}}; } + static inline std::vector getLEDTypes(void) { return {{TYPE_NONE, "", PSTR("None")}}; } // not used. just for reference for derived classes static constexpr uint8_t getNumberOfPins(uint8_t type) { return isVirtual(type) ? 4 : isPWM(type) ? numPWMPins(type) : is2Pin(type) + 1; } // credit @PaoloTK static constexpr uint8_t getNumberOfChannels(uint8_t type) { return hasWhite(type) + 3*hasRGB(type) + hasCCT(type); } static constexpr bool hasRGB(uint8_t type) { @@ -149,34 +148,14 @@ class Bus { static inline uint8_t getGlobalAWMode(void) { return _gAWM; } static inline void setCCT(int16_t cct) { _cct = cct; } static inline uint8_t getCCTBlend(void) { return _cctBlend; } - static void setCCTBlend(uint8_t b) { - if (b > 100) b = 100; - _cctBlend = (b * 127) / 100; + static inline void setCCTBlend(uint8_t b) { + _cctBlend = (std::min((int)b,100) * 127) / 100; //compile-time limiter for hardware that can't power both white channels at max #ifdef WLED_MAX_CCT_BLEND if (_cctBlend > WLED_MAX_CCT_BLEND) _cctBlend = WLED_MAX_CCT_BLEND; #endif } - static void calculateCCT(uint32_t c, uint8_t &ww, uint8_t &cw) { - uint8_t cct = 0; //0 - full warm white, 255 - full cold white - uint8_t w = byte(c >> 24); - - if (_cct > -1) { - if (_cct >= 1900) cct = (_cct - 1900) >> 5; - else if (_cct < 256) cct = _cct; - } else { - cct = (approximateKelvinFromRGB(c) - 1900) >> 5; - } - - //0 - linear (CCT 127 = 50% warm, 50% cold), 127 - additive CCT blending (CCT 127 = 100% warm, 100% cold) - if (cct < _cctBlend) ww = 255; - else ww = ((255-cct) * 255) / (255 - _cctBlend); - if ((255-cct) < _cctBlend) cw = 255; - else cw = (cct * 255) / (255 - _cctBlend); - - ww = (w * ww) / 255; //brightness scaling - cw = (w * cw) / 255; - } + static void calculateCCT(uint32_t c, uint8_t &ww, uint8_t &cw); protected: uint8_t _type;