-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathearthmap.cpp
More file actions
1579 lines (1333 loc) · 50.3 KB
/
earthmap.cpp
File metadata and controls
1579 lines (1333 loc) · 50.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* code to manage the earth map
*/
/* main map drawing routines.
*/
#include "HamClock.h"
// pan, zoom and popup state
PanZoom pan_zoom = {MIN_ZOOM, 0, 0};
MapPopup map_popup;
// DX location and path to DE
SCircle dx_c = {{0,0},DX_R}; // screen coords of DX symbol
LatLong dx_ll; // geo coords of dx spot
// DE and AntiPodal location
SCircle de_c = {{0,0},DE_R}; // screen coords of DE symbol
LatLong de_ll; // geo coords of DE
float sdelat, cdelat; // handy tri
SCircle deap_c = {{0,0},DEAP_R}; // screen coords of DE antipode symbol
LatLong deap_ll; // geo coords of DE antipode
// sun
AstroCir solar_cir;
SCircle sun_c = {{0,0},SUN_R}; // screen coords of sun symbol
LatLong sun_ss_ll; // subsolar location
float csslat, ssslat; // handy trig
// moon
AstroCir lunar_cir;
SCircle moon_c = {{0,0},MOON_R}; // screen coords of moon symbol
LatLong moon_ss_ll; // sublunar location
// dx options
uint8_t show_lp; // display long path, else short part heading
#define GRAYLINE_COS (-0.208F) // cos(90 + grayline angle), we use 12 degs
#define GRAYLINE_POW (0.75F) // cos power exponent, sqrt is too severe, 1 is too gradual
static SCoord moremap_s; // drawMoreEarth() scanning location
// cached grid colors
uint16_t EARTH_GRIDC, EARTH_GRIDC00; // main and highlighted
// flag to defer drawing over map until opportune time:
bool mapmenu_pending;
// grid spacing, degrees
#define LL_LAT_GRID 15
#define LL_LNG_GRID 15
#define RADIAL_GRID 15
#define THETA_GRID 15
#define FINESTEP_GRID (1.0F/pan_zoom.zoom)
// establish EARTH_GRIDC and EARTH_GRIDC00
static void getGridColorCache()
{
// get base color
EARTH_GRIDC = getMapColor(GRID_CSPR);
// hi contrast
uint8_t h, s, v;
RGB565_2_HSV (EARTH_GRIDC, &h, &s, &v);
EARTH_GRIDC00 = v < 128 ? RA8875_WHITE : RA8875_BLACK;
}
/* erase the DE symbol by restoring map contents.
* N.B. we assume coords insure marker will be wholy within map boundaries.
*/
void eraseDEMarker()
{
eraseSCircle (de_c);
}
/* return whether to display DE marker
*/
bool showDEMarker()
{
return (overMap(de_c.s));
}
/* draw DE marker.
*/
void drawDEMarker(bool force)
{
// check for being off zoomed mercator map
if (de_c.s.x == 0)
return;
if (force || showDEMarker()) {
tft.fillCircle (de_c.s.x, de_c.s.y, DE_R, RA8875_BLACK);
tft.drawCircle (de_c.s.x, de_c.s.y, DE_R, DE_COLOR);
tft.fillCircle (de_c.s.x, de_c.s.y, DE_R/2, DE_COLOR);
}
}
/* erase the antipode symbol by restoring map contents.
* N.B. we assume coords insure marker will be wholy within map boundaries.
*/
void eraseDEAPMarker()
{
eraseSCircle (deap_c);
}
/* return whether to display the DE antipode
*/
static bool showDEAPMarker()
{
return (map_proj != MAPP_AZIM1 && !dx_info_for_sat && overMap(deap_c.s));
}
/* return whether to display the DX marker:
* over map and either not showing sat or showing either DX weather or VOACAP.
*/
bool showDXMarker()
{
return ((!dx_info_for_sat
|| findPaneChoiceNow(PLOT_CH_DXWX) != PANE_NONE
|| findPaneChoiceNow(PLOT_CH_BC) != PANE_NONE)
&& overMap(dx_c.s));
}
/* draw antipodal marker if applicable.
*/
void drawDEAPMarker()
{
// checkf for being off zoomed mercator map
if (deap_c.s.x == 0)
return;
if (showDEAPMarker()) {
tft.fillCircle (deap_c.s.x, deap_c.s.y, DEAP_R, DE_COLOR);
tft.drawCircle (deap_c.s.x, deap_c.s.y, DEAP_R, RA8875_BLACK);
tft.fillCircle (deap_c.s.x, deap_c.s.y, DEAP_R/2, RA8875_BLACK);
}
}
/* draw the NVRAM grid square to 4 chars in the given screen location
*/
static void drawMaidenhead(NV_Name nv, SBox &b, uint16_t color)
{
char maid[MAID_CHARLEN];
getNVMaidenhead (nv, maid);
maid[4] = 0;
fillSBox (b, RA8875_BLACK);
selectFontStyle (LIGHT_FONT, SMALL_FONT);
tft.setTextColor (color);
tft.setCursor (b.x, b.y+b.h-7);
tft.print (maid);
}
/* draw de_info_b according to de_time_fmt unless showing a pane choice
*/
void drawDEInfo()
{
// skip if showing pane choice
if (SHOWING_PANE_0())
return;
// init box and set step size
fillSBox (de_info_b, RA8875_BLACK);
uint16_t vspace = de_info_b.h/DE_INFO_ROWS;
// draw desired contents
switch (de_time_fmt) {
case DETIME_INFO:
selectFontStyle (LIGHT_FONT, SMALL_FONT);
tft.setTextColor (DE_COLOR);
// time
drawDECalTime(false);
// lat and lon
char buf[50];
snprintf (buf, sizeof(buf), "%.0f%c %.0f%c",
roundf(fabsf(de_ll.lat_d)), de_ll.lat_d < 0 ? 'S' : 'N',
roundf(fabsf(de_ll.lng_d)), de_ll.lng_d < 0 ? 'W' : 'E');
tft.setCursor (de_info_b.x, de_info_b.y+2*vspace-6);
tft.print(buf);
// maidenhead
drawMaidenhead(NV_DE_GRID, de_maid_b, DE_COLOR);
// sun rise/set info
drawDESunRiseSetInfo();
break;
case DETIME_ANALOG: // fallthru
case DETIME_ANALOG_DTTM: // fallthru
case DETIME_DIGITAL_12: // fallthru
case DETIME_DIGITAL_24:
drawTZ (de_tz);
updateClocks(true);
break;
case DETIME_CAL:
drawDECalTime(true);
drawCalendar(true);
break;
}
}
/* draw the time in de_info_b suitable for DETIME_INFO and DETIME_CALENDAR formats
*/
void drawDECalTime(bool center)
{
drawTZ (de_tz);
// get time
time_t utc = nowWO();
time_t local = utc + getTZ (de_tz);
int hr = hour (local);
int mn = minute (local);
int dy = day(local);
int mo = month(local);
// generate text
char buf[32];
if (getDateFormat() == DF_MDY || getDateFormat() == DF_YMD)
snprintf (buf, sizeof(buf), "%02d:%02d %s %d", hr, mn, monthShortStr(mo), dy);
else
snprintf (buf, sizeof(buf), "%02d:%02d %d %s", hr, mn, dy, monthShortStr(mo));
// set position
selectFontStyle (LIGHT_FONT, SMALL_FONT);
uint16_t vspace = de_info_b.h/DE_INFO_ROWS;
uint16_t x0 = de_info_b.x;
if (center) {
uint16_t bw = getTextWidth (buf);
x0 += (de_info_b.w - bw)/2;
}
// draw
tft.fillRect (de_info_b.x, de_info_b.y, de_info_b.w, vspace, RA8875_BLACK);
tft.setTextColor (DE_COLOR);
tft.setCursor (x0, de_info_b.y+vspace-6);
tft.print(buf);
}
/* draw the Maidenhead grid key around the map if appropriate.
*/
static void drawMaidGridKey()
{
// only if selected and using mercator projection
if (mapgrid_choice != MAPGRID_MAID || map_proj != MAPP_MERCATOR)
return;
// keep right stripe above RSS and map scale, if on
uint16_t right_h = map_b.h;
if (rss_on)
right_h = rss_bnr_b.y - map_b.y;
if (mapScaleIsUp())
right_h = mapscale_b.y - map_b.y; // drap_b.y already above rss if on
// prep background stripes
tft.fillRect (map_b.x, map_b.y, map_b.w, MH_TR_H, RA8875_BLACK); // top
tft.fillRect (map_b.x+map_b.w-MH_RC_W, map_b.y, MH_RC_W, right_h, RA8875_BLACK); // right
selectFontStyle (LIGHT_FONT, FAST_FONT);
tft.setTextColor (RA8875_WHITE);
// print labels across the top, use latitude of map center then scan lng
uint16_t rowy = map_b.y + MH_TR_DY;
LatLong ll;
s2ll (map_b.x+map_b.w/2, map_b.y+map_b.h/2, ll);
for (uint8_t i = 0; i < 18; i++) {
SCoord s;
ll.lng_d = -180 + (i+0.45F)*360/18; // center character within square
ll2s (ll, s, 10);
if (s.x) { // might be off screen when mercator is zoomed
tft.setCursor (s.x, rowy);
tft.print ((char)('A' + (180+ll.lng_d)/20));
}
}
// print labels down the right, use lng of map center then scan lat
uint16_t colx = map_b.x + map_b.w - MH_RC_W + MH_RC_DX;
s2ll (map_b.x+map_b.w/2, map_b.y+map_b.h/2, ll);
for (uint8_t i = 0; i < 18; i++) {
SCoord s;
ll.lat_d = 90 - (i+0.45F)*180/18; // center character within square
ll2s (ll, s, 10);
if (s.x) { // might be off screen when mercator is zoomed
tft.setCursor (colx, s.y);
tft.print ((char)('A' + 17 - i));
}
}
}
/* check and fix pz to be sure it is legal
*/
void normalizePanZoom (PanZoom &pz)
{
pz.zoom = CLAMPF (pz.zoom, MIN_ZOOM, MAX_ZOOM); // N.B. set zoom first
pz.pan_x = ((pz.pan_x + EARTH_W + EARTH_W/2) % EARTH_W) - EARTH_W/2;
pz.pan_y = CLAMPF (pz.pan_y, MIN_PANY(pz.zoom), MAX_PANY(pz.zoom));
}
/* draw and operate the map popup menu
*/
static void drawMapPopup(void)
{
// offer to set DX or DE and possibly control pan and zoom, depending on context
Serial.printf ("POPUP before: pan_x %d pan_y %d zoom %d\n", pan_zoom.pan_x, pan_zoom.pan_y,
pan_zoom.zoom);
const int ZINDENT = 2;
bool zoom_ok = map_proj == MAPP_MERCATOR;
bool pan_ok = map_proj == MAPP_MERCATOR || map_proj == MAPP_ROB;
bool reset_ok = pan_ok && (pan_zoom.pan_x != 0 || pan_zoom.pan_y != 0 || pan_zoom.zoom != MIN_ZOOM);
MenuFieldType z1_mft = zoom_ok ? MENU_1OFN : MENU_IGNORE;
MenuFieldType z2_mft = zoom_ok ? MENU_1OFN : MENU_IGNORE;
MenuFieldType z3_mft = zoom_ok ? MENU_1OFN : MENU_IGNORE;
MenuFieldType z4_mft = zoom_ok && BUILD_W == 800 ? MENU_1OFN : MENU_IGNORE; // only 800x480 can 4x
MenuFieldType ctr_mft = pan_ok ? (reset_ok ? MENU_01OFN : MENU_TOGGLE) : MENU_IGNORE;
MenuFieldType rst_mft = reset_ok ? (pan_ok ? MENU_01OFN : MENU_TOGGLE) : MENU_IGNORE;
MenuItem mitems[] = {
{MENU_01OFN, false, 1, ZINDENT, "Set DX", 0}, // 0
{MENU_01OFN, false, 1, ZINDENT, "Set DE", 0}, // 1
{MENU_BLANK, false, 0, ZINDENT, NULL, 0}, // 2
{z1_mft, pan_zoom.zoom == 1, 2, ZINDENT, "Zoom 1x", 0}, // 3
{z2_mft, pan_zoom.zoom == 2, 2, ZINDENT, "Zoom 2x", 0}, // 4
{z3_mft, pan_zoom.zoom == 3, 2, ZINDENT, "Zoom 3x", 0}, // 5
{z4_mft, pan_zoom.zoom == 4, 2, ZINDENT, "Zoom 4x", 0}, // 6
{ctr_mft, false, 4, ZINDENT, "Recenter", 0}, // 7
{rst_mft, false, 4, ZINDENT, "Reset", 0}, // 8
};
const int n_menu = NARRAY(mitems);
// boxes
SBox menu_b = {map_popup.s.x, map_popup.s.y, 0, 0}; // shrink wrap
SBox ok_b;
// go
MenuInfo menu = {menu_b, ok_b, UF_CLOCKSOK, M_CANCELOK, 1, n_menu, mitems};
if (runMenu (menu)) {
// init copy for changes
PanZoom new_pz = pan_zoom;
// check for new DX or DE, rely on runMenu to never set both
if (mitems[0].set)
newDX (map_popup.ll, NULL, NULL);
if (mitems[1].set)
newDE (map_popup.ll, NULL);
// reset else other stuff
if (mitems[8].set) {
new_pz.pan_x = new_pz.pan_y = 0;
new_pz.zoom = MIN_ZOOM;
} else {
// pan BEFORE changing zoom because that's the zoom at which the location was selected
if (mitems[7].set) {
new_pz.pan_x += (map_popup.s.x - (map_b.x + map_b.w/2)) / new_pz.zoom;
new_pz.pan_y += ((map_b.y + map_b.h/2) - map_popup.s.y) / new_pz.zoom;
}
// N.B. rely on menu setup to know these make sense
if (mitems[3].set)
new_pz.zoom = MIN_ZOOM;
else if (mitems[4].set)
new_pz.zoom = MIN_ZOOM + 1;
else if (mitems[5].set)
new_pz.zoom = MIN_ZOOM + 2;
else if (mitems[6].set)
new_pz.zoom = MIN_ZOOM + 3;
// insure still in bounds
normalizePanZoom (new_pz);
}
// save and do full update if pz changed
if (memcmp (&pan_zoom, &new_pz, sizeof(pan_zoom))) {
pan_zoom = new_pz;
NVWriteUInt8 (NV_ZOOM, pan_zoom.zoom);
NVWriteInt16 (NV_PANX, pan_zoom.pan_x);
NVWriteInt16 (NV_PANY, pan_zoom.pan_y);
initEarthMap();
scheduleFreshMap();
}
Serial.printf ("POPUP after: pan_x %d pan_y %d zoom %d\n", pan_zoom.pan_x, pan_zoom.pan_y,
pan_zoom.zoom);
}
}
/* draw lat/long with given step sizes (used for ll and maidenhead).
*/
static void drawLLGrid (int lat_step, int lng_step)
{
SCoord s0, s1; // end points
// thickness if any
int lw = getRawPathWidth (GRID_CSPR);
if (lw == 0)
return;
// lines of latitude, exclude the poles
for (float lat = -90+lat_step; lat < 90; lat += lat_step) {
ll2sRaw (deg2rad(lat), deg2rad(-180), s0, lw);
for (float lng = -180+lng_step; lng <= 180; lng += lng_step) {
ll2sRaw (deg2rad(lat), deg2rad(lng), s1, lw);
for (float lg = lng-lng_step+FINESTEP_GRID; lg <= lng; lg += FINESTEP_GRID) {
ll2sRaw (deg2rad(lat), deg2rad(lg), s1, lw);
if (segmentSpanOkRaw (s0, s1, lw))
tft.drawLineRaw (s0.x, s0.y, s1.x, s1.y, lw, lat == 0 ? EARTH_GRIDC00 : EARTH_GRIDC);
s0 = s1;
}
s0 = s1;
}
}
// lines of longitude -- pole to pole
for (float lng = -180; lng < 180; lng += lng_step) {
ll2sRaw (deg2rad(-90), deg2rad(lng), s0, lw);
for (float lat = -90+lat_step; lat <= 90; lat += lat_step) {
ll2sRaw (deg2rad(lat), deg2rad(lng), s1, lw);
for (float lt = lat-lat_step+FINESTEP_GRID; lt <= lat; lt += FINESTEP_GRID) {
ll2sRaw (deg2rad(lt), deg2rad(lng), s1, lw);
if (segmentSpanOkRaw (s0, s1, lw))
tft.drawLineRaw (s0.x, s0.y, s1.x, s1.y, lw, lng == 0 ? EARTH_GRIDC00 : EARTH_GRIDC);
s0 = s1;
}
s0 = s1;
}
}
}
/* draw azimuthal grid lines from DE
*/
static void drawAzimGrid ()
{
const float min_pole_lat = deg2rad(-89);
const float max_pole_lat = deg2rad(89);
const float max_az1_r = deg2rad(RADIAL_GRID*floorf(rad2deg(M_PIF)/AZIM1_ZOOM/RADIAL_GRID));
const float min_az_gap = deg2rad(90-RADIAL_GRID);
const float max_az_gap = deg2rad(90+RADIAL_GRID);
SCoord s0, s1;
// thickness if any
int lw = getRawPathWidth (GRID_CSPR);
if (lw == 0)
return;
// radial lines
for (int ti = 0; ti < 360/THETA_GRID; ti++) {
float t = deg2rad (ti * THETA_GRID);
s0.x = 0;
for (float r = 0; r <= M_PIF; r += deg2rad(FINESTEP_GRID)) {
// skip near 90 for AZM and everything over the ZOOM horizon for AZIM1
if (map_proj == MAPP_AZIMUTHAL && r > min_az_gap && r < max_az_gap) {
s0.x = 0;
continue;
}
if (map_proj == MAPP_AZIM1 && r > max_az1_r)
break;
float ca, B;
solveSphere (t, r, sdelat, cdelat, &ca, &B);
float lat = M_PI_2F - acosf(ca);
// avoid poles on mercator plots
if (map_proj != MAPP_MERCATOR || (lat > min_pole_lat && lat < max_pole_lat)) {
float lng = de_ll.lng + B;
ll2sRaw (lat, lng, s1, lw);
if (segmentSpanOkRaw (s0, s1, lw))
tft.drawLineRaw (s0.x, s0.y, s1.x, s1.y, lw, EARTH_GRIDC);
s0 = s1;
} else
s0.x = 0;
}
}
// theta rings
for (int ri = 1; ri < 180/RADIAL_GRID; ri++) {
float r = deg2rad (ri * RADIAL_GRID);
// skip near 90 for AZM and everything over the ZOOM horizon for AZIM1
if (map_proj == MAPP_AZIMUTHAL && r > min_az_gap && r < max_az_gap) {
s0.x = 0;
continue;
}
if (map_proj == MAPP_AZIM1 && r > max_az1_r)
break;
s0.x = 0;
// reduce zaggies on smaller circles
float fine_step = r < M_PIF/4 || r > 3*M_PIF/4 ? 2*FINESTEP_GRID : FINESTEP_GRID;
for (int ti = 0; ti <= 360/fine_step; ti++) {
float t = deg2rad (ti * fine_step);
float ca, B;
solveSphere (t, r, sdelat, cdelat, &ca, &B);
float lat = M_PI_2F - acosf(ca);
// avoid poles on mercator plots
if (map_proj != MAPP_MERCATOR || (lat > min_pole_lat && lat < max_pole_lat)) {
float lng = de_ll.lng + B;
ll2sRaw (lat, lng, s1, lw);
if (segmentSpanOkRaw (s0, s1, lw))
tft.drawLineRaw (s0.x, s0.y, s1.x, s1.y, lw, EARTH_GRIDC);
s0 = s1;
} else
s0.x = 0;
}
}
}
/* draw tropics grid lines from DE
*/
static void drawTropicsGrid()
{
// thickness if any
int lw = getRawPathWidth (GRID_CSPR);
if (lw == 0)
return;
if (map_proj != MAPP_MERCATOR) {
// just 2 lines at lat +- 23.5
SCoord s00, s01, s10, s11;
ll2sRaw (deg2rad(-23.5F), deg2rad(-180), s00, lw);
ll2sRaw (deg2rad(23.5F), deg2rad(-180), s10, lw);
for (float lng = -180; lng <= 180; lng += FINESTEP_GRID) {
ll2sRaw (deg2rad(-23.5), deg2rad(lng), s01, lw);
ll2sRaw (deg2rad(23.5), deg2rad(lng), s11, lw);
if (segmentSpanOkRaw (s00, s01, lw))
tft.drawLineRaw (s00.x, s00.y, s01.x, s01.y, lw, EARTH_GRIDC);
s00 = s01;
if (segmentSpanOkRaw (s10, s11, lw))
tft.drawLineRaw (s10.x, s10.y, s11.x, s11.y, lw, EARTH_GRIDC);
s10 = s11;
}
} else {
// easy! just 2 straight lines
uint16_t y = map_b.y + map_b.h/2 - 23.5F*map_b.h/180;
tft.drawLine (map_b.x, y, map_b.x+map_b.w-1, y, lw, EARTH_GRIDC);
y = map_b.y + map_b.h/2 + 23.5F*map_b.h/180;
tft.drawLine (map_b.x, y, map_b.x+map_b.w-1, y, lw, EARTH_GRIDC);
}
}
/* draw the complete proper map grid
*/
static void drawMapGrid()
{
switch ((MapGridStyle)mapgrid_choice) {
case MAPGRID_OFF:
break;
case MAPGRID_MAID:
drawMaidGridKey();
drawLLGrid (10, 20);
break;
case MAPGRID_LATLNG:
drawLLGrid (LL_LAT_GRID, LL_LNG_GRID);
break;
case MAPGRID_TROPICS:
drawTropicsGrid();
break;
case MAPGRID_AZIM:
drawAzimGrid();
break;
case MAPGRID_CQZONES:
drawZone (ZONE_CQ, EARTH_GRIDC, -1);
break;
case MAPGRID_ITUZONES:
drawZone (ZONE_ITU, EARTH_GRIDC, -1);
break;
default:
fatalError ("drawMapGrid() bad mapgrid_choice: %d", mapgrid_choice);
break;
}
}
/* draw some fake stars for the azimuthal projection
*/
static void drawAzmStars()
{
#define N_AZMSTARS 100
uint8_t n_stars = 0;
switch ((MapProjection)map_proj) {
case MAPP_MERCATOR:
break;
case MAPP_AZIMUTHAL:
while (n_stars < N_AZMSTARS) {
int32_t x = random (map_b.w);
int32_t y = random (map_b.h);
int32_t dx = (x > map_b.w/2) ? (x - 3*map_b.w/4) : (x - map_b.w/4);
int32_t dy = y - map_b.h/2;
if (dx*dx + dy*dy > map_b.w*map_b.w/16) {
uint16_t c = random(256);
tft.drawPixel (map_b.x+x, map_b.y+y, RGB565(c,c,c));
n_stars++;
}
}
break;
case MAPP_AZIM1:
while (n_stars < N_AZMSTARS) {
int32_t x = random (map_b.w);
int32_t y = random (map_b.h);
int32_t dx = x - map_b.w/2;
int32_t dy = y - map_b.h/2;
if (dx*dx + dy*dy > map_b.h*map_b.h/4) {
uint16_t c = random(256);
tft.drawPixel (map_b.x+x, map_b.y+y, RGB565(c,c,c));
n_stars++;
}
}
break;
case MAPP_ROB:
while (n_stars < N_AZMSTARS) {
LatLong ll;
SCoord star;
star.x = map_b.x + random(map_b.w);
star.y = map_b.y + random(map_b.h);
if (!s2llRobinson(star,ll)) {
uint16_t c = random(256);
tft.drawPixel (star.x, star.y, RGB565(c,c,c));
n_stars++;
}
}
break;
default:
fatalError ("drawAzmStars() bad map_proj %d", map_proj);
}
}
static void updateCircumstances()
{
time_t utc = nowWO();
getSolarCir (utc, de_ll, solar_cir);
sun_ss_ll.lat_d = rad2deg(solar_cir.dec);
sun_ss_ll.lng_d = -rad2deg(solar_cir.gha);
sun_ss_ll.normalize();
csslat = cosf(sun_ss_ll.lat);
ssslat = sinf(sun_ss_ll.lat);
ll2s (sun_ss_ll, sun_c.s, SUN_R+1);
getLunarCir (utc, de_ll, lunar_cir);
moon_ss_ll.lat_d = rad2deg(lunar_cir.dec);
moon_ss_ll.lng_d = -rad2deg(lunar_cir.gha);
moon_ss_ll.normalize();
ll2s (moon_ss_ll, moon_c.s, MOON_R+1);
updateSatPath();
}
/* draw the map view menu button.
* N.B. adjust y position depending on whether we are drawing the maidenhead labels
*/
static void drawMapMenuButton()
{
if (mapgrid_choice == MAPGRID_MAID && map_proj == MAPP_MERCATOR)
view_btn_b.y = map_b.y + MH_TR_H;
else
view_btn_b.y = map_b.y;
// 1 pixel inside so overMap() gives 2-pixel thick sat footprints some room
tft.fillRect (view_btn_b.x, view_btn_b.y, view_btn_b.w-1, view_btn_b.h-1, RA8875_BLACK);
tft.drawRect (view_btn_b.x, view_btn_b.y, view_btn_b.w-1, view_btn_b.h-1, RA8875_WHITE);
char style_mem[NV_COREMAPSTYLE_LEN];
const char *str = getCoreMapStyle (core_map, style_mem);
selectFontStyle (LIGHT_FONT, FAST_FONT);
uint16_t str_w = getTextWidth(str);
tft.setCursor (view_btn_b.x+(view_btn_b.w-str_w)/2, view_btn_b.y+2);
tft.setTextColor (RA8875_WHITE);
tft.print (str);
}
/* draw, perform and engage results of the map View menu
*/
static void drawMapMenu()
{
enum MIName { // menu items -- N.B. must be in same order as mitems[]
MI_STY_TTL,
MI_STY_CTY, MI_STY_TER, MI_STY_DRA, MI_STY_MUF, MI_STY_MRT, MI_STY_AUR, MI_STY_WXX,
MI_STY_CLO, MI_STY_USR, MI_STY_TOA, MI_STY_REL,
MI_GRD_TTL,
MI_GRD_NON, MI_GRD_TRO, MI_GRD_LLG, MI_GRD_MAI, MI_GRD_AZM, MI_GRD_CQZ, MI_GRD_ITU,
MI_PRJ_TTL,
MI_PRJ_MER, MI_PRJ_AZM, MI_PRJ_AZ1, MI_PRJ_MOL,
MI_RSS_YES,
MI_NON_YES,
MI_CTY_YES,
MI_N
};
#define PRI_INDENT 2
#define SEC_INDENT 8
MenuItem mitems[MI_N] = {
{MENU_LABEL, false, 0, PRI_INDENT, "Style:", 0},
{MENU_AL1OFN, IS_CMROT(CM_COUNTRIES), 1, SEC_INDENT, cm_info[CM_COUNTRIES].name, 0},
{MENU_AL1OFN, IS_CMROT(CM_TERRAIN), 1, SEC_INDENT, cm_info[CM_TERRAIN].name, 0},
{MENU_AL1OFN, IS_CMROT(CM_DRAP), 1, SEC_INDENT, cm_info[CM_DRAP].name, 0},
{MENU_AL1OFN, IS_CMROT(CM_MUF_V), 1, SEC_INDENT, cm_info[CM_MUF_V].name, 0},
{MENU_AL1OFN, IS_CMROT(CM_MUF_RT), 1, SEC_INDENT, cm_info[CM_MUF_RT].name, 0},
{MENU_AL1OFN, IS_CMROT(CM_AURORA), 1, SEC_INDENT, cm_info[CM_AURORA].name, 0},
{MENU_AL1OFN, IS_CMROT(CM_WX), 1, SEC_INDENT, cm_info[CM_WX].name, 0},
{MENU_AL1OFN, IS_CMROT(CM_CLOUDS), 1, SEC_INDENT, cm_info[CM_CLOUDS].name, 0},
{MENU_IGNORE, false, 1, SEC_INDENT, NULL, 0}, // CM_USER see below
{MENU_IGNORE, false, 1, SEC_INDENT, NULL, 0}, // CM_PMTOA see below
{MENU_IGNORE, false, 1, SEC_INDENT, NULL, 0}, // CM_PMREL see below
{MENU_LABEL, false, 0, PRI_INDENT, "Grid:", 0},
{MENU_1OFN, false, 2, SEC_INDENT, "None", 0},
{MENU_1OFN, false, 2, SEC_INDENT, grid_styles[MAPGRID_TROPICS], 0},
{MENU_1OFN, false, 2, SEC_INDENT, grid_styles[MAPGRID_LATLNG], 0},
{MENU_1OFN, false, 2, SEC_INDENT, grid_styles[MAPGRID_MAID], 0},
{MENU_1OFN, false, 2, SEC_INDENT, grid_styles[MAPGRID_AZIM], 0},
{MENU_1OFN, false, 2, SEC_INDENT, grid_styles[MAPGRID_CQZONES], 0},
{MENU_1OFN, false, 2, SEC_INDENT, grid_styles[MAPGRID_ITUZONES], 0},
{MENU_LABEL, false, 0, PRI_INDENT, "Projection:", 0},
{MENU_1OFN, false, 3, SEC_INDENT, map_projnames[MAPP_MERCATOR], 0},
{MENU_1OFN, false, 3, SEC_INDENT, map_projnames[MAPP_AZIMUTHAL], 0},
{MENU_1OFN, false, 3, SEC_INDENT, map_projnames[MAPP_AZIM1], 0},
{MENU_1OFN, false, 3, SEC_INDENT, map_projnames[MAPP_ROB], 0},
{MENU_TOGGLE, false, 4, PRI_INDENT, "RSS", 0},
{MENU_TOGGLE, false, 5, PRI_INDENT, "Night", 0},
{MENU_TOGGLE, false, 6, PRI_INDENT, "Cities", 0},
};
// init selections with current states
// if TOA and/or REL are in rotation add to menu
char propname_toa[NV_COREMAPSTYLE_LEN]; // N.B. must be persistent for lifetime of runMenu()
char propname_rel[NV_COREMAPSTYLE_LEN]; // N.B. must be persistent for lifetime of runMenu()
if (IS_CMROT(CM_PMTOA)) {
mitems[MI_STY_TOA].type = MENU_AL1OFN;
mitems[MI_STY_TOA].set = true;
mitems[MI_STY_TOA].label = getCoreMapStyle (CM_PMTOA, propname_toa);
}
if (IS_CMROT(CM_PMREL)) {
mitems[MI_STY_REL].type = MENU_AL1OFN;
mitems[MI_STY_REL].set = true;
mitems[MI_STY_REL].label = getCoreMapStyle (CM_PMREL, propname_rel);
}
// if CM_USER is possible add to menu
if (allWebMapImagesOk()) {
mitems[MI_STY_USR].type = MENU_AL1OFN;
mitems[MI_STY_USR].set = IS_CMROT(CM_USER);
mitems[MI_STY_USR].label = cm_info[CM_USER].name;
}
mitems[MI_GRD_NON].set = mapgrid_choice == MAPGRID_OFF;
mitems[MI_GRD_TRO].set = mapgrid_choice == MAPGRID_TROPICS;
mitems[MI_GRD_LLG].set = mapgrid_choice == MAPGRID_LATLNG;
mitems[MI_GRD_MAI].set = mapgrid_choice == MAPGRID_MAID;
mitems[MI_GRD_AZM].set = mapgrid_choice == MAPGRID_AZIM;
mitems[MI_GRD_CQZ].set = mapgrid_choice == MAPGRID_CQZONES;
mitems[MI_GRD_ITU].set = mapgrid_choice == MAPGRID_ITUZONES;
mitems[MI_PRJ_MER].set = map_proj == MAPP_MERCATOR;
mitems[MI_PRJ_AZM].set = map_proj == MAPP_AZIMUTHAL;
mitems[MI_PRJ_AZ1].set = map_proj == MAPP_AZIM1;
mitems[MI_PRJ_MOL].set = map_proj == MAPP_ROB;
mitems[MI_RSS_YES].set = rss_on;
mitems[MI_NON_YES].set = night_on;
mitems[MI_CTY_YES].set = names_on;
// create a box for the menu
SBox menu_b;
menu_b.x = view_btn_b.x + 1; // left edge matches view button with slight indent
menu_b.y = view_btn_b.y+view_btn_b.h; // top just below view button
menu_b.w = 0; // shrink to fit
// run menu
SBox ok_b;
MenuInfo menu = {menu_b, ok_b, UF_CLOCKSOK, M_CANCELOK, 1, MI_N, mitems};
bool menu_ok = runMenu (menu);
if (menu_ok) {
// build new map_rotset
uint16_t prev_rotset = map_rotset;
map_rotset = 0;
if (mitems[MI_STY_CTY].set)
scheduleNewCoreMap (CM_COUNTRIES);
if (mitems[MI_STY_TER].set)
scheduleNewCoreMap (CM_TERRAIN);
if (mitems[MI_STY_DRA].set)
scheduleNewCoreMap (CM_DRAP);
if (mitems[MI_STY_MUF].set)
scheduleNewCoreMap (CM_MUF_V);
if (mitems[MI_STY_MRT].set)
scheduleNewCoreMap (CM_MUF_RT);
if (mitems[MI_STY_AUR].set)
scheduleNewCoreMap (CM_AURORA);
if (mitems[MI_STY_WXX].set)
scheduleNewCoreMap (CM_WX);
if (mitems[MI_STY_CLO].set)
scheduleNewCoreMap (CM_CLOUDS);
if (mitems[MI_STY_USR].set)
scheduleNewCoreMap (CM_USER);
if (mitems[MI_STY_TOA].set)
scheduleNewCoreMap (CM_PMTOA);
if (mitems[MI_STY_REL].set)
scheduleNewCoreMap (CM_PMREL);
// check for changes and confirm core_map
if (map_rotset != prev_rotset) {
// pick one and do full refresh if core_map no longer selected
if (!IS_CMROT(core_map))
insureCoreMap();
saveCoreMaps();
}
logMapRotSet();
// check for different grid
if (mitems[MI_GRD_NON].set && mapgrid_choice != MAPGRID_OFF) {
mapgrid_choice = MAPGRID_OFF;
NVWriteUInt8 (NV_GRIDSTYLE, mapgrid_choice);
} else if (mitems[MI_GRD_TRO].set && mapgrid_choice != MAPGRID_TROPICS) {
mapgrid_choice = MAPGRID_TROPICS;
NVWriteUInt8 (NV_GRIDSTYLE, mapgrid_choice);
} else if (mitems[MI_GRD_LLG].set && mapgrid_choice != MAPGRID_LATLNG) {
mapgrid_choice = MAPGRID_LATLNG;
NVWriteUInt8 (NV_GRIDSTYLE, mapgrid_choice);
} else if (mitems[MI_GRD_MAI].set && mapgrid_choice != MAPGRID_MAID) {
mapgrid_choice = MAPGRID_MAID;
NVWriteUInt8 (NV_GRIDSTYLE, mapgrid_choice);
} else if (mitems[MI_GRD_AZM].set && mapgrid_choice != MAPGRID_AZIM) {
mapgrid_choice = MAPGRID_AZIM;
NVWriteUInt8 (NV_GRIDSTYLE, mapgrid_choice);
} else if (mitems[MI_GRD_CQZ].set && map_proj != MAPGRID_CQZONES) {
mapgrid_choice = MAPGRID_CQZONES;
NVWriteUInt8 (NV_GRIDSTYLE, mapgrid_choice);
} else if (mitems[MI_GRD_ITU].set && map_proj != MAPGRID_ITUZONES) {
mapgrid_choice = MAPGRID_ITUZONES;
NVWriteUInt8 (NV_GRIDSTYLE, mapgrid_choice);
}
// check for different map projection
if (mitems[MI_PRJ_MER].set && map_proj != MAPP_MERCATOR) {
map_proj = MAPP_MERCATOR;
NVWriteUInt8 (NV_MAPPROJ, map_proj);
} else if (mitems[MI_PRJ_AZM].set && map_proj != MAPP_AZIMUTHAL) {
map_proj = MAPP_AZIMUTHAL;
NVWriteUInt8 (NV_MAPPROJ, map_proj);
} else if (mitems[MI_PRJ_AZ1].set && map_proj != MAPP_AZIM1) {
map_proj = MAPP_AZIM1;
NVWriteUInt8 (NV_MAPPROJ, map_proj);
} else if (mitems[MI_PRJ_MOL].set && map_proj != MAPP_ROB) {
map_proj = MAPP_ROB;
NVWriteUInt8 (NV_MAPPROJ, map_proj);
}
// check for change night option
if (mitems[MI_NON_YES].set != night_on) {
night_on = mitems[MI_NON_YES].set;
NVWriteUInt8 (NV_NIGHT_ON, night_on);
}
// check for change of names option
if (mitems[MI_CTY_YES].set != names_on) {
names_on = mitems[MI_CTY_YES].set;
NVWriteUInt8 (NV_NAMES_ON, names_on);
}
// check for changed RSS
if (mitems[MI_RSS_YES].set != rss_on) {
rss_on = mitems[MI_RSS_YES].set;
NVWriteUInt8 (NV_RSS_ON, rss_on);
}
// engage change
initEarthMap();
tft.drawPR();
}
// discard any extra taps
drainTouch();
printFreeHeap ("drawMapMenu");
}
/* restart map for current projection and de_ll and dx_ll
*/
void initEarthMap()
{
// completely erase map
fillSBox (map_b, RA8875_BLACK);
// add funky star field if azm
drawAzmStars();
// get grid colors
getGridColorCache();
// freshen RSS and clocks
scheduleRSSNow();
updateClocks(true);
// draw map view button
drawMapMenuButton();
// update astro info
updateCircumstances();
// update DE and DX info
sdelat = sinf(de_ll.lat);
cdelat = cosf(de_ll.lat);
ll2s (de_ll, de_c.s, DE_R);
antipode (deap_ll, de_ll);
ll2s (deap_ll, deap_c.s, DEAP_R);
ll2s (dx_ll, dx_c.s, DX_R);
// show updated info
drawDEInfo();
drawDXInfo();
// insure NCDXF screen coords match current map type
updateBeaconMapLocations();
// update zone screen boundaries
updateZoneSCoords(ZONE_CQ);
updateZoneSCoords(ZONE_ITU);
// init scan line in map_b
moremap_s.x = 0; // avoid updateCircumstances() first call to drawMoreEarth()
moremap_s.y = map_b.y;
// now main loop can resume with drawMoreEarth()
}
/* display another earth map row at mmoremap_s.
*/
void drawMoreEarth()
{
uint16_t last_x = map_b.x + EARTH_W - 1;
// draw next row
for (moremap_s.x = map_b.x; moremap_s.x <= last_x; moremap_s.x++)
drawMapCoord (moremap_s); // does not draw grid
// advance row, wrap and reset and finish up at the end
if ((moremap_s.y += 1) >= map_b.y + EARTH_H) {
// draw goodies unless showing CM_USER
if (core_map != CM_USER) {
drawMapGrid();
drawSatPathAndFoot();
if (waiting4DXPath())
drawDXPath();
drawPSKPaths ();
drawAllSymbols();
drawSatName();
drawInfoBox();
}
// draw now
tft.drawPR();
// check pending events
if (mapmenu_pending) {
drawMapMenu();
mapmenu_pending = false;
}
if (map_popup.pending) {
drawMapPopup();
map_popup.pending = false;