diff --git a/usermods/Battery/readme.md b/usermods/Battery/readme.md index d77eeccd..5a667870 100644 --- a/usermods/Battery/readme.md +++ b/usermods/Battery/readme.md @@ -36,7 +36,7 @@ define `USERMOD_BATTERY` in `wled00/my_config.h` | Name | Unit | Description | | ----------------------------------------------- | ----------- |-------------------------------------------------------------------------------------- | | `USERMOD_BATTERY` | | define this (in `my_config.h`) to have this usermod included wled00\usermods_list.cpp | -| `USERMOD_BATTERY_MEASUREMENT_PIN` | | defaults to A0 on ESP8266 and GPIO32 on ESP32 | +| `USERMOD_BATTERY_MEASUREMENT_PIN` | | defaults to A0 on ESP8266 and GPIO35 on ESP32 | | `USERMOD_BATTERY_MEASUREMENT_INTERVAL` | ms | battery check interval. defaults to 30 seconds | | `USERMOD_BATTERY_MIN_VOLTAGE` | v | minimum battery voltage. default is 2.6 (18650 battery standard) | | `USERMOD_BATTERY_MAX_VOLTAGE` | v | maximum battery voltage. default is 4.2 (18650 battery standard) | diff --git a/usermods/Battery/usermod_v2_Battery.h b/usermods/Battery/usermod_v2_Battery.h index ba61edd2..461613a4 100644 --- a/usermods/Battery/usermod_v2_Battery.h +++ b/usermods/Battery/usermod_v2_Battery.h @@ -93,6 +93,7 @@ class UsermodBattery : public Usermod void lowPowerIndicator() { if (!lowPowerIndicatorEnabled) return; + if (batteryPin < 0) return; // no measurement if (lowPowerIndicationDone && lowPowerIndicatorReactivationThreshold <= batteryLevel) lowPowerIndicationDone = false; if (lowPowerIndicatorThreshold <= batteryLevel) return; if (lowPowerIndicationDone) return; @@ -130,6 +131,8 @@ class UsermodBattery : public Usermod if (!success) { DEBUG_PRINTLN(F("Battery pin allocation failed.")); batteryPin = -1; // allocation failed + } else { + pinMode(batteryPin, INPUT); } #else //ESP8266 boards have only one analog input pin A0 @@ -168,6 +171,9 @@ class UsermodBattery : public Usermod nextReadTime = millis() + readingInterval; lastReadTime = millis(); + + if (batteryPin < 0) return; // nothing to read + initializing = false; // read battery raw input @@ -214,6 +220,13 @@ class UsermodBattery : public Usermod JsonObject user = root["u"]; if (user.isNull()) user = root.createNestedObject("u"); + if (batteryPin < 0) { + JsonArray infoVoltage = user.createNestedArray(F("Battery voltage")); + infoVoltage.add(F("n/a")); + infoVoltage.add(F(" invalid GPIO")); + return; // no GPIO - nothing to report + } + // info modal display names JsonArray infoPercentage = user.createNestedArray(F("Battery level")); JsonArray infoVoltage = user.createNestedArray(F("Battery voltage")); @@ -561,7 +574,7 @@ class UsermodBattery : public Usermod { #ifdef ARDUINO_ARCH_ESP32 // esp32 - return 4095.0f; + return 4096.0f; #else // esp8266 return 1024.0f;