What do you want to achieve?
I want to manually update parts of an lv_canvas
The canvas is an overview waveform and I want to add a 2px wide white line indicating the current play position
What have you tried so far?
lv_obj_invalidate works so far, but eats up processing time I need to spare, hence why I want to use lv_obj_invalidate_area
Code to reproduce
The function below draws the white line in the new position and restores the waveform lines in the old position
static uint16_t oldX = 0xFFFF; // Initialize to invalid position
// New function to update position efficiently
FASTRUN void updatePlaybackPosition(uint16_t newX)
{
if(oldX == newX) return; // No change, skip update
// Restore the old position by redrawing the waveform data
if (oldX < chartWidth && oldX + 1 < chartWidth) {
// Clear the old indicator position (both pixels)
for (uint8_t px = 0; px < 2; px++) {
uint16_t xPos = oldX + px;
drawFastVLine16BitOverview(xPos, 0, overviewChartHeight, 0x0000,
overviewCanvasBuffer, chartWidth);
// Redraw the waveform at old position
for (uint8_t i = 0; i < 3; i++) {
uint16_t height = overViewWaveSampleData[i][xPos];
uint16_t startY = overviewChartHeight - height;
drawFastVLine16BitOverview(xPos, startY, height, waveformColors[i],
overviewCanvasBuffer, chartWidth);
}
}
// Invalidate old area
lv_area_t area;
area.x1 = oldX;
area.y1 = 0;
area.x2 = oldX + 1;
area.y2 = overviewChartHeight - 1;
lv_obj_invalidate_area(static_waveform_canvas, &area);
}
// Draw the new position indicator (2px wide)
if (newX < chartWidth && newX + 1 < chartWidth) {
uint16_t indicatorColor = 0xFFFF; // White, or use your preferred indicator color
for (uint8_t px = 0; px < 2; px++) {
uint16_t xPos = newX + px;
// Draw full-height indicator line
drawFastVLine16BitOverview(xPos, 0, overviewChartHeight, indicatorColor,
overviewCanvasBuffer, chartWidth);
}
// Invalidate new area
lv_area_t area;
area.x1 = newX;
area.y1 = 0;
area.x2 = newX + 1;
area.y2 = overviewChartHeight - 1;
lv_obj_invalidate_area(static_waveform_canvas, &area);
}
// Update stored position
oldX = newX;
}
Screenshot and/or video
The bottom waveform:
Environment
- MCU/MPU/Board: Custom Micromod Teensy with SDRAM
- LVGL version: v8.4
