morning,
I have a working program that displays a map on an LCD screen at a zoom level set in a globalconfig.h file, ie (#define DEFAULT_MAP_ZOOM 2.0) . The WorkingWP.ino file, has a toggle button loop, to cycle between two values 0.5 and 1.0. This passes the value to a setter function in a class to change the private variable _zoomScale, which should be used in a render function to change the zoomlevel on an LCD when I press the button.
So far the button code works ok, toggling between the two values which are passed to the setter function which performs some maths and produces a new _zoomScale.
I can serial print out the new _zoomScale values from within the setter function so it appears a private variable named _zoomScale is changed by this function. However the actual function in the class that render's the map and uses the _zoomScale, always defaults to the original value defined (DEFAULT_MAP_ZOOM 2.0) in the initialisation function, and not changed. so I am questioning whether the private variable _zoomScale is changed outside of the setter function.
Whatever I have done the render function does not see any change and uses the default _zoomScale set in the initialisation function. After many hours I am not getting any closer to solving it.
any suggestiions would be appreciated
regards
TileBlockRenderer.h
class TileBlockRenderer {
private:
bool _hasPositionProvider, _hasHeader, _hasTrackIn;
int _heading;
float* _rotMtxBuf;
uint64_t* _renderTileIds;
int16_t* _renderTileData; // changed from int16_t
uint64_t* _renderTileSizes;
uint64_t _perTileBufferSize;
uint64_t _centerTileId, _prevCenterTileId;
long long _prevCenterChangeTime, _prevTileUpdateTime;
int* _offsetDirectionMap;
float _zoomLevel, _zoomScale;
SimpleTile::Header* _header;
SharedSPISDCard* _sd;
SharedSPIDisplay* _display;
GPXTrack* _track;
GeoPositionProvider* _positionProvider;
bool isOnDisplay(int disp_LL_x, int disp_LL_y, int disp_UR_x, int disp_UR_y, int16_t x0, int16_t y0);
void updateTileBuffer(LocalGeoPosition& center);
void render(LocalGeoPosition& center);
void renderGPX(LocalGeoPosition& center);
public:
TileBlockRenderer(); // constructor
void initialize(SimpleTile::Header* mapHeader, SharedSPISDCard* sd, SharedSPIDisplay* display);
void setPositionProvider(GeoPositionProvider* newPositionProvider);
void setGPXTrackIn(GPXTrack* track);
void setZoom(float newZoomLevel);
float getZoom();
bool step(bool holdOn=false);
};
TileBlockRenderer.cpp
tyTileBlockRenderer::TileBlockRenderer()
: _hasPositionProvider(false), _hasHeader(false), _hasTrackIn(false) {
_renderTileIds = new uint64_t[N_RENDER_TILES]{ 0 }; // Store tile IDs currently in view
_renderTileSizes = new uint64_t[N_RENDER_TILES]{ 0 }; // Array to store tile size for each tile
_prevCenterTileId = 0; // Initialize previous center tile ID
_prevTileUpdateTime = -TILE_UPDATE_DEBOUNCE_MS; // Initialize previous tile update time.
_heading = 0; // Initialise heading to zero
_rotMtxBuf = new float[4]; // map rotation matrix
_zoomLevel = DETAULT_ZOOM_LEVEL ; // set defaul _zoomLevel from (globalconfig.h)
}
void TileBlockRenderer::initialize(SimpleTile::Header* mapHeader, SharedSPISDCard* sd, SharedSPIDisplay* display) {
_header = mapHeader;
_sd = sd;
_display = display;
_zoomScale = ((float)_zoomLevel) * ((float)120 / (float)(_header->tile_size));
_perTileBufferSize = _header->max_nodes * 2;
_renderTileData = new int16_t[_perTileBufferSize * N_RENDER_TILES]{ 0 }; //changed int32_t
_hasHeader = true;
}
// THIS (setZoom) WORKS,,, pressing the button toggles between two set values 0.5 and 1.0 from main loop()
// HOWEVER the retun value
void TileBlockRenderer::setZoom(float newZoomLevel){ // Setter function to get value from togglebutton code in loop()
_zoomScale = ((float)newZoomLevel) * ((float)120 / (float)(10000));// create new zoomScale from newzoomLevel passed to this function/method from main loop()
Serial.print("newzoomlevel "); // confirm the toggle button code in loop() works... IT DOES
Serial.println(newZoomLevel,2); // confirm pressing button toggles zoomLevels ....IT WORKS
Serial.print("changed_zoomScale "); // confirm the code changes the _zoomScale ....IT DOES
Serial.println(_zoomScale, 3); // prints out the variable _zoomScale...IT WORKS and DOES
}
float TileBlockRenderer::getZoom(){ // Getter function to return value -zoomScale from Setter funtion above
return _zoomScale; // returns the new Scale into private variable _zoomScale
}
void TileBlockRenderer::render(LocalGeoPosition& center) {
// Now we have the tile data in the buffer and the current position
// Serial.print("renderZoom ");
// Serial.println(_zoomScale, 3);
int x0, y0, x1, y1;
int curr_tile_offset_x, curr_tile_offset_y;
int64_t curr_tile_LL_x, curr_tile_LL_y;
int disp_LL_x, disp_LL_y, disp_UR_x, disp_UR_y;
for (int tidx = 0; tidx < N_RENDER_TILES; tidx++) {
// Get lower left corner of tile in global (x, y) coordinates
LocalGeoPosition::getTileLL(_renderTileIds[tidx], _header, &curr_tile_LL_x, &curr_tile_LL_y);
// Current position relative to current tile.
curr_tile_offset_x = center.x() - curr_tile_LL_x;
curr_tile_offset_y = center.y() - curr_tile_LL_y;
// Get lower left and upper right corner of display relative to tile origin.
// TODO: make this a bit nicer
if (std::abs(_heading % 180) > 15) {
disp_LL_x = curr_tile_offset_x - DISPLAY_MAX_DIM / (_zoomScale); // DISPLAY_MAX_DIM sqrt(DISPLAY_WIDTH*DISPLAY_WIDTH/2)
disp_UR_x = curr_tile_offset_x + DISPLAY_MAX_DIM / (_zoomScale);
disp_LL_y = curr_tile_offset_y - DISPLAY_MAX_DIM / (_zoomScale);
disp_UR_y = curr_tile_offset_y + DISPLAY_MAX_DIM / (_zoomScale);
} else {
disp_LL_x = curr_tile_offset_x - DISPLAY_WIDTH_HALF / (_zoomScale); // DISPLAY_WIDTH_HALF/(**_zoomScale**)
disp_UR_x = curr_tile_offset_x + DISPLAY_WIDTH_HALF / (_zoomScale);
disp_LL_y = curr_tile_offset_y - DISPLAY_WIDTH_HALF / (_zoomScale);
disp_UR_y = curr_tile_offset_y + DISPLAY_WIDTH_HALF / (_zoomScale);
}