fix(bw): Channel Monitor view not working correctly on startup (#4490)

This commit is contained in:
philmoz
2024-01-03 09:45:13 +10:00
committed by GitHub
parent 7d18edc48d
commit 17fb2fc992
3 changed files with 29 additions and 28 deletions
+13 -10
View File
@@ -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) #define EVT_KEY_PREVIOUS_PAGE EVT_KEY_BREAK(KEY_LEFT)
#endif #endif
struct ViewChannelsState {
bool longNames;
bool mixersView;
};
static ViewChannelsState viewChannels = { false, false };
void menuChannelsViewCommon(event_t event) void menuChannelsViewCommon(event_t event)
{ {
bool newLongNames = false; bool newLongNames = false;
@@ -61,19 +68,15 @@ void menuChannelsViewCommon(event_t event)
uint8_t ch; uint8_t ch;
switch (event) { switch (event) {
case EVT_ENTRY:
memclear(&reusableBuffer.viewChannels, sizeof(reusableBuffer.viewChannels));
break;
case EVT_KEY_BREAK(KEY_ENTER): case EVT_KEY_BREAK(KEY_ENTER):
reusableBuffer.viewChannels.mixersView = !reusableBuffer.viewChannels.mixersView; viewChannels.mixersView = !viewChannels.mixersView;
break; break;
} }
ch = 8 * (g_eeGeneral.view / ALTERNATE_VIEW); ch = 8 * (g_eeGeneral.view / ALTERNATE_VIEW);
// Screen title // 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); lcdInvertLine(0);
int16_t limits = 512 * 2; int16_t limits = 512 * 2;
@@ -82,13 +85,13 @@ void menuChannelsViewCommon(event_t event)
for (uint8_t line = 0; line < 8; line++) { for (uint8_t line = 0; line < 8; line++) {
LimitData * ld = limitAddress(ch); LimitData * ld = limitAddress(ch);
const uint8_t y = 9 + line * 7; 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); const uint8_t lenLabel = ZLEN(g_model.limitData[ch].name);
// Channel name if present, number if not // Channel name if present, number if not
if (lenLabel > 0) { if (lenLabel > 0) {
if (lenLabel > 4) 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); lcdDrawSizedText(CHANNEL_NAME_OFFSET, y, g_model.limitData[ch].name, sizeof(g_model.limitData[ch].name), SMLSIZE);
} }
else { else {
@@ -107,7 +110,7 @@ void menuChannelsViewCommon(event_t event)
// Gauge // Gauge
drawGauge(CHANNEL_GAUGE_OFFSET, y, CHANNEL_BAR_WIDTH, 6, val, limits); drawGauge(CHANNEL_GAUGE_OFFSET, y, CHANNEL_BAR_WIDTH, 6, val, limits);
if (!reusableBuffer.viewChannels.mixersView) { if (!viewChannels.mixersView) {
// Properties // Properties
#if defined(OVERRIDE_CHANNEL_FUNCTION) #if defined(OVERRIDE_CHANNEL_FUNCTION)
if (safetyCh[ch] != OVERRIDE_CHANNEL_UNDEFINED) if (safetyCh[ch] != OVERRIDE_CHANNEL_UNDEFINED)
@@ -122,7 +125,7 @@ void menuChannelsViewCommon(event_t event)
++ch; ++ch;
} }
reusableBuffer.viewChannels.longNames = newLongNames; viewChannels.longNames = newLongNames;
} }
void menuChannelsView(event_t event) void menuChannelsView(event_t event)
+16 -12
View File
@@ -21,10 +21,18 @@
#include "opentx.h" #include "opentx.h"
struct ViewChannelsState {
bool longNames;
bool secondPage;
bool mixersView;
};
static ViewChannelsState viewChannels = { false, false, false };
void menuChannelsView(event_t event) void menuChannelsView(event_t event)
{ {
uint8_t ch = 0; uint8_t ch = 0;
uint8_t wbar = (reusableBuffer.viewChannels.longNames ? 54 : 64); uint8_t wbar = (viewChannels.longNames ? 54 : 64);
int16_t limits = 512 * 2; int16_t limits = 512 * 2;
if (g_eeGeneral.ppmunit == PPM_PERCENT_PREC1) { if (g_eeGeneral.ppmunit == PPM_PERCENT_PREC1) {
@@ -32,10 +40,6 @@ void menuChannelsView(event_t event)
} }
switch(event) { switch(event) {
case EVT_ENTRY:
memclear(&reusableBuffer.viewChannels, sizeof(reusableBuffer.viewChannels));
break;
case EVT_KEY_BREAK(KEY_EXIT): case EVT_KEY_BREAK(KEY_EXIT):
popMenu(); popMenu();
break; break;
@@ -44,23 +48,23 @@ void menuChannelsView(event_t event)
case EVT_ROTARY_RIGHT: case EVT_ROTARY_RIGHT:
case EVT_KEY_FIRST(KEY_PLUS): case EVT_KEY_FIRST(KEY_PLUS):
case EVT_KEY_FIRST(KEY_MINUS): case EVT_KEY_FIRST(KEY_MINUS):
reusableBuffer.viewChannels.secondPage = !reusableBuffer.viewChannels.secondPage; viewChannels.secondPage = !viewChannels.secondPage;
break; break;
case EVT_KEY_FIRST(KEY_ENTER): case EVT_KEY_FIRST(KEY_ENTER):
reusableBuffer.viewChannels.mixersView = !reusableBuffer.viewChannels.mixersView; viewChannels.mixersView = !viewChannels.mixersView;
break; break;
} }
if (reusableBuffer.viewChannels.secondPage) if (viewChannels.secondPage)
ch = 16; 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 limits *= 2; // this could be handled nicer, but slower, by checking actual range for this mixer
else if (g_model.extendedLimits) else if (g_model.extendedLimits)
limits *= LIMIT_EXT_PERCENT / 100; 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); lcdInvertLine(0);
// Column separator // Column separator
@@ -73,13 +77,13 @@ void menuChannelsView(event_t event)
// Channels // Channels
for (uint8_t line=0; line < 8; line++) { for (uint8_t line=0; line < 8; line++) {
const uint8_t y = 9 + line * 7; 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); const uint8_t lenLabel = ZLEN(g_model.limitData[ch].name);
// Channel name if present, number if not // Channel name if present, number if not
if (lenLabel > 0) { if (lenLabel > 0) {
if (lenLabel > 4) 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); lcdDrawSizedText(x+1-ofs, y, g_model.limitData[ch].name, sizeof(g_model.limitData[ch].name), ZCHAR | SMLSIZE);
} }
else { else {
-6
View File
@@ -805,12 +805,6 @@ union ReusableBuffer
} viewText; } viewText;
#endif #endif
struct {
bool longNames;
bool secondPage;
bool mixersView;
} viewChannels;
struct { struct {
uint8_t maxNameLen; uint8_t maxNameLen;
} modelFailsafe; } modelFailsafe;