From 81bebad4595b8a303ed85bec1a90439e5d308d0e Mon Sep 17 00:00:00 2001 From: Torrie Fischer Date: Mon, 11 Dec 2023 08:08:27 +0100 Subject: [PATCH] animations: updatestatus: avoid writing past end of LED array --- src/animations/UpdateStatus.cpp | 9 +++++---- src/animations/UpdateStatus.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/animations/UpdateStatus.cpp b/src/animations/UpdateStatus.cpp index 389b777..6da47db 100644 --- a/src/animations/UpdateStatus.cpp +++ b/src/animations/UpdateStatus.cpp @@ -8,7 +8,7 @@ UpdateStatus::handleEvent(const InputEvent& evt) if (evt.intent == InputEvent::FirmwareUpdate) { static int updateCount = 0; updateCount++; - //Log.info("Update count %d", updateCount); + Log.info("Update count %d", updateCount); m_updateReady = true; } } @@ -22,11 +22,12 @@ UpdateStatus::loop() void UpdateStatus::render(Display* dpy) const { + int pos = m_pos % dpy->pixelCount(); if (m_updateReady) { for(int i = 0; i < 12; i+=3) { - dpy->pixelAt(m_pos + i) = CRGB(255, 0, 0); - dpy->pixelAt(m_pos + i + 1) = CRGB(0, 255, 0); - dpy->pixelAt(m_pos + i + 2) = CRGB(0, 0, 255); + dpy->pixelAt(pos + i) = CRGB(255, 0, 0); + dpy->pixelAt(pos + i + 1) = CRGB(0, 255, 0); + dpy->pixelAt(pos + i + 2) = CRGB(0, 0, 255); } } } diff --git a/src/animations/UpdateStatus.h b/src/animations/UpdateStatus.h index d52e0e2..4397135 100644 --- a/src/animations/UpdateStatus.h +++ b/src/animations/UpdateStatus.h @@ -10,5 +10,5 @@ public: private: bool m_updateReady = false; - uint8_t m_pos = 0; + int m_pos = 0; };