Skip to content

Commit

Permalink
Fix Load Render Map - Avoid multiple File Reading
Browse files Browse the repository at this point in the history
  • Loading branch information
jgauchia committed Jul 1, 2024
1 parent afb164d commit 1eacb35
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
48 changes: 21 additions & 27 deletions lib/gui/src/mainScr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
bool isMainScreen = false; // Flag to indicate main screen is selected
bool isScrolled = true; // Flag to indicate when tileview was scrolled
bool isReady = false; // Flag to indicate when tileview scroll was finished
bool redrawMap = false; // Flag to indicate when needs to redraw Map
bool redrawMap = true; // Flag to indicate when needs to redraw Map
uint8_t activeTile = 0; // Current active tile

lv_obj_t *compassHeading;
Expand Down Expand Up @@ -146,7 +146,6 @@ void getActTile(lv_event_t *event)
// if (activeTile == MAP || activeTile == NAV)
if (activeTile == MAP)
{
createMapScrSprites();
isPosMoved = true;
redrawMap = true;
}
Expand All @@ -169,6 +168,8 @@ void getActTile(lv_event_t *event)
else
{
isReady = true;
redrawMap = false;
isPosMoved = false;
}

lv_obj_t *actTile = lv_tileview_get_tile_act(tilesScreen);
Expand All @@ -185,8 +186,9 @@ void scrollTile(lv_event_t *event)
{
isScrolled = false;
isReady = false;
redrawMap = false;

deleteMapScrSprites();
//deleteMapScrSprites();
deleteSatInfoSprites();
}

Expand Down Expand Up @@ -254,35 +256,27 @@ void getZoomValue(lv_event_t *event)
*/
void updateMap(lv_event_t *event)
{
// if (!waitScreenRefresh)
// {
// if (tft.getStartCount() == 0)
// tft.startWrite();

if (isVectorMap)
if (isVectorMap)
{
getPosition(getLat(), getLon());
if (isPosMoved)
{
getPosition(getLat(), getLon());
if (isPosMoved)
{

tileSize = VECTOR_TILE_SIZE;
viewPort.setCenter(point);
getMapBlocks(viewPort.bbox, memCache);
generateVectorMap(viewPort, memCache, mapTempSprite);
isPosMoved = false;
}

tileSize = VECTOR_TILE_SIZE;
viewPort.setCenter(point);
getMapBlocks(viewPort.bbox, memCache);
generateVectorMap(viewPort, memCache, mapTempSprite);
isPosMoved = false;
}
else
{
tileSize = RENDER_TILE_SIZE;
}
else
{
tileSize = RENDER_TILE_SIZE;
generateRenderMap();
}
}

if (redrawMap)
displayMap(tileSize);

// if (tft.getStartCount() > 0)
// tft.endWrite();
/* } */
}

/**
Expand Down
8 changes: 6 additions & 2 deletions lib/maps/src/renderMaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include "renderMaps.hpp"
#include "mapsDrawFunc.h"

MapTile oldMapTile = {"", 0, 0, 0}; // Old Map tile coordinates and zoom
MapTile currentMapTile = {"", 0, 0, 0}; // Curreng Map tile coordinates and zoom
Expand Down Expand Up @@ -86,8 +87,11 @@ void generateRenderMap()
if (strcmp(currentMapTile.file, oldMapTile.file) != 0 ||
currentMapTile.zoom != oldMapTile.zoom ||
currentMapTile.tilex != oldMapTile.tilex ||
currentMapTile.tiley != oldMapTile.tiley || redrawMap)
currentMapTile.tiley != oldMapTile.tiley)
{
deleteMapScrSprites();
createMapScrSprites();

mapTempSprite.fillScreen(TFT_BLACK);
isMapFound = mapTempSprite.drawPngFile(SD, currentMapTile.file, tileSize, tileSize);

Expand Down Expand Up @@ -124,7 +128,7 @@ void generateRenderMap()
oldMapTile.zoom = currentMapTile.zoom;
oldMapTile.tilex = currentMapTile.tilex;
oldMapTile.tiley = currentMapTile.tiley;
redrawMap = false;
redrawMap = true;
}

log_v("TILE: %s", oldMapTile.file);
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ extern xSemaphoreHandle guiMutex;
*/
void setup()
{
guiMutex = xSemaphoreCreateMutex();

#ifdef ARDUINO_USB_CDC_ON_BOOT
Serial.begin(115200);
#endif
Expand Down Expand Up @@ -78,8 +80,6 @@ void setup()

initADC();

guiMutex = xSemaphoreCreateMutex();

// Reserve PSRAM for buffer map
mapTempSprite.deleteSprite();
mapTempSprite.createSprite(TILE_WIDTH, TILE_HEIGHT);
Expand Down

0 comments on commit 1eacb35

Please sign in to comment.