animations: updatestatus: avoid writing past end of LED array

This commit is contained in:
Torrie Fischer 2023-12-11 08:08:27 +01:00
parent d36de899fd
commit 81bebad459
2 changed files with 6 additions and 5 deletions

View File

@ -8,7 +8,7 @@ UpdateStatus::handleEvent(const InputEvent& evt)
if (evt.intent == InputEvent::FirmwareUpdate) { if (evt.intent == InputEvent::FirmwareUpdate) {
static int updateCount = 0; static int updateCount = 0;
updateCount++; updateCount++;
//Log.info("Update count %d", updateCount); Log.info("Update count %d", updateCount);
m_updateReady = true; m_updateReady = true;
} }
} }
@ -22,11 +22,12 @@ UpdateStatus::loop()
void void
UpdateStatus::render(Display* dpy) const UpdateStatus::render(Display* dpy) const
{ {
int pos = m_pos % dpy->pixelCount();
if (m_updateReady) { if (m_updateReady) {
for(int i = 0; i < 12; i+=3) { for(int i = 0; i < 12; i+=3) {
dpy->pixelAt(m_pos + i) = CRGB(255, 0, 0); dpy->pixelAt(pos + i) = CRGB(255, 0, 0);
dpy->pixelAt(m_pos + i + 1) = CRGB(0, 255, 0); dpy->pixelAt(pos + i + 1) = CRGB(0, 255, 0);
dpy->pixelAt(m_pos + i + 2) = CRGB(0, 0, 255); dpy->pixelAt(pos + i + 2) = CRGB(0, 0, 255);
} }
} }
} }

View File

@ -10,5 +10,5 @@ public:
private: private:
bool m_updateReady = false; bool m_updateReady = false;
uint8_t m_pos = 0; int m_pos = 0;
}; };