From 742341c01f94b654b2616971072984e94ef743c6 Mon Sep 17 00:00:00 2001 From: fuse314 Date: Thu, 19 Jan 2023 19:48:28 +0100 Subject: [PATCH] fix off-by-one bug in fadeStripColor --- src/config_dist.h | 7 ++----- src/ledutils.h | 14 ++++++++------ src/main.cpp | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/config_dist.h b/src/config_dist.h index 3c374a5..a7160df 100644 --- a/src/config_dist.h +++ b/src/config_dist.h @@ -1,9 +1,8 @@ // User configuration -#ifndef nightlightConfig_h -#define nightlightConfig_h +#pragma once -#define NIGHTLIGHT_VERSION "1.0" +#define NIGHTLIGHT_VERSION "1.3" // wifi stuff #define WIFI_CONFIGURED 3 @@ -24,5 +23,3 @@ // serial debug enabled (comment out to disable) #define SERIAL_DEBUG - -#endif \ No newline at end of file diff --git a/src/ledutils.h b/src/ledutils.h index 11b2cd5..c615098 100644 --- a/src/ledutils.h +++ b/src/ledutils.h @@ -15,12 +15,12 @@ struct gRGB }; /// allow construction from R, G, B inline gRGB(uint8_t ir, uint8_t ig, uint8_t ib) __attribute__((always_inline)) - : r(ir), g(ig), b(ib) + : r(ir), g(ig), b(ib) { } /// allow construction from 32-bit (really 24-bit) bit 0xRRGGBB color code inline gRGB(uint32_t colorcode) __attribute__((always_inline)) - : r((colorcode >> 16) & 0xFF), g((colorcode >> 8) & 0xFF), b((colorcode >> 0) & 0xFF) + : r((colorcode >> 16) & 0xFF), g((colorcode >> 8) & 0xFF), b((colorcode >> 0) & 0xFF) { } }; @@ -44,7 +44,7 @@ uint8_t blend8(uint8_t a, uint8_t b, uint8_t amountOfB) return result; } -void setStripColor(Adafruit_NeoPixel* strip, uint32_t color) +void setStripColor(Adafruit_NeoPixel *strip, uint32_t color) { for (int i = 0; i < strip->numPixels(); i++) { @@ -53,7 +53,7 @@ void setStripColor(Adafruit_NeoPixel* strip, uint32_t color) strip->show(); } -void fadeStripColor(Adafruit_NeoPixel* strip, gRGB prev, gRGB next) +void fadeStripColor(Adafruit_NeoPixel *strip, gRGB prev, gRGB next) { gRGB curr = prev; uint8_t fadeSteps = 100; @@ -68,13 +68,15 @@ void fadeStripColor(Adafruit_NeoPixel* strip, gRGB prev, gRGB next) setStripColor(strip, cColor(curr.r, curr.g, curr.b)); delay(delayTime); } + curr = next; + setStripColor(strip, cColor(curr.r, curr.g, curr.b)); } -void setFirstPixelTemporary(Adafruit_NeoPixel* strip, uint32_t color, uint16_t time) +void setFirstPixelTemporary(Adafruit_NeoPixel *strip, uint32_t color, uint16_t time) { strip->setPixelColor(0, color); strip->show(); delay(time); strip->setPixelColor(0, strip->getPixelColor(1)); strip->show(); -} \ No newline at end of file +} diff --git a/src/main.cpp b/src/main.cpp index 56ec1a2..33aaefb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -277,4 +277,4 @@ void loop() } delay(100); -} \ No newline at end of file +}