From 03cb418d63d49cc4afd7ee7dccd1d228e289e519 Mon Sep 17 00:00:00 2001 From: shylie Date: Sun, 11 Jan 2026 08:28:22 -0500 Subject: [PATCH] Improve animation smoothness --- include/display.h | 1 + include/pixelstream.h | 3 +++ src/display.cpp | 5 +++++ src/manamenu.cpp | 24 ++++++++++++++++++------ src/pixelstream.cpp | 10 +++++++--- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/include/display.h b/include/display.h index 4329f92..38476c6 100644 --- a/include/display.h +++ b/include/display.h @@ -31,6 +31,7 @@ private: void send_command_and_begin_data_stream(uint8_t command); void send_data(uint8_t data); + void send_data(const uint8_t* data, size_t data_len); void end_data_stream(); }; diff --git a/include/pixelstream.h b/include/pixelstream.h index e8c7a85..811a43f 100644 --- a/include/pixelstream.h +++ b/include/pixelstream.h @@ -21,6 +21,9 @@ public: void write(uint8_t data); void write(uint8_t red, uint8_t green, uint8_t blue); + // use for large transfers + void write(const uint8_t* data, size_t datalen); + private: PixelStream(Display&); diff --git a/src/display.cpp b/src/display.cpp index 15bb5c8..21afc5a 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -140,4 +140,9 @@ void Display::send_command_and_begin_data_stream(uint8_t command) void Display::send_data(uint8_t data) { spi_write_blocking(spi, &data, 1); } +void Display::send_data(const uint8_t* data, size_t datalen) +{ + spi_write_blocking(spi, data, datalen); +} + void Display::end_data_stream() { gpio_put(cs, true); } diff --git a/src/manamenu.cpp b/src/manamenu.cpp index b4ec396..4483524 100644 --- a/src/manamenu.cpp +++ b/src/manamenu.cpp @@ -39,7 +39,7 @@ void ManaMenu::onTick(float dt) // erase previous for (int i = 0; i < sizeof(COLORS) / sizeof(*COLORS); i++) { - const float angle = (i - current) * STEP - offset; + const float angle = i * STEP - offset; const float x = cosf(angle) * RADIUS; const float y = sinf(angle) * RADIUS; @@ -88,7 +88,7 @@ void ManaMenu::onTick(float dt) } } - progress += dt * 1.2f; + progress += dt * 2.0f; if (progress > 1.0f) { progress = 1.0f; @@ -107,10 +107,8 @@ void ManaMenu::onTick(float dt) display->set_update_area(left, top, 31, 32); auto pixels = display->pixels(); - for (int pixel = 0; pixel < icon::LENGTH; pixel++) - { - pixels.write(icon::wubrgc(COLORS[i])[pixel]); - } + const uint8_t* data = icon::wubrgc(COLORS[i]); + pixels.write(data, icon::LENGTH); } sleep_ms(1); @@ -119,6 +117,13 @@ void ManaMenu::onTick(float dt) void ManaMenu::onLeftPressed() { + if (progress < 1.0f) + { + return; + } + + going_left = true; + if (current == 0) { current = 5; @@ -137,6 +142,13 @@ void ManaMenu::onMenuHeld() {} void ManaMenu::onRightPressed() { + if (progress < 1.0f) + { + return; + } + + going_left = false; + if (current == 5) { current = 0; diff --git a/src/pixelstream.cpp b/src/pixelstream.cpp index f2027a4..c06adff 100644 --- a/src/pixelstream.cpp +++ b/src/pixelstream.cpp @@ -14,9 +14,13 @@ void PixelStream::write(uint8_t data) { display.send_data(data); } void PixelStream::write(uint8_t red, uint8_t green, uint8_t blue) { - display.send_data(red); - display.send_data(green); - display.send_data(blue); + const uint8_t data[3] = { red, green, blue }; + display.send_data(data, 3); +} + +void PixelStream::write(const uint8_t* data, size_t datalen) +{ + display.send_data(data, datalen); } PixelStream::~PixelStream() { display.end_data_stream(); }