Skip to content

Commit b931e28

Browse files
committed
added extra gpio pins to avoid
1 parent 66df803 commit b931e28

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/system.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ PButton System::myPButton_;
3939
// value: true = HIGH, false = LOW
4040
// e.g. http://ems-esp/api?device=system&cmd=pin&data=1&id=2
4141
bool System::command_pin(const char * value, const int8_t id) {
42-
if (id < 0) {
42+
if (!is_valid_gpio(id)) {
4343
return false;
4444
}
4545

@@ -198,17 +198,18 @@ void System::wifi_tweak() {
198198
bool s1 = WiFi.getSleep();
199199
WiFi.setSleep(false); // turn off sleep - WIFI_PS_NONE
200200
bool s2 = WiFi.getSleep();
201-
LOG_INFO(F("Adjusting Wifi - Tx power %d->%d, Sleep %d->%d"), p1, p2, s1, s2);
201+
LOG_DEBUG(F("Adjusting WiFi - Tx power %d->%d, Sleep %d->%d"), p1, p2, s1, s2);
202202
#endif
203203
}
204204

205-
// check for valid ESP32 pins
206-
// 1, 6-11, 12, 14 & 15 are not allowed
207-
// we allow 0 (since its pulled high)
205+
// check for valid ESP32 pins. This is very dependent on which ESP32 board is being used.
206+
// Typically you can't use 1, 6-11 (SPI flash), 12, 14 & 15, 20, 24 and 28-31
207+
// we allow 0 as it has a special function on the NodeMCU apparently
208208
// See https://diyprojects.io/esp32-how-to-use-gpio-digital-io-arduino-code/#.YFpVEq9KhjG
209+
// and https://nodemcu.readthedocs.io/en/dev-esp32/modules/gpio/
209210
bool System::is_valid_gpio(uint8_t pin) {
210-
if ((pin == 1) || (pin >= 6 && pin <= 12) || (pin >= 14 && pin <= 15)) {
211-
return false; // bad
211+
if ((pin == 1) || (pin >= 6 && pin <= 12) || (pin >= 14 && pin <= 15) || (pin == 20) || (pin == 24) || (pin >= 28 && pin <= 31)) {
212+
return false; // bad pin
212213
}
213214
return true;
214215
}
@@ -318,9 +319,9 @@ void System::led_init(bool refresh) {
318319
get_settings();
319320
}
320321

321-
if (led_gpio_) {
322+
if ((led_gpio_ != 0) && is_valid_gpio(led_gpio_)) {
322323
pinMode(led_gpio_, OUTPUT); // 0 means disabled
323-
digitalWrite(led_gpio_, hide_led_ ? !LED_ON : LED_ON); // LED on, for ever
324+
digitalWrite(led_gpio_, hide_led_ ? !LED_ON : LED_ON); // LED on, forever
324325
}
325326
}
326327

0 commit comments

Comments
 (0)