From 17fb2fc99244481f57abf130c0e01183c10b59d8 Mon Sep 17 00:00:00 2001 From: philmoz Date: Wed, 3 Jan 2024 10:45:13 +1100 Subject: [PATCH] fix(bw): Channel Monitor view not working correctly on startup (#4490) --- radio/src/gui/128x64/view_channels.cpp | 23 ++++++++++++--------- radio/src/gui/212x64/view_channels.cpp | 28 +++++++++++++++----------- radio/src/opentx.h | 6 ------ 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/radio/src/gui/128x64/view_channels.cpp b/radio/src/gui/128x64/view_channels.cpp index 904979c34..2d2b339ca 100644 --- a/radio/src/gui/128x64/view_channels.cpp +++ b/radio/src/gui/128x64/view_channels.cpp @@ -54,6 +54,13 @@ constexpr coord_t CHANNEL_PROPERTIES_OFFSET = CHANNEL_GAUGE_OFFSET + CHANNEL_BAR #define EVT_KEY_PREVIOUS_PAGE EVT_KEY_BREAK(KEY_LEFT) #endif +struct ViewChannelsState { + bool longNames; + bool mixersView; +}; + +static ViewChannelsState viewChannels = { false, false }; + void menuChannelsViewCommon(event_t event) { bool newLongNames = false; @@ -61,19 +68,15 @@ void menuChannelsViewCommon(event_t event) uint8_t ch; switch (event) { - case EVT_ENTRY: - memclear(&reusableBuffer.viewChannels, sizeof(reusableBuffer.viewChannels)); - break; - case EVT_KEY_BREAK(KEY_ENTER): - reusableBuffer.viewChannels.mixersView = !reusableBuffer.viewChannels.mixersView; + viewChannels.mixersView = !viewChannels.mixersView; break; } ch = 8 * (g_eeGeneral.view / ALTERNATE_VIEW); // Screen title - lcdDrawText(LCD_W / 2, 0, reusableBuffer.viewChannels.mixersView ? STR_MIXERS_MONITOR : STR_CHANNELS_MONITOR, CENTERED); + lcdDrawText(LCD_W / 2, 0, viewChannels.mixersView ? STR_MIXERS_MONITOR : STR_CHANNELS_MONITOR, CENTERED); lcdInvertLine(0); int16_t limits = 512 * 2; @@ -82,13 +85,13 @@ void menuChannelsViewCommon(event_t event) for (uint8_t line = 0; line < 8; line++) { LimitData * ld = limitAddress(ch); const uint8_t y = 9 + line * 7; - const int32_t val = reusableBuffer.viewChannels.mixersView ? ex_chans[ch] : channelOutputs[ch]; + const int32_t val = viewChannels.mixersView ? ex_chans[ch] : channelOutputs[ch]; const uint8_t lenLabel = ZLEN(g_model.limitData[ch].name); // Channel name if present, number if not if (lenLabel > 0) { if (lenLabel > 4) - reusableBuffer.viewChannels.longNames = true; + viewChannels.longNames = true; lcdDrawSizedText(CHANNEL_NAME_OFFSET, y, g_model.limitData[ch].name, sizeof(g_model.limitData[ch].name), SMLSIZE); } else { @@ -107,7 +110,7 @@ void menuChannelsViewCommon(event_t event) // Gauge drawGauge(CHANNEL_GAUGE_OFFSET, y, CHANNEL_BAR_WIDTH, 6, val, limits); - if (!reusableBuffer.viewChannels.mixersView) { + if (!viewChannels.mixersView) { // Properties #if defined(OVERRIDE_CHANNEL_FUNCTION) if (safetyCh[ch] != OVERRIDE_CHANNEL_UNDEFINED) @@ -122,7 +125,7 @@ void menuChannelsViewCommon(event_t event) ++ch; } - reusableBuffer.viewChannels.longNames = newLongNames; + viewChannels.longNames = newLongNames; } void menuChannelsView(event_t event) diff --git a/radio/src/gui/212x64/view_channels.cpp b/radio/src/gui/212x64/view_channels.cpp index 40495df2f..2972eb6f7 100644 --- a/radio/src/gui/212x64/view_channels.cpp +++ b/radio/src/gui/212x64/view_channels.cpp @@ -21,10 +21,18 @@ #include "opentx.h" +struct ViewChannelsState { + bool longNames; + bool secondPage; + bool mixersView; +}; + +static ViewChannelsState viewChannels = { false, false, false }; + void menuChannelsView(event_t event) { uint8_t ch = 0; - uint8_t wbar = (reusableBuffer.viewChannels.longNames ? 54 : 64); + uint8_t wbar = (viewChannels.longNames ? 54 : 64); int16_t limits = 512 * 2; if (g_eeGeneral.ppmunit == PPM_PERCENT_PREC1) { @@ -32,10 +40,6 @@ void menuChannelsView(event_t event) } switch(event) { - case EVT_ENTRY: - memclear(&reusableBuffer.viewChannels, sizeof(reusableBuffer.viewChannels)); - break; - case EVT_KEY_BREAK(KEY_EXIT): popMenu(); break; @@ -44,23 +48,23 @@ void menuChannelsView(event_t event) case EVT_ROTARY_RIGHT: case EVT_KEY_FIRST(KEY_PLUS): case EVT_KEY_FIRST(KEY_MINUS): - reusableBuffer.viewChannels.secondPage = !reusableBuffer.viewChannels.secondPage; + viewChannels.secondPage = !viewChannels.secondPage; break; case EVT_KEY_FIRST(KEY_ENTER): - reusableBuffer.viewChannels.mixersView = !reusableBuffer.viewChannels.mixersView; + viewChannels.mixersView = !viewChannels.mixersView; break; } - if (reusableBuffer.viewChannels.secondPage) + if (viewChannels.secondPage) ch = 16; - if (reusableBuffer.viewChannels.mixersView) + if (viewChannels.mixersView) limits *= 2; // this could be handled nicer, but slower, by checking actual range for this mixer else if (g_model.extendedLimits) limits *= LIMIT_EXT_PERCENT / 100; - lcdDrawText(LCD_W / 2, 0, reusableBuffer.viewChannels.mixersView ? STR_MIXERS_MONITOR : STR_CHANNELS_MONITOR, CENTERED); + lcdDrawText(LCD_W / 2, 0, viewChannels.mixersView ? STR_MIXERS_MONITOR : STR_CHANNELS_MONITOR, CENTERED); lcdInvertLine(0); // Column separator @@ -73,13 +77,13 @@ void menuChannelsView(event_t event) // Channels for (uint8_t line=0; line < 8; line++) { const uint8_t y = 9 + line * 7; - const int32_t val = reusableBuffer.viewChannels.mixersView ? ex_chans[ch] : channelOutputs[ch]; + const int32_t val = viewChannels.mixersView ? ex_chans[ch] : channelOutputs[ch]; const uint8_t lenLabel = ZLEN(g_model.limitData[ch].name); // Channel name if present, number if not if (lenLabel > 0) { if (lenLabel > 4) - reusableBuffer.viewChannels.longNames = true; + viewChannels.longNames = true; lcdDrawSizedText(x+1-ofs, y, g_model.limitData[ch].name, sizeof(g_model.limitData[ch].name), ZCHAR | SMLSIZE); } else { diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 3387a29fe..e9119dae6 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -805,12 +805,6 @@ union ReusableBuffer } viewText; #endif - struct { - bool longNames; - bool secondPage; - bool mixersView; - } viewChannels; - struct { uint8_t maxNameLen; } modelFailsafe;