From d0da9ac73c45089d5f4e6d30a82a33a813a9b56c Mon Sep 17 00:00:00 2001 From: John Flinchbaugh Date: Tue, 7 Jan 2025 23:10:48 -0500 Subject: [PATCH 1/9] fix #322: scale bandscope for any number of samples retain stretch of bars for short ranges, but after 128, scale 1:1 to always fill the width of the screen. --- app/spectrum.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/spectrum.c b/app/spectrum.c index 57a7647..93fedeb 100644 --- a/app/spectrum.c +++ b/app/spectrum.c @@ -870,13 +870,14 @@ uint8_t Rssi2Y(uint16_t rssi) #ifdef ENABLE_FEAT_F4HWN_SPECTRUM static void DrawSpectrum() { + uint16_t steps = GetStepsCount(); uint8_t ox = 0; for (uint8_t i = 0; i < 128; ++i) { uint16_t rssi = rssiHistory[i >> settings.stepsCount]; if (rssi != RSSI_MAX_VALUE) { - uint8_t x = i * 128 / GetStepsCount(); + uint8_t x = i * 128 / ((steps > 128) ? 128 : steps) + 1; for (uint8_t xx = ox; xx < x; xx++) { DrawVLine(Rssi2Y(rssi), DrawingEndY, xx, true); From bc1a765c685d9b0ae09499809bf25f8a144fdd1b Mon Sep 17 00:00:00 2001 From: John Flinchbaugh Date: Wed, 8 Jan 2025 08:00:53 -0500 Subject: [PATCH 2/9] shift the graph to center large bars --- app/spectrum.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/spectrum.c b/app/spectrum.c index 93fedeb..369b2be 100644 --- a/app/spectrum.c +++ b/app/spectrum.c @@ -871,13 +871,15 @@ uint8_t Rssi2Y(uint16_t rssi) static void DrawSpectrum() { uint16_t steps = GetStepsCount(); + uint16_t scale = ((steps > 128) ? 128 : steps); + uint16_t shift = 64 / steps + 1; uint8_t ox = 0; for (uint8_t i = 0; i < 128; ++i) { uint16_t rssi = rssiHistory[i >> settings.stepsCount]; if (rssi != RSSI_MAX_VALUE) { - uint8_t x = i * 128 / ((steps > 128) ? 128 : steps) + 1; + uint8_t x = i * 128 / scale + shift; for (uint8_t xx = ox; xx < x; xx++) { DrawVLine(Rssi2Y(rssi), DrawingEndY, xx, true); From 7bcb372f5c50183b13dde49ed164583fed525b6c Mon Sep 17 00:00:00 2001 From: John Flinchbaugh Date: Wed, 8 Jan 2025 08:02:53 -0500 Subject: [PATCH 3/9] indent --- app/spectrum.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/spectrum.c b/app/spectrum.c index 369b2be..bc20851 100644 --- a/app/spectrum.c +++ b/app/spectrum.c @@ -879,7 +879,7 @@ uint8_t Rssi2Y(uint16_t rssi) uint16_t rssi = rssiHistory[i >> settings.stepsCount]; if (rssi != RSSI_MAX_VALUE) { - uint8_t x = i * 128 / scale + shift; + uint8_t x = i * 128 / scale + shift; for (uint8_t xx = ox; xx < x; xx++) { DrawVLine(Rssi2Y(rssi), DrawingEndY, xx, true); From 911200d0a04eec33c6746a1a1d513cad473ff248 Mon Sep 17 00:00:00 2001 From: John Flinchbaugh Date: Wed, 8 Jan 2025 08:04:07 -0500 Subject: [PATCH 4/9] unneeded parens --- app/spectrum.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/spectrum.c b/app/spectrum.c index bc20851..79bab35 100644 --- a/app/spectrum.c +++ b/app/spectrum.c @@ -871,7 +871,7 @@ uint8_t Rssi2Y(uint16_t rssi) static void DrawSpectrum() { uint16_t steps = GetStepsCount(); - uint16_t scale = ((steps > 128) ? 128 : steps); + uint16_t scale = (steps > 128) ? 128 : steps; uint16_t shift = 64 / steps + 1; uint8_t ox = 0; for (uint8_t i = 0; i < 128; ++i) From be7d229b3d2ea1452db3203d23466ef698109f26 Mon Sep 17 00:00:00 2001 From: John Flinchbaugh Date: Wed, 8 Jan 2025 08:12:36 -0500 Subject: [PATCH 5/9] better var names + comment --- app/spectrum.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/spectrum.c b/app/spectrum.c index 79bab35..568ea0c 100644 --- a/app/spectrum.c +++ b/app/spectrum.c @@ -871,15 +871,15 @@ uint8_t Rssi2Y(uint16_t rssi) static void DrawSpectrum() { uint16_t steps = GetStepsCount(); - uint16_t scale = (steps > 128) ? 128 : steps; - uint16_t shift = 64 / steps + 1; + uint16_t bars = (steps > 128) ? 128 : steps; + uint16_t shift_graph = 64 / steps + 1; // to center bar on freq marker uint8_t ox = 0; for (uint8_t i = 0; i < 128; ++i) { uint16_t rssi = rssiHistory[i >> settings.stepsCount]; if (rssi != RSSI_MAX_VALUE) { - uint8_t x = i * 128 / scale + shift; + uint8_t x = i * 128 / bars + shift_graph; for (uint8_t xx = ox; xx < x; xx++) { DrawVLine(Rssi2Y(rssi), DrawingEndY, xx, true); From 87c354a2eeee0af623bda2123354e49f3cec4670 Mon Sep 17 00:00:00 2001 From: John Flinchbaugh Date: Wed, 8 Jan 2025 08:17:44 -0500 Subject: [PATCH 6/9] smaller? types. it didn't change image size --- app/spectrum.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/spectrum.c b/app/spectrum.c index 568ea0c..b1b4826 100644 --- a/app/spectrum.c +++ b/app/spectrum.c @@ -871,8 +871,8 @@ uint8_t Rssi2Y(uint16_t rssi) static void DrawSpectrum() { uint16_t steps = GetStepsCount(); - uint16_t bars = (steps > 128) ? 128 : steps; - uint16_t shift_graph = 64 / steps + 1; // to center bar on freq marker + uint8_t bars = (steps > 128) ? 128 : steps; + uint8_t shift_graph = 64 / steps + 1; // to center bar on freq marker uint8_t ox = 0; for (uint8_t i = 0; i < 128; ++i) { From f75f65f6c28f28548ceccdbe84ebe9b44e033320 Mon Sep 17 00:00:00 2001 From: John Flinchbaugh Date: Wed, 8 Jan 2025 08:25:17 -0500 Subject: [PATCH 7/9] comments --- app/spectrum.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/spectrum.c b/app/spectrum.c index b1b4826..602e06c 100644 --- a/app/spectrum.c +++ b/app/spectrum.c @@ -871,8 +871,11 @@ uint8_t Rssi2Y(uint16_t rssi) static void DrawSpectrum() { uint16_t steps = GetStepsCount(); + // for larger numbers of samples, max at 128 to correctly draw uint8_t bars = (steps > 128) ? 128 : steps; - uint8_t shift_graph = 64 / steps + 1; // to center bar on freq marker + // to center bar on freq marker + uint8_t shift_graph = 64 / steps + 1; + uint8_t ox = 0; for (uint8_t i = 0; i < 128; ++i) { From b8900863e60179daabd9df3590939d331db12fbc Mon Sep 17 00:00:00 2001 From: John Flinchbaugh Date: Wed, 8 Jan 2025 08:27:10 -0500 Subject: [PATCH 8/9] comments --- app/spectrum.c | 1 + 1 file changed, 1 insertion(+) diff --git a/app/spectrum.c b/app/spectrum.c index 602e06c..08e340f 100644 --- a/app/spectrum.c +++ b/app/spectrum.c @@ -882,6 +882,7 @@ uint8_t Rssi2Y(uint16_t rssi) uint16_t rssi = rssiHistory[i >> settings.stepsCount]; if (rssi != RSSI_MAX_VALUE) { + // stretch bars to fill the screen width uint8_t x = i * 128 / bars + shift_graph; for (uint8_t xx = ox; xx < x; xx++) { From 85bdc60c5b1638e0364ab27156ca6753b7a8d521 Mon Sep 17 00:00:00 2001 From: John Flinchbaugh Date: Wed, 8 Jan 2025 08:29:04 -0500 Subject: [PATCH 9/9] samples --- app/spectrum.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/spectrum.c b/app/spectrum.c index 08e340f..6a0e799 100644 --- a/app/spectrum.c +++ b/app/spectrum.c @@ -871,9 +871,9 @@ uint8_t Rssi2Y(uint16_t rssi) static void DrawSpectrum() { uint16_t steps = GetStepsCount(); - // for larger numbers of samples, max at 128 to correctly draw + // max bars at 128 to correctly draw larger numbers of samples uint8_t bars = (steps > 128) ? 128 : steps; - // to center bar on freq marker + // shift to center bar on freq marker uint8_t shift_graph = 64 / steps + 1; uint8_t ox = 0;