From fa558967220c45a1c3ca1c159a1881d1a7172614 Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Wed, 17 Aug 2022 20:45:30 +0200 Subject: [PATCH] Const functions. --- wled00/FX.h | 30 +++++++++++++++--------------- wled00/FX_fcn.cpp | 12 ++++++------ wled00/wled.h | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/wled00/FX.h b/wled00/FX.h index b160622d..486a07e1 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -491,18 +491,18 @@ typedef struct Segment { Segment& operator= (Segment &&orig) noexcept; // move assignment #ifdef WLED_DEBUG - size_t getSize() { return sizeof(Segment) + (data?_dataLen:0) + (name?strlen(name):0) + (_t?sizeof(Transition):0) + (!Segment::_globalLeds && leds?sizeof(CRGB)*length():0); } + size_t getSize() const { return sizeof(Segment) + (data?_dataLen:0) + (name?strlen(name):0) + (_t?sizeof(Transition):0) + (!Segment::_globalLeds && leds?sizeof(CRGB)*length():0); } #endif - inline bool getOption(uint8_t n) { return ((options >> n) & 0x01); } - inline bool isSelected(void) { return selected; } - inline bool isActive(void) { return stop > start; } - inline bool is2D(void) { return !(startY == 0 && stopY == 1); } - inline uint16_t width(void) { return stop - start; } // segment width in physical pixels (length if 1D) - inline uint16_t height(void) { return stopY - startY; } // segment height (if 2D) in physical pixels - inline uint16_t length(void) { return width() * height(); } // segment length (count) in physical pixels - inline uint16_t groupLength(void) { return grouping + spacing; } - inline uint8_t getLightCapabilities(void) { return _capabilities; } + inline bool getOption(uint8_t n) const { return ((options >> n) & 0x01); } + inline bool isSelected(void) const { return selected; } + inline bool isActive(void) const { return stop > start; } + inline bool is2D(void) const { return !(startY == 0 && stopY == 1); } + inline uint16_t width(void) const { return stop - start; } // segment width in physical pixels (length if 1D) + inline uint16_t height(void) const { return stopY - startY; } // segment height (if 2D) in physical pixels + inline uint16_t length(void) const { return width() * height(); } // segment length (count) in physical pixels + inline uint16_t groupLength(void) const { return grouping + spacing; } + inline uint8_t getLightCapabilities(void) const { return _capabilities; } static uint16_t getUsedSegmentData(void) { return _usedSegmentData; } static void addUsedSegmentData(int len) { _usedSegmentData += len; } @@ -511,11 +511,11 @@ typedef struct Segment { void setCCT(uint16_t k); void setOpacity(uint8_t o); void setOption(uint8_t n, bool val); - uint8_t differs(Segment& b); + uint8_t differs(Segment& b) const; void refreshLightCapabilities(void); // runtime data functions - inline uint16_t dataSize(void) { return _dataLen; } + inline uint16_t dataSize(void) const { return _dataLen; } bool allocateData(size_t len); void deallocateData(void); void resetIfRequired(void); @@ -540,7 +540,7 @@ typedef struct Segment { CRGBPalette16 ¤tPalette(CRGBPalette16 &tgt, uint8_t paletteID); // 1D strip - uint16_t virtualLength(void); + uint16_t virtualLength(void) const; void setPixelColor(int n, uint32_t c); // set relative pixel within segment with color void setPixelColor(int n, byte r, byte g, byte b, byte w = 0) { setPixelColor(n, RGBW32(r,g,b,w)); } // automatically inline void setPixelColor(int n, CRGB c) { setPixelColor(n, RGBW32(c.r,c.g,c.b,0)); } // automatically inline @@ -564,8 +564,8 @@ typedef struct Segment { uint32_t color_wheel(uint8_t pos); // 2D matrix - uint16_t virtualWidth(void); - uint16_t virtualHeight(void); + uint16_t virtualWidth(void) const; + uint16_t virtualHeight(void) const; #ifndef WLED_DISABLE_2D uint16_t XY(uint16_t x, uint16_t y); // support function to get relative index within segment (for leds[]) void setPixelColorXY(int x, int y, uint32_t c); // set relative pixel within segment with color diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 8e112f82..13fe77dc 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -386,14 +386,14 @@ void Segment::setOption(uint8_t n, bool val) { } // 2D matrix -uint16_t Segment::virtualWidth() { +uint16_t Segment::virtualWidth() const { uint16_t groupLen = groupLength(); uint16_t vWidth = ((transpose ? height() : width()) + groupLen - 1) / groupLen; if (mirror) vWidth = (vWidth + 1) /2; // divide by 2 if mirror, leave at least a single LED return vWidth; } -uint16_t Segment::virtualHeight() { +uint16_t Segment::virtualHeight() const { uint16_t groupLen = groupLength(); uint16_t vHeight = ((transpose ? width() : height()) + groupLen - 1) / groupLen; if (mirror_y) vHeight = (vHeight + 1) /2; // divide by 2 if mirror, leave at least a single LED @@ -401,7 +401,7 @@ uint16_t Segment::virtualHeight() { } // 1D strip -uint16_t Segment::virtualLength() { +uint16_t Segment::virtualLength() const { #ifndef WLED_DISABLE_2D if (is2D()) { uint16_t vW = virtualWidth(); @@ -561,7 +561,7 @@ uint32_t Segment::getPixelColor(uint16_t i) return strip.getPixelColor(i); } -uint8_t Segment::differs(Segment& b) { +uint8_t Segment::differs(Segment& b) const { uint8_t d = 0; if (start != b.start) d |= SEG_DIFFERS_BOUNDS; if (stop != b.stop) d |= SEG_DIFFERS_BOUNDS; @@ -583,7 +583,7 @@ uint8_t Segment::differs(Segment& b) { if ((options & 0b1111111100101110) != (b.options & 0b1111111100101110)) d |= SEG_DIFFERS_OPT; if ((options & 0x01) != (b.options & 0x01)) d |= SEG_DIFFERS_SEL; - for (uint8_t i = 0; i < NUM_COLORS; i++) if (colors[i] != b.colors[i]) d |= SEG_DIFFERS_COL; + for (uint8_t i = 0; i < NUM_COLORS; i++) if (colors[i] != b.colors[i]) d |= SEG_DIFFERS_COL; return d; } @@ -1394,7 +1394,7 @@ void WS2812FX::setTransitionMode(bool t) void WS2812FX::printSize() { size_t size = 0; - for (Segment seg : _segments) size += seg.getSize(); + for (const Segment seg : _segments) size += seg.getSize(); DEBUG_PRINTF("Segments: %d -> %uB\n", _segments.size(), size); DEBUG_PRINTF("Modes: %d*%d=%uB\n", sizeof(mode_ptr), _mode.size(), (_mode.capacity()*sizeof(mode_ptr))); DEBUG_PRINTF("Data: %d*%d=%uB\n", sizeof(const char *), _modeData.size(), (_modeData.capacity()*sizeof(const char *))); diff --git a/wled00/wled.h b/wled00/wled.h index 1479e37d..379dde66 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2208171 +#define VERSION 2208172 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG