mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-28 04:07:47 +00:00
[PWM Motor] Cleanup GPIO selection code
This commit is contained in:
+62
-51
@@ -47,7 +47,7 @@ boolean Plugin_098(byte function, struct EventStruct *event, String& string)
|
||||
case PLUGIN_DEVICE_ADD:
|
||||
{
|
||||
Device[++deviceCount].Number = PLUGIN_ID_098;
|
||||
Device[deviceCount].Type = DEVICE_TYPE_CUSTOM3;
|
||||
Device[deviceCount].Type = DEVICE_TYPE_CUSTOM0;
|
||||
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_QUAD;
|
||||
Device[deviceCount].Ports = 0;
|
||||
Device[deviceCount].PullUpOption = false;
|
||||
@@ -74,64 +74,56 @@ boolean Plugin_098(byte function, struct EventStruct *event, String& string)
|
||||
break;
|
||||
}
|
||||
|
||||
case PLUGIN_GET_DEVICEGPIONAMES:
|
||||
{
|
||||
event->String1 = formatGpioName_output(F("Motor Fwd"));
|
||||
event->String2 = formatGpioName_output(F("Motor Rev"));
|
||||
event->String3 = formatGpioName_input_optional(F("Encoder"));
|
||||
break;
|
||||
}
|
||||
|
||||
case PLUGIN_WEBFORM_SHOW_GPIO_DESCR:
|
||||
{
|
||||
string = F("M Fwd:");
|
||||
string += F(" ");
|
||||
string += formatGpioLabel(Settings.TaskDevicePin1[event->TaskIndex], true);
|
||||
string += event->String1;
|
||||
string += F("M Rev:");
|
||||
string += F(" ");
|
||||
string += formatGpioLabel(Settings.TaskDevicePin2[event->TaskIndex], true);
|
||||
string += event->String1;
|
||||
string += F("Enc:");
|
||||
string += F(" ");
|
||||
string += formatGpioLabel(Settings.TaskDevicePin3[event->TaskIndex], true);
|
||||
string += event->String1;
|
||||
addHtml(F("M Fwd:"));
|
||||
addHtml(F(" "));
|
||||
addHtml(formatGpioLabel(Settings.TaskDevicePin1[event->TaskIndex], true));
|
||||
addHtml(event->String1);
|
||||
addHtml(F("M Rev:"));
|
||||
addHtml(F(" "));
|
||||
addHtml(formatGpioLabel(Settings.TaskDevicePin2[event->TaskIndex], true));
|
||||
addHtml(event->String1);
|
||||
addHtml(F("Enc:"));
|
||||
addHtml(F(" "));
|
||||
addHtml(formatGpioLabel(Settings.TaskDevicePin3[event->TaskIndex], true));
|
||||
addHtml(event->String1);
|
||||
# ifdef ESP32
|
||||
string += F("Analog:");
|
||||
string += F(" ");
|
||||
string += formatGpioLabel(P098_ANALOG_GPIO, true);
|
||||
string += event->String1;
|
||||
#endif
|
||||
string += F("Lim A:");
|
||||
string += F(" ");
|
||||
string += formatGpioLabel(P098_LIMIT_SWA_GPIO, true);
|
||||
string += event->String1;
|
||||
string += F("Lim B:");
|
||||
string += F(" ");
|
||||
string += formatGpioLabel(P098_LIMIT_SWB_GPIO, true);
|
||||
addHtml(F("Analog:"));
|
||||
addHtml(F(" "));
|
||||
addHtml(formatGpioLabel(P098_ANALOG_GPIO, true));
|
||||
addHtml(event->String1);
|
||||
# endif // ifdef ESP32
|
||||
addHtml(F("Lim A:"));
|
||||
addHtml(F(" "));
|
||||
addHtml(formatGpioLabel(P098_LIMIT_SWA_GPIO, true));
|
||||
addHtml(event->String1);
|
||||
addHtml(F("Lim B:"));
|
||||
addHtml(F(" "));
|
||||
addHtml(formatGpioLabel(P098_LIMIT_SWB_GPIO, true));
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
case PLUGIN_WEBFORM_SHOW_VALUES:
|
||||
{
|
||||
P098_data_struct *P098_data =
|
||||
static_cast<P098_data_struct *>(getPluginTaskData(event->TaskIndex));
|
||||
/*
|
||||
case PLUGIN_WEBFORM_SHOW_VALUES:
|
||||
{
|
||||
P098_data_struct *P098_data =
|
||||
static_cast<P098_data_struct *>(getPluginTaskData(event->TaskIndex));
|
||||
|
||||
if (nullptr != P098_data) {
|
||||
byte varNr = VARS_PER_TASK;
|
||||
int limitApos, limitBpos;
|
||||
P098_data->getLimitSwitchPositions(limitApos, limitBpos);
|
||||
if (nullptr != P098_data) {
|
||||
byte varNr = VARS_PER_TASK;
|
||||
int limitApos, limitBpos;
|
||||
P098_data->getLimitSwitchPositions(limitApos, limitBpos);
|
||||
|
||||
pluginWebformShowValue(event->TaskIndex, varNr++, F("LimitBpos"), String(limitBpos));
|
||||
pluginWebformShowValue(event->TaskIndex, varNr++, F("State"), String(static_cast<int>(P098_data->state)), true);
|
||||
pluginWebformShowValue(event->TaskIndex, varNr++, F("LimitBpos"), String(limitBpos));
|
||||
pluginWebformShowValue(event->TaskIndex, varNr++, F("State"), String(static_cast<int>(P098_data->state)), true);
|
||||
|
||||
// success = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
*/
|
||||
// success = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
*/
|
||||
case PLUGIN_SET_DEFAULTS:
|
||||
{
|
||||
P098_LIMIT_SWA_GPIO = -1;
|
||||
@@ -149,9 +141,18 @@ boolean Plugin_098(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case PLUGIN_WEBFORM_LOAD:
|
||||
{
|
||||
addFormSubHeader(F("Motor Control"));
|
||||
|
||||
// We load/save the TaskDevicePin ourselves to allow to combine the pin specific configuration be shown along with the pin selection.
|
||||
addFormPinSelect(formatGpioName_output(F("Motor Fwd")), F("taskdevicepin1"), Settings.TaskDevicePin1[event->TaskIndex]);
|
||||
addFormCheckBox(F("Motor Fwd Inverted"), F("mot_fwd_inv"), bitRead(P098_FLAGS, P098_FLAGBIT_MOTOR_FWD_INVERTED));
|
||||
|
||||
addFormSeparator(2);
|
||||
|
||||
addFormPinSelect(formatGpioName_output(F("Motor Rev")), F("taskdevicepin2"), Settings.TaskDevicePin2[event->TaskIndex]);
|
||||
addFormCheckBox(F("Motor Rev Inverted"), F("mot_rev_inv"), bitRead(P098_FLAGS, P098_FLAGBIT_MOTOR_REV_INVERTED));
|
||||
addFormCheckBox(F("Encoder Pull-Up"), F("enc_pu"), bitRead(P098_FLAGS, P098_FLAGBIT_ENC_IN_PULLUP));
|
||||
|
||||
addFormSeparator(2);
|
||||
|
||||
{
|
||||
# define P098_PWM_MODE_TYPES static_cast<int>(P098_config_struct::PWM_mode_type::MAX_TYPE)
|
||||
@@ -166,6 +167,12 @@ boolean Plugin_098(byte function, struct EventStruct *event, String& string)
|
||||
}
|
||||
addFormNumericBox(F("PWM Frequency"), F("p098_pwm_freq"), P098_PWM_FREQ, 1000, 100000);
|
||||
addUnit(F("Hz"));
|
||||
|
||||
addFormSubHeader(F("Feedback"));
|
||||
|
||||
addFormPinSelect(formatGpioName_input_optional(F("Encoder")), F("taskdevicepin3"), Settings.TaskDevicePin3[event->TaskIndex]);
|
||||
addFormCheckBox(F("Encoder Pull-Up"), F("enc_pu"), bitRead(P098_FLAGS, P098_FLAGBIT_ENC_IN_PULLUP));
|
||||
|
||||
# ifdef ESP32
|
||||
{
|
||||
addRowLabel(formatGpioName_input_optional(F("Analog Feedback")));
|
||||
@@ -173,7 +180,6 @@ boolean Plugin_098(byte function, struct EventStruct *event, String& string)
|
||||
}
|
||||
# endif // ifdef ESP32
|
||||
|
||||
|
||||
addFormSubHeader(F("Limit Switches"));
|
||||
|
||||
addFormPinSelect(formatGpioName_input_optional(F("Limit A")), F("limit_a"), P098_LIMIT_SWA_GPIO);
|
||||
@@ -197,6 +203,11 @@ boolean Plugin_098(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case PLUGIN_WEBFORM_SAVE:
|
||||
{
|
||||
// We load/save the TaskDevicePin ourselves to allow to combine the pin specific configuration be shown along with the pin selection.
|
||||
Settings.TaskDevicePin1[event->TaskIndex] = getFormItemInt(F("taskdevicepin1"));
|
||||
Settings.TaskDevicePin2[event->TaskIndex] = getFormItemInt(F("taskdevicepin2"));
|
||||
Settings.TaskDevicePin3[event->TaskIndex] = getFormItemInt(F("taskdevicepin3"));
|
||||
|
||||
P098_LIMIT_SWA_GPIO = getFormItemInt(F("limit_a"));
|
||||
P098_LIMIT_SWB_GPIO = getFormItemInt(F("limit_b"));
|
||||
P098_LIMIT_SWA_DEBOUNCE = getFormItemInt(F("limit_a_debounce"));
|
||||
|
||||
@@ -136,11 +136,12 @@ bool pluginOptionalTaskIndexArgumentMatch(taskIndex_t taskIndex, const String& s
|
||||
return found_taskIndex == taskIndex;
|
||||
}
|
||||
|
||||
bool pluginWebformShowGPIOdescription(taskIndex_t taskIndex, String& description, const String& newline)
|
||||
bool pluginWebformShowGPIOdescription(taskIndex_t taskIndex, const String& newline)
|
||||
{
|
||||
struct EventStruct TempEvent(taskIndex);
|
||||
TempEvent.String1 = newline;
|
||||
return PluginCall(PLUGIN_WEBFORM_SHOW_GPIO_DESCR, &TempEvent, description);
|
||||
String dummy;
|
||||
return PluginCall(PLUGIN_WEBFORM_SHOW_GPIO_DESCR, &TempEvent, dummy);
|
||||
}
|
||||
|
||||
int getValueCountForTask(taskIndex_t taskIndex) {
|
||||
|
||||
@@ -143,7 +143,7 @@ bool pluginOptionalTaskIndexArgumentMatch(taskIndex_t taskIndex,
|
||||
const String& string,
|
||||
byte paramNr);
|
||||
|
||||
bool pluginWebformShowGPIOdescription(taskIndex_t taskIndex, String& description, const String& newline);
|
||||
bool pluginWebformShowGPIOdescription(taskIndex_t taskIndex, const String& newline);
|
||||
|
||||
int getValueCountForTask(taskIndex_t taskIndex);
|
||||
|
||||
|
||||
@@ -15,9 +15,10 @@
|
||||
#define DEVICE_TYPE_SPI 23 // connected through SPI
|
||||
#define DEVICE_TYPE_SPI2 24 // connected through SPI, 2 GPIOs
|
||||
#define DEVICE_TYPE_SPI3 25 // connected through SPI, 3 GPIOs
|
||||
#define DEVICE_TYPE_CUSTOM1 30 // Custom labels, 1 GPIO
|
||||
#define DEVICE_TYPE_CUSTOM2 31 // Custom labels, 2 GPIOs
|
||||
#define DEVICE_TYPE_CUSTOM3 32 // Custom labels, 3 GPIOs
|
||||
#define DEVICE_TYPE_CUSTOM0 30 // Custom labels, Not using TaskDevicePin1 ... TaskDevicePin3
|
||||
#define DEVICE_TYPE_CUSTOM1 31 // Custom labels, 1 GPIO
|
||||
#define DEVICE_TYPE_CUSTOM2 32 // Custom labels, 2 GPIOs
|
||||
#define DEVICE_TYPE_CUSTOM3 33 // Custom labels, 3 GPIOs
|
||||
#define DEVICE_TYPE_DUMMY 99 // Dummy device, has no physical connection
|
||||
|
||||
#define I2C_MULTIPLEXER_NONE -1 // None selected
|
||||
|
||||
@@ -469,6 +469,68 @@ void SettingsStruct_tmpl<N_TASKS>::setPinBootState(uint8_t gpio_pin, PinBootStat
|
||||
#endif
|
||||
}
|
||||
|
||||
template<unsigned int N_TASKS>
|
||||
bool SettingsStruct_tmpl<N_TASKS>::getSPI_pins(int8_t spi_gpios[3]) const {
|
||||
spi_gpios[0] = -1;
|
||||
spi_gpios[1] = -1;
|
||||
spi_gpios[2] = -1;
|
||||
if (InitSPI > 0) {
|
||||
# ifdef ESP32
|
||||
switch (InitSPI) {
|
||||
case 1:
|
||||
{
|
||||
spi_gpios[0] = 18; spi_gpios[1] = 19; spi_gpios[2] = 23;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
spi_gpios[0] = 14; // HSPI_SCLK
|
||||
spi_gpios[1] = 12; // HSPI_MISO
|
||||
spi_gpios[2] = 13; // HSPI_MOSI
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
# endif // ifdef ESP32
|
||||
# ifdef ESP8266
|
||||
spi_gpios[0] = 14; spi_gpios[1] = 12; spi_gpios[2] = 13;
|
||||
# endif // ifdef ESP8266
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<unsigned int N_TASKS>
|
||||
bool SettingsStruct_tmpl<N_TASKS>::isSPI_pin(int8_t pin) const {
|
||||
if (pin < 0) return false;
|
||||
int8_t spi_gpios[3];
|
||||
if (getSPI_pins(spi_gpios)) {
|
||||
for (byte i = 0; i < 3; ++i) {
|
||||
if (spi_gpios[i] == pin) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<unsigned int N_TASKS>
|
||||
bool SettingsStruct_tmpl<N_TASKS>::isI2C_pin(int8_t pin) const {
|
||||
if (pin < 0) return false;
|
||||
return Pin_i2c_sda == pin || Pin_i2c_scl == pin;
|
||||
}
|
||||
|
||||
template<unsigned int N_TASKS>
|
||||
int8_t SettingsStruct_tmpl<N_TASKS>::getTaskDevicePin(taskIndex_t taskIndex, byte pinnr) const {
|
||||
if (validTaskIndex(taskIndex)) {
|
||||
switch(pinnr) {
|
||||
case 1: return TaskDevicePin1[taskIndex];
|
||||
case 2: return TaskDevicePin2[taskIndex];
|
||||
case 3: return TaskDevicePin3[taskIndex];
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
template<unsigned int N_TASKS>
|
||||
float SettingsStruct_tmpl<N_TASKS>::getWiFi_TX_power() const {
|
||||
return WiFi_TX_power / 4.0f;
|
||||
|
||||
@@ -151,6 +151,15 @@ class SettingsStruct_tmpl
|
||||
PinBootState getPinBootState(uint8_t gpio_pin) const;
|
||||
void setPinBootState(uint8_t gpio_pin, PinBootState state);
|
||||
|
||||
bool getSPI_pins(int8_t spi_gpios[3]) const;
|
||||
|
||||
bool isSPI_pin(int8_t pin) const;
|
||||
bool isI2C_pin(int8_t pin) const;
|
||||
|
||||
// Access to TaskDevicePin1 ... TaskDevicePin3
|
||||
// @param pinnr 1 = TaskDevicePin1, ..., 3 = TaskDevicePin3
|
||||
int8_t getTaskDevicePin(taskIndex_t taskIndex, byte pinnr) const;
|
||||
|
||||
float getWiFi_TX_power() const;
|
||||
void setWiFi_TX_power(float dBm);
|
||||
|
||||
|
||||
@@ -859,6 +859,7 @@ bool getGpioInfo(int gpio, int& pinnr, bool& input, bool& output, bool& warning)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// FIXME TD-er: Must we also check for pins used for MDC/MDIO and Eth PHY power?
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
/*********************************************************************************************\
|
||||
Device GPIO name functions to share flash strings
|
||||
\*********************************************************************************************/
|
||||
String formatGpioDirection(gpio_direction direction) {
|
||||
const __FlashStringHelper * formatGpioDirection(gpio_direction direction) {
|
||||
switch (direction) {
|
||||
case gpio_input: return F("← ");
|
||||
case gpio_output: return F("→ ");
|
||||
case gpio_bidirectional: return F("⇄ ");
|
||||
}
|
||||
return "";
|
||||
return F("");
|
||||
}
|
||||
|
||||
String formatGpioLabel(int gpio, bool includeWarning) {
|
||||
@@ -139,14 +139,24 @@ String createGPIO_label(int gpio, int pinnr, bool input, bool output, bool warni
|
||||
if (warning) {
|
||||
result += ' ';
|
||||
result += F(HTML_SYMBOL_WARNING);
|
||||
|
||||
bool serialPinConflict = (Settings.UseSerial && (gpio == 1 || gpio == 3));
|
||||
|
||||
if (serialPinConflict) {
|
||||
if (gpio == 1) { result += F(" TX0"); }
|
||||
|
||||
if (gpio == 3) { result += F(" RX0"); }
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const __FlashStringHelper * getConflictingUse(int gpio, bool includeI2C)
|
||||
{
|
||||
bool serialPinConflict = (Settings.UseSerial && (gpio == 1 || gpio == 3));
|
||||
|
||||
if (serialPinConflict) {
|
||||
if (gpio == 1) { return F(" TX0"); }
|
||||
|
||||
if (gpio == 3) { return F(" RX0"); }
|
||||
}
|
||||
if (includeI2C && Settings.isI2C_pin(gpio)) {
|
||||
return F(" I2C");
|
||||
}
|
||||
if (Settings.isSPI_pin(gpio)) {
|
||||
return F(" SPI");
|
||||
}
|
||||
return F("");
|
||||
}
|
||||
@@ -21,7 +21,7 @@ enum gpio_direction {
|
||||
/*********************************************************************************************\
|
||||
Device GPIO name functions to share flash strings
|
||||
\*********************************************************************************************/
|
||||
String formatGpioDirection(gpio_direction direction);
|
||||
const __FlashStringHelper * formatGpioDirection(gpio_direction direction);
|
||||
|
||||
String formatGpioLabel(int gpio,
|
||||
bool includeWarning);
|
||||
@@ -62,6 +62,7 @@ String createGPIO_label(int gpio,
|
||||
bool output,
|
||||
bool warning);
|
||||
|
||||
const __FlashStringHelper * getConflictingUse(int gpio, bool includeI2C = true);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -391,6 +391,23 @@ void handle_devices_CopySubmittedSettings(taskIndex_t taskIndex, pluginID_t task
|
||||
}
|
||||
}
|
||||
|
||||
void GpioToHtml(int8_t pin) {
|
||||
if (pin == -1) return;
|
||||
addHtml(formatGpioLabel(pin, false));
|
||||
if (Settings.isSPI_pin(pin) ||
|
||||
Settings.isI2C_pin(pin)) {
|
||||
addHtml(' ');
|
||||
addHtml(F(HTML_SYMBOL_WARNING));
|
||||
}
|
||||
}
|
||||
|
||||
void Label_Gpio_toHtml(const __FlashStringHelper * label, const String& gpio_pin_descr) {
|
||||
addHtml(label);
|
||||
addHtml(':');
|
||||
addHtml(F(" "));
|
||||
addHtml(gpio_pin_descr);
|
||||
}
|
||||
|
||||
// ********************************************************************************
|
||||
// Show table with all selected Tasks/Devices
|
||||
// ********************************************************************************
|
||||
@@ -653,14 +670,13 @@ void handle_devicess_ShowAllTasksTable(byte page)
|
||||
|
||||
// fallthrough
|
||||
case DEVICE_TYPE_CUSTOM1:
|
||||
case DEVICE_TYPE_CUSTOM0:
|
||||
{
|
||||
showpin1 = true;
|
||||
String description;
|
||||
if (pluginWebformShowGPIOdescription(x, description, F("<BR>"))) {
|
||||
if (pluginWebformShowGPIOdescription(x, F("<BR>")) || Device[DeviceIndex].Type == DEVICE_TYPE_CUSTOM0) {
|
||||
showpin1 = false;
|
||||
showpin2 = false;
|
||||
showpin3 = false;
|
||||
addHtml(description);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -672,51 +688,19 @@ void handle_devicess_ShowAllTasksTable(byte page)
|
||||
break;
|
||||
}
|
||||
|
||||
if ((Settings.TaskDevicePin1[x] != -1) && showpin1)
|
||||
if (showpin1)
|
||||
{
|
||||
String html = formatGpioLabel(Settings.TaskDevicePin1[x], false);
|
||||
|
||||
if ((spi_gpios[0] == Settings.TaskDevicePin1[x])
|
||||
|| (spi_gpios[1] == Settings.TaskDevicePin1[x])
|
||||
|| (spi_gpios[2] == Settings.TaskDevicePin1[x])
|
||||
|| (Settings.Pin_i2c_sda == Settings.TaskDevicePin1[x])
|
||||
|| (Settings.Pin_i2c_scl == Settings.TaskDevicePin1[x])) {
|
||||
html += ' ';
|
||||
html += F(HTML_SYMBOL_WARNING);
|
||||
}
|
||||
addHtml(html);
|
||||
GpioToHtml(Settings.getTaskDevicePin(x, 1));
|
||||
}
|
||||
|
||||
if ((Settings.TaskDevicePin2[x] != -1) && showpin2)
|
||||
if (showpin2)
|
||||
{
|
||||
html_BR();
|
||||
String html = formatGpioLabel(Settings.TaskDevicePin2[x], false);
|
||||
|
||||
if ((spi_gpios[0] == Settings.TaskDevicePin2[x])
|
||||
|| (spi_gpios[1] == Settings.TaskDevicePin2[x])
|
||||
|| (spi_gpios[2] == Settings.TaskDevicePin2[x])
|
||||
|| (Settings.Pin_i2c_sda == Settings.TaskDevicePin2[x])
|
||||
|| (Settings.Pin_i2c_scl == Settings.TaskDevicePin2[x])) {
|
||||
html += ' ';
|
||||
html += F(HTML_SYMBOL_WARNING);
|
||||
}
|
||||
addHtml(html);
|
||||
GpioToHtml(Settings.getTaskDevicePin(x, 2));
|
||||
}
|
||||
|
||||
if ((Settings.TaskDevicePin3[x] != -1) && showpin3)
|
||||
if (showpin3)
|
||||
{
|
||||
html_BR();
|
||||
String html = formatGpioLabel(Settings.TaskDevicePin3[x], false);
|
||||
|
||||
if ((spi_gpios[0] == Settings.TaskDevicePin3[x])
|
||||
|| (spi_gpios[1] == Settings.TaskDevicePin3[x])
|
||||
|| (spi_gpios[2] == Settings.TaskDevicePin3[x])
|
||||
|| (Settings.Pin_i2c_sda == Settings.TaskDevicePin3[x])
|
||||
|| (Settings.Pin_i2c_scl == Settings.TaskDevicePin3[x])) {
|
||||
html += ' ';
|
||||
html += F(HTML_SYMBOL_WARNING);
|
||||
}
|
||||
addHtml(html);
|
||||
GpioToHtml(Settings.getTaskDevicePin(x, 3));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -795,60 +779,50 @@ void format_I2C_port_description(taskIndex_t x)
|
||||
|
||||
void format_SPI_port_description(int8_t spi_gpios[3])
|
||||
{
|
||||
if (Settings.InitSPI == 0) {
|
||||
if (!Settings.getSPI_pins(spi_gpios)) {
|
||||
addHtml(F("SPI (Not enabled)"));
|
||||
} else {
|
||||
# ifdef ESP32
|
||||
|
||||
switch (Settings.InitSPI) {
|
||||
case 1:
|
||||
{
|
||||
addHtml(F("VSPI"));
|
||||
spi_gpios[0] = 18; spi_gpios[1] = 19; spi_gpios[2] = 23;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
addHtml(F("HSPI"));
|
||||
spi_gpios[0] = 14; spi_gpios[1] = 12; spi_gpios[2] = 13;
|
||||
break;
|
||||
}
|
||||
}
|
||||
# endif // ifdef ESP32
|
||||
# ifdef ESP8266
|
||||
addHtml(F("SPI"));
|
||||
spi_gpios[0] = 14; spi_gpios[1] = 12; spi_gpios[2] = 13;
|
||||
# endif // ifdef ESP8266
|
||||
return;
|
||||
}
|
||||
# ifdef ESP32
|
||||
|
||||
switch (Settings.InitSPI) {
|
||||
case 1:
|
||||
{
|
||||
addHtml(F("VSPI"));
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
addHtml(F("HSPI"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
# endif // ifdef ESP32
|
||||
# ifdef ESP8266
|
||||
addHtml(F("SPI"));
|
||||
# endif // ifdef ESP8266
|
||||
}
|
||||
|
||||
void format_I2C_pin_description()
|
||||
{
|
||||
String html;
|
||||
|
||||
html.reserve(20);
|
||||
html += F("SDA: ");
|
||||
html += formatGpioLabel(Settings.Pin_i2c_sda, false);
|
||||
html += F("<BR>SCL: ");
|
||||
html += formatGpioLabel(Settings.Pin_i2c_scl, false);
|
||||
|
||||
addHtml(html);
|
||||
Label_Gpio_toHtml(F("SDA"), formatGpioLabel(Settings.Pin_i2c_sda, false));
|
||||
html_BR();
|
||||
Label_Gpio_toHtml(F("SCL"), formatGpioLabel(Settings.Pin_i2c_scl, false));
|
||||
}
|
||||
|
||||
void format_SPI_pin_description(int8_t spi_gpios[3], taskIndex_t x)
|
||||
{
|
||||
if (Settings.InitSPI != 0) {
|
||||
if (Settings.InitSPI > 0) {
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
const String pin_descr = formatGpioLabel(spi_gpios[i], false);
|
||||
switch (i) {
|
||||
case 0: addHtml(F("CLK: ")); break;
|
||||
case 1: addHtml(F("MISO: ")); break;
|
||||
case 2: addHtml(F("MOSI: ")); break;
|
||||
case 0: Label_Gpio_toHtml(F("CLK"), pin_descr); break;
|
||||
case 1: Label_Gpio_toHtml(F("MISO"), pin_descr); break;
|
||||
case 2: Label_Gpio_toHtml(F("MOSI"), pin_descr); break;
|
||||
}
|
||||
addHtml(formatGpioLabel(spi_gpios[i], false));
|
||||
html_BR();
|
||||
}
|
||||
addHtml(F("CS: "));
|
||||
addHtml(formatGpioLabel(Settings.TaskDevicePin1[x], false));
|
||||
Label_Gpio_toHtml(F("CS"), formatGpioLabel(Settings.TaskDevicePin1[x], false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,10 @@ void handle_hardware() {
|
||||
addFormSubHeader(F("SPI Interface"));
|
||||
#ifdef ESP32
|
||||
{
|
||||
const __FlashStringHelper * spi_options[3] = { F("Disabled"), F("VSPI: CLK=GPIO-18, MISO=GPIO-19, MOSI=GPIO-23"), F("HSPI: CLK=GPIO-14, MISO=GPIO-12, MOSI=GPIO-13")};
|
||||
const __FlashStringHelper * spi_options[3] = {
|
||||
F("Disabled"),
|
||||
F("VSPI: CLK=GPIO-18, MISO=GPIO-19, MOSI=GPIO-23"),
|
||||
F("HSPI: CLK=GPIO-14, MISO=GPIO-12, MOSI=GPIO-13")};
|
||||
addFormSelector(F("Init SPI"), F("initspi"), 3, spi_options, NULL, Settings.InitSPI);
|
||||
addFormNote(F("Changing SPI settings requires to manualy restart"));
|
||||
}
|
||||
|
||||
@@ -653,10 +653,13 @@ void addPinSelect(boolean forI2C, const String& id, int choice)
|
||||
|
||||
while (i < NR_ITEMS_PIN_DROPDOWN && gpio <= MAX_GPIO) {
|
||||
int pinnr = -1;
|
||||
bool input, output, warning;
|
||||
bool input, output, warning = false;
|
||||
|
||||
if (getGpioInfo(gpio, pinnr, input, output, warning) || (i == 0)) {
|
||||
// Make sure getGpioInfo is called (compiler may optimize it away if (i == 0))
|
||||
const bool UsableGPIO = getGpioInfo(gpio, pinnr, input, output, warning);
|
||||
if (UsableGPIO || (i == 0)) {
|
||||
gpio_labels[i] = createGPIO_label(gpio, pinnr, input, output, warning);
|
||||
gpio_labels[i] += getConflictingUse(gpio, !forI2C);
|
||||
gpio_numbers[i] = gpio;
|
||||
++i;
|
||||
}
|
||||
@@ -699,6 +702,7 @@ void addADC_PinSelect(bool touchOnly, const String& id, int choice)
|
||||
if (adc != 0) {
|
||||
gpio_labels[i] += F(" / ");
|
||||
gpio_labels[i] += createGPIO_label(gpio, pinnr, input, output, warning);
|
||||
gpio_labels[i] += getConflictingUse(gpio);
|
||||
}
|
||||
gpio_numbers[i] = gpio;
|
||||
++i;
|
||||
@@ -729,7 +733,7 @@ void renderHTMLForPinSelect(String options[], int optionValues[], boolean forI2C
|
||||
|
||||
if (optionValues[x] != -1) // empty selection can never be disabled...
|
||||
{
|
||||
if (!forI2C && ((optionValues[x] == Settings.Pin_i2c_sda) || (optionValues[x] == Settings.Pin_i2c_scl))) {
|
||||
if (!forI2C && Settings.isI2C_pin(optionValues[x])) {
|
||||
disabled = true;
|
||||
}
|
||||
|
||||
@@ -737,22 +741,10 @@ void renderHTMLForPinSelect(String options[], int optionValues[], boolean forI2C
|
||||
disabled = true;
|
||||
}
|
||||
|
||||
if (Settings.InitSPI != 0) {
|
||||
#ifdef ESP32
|
||||
|
||||
switch (Settings.InitSPI)
|
||||
{
|
||||
case 1:
|
||||
disabled = (optionValues[x] == 18 || optionValues[x] == 19 || optionValues[x] == 23);
|
||||
break;
|
||||
case 2:
|
||||
disabled = (optionValues[x] == 14 || optionValues[x] == 12 || optionValues[x] == 13);
|
||||
break;
|
||||
}
|
||||
#else // #ifdef ESP32
|
||||
disabled = (optionValues[x] == 14 || optionValues[x] == 12 || optionValues[x] == 13);
|
||||
#endif // ifdef ESP32
|
||||
if (Settings.isSPI_pin(optionValues[x])) {
|
||||
disabled = true;
|
||||
}
|
||||
|
||||
}
|
||||
addSelector_Item(options[x],
|
||||
optionValues[x],
|
||||
|
||||
@@ -348,6 +348,7 @@ void addFormPinStateSelect(int gpio, int choice)
|
||||
label.reserve(32);
|
||||
label = F("Pin mode ");
|
||||
label += createGPIO_label(gpio, pinnr, input, output, warning);
|
||||
label += getConflictingUse(gpio);
|
||||
String id = "p";
|
||||
id += gpio;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user