Files
Flipdot-display/src/esp32/display/frames.cpp
T
mangavalkandClaude Opus 5.5 47ef65ee7d Send only the changed dots of a frame to the Nano
Frames were sent as F0 plus one s command per yellow dot (thousands of
characters). During scrolling that overran the Nano's serial buffer, and
half-received frames redrew the whole screen. showBitmap() now sends two B
commands over the changed rectangle (dots off, dots on), or one B command for
a full frame, and the pacing counts the characters sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 21:14:48 +02:00

93 lines
2.3 KiB
C++

#include "display/frames.h"
#include <stdio.h>
#include <string.h>
#include "config.h"
#include "display/text.h"
FlipdotFrames::FlipdotFrames(BROSE9323 &display, PageResources &resources) : _display(display), _resources(resources)
{
}
// Only the dots that changed are sent (unless redraw: the Nano's image is unknown)
uint32_t FlipdotFrames::dynamicPage(const LocalTime &time, uint32_t now, bool redraw)
{
uint8_t bitmap[BITMAP_BYTES];
uint32_t wait = renderPage(_dynamic, time, now, _resources, bitmap);
bool moving = wait != 0;
// The Nano has no acknowledgement: the next frame waits until it has received this one
// and flipped its dots, or the next frame overflows its serial buffer
uint32_t busy = _show(bitmap, !redraw, moving);
return moving && wait < busy ? busy : wait;
}
void FlipdotFrames::setDrive(uint16_t flip_time, const DriveSettings &drive)
{
_dot_us = (uint32_t)drive.pulses * (flip_time + drive.flip_gap);
}
// Sends the bitmap; returns about how long the Nano takes to receive and show it in ms
uint32_t FlipdotFrames::_show(const uint8_t *bitmap, bool changes_only, bool instant)
{
uint32_t dots = 0;
for (int y = 0; y < BITMAP_HEIGHT; y++)
for (int x = 0; x < BITMAP_WIDTH; x++)
dots += bitmapPixel(bitmap, x, y) != _display.shownPixel(x, y);
size_t chars = _display.showBitmap(bitmap, changes_only, instant);
if (chars == 0)
return 0;
return chars / NANO_CHARS_PER_MS + dots * _dot_us / 1000 + FRAME_MARGIN;
}
void FlipdotFrames::noWifi(int hour, int minute)
{
char time[6];
snprintf(time, sizeof(time), "%02d:%02d", hour, minute);
drawTextLines(_display, "No WiFi", time);
_display.display();
}
void FlipdotFrames::page()
{
_drawFullScreen(_page);
}
void FlipdotFrames::live()
{
_drawFullScreen(_live);
}
void FlipdotFrames::off()
{
_drawFullScreen(_off);
}
void FlipdotFrames::setDynamicPage(const DynamicPage &page)
{
_dynamic = page;
}
void FlipdotFrames::setPageBitmap(const uint8_t *bitmap)
{
memcpy(_page, bitmap, BITMAP_BYTES);
}
void FlipdotFrames::setLiveBitmap(const uint8_t *bitmap)
{
memcpy(_live, bitmap, BITMAP_BYTES);
}
void FlipdotFrames::setOffBitmap(const uint8_t *bitmap)
{
if (bitmap)
memcpy(_off, bitmap, BITMAP_BYTES);
else
memset(_off, 0, BITMAP_BYTES);
}
void FlipdotFrames::_drawFullScreen(const uint8_t *bitmap)
{
_show(bitmap, false, false);
}