Skip to content

Commit 11f100e

Browse files
authored
Merge pull request #277 from jgauchia/devel_pan_map
Add pan map
2 parents fa6d2ae + 24a3094 commit 11f100e

File tree

21 files changed

+824
-401
lines changed

21 files changed

+824
-401
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ESP32 Based GPS Navigator (LVGL - LovyanGFX).
2929

3030
|<img src="images/dev/splash.png">|<img src="images/dev/searchsat.jpg">|<img src="images/dev/compass.jpg">|<img src="images/dev/options.jpg">|<img src="images/dev/wptopt.jpg">|
3131
|:-:|:-:|:-:|:-:|:-:|
32-
| Splash Screen | Search Satellite | Compass | Main Options | Waypoint Options |
32+
| Splash Screen | Search Satellite | Compass | Main Options | Wpt/Track Options |
3333

3434
|<img src="images/dev/rendermap.jpg">|<img src="images/dev/vectormap.jpg">|<img src="images/dev/navscreen.jpg">|<img src="images/dev/navscreen2.jpg">|<img src="images/dev/satelliteinfo.jpg">|
3535
|:-:|:-:|:-:|:-:|:-:|

images/dev/options.jpg

36.9 KB
Loading

images/dev/rendermap.jpg

95.3 KB
Loading

images/dev/vectormap.jpg

72.1 KB
Loading

images/dev/wptopt.jpg

20 KB
Loading

lib/gui/src/mainScr.cpp

Lines changed: 99 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
bool isMainScreen = false; // Flag to indicate main screen is selected
1212
bool isScrolled = true; // Flag to indicate when tileview was scrolled
1313
bool isReady = false; // Flag to indicate when tileview scroll was finished
14+
bool isScrollingMap = false; // Flag to indicate if map is scrolling
15+
bool canScrollMap = false; // Flag to indicate whet can scroll map
1416
uint8_t activeTile = 0; // Current active tile
1517
uint8_t gpxAction = WPT_NONE; // Current Waypoint Action
1618
int heading = 0; // Heading value (Compass or GPS)
19+
extern uint32_t DOUBLE_TOUCH_EVENT;
1720

1821
extern Compass compass;
1922
extern Gps gps;
@@ -197,20 +200,32 @@ void updateMainScreen(lv_timer_t *t)
197200
*/
198201
void gestureEvent(lv_event_t *event)
199202
{
200-
lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act());
201-
if (activeTile == MAP && isMainScreen)
203+
lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_active());
204+
205+
if (showMapToolBar)
202206
{
203-
switch (dir)
204-
{
205-
case LV_DIR_LEFT:
206-
break;
207-
case LV_DIR_RIGHT:
208-
break;
209-
case LV_DIR_TOP:
210-
break;
211-
case LV_DIR_BOTTOM:
212-
break;
213-
}
207+
// if (activeTile == MAP && isMainScreen)
208+
// {
209+
// switch (dir)
210+
// {
211+
// case LV_DIR_LEFT:
212+
// // mapView.panMap(1,0);
213+
// mapView.scrollMap(30,0);
214+
// break;
215+
// case LV_DIR_RIGHT:
216+
// // mapView.panMap(-1,0);
217+
// mapView.scrollMap(-30,0);
218+
// break;
219+
// case LV_DIR_TOP:
220+
// //mapView.panMap(0,1);
221+
// mapView.scrollMap(0,30);
222+
// break;
223+
// case LV_DIR_BOTTOM:
224+
// // mapView.panMap(0,-1);
225+
// mapView.scrollMap(0,-30);
226+
// break;
227+
// }
228+
// }
214229
}
215230
}
216231

@@ -252,13 +267,16 @@ void updateSatTrack(lv_event_t *event)
252267
}
253268

254269
/**
255-
* @brief Tool Bar Event
270+
* @brief Map Tool Bar Event
256271
*
257272
* @param event
258273
*/
259-
void toolBarEvent(lv_event_t *event)
274+
void mapToolBarEvent(lv_event_t *event)
260275
{
261-
showToolBar = !showToolBar;
276+
lv_event_code_t code = lv_event_get_code(event);
277+
278+
showMapToolBar = !showMapToolBar;
279+
canScrollMap = !canScrollMap;
262280

263281
if (!mapSet.mapFullScreen)
264282
{
@@ -273,20 +291,79 @@ void toolBarEvent(lv_event_t *event)
273291
lv_obj_set_pos(btnZoomIn, 10, mapView.mapScrFull - (toolBarOffset + (2 * toolBarSpace) + 24));
274292
}
275293

276-
if (!showToolBar)
294+
if (!showMapToolBar)
277295
{
278296
lv_obj_clear_flag(btnFullScreen, LV_OBJ_FLAG_CLICKABLE);
279297
lv_obj_clear_flag(btnZoomOut, LV_OBJ_FLAG_CLICKABLE);
280298
lv_obj_clear_flag(btnZoomIn, LV_OBJ_FLAG_CLICKABLE);
299+
lv_obj_add_flag(tilesScreen, LV_OBJ_FLAG_SCROLLABLE);
300+
mapView.centerOnGps(gps.gpsData.latitude, gps.gpsData.longitude);
281301
}
282302
else
283303
{
284304
lv_obj_add_flag(btnFullScreen, LV_OBJ_FLAG_CLICKABLE);
285305
lv_obj_add_flag(btnZoomOut, LV_OBJ_FLAG_CLICKABLE);
286306
lv_obj_add_flag(btnZoomIn, LV_OBJ_FLAG_CLICKABLE);
307+
lv_obj_clear_flag(tilesScreen, LV_OBJ_FLAG_SCROLLABLE);
287308
}
288309
}
289310

