[Serial] Simplify API

This commit is contained in:
Ton Huisman
2026-07-17 23:32:12 +02:00
parent 0144de4e47
commit e4c6c93d61
5 changed files with 21 additions and 28 deletions
+1 -1
View File
@@ -115,7 +115,7 @@ void C018_ConfigStruct::webform_load(C018_data_struct *C018_data) {
addTableSeparator(F("Serial Port Configuration"), 2, 3);
serialHelper_webformLoad(port, rxpin, txpin, true);
serialHelper_webformLoad(port, rxpin, txpin, INCLUDE_SW_SERIAL | INCLUDE_HW_SERIAL | INCLUDE_I2C_SERIAL);
// Show serial port selection
addFormPinSelect(PinSelectPurpose::Generic_input, formatGpioName_serialRX(false), F("taskdevicepin1"), rxpin);
+1 -1
View File
@@ -121,7 +121,7 @@ void C023_ConfigStruct::webform_load(C023_data_struct *C023_data) {
addTableSeparator(F("Serial Port Configuration"), 2, 3);
serialHelper_webformLoad(port, rxpin, txpin, true);
serialHelper_webformLoad(port, rxpin, txpin, INCLUDE_SW_SERIAL | INCLUDE_HW_SERIAL | INCLUDE_I2C_SERIAL);
// Show serial port selection
addFormPinSelect(PinSelectPurpose::Generic_input, formatGpioName_serialRX(false), F("taskdevicepin1"), rxpin);
+11 -16
View File
@@ -178,28 +178,24 @@ void serialHelper_addI2CuartSelectors(int address, int channel, String id, Strin
#endif // ifndef DISABLE_SC16IS752_Serial
void serialHelper_webformLoad(struct EventStruct *event) {
serialHelper_webformLoad(event, true);
serialHelper_webformLoad(event, INCLUDE_SW_SERIAL | INCLUDE_HW_SERIAL | INCLUDE_I2C_SERIAL);
}
// These helper functions were made to create a generic interface to setup serial port config.
// See issue #2343 and Pull request https://github.com/letscontrolit/ESPEasy/pull/2352
// For now P020 and P044 have been reverted to make them work again.
void serialHelper_webformLoad(struct EventStruct *event, bool allowSoftwareSerial, bool allowI2CSerial, bool allowCDCSerial) {
void serialHelper_webformLoad(struct EventStruct *event, uint8_t allowedSerial) {
serialHelper_webformLoad(static_cast<ESPEasySerialPort>(CONFIG_PORT),
serialHelper_getRxPin(event),
serialHelper_getTxPin(event),
allowSoftwareSerial,
allowI2CSerial,
allowCDCSerial);
allowedSerial);
}
void serialHelper_webformLoad(ESPEasySerialPort port, int rxPinDef, int txPinDef, bool allowSoftwareSerial, bool allowI2CSerial, bool allowCDCSerial) {
void serialHelper_webformLoad(ESPEasySerialPort port, int rxPinDef, int txPinDef, uint8_t allowedSerial) {
serialHelper_webformLoad(port,
rxPinDef,
txPinDef,
allowSoftwareSerial,
allowI2CSerial,
allowCDCSerial,
allowedSerial,
F("Serial Port"),
F("serPort"),
EMPTY_STRING,
@@ -210,9 +206,7 @@ void serialHelper_webformLoad(ESPEasySerialPort port, int rxPinDef, int txPinDef
void serialHelper_webformLoad(ESPEasySerialPort port,
int rxPinDef,
int txPinDef,
bool allowSoftwareSerial,
bool allowI2CSerial,
bool allowCDCSerial,
uint8_t allowedSerial,
String label,
String id,
String pin1Var,
@@ -372,16 +366,17 @@ void serialHelper_webformLoad(ESPEasySerialPort port,
}
#endif
options[i] = option;
if (!allowSoftwareSerial && (serType == ESPEasySerialPort::software)) {
// FIXME tonhuisman Check for INCLUDE_HW_SERIAL not implemented yet
if ((allowedSerial & INCLUDE_SW_SERIAL) && (serType == ESPEasySerialPort::software)) {
attr[i] = F("disabled");
}
#if USES_I2C_SC16IS752
if (!allowI2CSerial && (serType == ESPEasySerialPort::sc16is752)) {
if ((allowedSerial & INCLUDE_I2C_SERIAL) && (serType == ESPEasySerialPort::sc16is752)) {
attr[i] = F("disabled");
}
#endif // if USES_I2C_SC16IS752
#if USES_HWCDC || USES_USBCDC
if (!allowCDCSerial
if ((allowedSerial & INCLUDE_CDC_SERIAL)
#if USES_HWCDC
&& (serType == ESPEasySerialPort::usb_hw_cdc)
#endif // if USES_HWCDC
@@ -407,7 +402,7 @@ void serialHelper_webformLoad(ESPEasySerialPort port,
// static_cast<int>(ESPeasySerialType::getSerialType(port, rxPinDef, txPinDef)));
static_cast<int>(port));
#if USES_I2C_SC16IS752
if (allowI2CSerial) {
if (allowedSerial & INCLUDE_I2C_SERIAL) {
serialHelper_addI2CuartSelectors(rxPinDef, txPinDef, i2c1Var, i2c2Var);
}
#endif // ifndef DISABLE_SC16IS752_Serial
+7 -9
View File
@@ -8,6 +8,10 @@
#include <ESPeasySerial.h>
#define INCLUDE_SW_SERIAL (1 << 0)
#define INCLUDE_HW_SERIAL (1 << 1) // Ignored for now, always enabled
#define INCLUDE_I2C_SERIAL (1 << 2)
#define INCLUDE_CDC_SERIAL (1 << 3)
struct ESPeasySerialType;
@@ -53,23 +57,17 @@ void serialHelper_webformLoad(struct EventStruct *event);
// See issue #2343 and Pull request https://github.com/letscontrolit/ESPEasy/pull/2352
// For now P020 and P044 have been reverted to make them work again.
void serialHelper_webformLoad(struct EventStruct *event,
bool allowSoftwareSerial,
bool allowI2CSerial = true,
bool allowCDCSerial = true);
uint8_t allowedSerial);
void serialHelper_webformLoad(ESPEasySerialPort port,
int rxPinDef,
int txPinDef,
bool allowSoftwareSerial,
bool allowI2CSerial = true,
bool allowCDCSerial = true);
uint8_t allowedSerial);
void serialHelper_webformLoad(ESPEasySerialPort port,
int rxPinDef,
int txPinDef,
bool allowSoftwareSerial,
bool allowI2CSerial,
bool allowCDCSerial,
uint8_t allowedSerial,
String label,
String id,
String pin1Var,
+1 -1
View File
@@ -254,7 +254,7 @@ void handle_advanced() {
static_cast<ESPEasySerialPort>(Settings.console_serial_port),
Settings.console_serial_rxpin,
Settings.console_serial_txpin,
true);
INCLUDE_SW_SERIAL | INCLUDE_HW_SERIAL | INCLUDE_I2C_SERIAL);
// Show serial port selection
addFormPinSelect(