Skip to content

Commit 3b32706

Browse files
committed
Fixed Bug #2 and re-releasing 0.0.5
1 parent 77ff19b commit 3b32706

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Need Help? [![Discord](https://img.shields.io/badge/Discuss-on%20Discord-7289d9?
44

55
# Initial Development!
66
Please be aware that this Library is currently in its initial development stages. It will function on the ESP32 just fine (tested and verified using PlatformIO for /examples/BasicDemo).
7-
The next release will include working support for the Arduino Uno and Nano R3 will be completed, tested, and submitted for 0.0.5.
87

98
# LithiumPowered
109
A (hopefully) Universal Library for Lithium-Powered Projects, designed to be available for both Arduino IDE and PlatformIO Projects.

examples/BasicDemo/src/main.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <LithiumPowered.hpp>
88

9-
#define BATTERY_RATED_CAPACITY 900.00 // Set this to the Rated Capacity of your Battery in mAh!
9+
#define BATTERY_RATED_CAPACITY 5000.00 // Set this to the Rated Capacity of your Battery in mAh!
1010

1111
class MyBatteryCallbacks: public BatteryCallbacks {
1212
public:
@@ -20,20 +20,23 @@ class MyBatteryCallbacks: public BatteryCallbacks {
2020

2121
virtual void onBatteryRemainingCapacityChanged() {
2222
Serial.print("Battery Update: ");
23+
Serial.print(Battery.getIsCharging() ? "Gained " : "Lost ");
24+
Serial.print(Battery.getChangeCapacity());
25+
Serial.print("mA - ");
2326
Serial.print(Battery.getPercentage());
2427
Serial.print("% ");
2528
Serial.print(Battery.getCurrentCapacity());
2629
Serial.print("mAh remaining. ");
2730
Serial.print(Battery.getIsCharging() ? "Charging at +" : "Discharging at ");
28-
Serial.print(Battery.getChangeCapacityWithPolarity());
31+
Serial.print(Battery.getChangeCapacityPerHourWithPolarity());
2932
Serial.print("mAh");
3033
if (Battery.getIsCharging()) {
31-
Serial.print(" - Time to full: ");
32-
Serial.print(Battery.getTimeToChargeInMinutes());
34+
Serial.print(" - Time to full: ");
35+
Serial.print(Battery.getTimeToChargeInMinutes());
3336
}
3437
else {
35-
Serial.print(" - Time to empty: ");
36-
Serial.print(Battery.getTimeToDischargeInMinutes());
38+
Serial.print(" - Time to empty: ");
39+
Serial.print(Battery.getTimeToDischargeInMinutes());
3740
}
3841
Serial.println(" min");
3942
};

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=LithiumPowered
2-
version=0.0.4
2+
version=0.0.5
33
author=Flowduino
44
maintainer=Flowduino <support@flowduino.com>
55
sentence=All-In-One Code Solution for Lithium Battery Management using the LTC4150 Coulomb Counter circuit.

src/LithiumPowered.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
double _mAh; // Current Capacity
106106
double _mAhMax; // Capacity when Battery is full
107107
double _mAhRated; // Capacity stated on the Battery's label
108-
double _mAhChange; // Capacity lost (!_wasCharging) or gained (_wasCharging)
108+
double _mAChange; // Capacity lost (!_wasCharging) or gained (_wasCharging)
109109
volatile BatteryState _state; // Is the Battery Charging or Discharging?
110110
uint8_t _pinInterrupt; // The GPIO Pin to use as the Interrupt
111111
uint8_t _pinPolarity; // The GPIO Pin to interrogate the Polarity
@@ -158,7 +158,7 @@
158158
_mAhRated = defaultCapacity;
159159
_mAh = _pStorage->getLastBatteryCapacity(defaultCapacity);
160160
_mAhMax = _pStorage->getMaxmimumBatteryCapacity(defaultCapacity);
161-
_mAhChange = 0.00; // Default is that there was no change.
161+
_mAChange = 0.00; // Default is that there was no change.
162162
_percentage = (_mAh / _mAhMax) * 100.00;
163163
_percentQuanta = 1.0 / (_mAhMax / 1000.0 * 5859.0 / 100.0);
164164
_isr = false;
@@ -210,7 +210,7 @@
210210
}
211211
}
212212

213-
_mAhChange = 614.4/((_deltaTime)/1000000.0); // Calculate by how much the capacity just changed.
213+
_mAChange = 614.4/((_deltaTime)/1000000.0); // Calculate by how much the capacity just changed.
214214

215215
_pStorage->setLastBatteryCapacity(_mAh);
216216
_pStorage->setMaximumBatteryCapacity(_mAhMax);
@@ -254,24 +254,25 @@
254254

255255
inline double getCurrentCapacity() { return _mAh; };
256256
inline double getMaximumCapacity() { return _mAhMax; };
257-
inline double getChangeCapacity() { return _mAhChange; };
257+
inline double getChangeCapacity() { return _mAChange; };
258258
inline double getPercentage() { return _percentage; };
259259
inline bool getIsCharging() { return _state == Charging; };
260260
inline bool getIsDischarging() { return _state == Discharging; };
261261
inline BatteryState getState() { return _state; };
262262

263-
inline double getChangeCapacityWithPolarity() { return _lastState == Charging ? _mAhChange : _mAhChange * -1.0; }; // This is corrected for negative value on Discharge, positive on Charge.
263+
inline double getChangeCapacityWithPolarity() { return _lastState == Charging ? _mAChange : _mAChange * -1.0; }; // This is corrected for negative value on Discharge, positive on Charge.
264+
inline double getChangeCapacityPerHourWithPolarity() { return _lastState == Charging ? (_mAChange / _deltaTime) * 3600000000.00 : ((_mAChange / _deltaTime) * 3600000000.00) * -1.0; };
264265
inline unsigned long getLastTime() { return _lastTime; };
265266
inline unsigned long getDeltaTime() { return _deltaTime; };
266267

267268
// Discharging Times
268-
inline double getTimeToDischargeInHours() { return getIsCharging() ? __DBL_MAX__ : _mAh / _mAhChange; };
269+
inline double getTimeToDischargeInHours() { return getIsCharging() ? __DBL_MAX__ : _mAh / _mAChange; };
269270
inline double getTimeToDischargeInMinutes() { return getIsCharging() ? __DBL_MAX__ : getTimeToDischargeInHours() * 60.00; };
270271
inline double getTimeToDischargeInSeconds() { return getIsCharging() ? __DBL_MAX__ : getTimeToDischargeInMinutes() * 60.00; };
271272
inline double getTimeToDischargeInMilliseconds() { return getIsCharging() ? __DBL_MAX__ : getTimeToDischargeInSeconds() * 1000.00; };
272273
inline double getTimeToDischargeInMicroseconds() { return getIsCharging() ? __DBL_MAX__ : getTimeToDischargeInMilliseconds() * 1000.00; };
273274
// Charging Times
274-
inline double getTimeToChargeInHours() { return getIsDischarging() ? __DBL_MAX__ : (_mAhMax - _mAh) / _mAhChange; };
275+
inline double getTimeToChargeInHours() { return getIsDischarging() ? __DBL_MAX__ : (_mAhMax - _mAh) / _mAChange; };
275276
inline double getTimeToChargeInMinutes() { return getIsDischarging() ? __DBL_MAX__ : getTimeToChargeInHours() * 60.00; };
276277
inline double getTimeToChargeInSeconds() { return getIsDischarging() ? __DBL_MAX__ : getTimeToChargeInMinutes() * 60.00; };
277278
inline double getTimeToChargeInMilliseconds() { return getIsDischarging() ? __DBL_MAX__ : getTimeToChargeInSeconds() * 1000.00; };

0 commit comments

Comments
 (0)