Skip to content

Commit 0130958

Browse files
committed
Dynamically calculate number of telemetry lines
1 parent 038430d commit 0130958

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/modules/Telemetry/EnvironmentTelemetry.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,18 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt
278278
static bool scrollingDown = true;
279279
static uint32_t lastScrollTime = millis();
280280

281-
// Draw up to 3 sensor data lines
282-
int linesToShow = min(3, sensorCount);
281+
// Determine how many lines we can fit on display
282+
// Calculated once only: display dimensions don't change during runtime.
283+
static int maxLines = 0;
284+
if (!maxLines) {
285+
const int16_t paddingTop = _fontHeight(FONT_SMALL); // Heading text
286+
const int16_t paddingBottom = 8; // Indicator dots
287+
maxLines = (display->getHeight() - paddingTop - paddingBottom) / _fontHeight(FONT_SMALL);
288+
assert(maxLines > 0);
289+
}
290+
291+
// Draw as many lines of data as we can fit
292+
int linesToShow = min(maxLines, sensorCount);
283293
for (int i = 0; i < linesToShow; i++) {
284294
int index = (scrollOffset + i) % sensorCount;
285295
display->drawString(x, y += _fontHeight(FONT_SMALL), sensorData[index]);

0 commit comments

Comments
 (0)