Skip to content

Commit 26ab987

Browse files
committed
Additional debug for pane choice; Sat Alerts instead of Sat Activations; Fix compiler warnings; for new installers or users of Sat Alerts and Flex Pane is displayed don't overflow
1 parent e540272 commit 26ab987

6 files changed

Lines changed: 67 additions & 18 deletions

File tree

ESPHamClock/ESPHamClock.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,10 @@ void drawDEFormatMenu()
18861886
// number of core menu items
18871887
#define N_DEFMT_CORE 8
18881888

1889-
MenuItem mitems[N_DEFMT_CORE+N_PANE_0_CH] = {
1889+
// PLOT_CH_SATACT can't join PANE_0_CH_MASK -- that's a 32-bit bitmask constant and SATACT's
1890+
// ordinal (32) can never fit in one, by the same design as everywhere else PLOTBIT() is used.
1891+
// it's offered as one extra, separately-handled menu item instead.
1892+
MenuItem mitems[N_DEFMT_CORE+N_PANE_0_CH+1] = {
18901893

18911894
// outer menu is whether to display the DE pane or use both DE+DX for a pane choice
18921895
{MENU_1OFN, !SHOWING_PANE_0(), 1, mi, "DE format:", NULL},
@@ -1920,11 +1923,22 @@ void drawDEFormatMenu()
19201923
PlotPane pp = findPaneForChoice ((PlotChoice)plot_n);
19211924
bool available = plotChoiceIsAvailable((PlotChoice)plot_n) && (pp == PANE_NONE || pp == PANE_0);
19221925
MenuFieldType type = available ? MENU_AL1OFN : MENU_IGNORE;
1923-
mitems[N_DEFMT_CORE+i] = {type, !!(plot_rotset[PANE_0] & (1<<plot_n)), 3, Mi, plot_names[plot_n], 0};
1926+
mitems[N_DEFMT_CORE+i] = {type, !!(plot_rotset[PANE_0] & PLOTBIT(plot_n)), 3, Mi, plot_names[plot_n], 0};
19241927
}
19251928
if (pane_0_bits != 0)
19261929
fatalError ("drawDEFormatMenu() %d %d 0x%x\n", pane_0_bits, N_PANE_0_CH, PANE_0_CH_MASK);
19271930

1931+
// extra SATACT item -- can't be represented in plot_rotset (see comment above), so its
1932+
// "currently set" state is determined the same way paneHasChoice() checks a solo choice
1933+
const int SATACT_MI = N_DEFMT_CORE + N_PANE_0_CH;
1934+
{
1935+
PlotPane pp = findPaneForChoice (PLOT_CH_SATACT);
1936+
bool available = plotChoiceIsAvailable (PLOT_CH_SATACT) && (pp == PANE_NONE || pp == PANE_0);
1937+
MenuFieldType type = available ? MENU_AL1OFN : MENU_IGNORE;
1938+
bool is_set = (plot_ch[PANE_0] == PLOT_CH_SATACT && plot_rotset[PANE_0] == 0);
1939+
mitems[SATACT_MI] = {type, is_set, 3, Mi, plot_names[PLOT_CH_SATACT], 0};
1940+
}
1941+
19281942
// create a box for the menu
19291943
SBox menu_b;
19301944
menu_b.x = de_info_b.x + 4;
@@ -1966,18 +1980,26 @@ void drawDEFormatMenu()
19661980
uint32_t new_rotset = 0;
19671981
for (int i = 0; i < N_PANE_0_CH; i++) {
19681982
if (mitems[N_DEFMT_CORE+i].set)
1969-
new_rotset |= (1<<menu_ch[i]);
1983+
new_rotset |= PLOTBIT(menu_ch[i]);
19701984
}
19711985

1972-
// might not be any if user clicked this section but made no choice
1973-
if (new_rotset != 0) {
1986+
bool satact_set = mitems[SATACT_MI].set;
1987+
1988+
if (satact_set && new_rotset == 0) {
1989+
1990+
// SATACT alone: solo, non-rotating choice -- can't be represented in plot_rotset
1991+
plot_ch[PANE_0] = PLOT_CH_SATACT;
1992+
plot_rotset[PANE_0] = 0;
1993+
1994+
} else if (new_rotset != 0) {
19741995

1975-
// ok!
1996+
// one or more mask-based choices (SATACT, if also checked, can't join a
1997+
// multi-item rotation set the way these can, so it's dropped in that case)
19761998
plot_rotset[PANE_0] = new_rotset;
19771999

19782000
// pick any one as current
19792001
for (int i = 0; i < PLOT_CH_N; i++) {
1980-
if (plot_rotset[PANE_0] & (1 << i)) {
2002+
if (plot_rotset[PANE_0] & PLOTBIT(i)) {
19812003
plot_ch[PANE_0] = (PlotChoice) i;
19822004
break;
19832005
}

ESPHamClock/HamClock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ typedef enum {
419419
X(PLOT_CH_LAUNCHES, "Launches") \
420420
X(PLOT_CH_HFCOND, "HF_Bands") \
421421
X(PLOT_CH_VHFCOND, "VHF_Cond") \
422-
X(PLOT_CH_SATACT, "Sat_Activations")
422+
X(PLOT_CH_SATACT, "Sat_Alerts")
423423

424424
#define X(a,b) a, // expands PLOTNAMES to each enum and comma
425425
typedef enum {

ESPHamClock/clocks.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,9 +1209,12 @@ bool checkClockTouch (SCoord &s)
12091209
return (true);
12101210
}
12111211

1212-
// ADS-B airplane icon: always present, opens adsb.lol
1212+
// ADS-B airplane icon: always present, opens adsb.lol centered on DE's location
12131213
if (inBox (s, adsb_btn_b)) {
1214-
openURL ("https://adsb.lol");
1214+
char url[100];
1215+
snprintf (url, sizeof(url), "https://adsb.lol/?lat=%.3f&lon=%.3f&zoom=10",
1216+
de_ll.lat_d, de_ll.lng_d);
1217+
openURL (url);
12151218
return (true);
12161219
}
12171220

ESPHamClock/hamsat.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,11 @@ static void formatCountdown (time_t aos, time_t now, char *buf, size_t buflen)
395395
long dt = aos - now;
396396
int hr = dt / 3600;
397397
int mn = (dt % 3600) / 60;
398+
// clamp so %d always fits buf regardless of dt's theoretical range; also satisfies GCC's
399+
// value-range analysis to avoid -Wformat-truncation (same convention used in lightning.cpp)
400+
#define CD_CLAMP(n) ((n) > 99 ? 99 : (n))
398401
if (hr > 0)
399-
snprintf (buf, buflen, "%dh%02dm", hr, mn);
402+
snprintf (buf, buflen, "%dh%02dm", CD_CLAMP(hr), mn);
400403
else
401404
snprintf (buf, buflen, "%dm", mn);
402405
}
@@ -430,8 +433,11 @@ static void drawHamsatVisAlerts (const SBox &box)
430433

431434
// match% badge, fixed width
432435
char mbuf[6];
436+
// clamp to satisfy GCC's -Wformat-truncation value-range analysis (same convention
437+
// as lightning.cpp) -- also just correct, since this is logically always 0-100
438+
#define MP_CLAMP(n) ((n) < 0 ? 0 : (n) > 999 ? 999 : (n))
433439
if (a.match_percent >= 0)
434-
snprintf (mbuf, sizeof(mbuf), "%3d%%", a.match_percent);
440+
snprintf (mbuf, sizeof(mbuf), "%3d%%", MP_CLAMP(a.match_percent));
435441
else
436442
snprintf (mbuf, sizeof(mbuf), " -- ");
437443
uint16_t bg = matchColor (a.match_percent);
@@ -472,7 +478,7 @@ static void drawHamsatPane (const SBox &box)
472478

473479
// subtitle: source + whether personalized
474480
selectFontStyle (LIGHT_FONT, FAST_FONT);
475-
const char *sub = hamsat_key[0] ? "hams.at (has key)" : "hams.at (no key)";
481+
const char *sub = hamsat_key[0] ? "https://hams.at (has key)" : "https://hams.at (no key)";
476482
uint16_t sw = maxStringW ((char*)sub, box.w-2);
477483
tft.setTextColor (hamsat_key[0] ? RA8875_WHITE : RGB565(180,140,60));
478484
tft.setCursor (box.x + (box.w-sw)/2, box.y + SUBTITLE_Y0);
@@ -515,7 +521,7 @@ bool updateHamsat (const SBox &box, bool fresh)
515521
hamsat_ss.scrollToNewest();
516522
drawHamsatPane (box);
517523
} else {
518-
plotMessage (box, RA8875_RED, "hams.at download error");
524+
plotMessage (box, RA8875_RED, "https://hams.at download error");
519525
}
520526

521527
return (ok);
@@ -624,7 +630,7 @@ void drawHamsatOnMap (void)
624630
continue;
625631

626632
DXSpot spot{};
627-
strncpy (spot.tx_call, a.callsign, sizeof(spot.tx_call)-1);
633+
quietStrncpy (spot.tx_call, a.callsign, sizeof(spot.tx_call));
628634
spot.tx_ll = ll;
629635
spot.kHz = a.mhz * 1000.0F; // DXSpot wants kHz, we store MHz
630636

ESPHamClock/plotmgmnt.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,15 @@ static bool paneHasChoice (PlotPane pp, PlotChoice pc)
2626
{
2727
if (plot_rotset[pp] & PLOTBIT(pc))
2828
return (true);
29-
if (PLOTBIT(pc) == 0 && plot_ch[pp] == pc && plot_rotset[pp] == 0)
29+
if (PLOTBIT(pc) == 0 && plot_ch[pp] == pc && plot_rotset[pp] == 0) {
30+
// PANE_0 is restricted to PANE_0_CH_MASK for its normal choices, but that mask can
31+
// never include a solo/unrepresentable choice like this (PLOTBIT(pc)==0 means pc can't
32+
// fit in any 32-bit bitmask, including PANE_0_CH_MASK) -- so it needs its own explicit
33+
// whitelist here instead, or a stale/leftover value could silently reload forever.
34+
if (pp == PANE_0)
35+
return (pc == PLOT_CH_SATACT);
3036
return (true);
37+
}
3138
return (false);
3239
}
3340

@@ -89,8 +96,8 @@ static void setDefaultPaneChoice (PlotPane pp)
8996
plot_ch[pp] = PLOT_CH_NONE;
9097
Serial.println ("PANE: Setting pane 0 to default NONE");
9198
} else {
92-
const PlotChoice ch_defaults[PANE_N] = {PLOT_CH_SSN, PLOT_CH_XRAY, PLOT_CH_SDO};
93-
plot_ch[pp] = ch_defaults[pp];
99+
const PlotChoice ch_defaults[PANE_N-1] = {PLOT_CH_SSN, PLOT_CH_XRAY, PLOT_CH_SDO};
100+
plot_ch[pp] = ch_defaults[pp-1];
94101
plot_rotset[pp] = PLOTBIT(plot_ch[pp]);
95102
Serial.printf ("PANE: Setting pane %d to default %s\n", (int)pp, plot_names[plot_ch[pp]]);
96103
}
@@ -677,6 +684,15 @@ void initPlotPanes()
677684
plot_rotset[i] |= PLOTBIT(plot_ch[i]);
678685

679686
// log and save final arrangement
687+
// N.B. logPaneRotSet() only iterates plot_rotset[] bits, which can never reveal a solo choice
688+
// like PLOT_CH_SATACT (PLOTBIT() is always 0 for it by design) -- print the raw plot_ch[]
689+
// values directly too so a bug placing such a choice on the wrong pane is never invisible.
690+
Serial.printf ("PANE: raw plot_ch[] = %d %d %d %d (%s %s %s %s)\n",
691+
(int)plot_ch[PANE_0], (int)plot_ch[PANE_1], (int)plot_ch[PANE_2], (int)plot_ch[PANE_3],
692+
plot_ch[PANE_0]==PLOT_CH_NONE ? "NONE" : plot_names[plot_ch[PANE_0]],
693+
plot_ch[PANE_1]==PLOT_CH_NONE ? "NONE" : plot_names[plot_ch[PANE_1]],
694+
plot_ch[PANE_2]==PLOT_CH_NONE ? "NONE" : plot_names[plot_ch[PANE_2]],
695+
plot_ch[PANE_3]==PLOT_CH_NONE ? "NONE" : plot_names[plot_ch[PANE_3]]);
680696
for (int i = PANE_0; i < PANE_N; i++)
681697
logPaneRotSet ((PlotPane)i, plot_ch[i]);
682698
savePlotOps();

ESPHamClock/wifi.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,6 +2403,8 @@ void updateWiFi(void)
24032403
break;
24042404

24052405
case PLOT_CH_SATACT:
2406+
if (fresh_redraw[pc])
2407+
Serial.printf ("PANE: entering PLOT_CH_SATACT case for pp=%d (fresh)\n", (int)pp);
24062408
if (t0 >= next_update[pp]) {
24072409
if (updateHamsat(box, fresh_redraw[pc])) {
24082410
next_update[pp] = nextPaneUpdate (pc, 90); // secs, matches hamsat.cpp cache age

0 commit comments

Comments
 (0)