fix(color): spectrum analyzer on non 480x272 screens (#7324)

This commit is contained in:
3djc
2026-04-28 11:50:22 +10:00
committed by GitHub
parent ef3008bb37
commit c51728154b
2 changed files with 22 additions and 42 deletions
@@ -32,6 +32,15 @@ constexpr coord_t SPECTRUM_HEIGHT = LCD_H - EdgeTxStyles::MENU_HEADER_HEIGHT -
SCALE_HEIGHT - SCALE_HEIGHT -
EdgeTxStyles::UI_ELEMENT_HEIGHT; EdgeTxStyles::UI_ELEMENT_HEIGHT;
// Empirical full-scale value of bars/max/peak samples. Used to map sample
// values to chart pixels so bars fill the available height on any LCD.
constexpr uint8_t SPECTRUM_FULL_SCALE = 90;
static inline coord_t scaleSample(uint16_t value)
{
return (value * SPECTRUM_HEIGHT) / SPECTRUM_FULL_SCALE;
}
template <uint8_t CNT> template <uint8_t CNT>
coord_t getAverage(const uint8_t* value) coord_t getAverage(const uint8_t* value)
{ {
@@ -39,16 +48,14 @@ coord_t getAverage(const uint8_t* value)
for (uint8_t i = 0; i < CNT; i++) { for (uint8_t i = 0; i < CNT; i++) {
sum += value[i]; sum += value[i];
} }
if (SPECTRUM_HEIGHT > 300) sum = sum * 2; return scaleSample(sum / CNT);
return sum / CNT;
} }
template <> template <>
coord_t getAverage<4>(const uint8_t* value) coord_t getAverage<4>(const uint8_t* value)
{ {
uint16_t sum = value[0] + value[1] + value[2] + value[3]; uint16_t sum = value[0] + value[1] + value[2] + value[3];
if (SPECTRUM_HEIGHT > 300) sum = sum * 2; return scaleSample(sum / 4);
return sum / 4;
} }
class SpectrumFooterWindow : public Window class SpectrumFooterWindow : public Window
@@ -238,19 +245,17 @@ class SpectrumWindow : public Window
lv_coord_t yv = lv_coord_t yv =
SCALE_TOP - 1 - SCALE_TOP - 1 -
limit<int>(0, limit<int>(0,
getAverage<step>(&reusableBuffer.spectrumAnalyser.bars[x]) getAverage<step>(&reusableBuffer.spectrumAnalyser.bars[x]),
<< 1,
SCALE_TOP); SCALE_TOP);
lv_coord_t max_yv = lv_coord_t max_yv =
SCALE_TOP - 1 - SCALE_TOP - 1 -
limit<int>( limit<int>(
0, getAverage<step>(&reusableBuffer.spectrumAnalyser.max[x]) << 1, 0, getAverage<step>(&reusableBuffer.spectrumAnalyser.max[x]),
SCALE_TOP); SCALE_TOP);
lv_coord_t peak_yv = lv_coord_t peak_yv =
SCALE_TOP - 1 - SCALE_TOP - 1 -
limit<int>(0, limit<int>(0,
getAverage<step>(&reusableBuffer.spectrumAnalyser.peak[x]) getAverage<step>(&reusableBuffer.spectrumAnalyser.peak[x]),
<< 1,
SCALE_TOP); SCALE_TOP);
maxPts[i] = {x, max_yv}; maxPts[i] = {x, max_yv};
+8 -33
View File
@@ -160,28 +160,14 @@ static void processMultiScannerPacket(const uint8_t *data, const uint8_t moduleI
for (uint8_t channel = 0; channel <5; channel++) { for (uint8_t channel = 0; channel <5; channel++) {
uint8_t power = max<int>(0,(data[channel+1] - 34) >> 1); // remove everything below -120dB uint8_t power = max<int>(0,(data[channel+1] - 34) >> 1); // remove everything below -120dB
#if LCD_W == 480 // Spread the (MULTI_SCANNER_MAX_CHANNEL + 1) channels across the full
coord_t x = cur_channel*2; // chart width so the spectrum fills the screen on any LCD size.
if (x < LCD_W) { coord_t x_start =
reusableBuffer.spectrumAnalyser.bars[x] = power; ((coord_t)cur_channel * LCD_W) / (MULTI_SCANNER_MAX_CHANNEL + 1);
if (x + 1 < LCD_W) { coord_t x_end = ((coord_t)(cur_channel + 1) * LCD_W) /
reusableBuffer.spectrumAnalyser.bars[x + 1] = power; (MULTI_SCANNER_MAX_CHANNEL + 1);
} if (x_end <= x_start) x_end = x_start + 1;
if (power > reusableBuffer.spectrumAnalyser.max[x]) { for (coord_t x = x_start; x < x_end && x < LCD_W; x++) {
reusableBuffer.spectrumAnalyser.max[x] = power;
if (x + 1 < LCD_W) {
reusableBuffer.spectrumAnalyser.max[x + 1] = power;
}
}
if (power > reusableBuffer.spectrumAnalyser.peak[x]) {
reusableBuffer.spectrumAnalyser.peak[x] = power;
if (x + 1 < LCD_W) {
reusableBuffer.spectrumAnalyser.peak[x + 1] = power;
}
}
#elif LCD_W == 212
coord_t x = cur_channel;
if (x < LCD_W) {
reusableBuffer.spectrumAnalyser.bars[x] = power; reusableBuffer.spectrumAnalyser.bars[x] = power;
if (power > reusableBuffer.spectrumAnalyser.max[x]) { if (power > reusableBuffer.spectrumAnalyser.max[x]) {
reusableBuffer.spectrumAnalyser.max[x] = power; reusableBuffer.spectrumAnalyser.max[x] = power;
@@ -189,17 +175,6 @@ static void processMultiScannerPacket(const uint8_t *data, const uint8_t moduleI
if (power > reusableBuffer.spectrumAnalyser.peak[x]) { if (power > reusableBuffer.spectrumAnalyser.peak[x]) {
reusableBuffer.spectrumAnalyser.peak[x] = power; reusableBuffer.spectrumAnalyser.peak[x] = power;
} }
#else
coord_t x = cur_channel / 2 + 1;
if (x < LCD_W) {
reusableBuffer.spectrumAnalyser.bars[x] = power;
if (power > reusableBuffer.spectrumAnalyser.max[x]) {
reusableBuffer.spectrumAnalyser.max[x] = power;
}
if (power > reusableBuffer.spectrumAnalyser.peak[x]) {
reusableBuffer.spectrumAnalyser.peak[x] = power;
}
#endif
} }
if (++cur_channel > MULTI_SCANNER_MAX_CHANNEL) if (++cur_channel > MULTI_SCANNER_MAX_CHANNEL)
cur_channel = 0; cur_channel = 0;