Improve animation smoothness
This commit is contained in:
parent
b28f81404e
commit
03cb418d63
@ -31,6 +31,7 @@ private:
|
|||||||
|
|
||||||
void send_command_and_begin_data_stream(uint8_t command);
|
void send_command_and_begin_data_stream(uint8_t command);
|
||||||
void send_data(uint8_t data);
|
void send_data(uint8_t data);
|
||||||
|
void send_data(const uint8_t* data, size_t data_len);
|
||||||
void end_data_stream();
|
void end_data_stream();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -21,6 +21,9 @@ public:
|
|||||||
void write(uint8_t data);
|
void write(uint8_t data);
|
||||||
void write(uint8_t red, uint8_t green, uint8_t blue);
|
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:
|
private:
|
||||||
PixelStream(Display&);
|
PixelStream(Display&);
|
||||||
|
|
||||||
|
|||||||
@ -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(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); }
|
void Display::end_data_stream() { gpio_put(cs, true); }
|
||||||
|
|||||||
@ -39,7 +39,7 @@ void ManaMenu::onTick(float dt)
|
|||||||
// erase previous
|
// erase previous
|
||||||
for (int i = 0; i < sizeof(COLORS) / sizeof(*COLORS); i++)
|
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 x = cosf(angle) * RADIUS;
|
||||||
const float y = sinf(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)
|
if (progress > 1.0f)
|
||||||
{
|
{
|
||||||
progress = 1.0f;
|
progress = 1.0f;
|
||||||
@ -107,10 +107,8 @@ void ManaMenu::onTick(float dt)
|
|||||||
|
|
||||||
display->set_update_area(left, top, 31, 32);
|
display->set_update_area(left, top, 31, 32);
|
||||||
auto pixels = display->pixels();
|
auto pixels = display->pixels();
|
||||||
for (int pixel = 0; pixel < icon::LENGTH; pixel++)
|
const uint8_t* data = icon::wubrgc(COLORS[i]);
|
||||||
{
|
pixels.write(data, icon::LENGTH);
|
||||||
pixels.write(icon::wubrgc(COLORS[i])[pixel]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep_ms(1);
|
sleep_ms(1);
|
||||||
@ -119,6 +117,13 @@ void ManaMenu::onTick(float dt)
|
|||||||
|
|
||||||
void ManaMenu::onLeftPressed()
|
void ManaMenu::onLeftPressed()
|
||||||
{
|
{
|
||||||
|
if (progress < 1.0f)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
going_left = true;
|
||||||
|
|
||||||
if (current == 0)
|
if (current == 0)
|
||||||
{
|
{
|
||||||
current = 5;
|
current = 5;
|
||||||
@ -137,6 +142,13 @@ void ManaMenu::onMenuHeld() {}
|
|||||||
|
|
||||||
void ManaMenu::onRightPressed()
|
void ManaMenu::onRightPressed()
|
||||||
{
|
{
|
||||||
|
if (progress < 1.0f)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
going_left = false;
|
||||||
|
|
||||||
if (current == 5)
|
if (current == 5)
|
||||||
{
|
{
|
||||||
current = 0;
|
current = 0;
|
||||||
|
|||||||
@ -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)
|
void PixelStream::write(uint8_t red, uint8_t green, uint8_t blue)
|
||||||
{
|
{
|
||||||
display.send_data(red);
|
const uint8_t data[3] = { red, green, blue };
|
||||||
display.send_data(green);
|
display.send_data(data, 3);
|
||||||
display.send_data(blue);
|
}
|
||||||
|
|
||||||
|
void PixelStream::write(const uint8_t* data, size_t datalen)
|
||||||
|
{
|
||||||
|
display.send_data(data, datalen);
|
||||||
}
|
}
|
||||||
|
|
||||||
PixelStream::~PixelStream() { display.end_data_stream(); }
|
PixelStream::~PixelStream() { display.end_data_stream(); }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user