311+
/**
312+
* @brief Scrool Map Event
313+
*
314+
* @param event
315+
*/
316+
void scrollMapEvent(lv_event_t *event)
317+
{
318+
if (canScrollMap)
319+
{
320+
lv_event_code_t code = lv_event_get_code(event);
321+
lv_indev_t * indev = lv_event_get_indev(event);
322+
static int last_x = 0, last_y = 0;
323+
static int dx = 0, dy = 0;
324+
lv_point_t p;
325+
326+
327+
switch (code)
328+
{
329+
case LV_EVENT_PRESSED:
330+
{
331+
lv_indev_get_point(indev, &p);
332+
last_x = p.x;
333+
last_y = p.y;
334+
isScrollingMap = true;
335+
break;
336+
}
337+
338+
case LV_EVENT_PRESSING:
339+
{
340+
lv_indev_get_point(indev, &p);
341+
342+
int dx = p.x - last_x;
343+
int dy = p.y - last_y;
344+
345+
const int SCROLL_THRESHOLD = 5;
346+
347+
if (abs(dx) > SCROLL_THRESHOLD || abs(dy) > SCROLL_THRESHOLD)
348+
{
349+
mapView.scrollMap(-dx, -dy);
350+
last_x = p.x;
351+
last_y = p.y;
352+
}
353+
break;
354+
}
355+
356+
case LV_EVENT_PRESS_LOST:
357+
{
358+
isScrollingMap = false;
359+
break;
360+
}
361+
}
362+
}
363+
}
364+
365+
366+
290367
/**
291368
* @brief Full Screen Event Toolbar
292369
*
@@ -486,7 +563,7 @@ void createMainScr()
486563
lv_obj_set_pos(btnZoomIn, 10, mapView.mapScrFull - (toolBarOffset + (2 * toolBarSpace) + 24));
487564
}
488565

489-
if (!showToolBar)
566+
if (!showMapToolBar)
490567
{
491568
lv_obj_clear_flag(btnFullScreen, LV_OBJ_FLAG_CLICKABLE);
492569
lv_obj_clear_flag(btnZoomOut, LV_OBJ_FLAG_CLICKABLE);
@@ -501,8 +578,10 @@ void createMainScr()
501578

502579
// Map Tile Events
503580
lv_obj_add_event_cb(mapTile, updateMap, LV_EVENT_VALUE_CHANGED, NULL);
504-
lv_obj_add_event_cb(mapTile, gestureEvent, LV_EVENT_GESTURE, NULL);
505-
lv_obj_add_event_cb(mapTile, toolBarEvent, LV_EVENT_LONG_PRESSED, NULL);
581+
lv_obj_add_event_cb(mainScreen, gestureEvent, LV_EVENT_GESTURE, NULL);
582+
DOUBLE_TOUCH_EVENT = lv_event_register_id();
583+
lv_obj_add_event_cb(mapTile, mapToolBarEvent, (lv_event_code_t)DOUBLE_TOUCH_EVENT, NULL);
584+
lv_obj_add_event_cb(mapTile, scrollMapEvent, LV_EVENT_ALL, NULL);
506585

507586
// Navigation Tile
508587
navigationScr(navTile);

lib/gui/src/mainScr.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ extern lv_timer_t *mainTimer; // Main Screen Timer
2424
extern bool isScrolled; // Flag to indicate when tileview was scrolled
2525
extern bool isMainScreen; // Flag to indicate main screen is selected
2626
extern bool isReady; // Flag to indicate when tileview scroll was finished
27+
extern bool canScrollMap; // Flag to indicate whet can scroll map
28+
extern bool isScrollingMap; // Flag to indicate if map is scrolling
2729
static TFT_eSprite zoomSprite = TFT_eSprite(&tft); // Zoom sprite
2830

2931
extern uint8_t activeTile; // Active Tile in TileView control
@@ -66,7 +68,8 @@ void gestureEvent(lv_event_t *event);
6668

6769
void updateMap(lv_event_t *event);
6870
void updateSatTrack(lv_event_t *event);
69-
void toolBarEvent(lv_event_t *event);
71+
void mapToolBarEvent(lv_event_t *event);
72+
void scrollMapEvent(lv_event_t *event);
7073
void fullScreenEvent(lv_event_t *event);
7174
void zoomOutEvent(lv_event_t *event);
7275
void zoomInEvent(lv_event_t *event);

lib/gui/src/splashScr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
static unsigned long millisActual = 0;
1212
extern Maps mapView;
13+
extern Gps gps;
1314

1415
/**
1516
* @brief Splash screen
@@ -24,7 +25,10 @@ void splashScreen()
2425
mapView.generateVectorMap(zoom);
2526
}
2627
else
28+
{
29+
mapView.currentMapTile = mapView.getMapTile(gps.gpsData.longitude, gps.gpsData.latitude, zoom, 0, 0);
2730
mapView.generateRenderMap(zoom);
31+
}
2832

2933
setTime = false;
3034

0 commit comments

Comments
 (0)