More generic serial port config

This commit is contained in:
Raphael Coeffic
2022-03-20 16:30:58 +01:00
parent b39baa2360
commit b5779f2a6a
27 changed files with 209 additions and 281 deletions
+24 -30
View File
@@ -373,38 +373,32 @@ void RadioHardwarePage::build(FormWindow * window)
}
#endif
#if defined(AUX_SERIAL)
new StaticText(window, grid.getLabelSlot(), STR_AUX_SERIAL_MODE, 0, COLOR_THEME_PRIMARY1);
auto aux =
new Choice(window, grid.getFieldSlot(1, 0), STR_AUX_SERIAL_MODES, 0,
UART_MODE_MAX, GET_DEFAULT(g_eeGeneral.auxSerialMode),
[](int value) {
g_eeGeneral.auxSerialMode = value;
serialInit(SP_AUX1, value);
SET_DIRTY();
});
aux->setAvailableHandler(isAuxModeAvailable);
grid.nextLine();
#endif
bool display_ttl_warning = false;
for (uint8_t port_nr = 0; port_nr < MAX_SERIAL_PORTS; port_nr++) {
auto port = serialGetPort(port_nr);
if (!port) continue;
#if defined(AUX2_SERIAL)
new StaticText(window, grid.getLabelSlot(), STR_AUX2_SERIAL_MODE, 0, COLOR_THEME_PRIMARY1);
auto aux2 =
new Choice(window, grid.getFieldSlot(1, 0), STR_AUX_SERIAL_MODES, 0,
UART_MODE_MAX, GET_DEFAULT(g_eeGeneral.aux2SerialMode),
[](int value) {
g_eeGeneral.aux2SerialMode = value;
serialInit(SP_AUX2, value);
SET_DIRTY();
});
aux2->setAvailableHandler(isAux2ModeAvailable);
grid.nextLine();
#endif
display_ttl_warning = true;
new StaticText(window, grid.getLabelSlot(), STR_AUX_SERIAL_MODE, 0,
COLOR_THEME_PRIMARY1);
auto aux = new Choice(
window, grid.getFieldSlot(1, 0), STR_AUX_SERIAL_MODES, 0, UART_MODE_MAX,
[=]() { return serialGetMode(port_nr); },
[=](int value) {
serialSetMode(port_nr, value);
serialInit(port_nr, value);
SET_DIRTY();
});
aux->setAvailableHandler(
[=](int value) { return isAuxModeAvailable(port_nr, value); });
grid.nextLine();
}
#if defined(AUX_SERIAL) || defined(AUX2_SERIAL)
new StaticText(window, grid.getFieldSlot(1,0), STR_TTL_WARNING, 0, COLOR_THEME_WARNING);
grid.nextLine();
#endif
if (display_ttl_warning) {
new StaticText(window, grid.getFieldSlot(1, 0), STR_TTL_WARNING, 0,
COLOR_THEME_WARNING);
grid.nextLine();
}
// ADC filter
new StaticText(window, grid.getLabelSlot(), STR_JITTER_FILTER, 0, COLOR_THEME_PRIMARY1);
+15 -28
View File
@@ -367,29 +367,18 @@ bool isSwitchAvailable(int swtch, SwitchContext context)
return true;
}
bool isAuxModeAvailable(int mode)
int hasSerialMode(int mode)
{
#if defined(AUX2_SERIAL)
if (mode == UART_MODE_SBUS_TRAINER)
return g_eeGeneral.aux2SerialMode != UART_MODE_SBUS_TRAINER;
#if defined(RADIO_TX16S)
else
return (g_model.trainerData.mode != TRAINER_MODE_MASTER_BATTERY_COMPARTMENT || g_eeGeneral.aux2SerialMode == UART_MODE_SBUS_TRAINER);
#endif
#endif
return true;
for (int p = 0; p < MAX_SERIAL_PORTS; p++) {
if (serialGetMode(p) == mode) return p;
}
return -1;
}
bool isAux2ModeAvailable(int mode)
bool isAuxModeAvailable(uint8_t port_nr, int mode)
{
#if defined(AUX_SERIAL)
if (mode == UART_MODE_SBUS_TRAINER)
return g_eeGeneral.auxSerialMode != UART_MODE_SBUS_TRAINER;
#if defined(RADIO_TX16S)
else
return (g_model.trainerData.mode != TRAINER_MODE_MASTER_BATTERY_COMPARTMENT || g_eeGeneral.auxSerialMode == UART_MODE_SBUS_TRAINER);
#endif
#endif
auto p = hasSerialMode(mode);
if (p >= 0 && p != port_nr) return false;
return true;
}
@@ -755,7 +744,8 @@ bool isRfProtocolAvailable(int protocol)
bool isTelemetryProtocolAvailable(int protocol)
{
#if defined(PCBTARANIS)
if (protocol == PROTOCOL_TELEMETRY_FRSKY_D_SECONDARY && g_eeGeneral.auxSerialMode != UART_MODE_TELEMETRY) {
if (protocol == PROTOCOL_TELEMETRY_FRSKY_D_SECONDARY &&
hasSerialMode(UART_MODE_TELEMETRY) < 0) {
return false;
}
#endif
@@ -803,16 +793,13 @@ bool isTrainerModeAvailable(int mode)
}
#endif
#if defined(RADIO_TX16S) && defined(TRAINER_BATTERY_COMPARTMENT)
if (mode == TRAINER_MODE_MASTER_BATTERY_COMPARTMENT)
return (g_eeGeneral.auxSerialMode == UART_MODE_SBUS_TRAINER || g_eeGeneral.aux2SerialMode == UART_MODE_SBUS_TRAINER);
#elif defined(PCBTARANIS) && !defined(TRAINER_BATTERY_COMPARTMENT)
if (mode == TRAINER_MODE_MASTER_BATTERY_COMPARTMENT)
if (mode == TRAINER_MODE_MASTER_BATTERY_COMPARTMENT) {
#if defined(TRAINER_BATTERY_COMPARTMENT)
return hasSerialMode(UART_MODE_SBUS_TRAINER) >= 0;
#else
return false;
#elif defined(PCBTARANIS)
if (mode == TRAINER_MODE_MASTER_BATTERY_COMPARTMENT)
return g_eeGeneral.auxSerialMode == UART_MODE_SBUS_TRAINER;
#endif
}
#if defined(BLUETOOTH) && !defined(PCBX9E)
if (g_eeGeneral.bluetoothMode != BLUETOOTH_TRAINER && (mode == TRAINER_MODE_MASTER_BLUETOOTH || mode == TRAINER_MODE_SLAVE_BLUETOOTH))
+2 -2
View File
@@ -86,8 +86,8 @@ bool isSourceAvailableInCustomSwitches(int source);
bool isSourceAvailableInResetSpecialFunction(int index);
bool isSourceAvailableInGlobalResetSpecialFunction(int index);
bool isSwitchAvailable(int swtch, SwitchContext context);
bool isAuxModeAvailable(int mode);
bool isAux2ModeAvailable(int mode);
bool isAuxModeAvailable(uint8_t port_nr, int mode);
int hasSerialMode(int mode);
bool isSwitchAvailableInLogicalSwitches(int swtch);
bool isSwitchAvailableInCustomFunctions(int swtch);
bool isSwitchAvailableInMixes(int swtch);