mirror of
https://github.com/vshymanskyy/TinyGSM.git
synced 2026-01-31 11:16:26 +00:00
Made battery return types signed
Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
This commit is contained in:
@@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Changed inputs for (unimplemented) SSL certificate functions.
|
||||
- All modems will now return the pre-defined manufacturer and model in the name if the function to get the internal name fails.
|
||||
- Cleaned up code for getting modem names.
|
||||
- Made battery return types signed.
|
||||
|
||||
### Added
|
||||
- Added support for SSL for the Quentcel BG95 and BG96 from [Aurelien BOUIN](https://github.com/aurelihein) and [George O'Connor](https://github.com/georgeman93)
|
||||
|
||||
@@ -479,9 +479,9 @@ void loop() {
|
||||
|
||||
// Test Battery functions
|
||||
#if TINY_GSM_TEST_BATTERY && defined TINY_GSM_MODEM_HAS_BATTERY
|
||||
uint8_t chargeState = -99;
|
||||
int8_t chargePercent = -99;
|
||||
uint16_t milliVolts = -9999;
|
||||
int8_t chargeState = -99;
|
||||
int8_t chargePercent = -99;
|
||||
int16_t milliVolts = -9999;
|
||||
modem.getBattStats(chargeState, chargePercent, milliVolts);
|
||||
DBG("Battery charge state:", chargeState);
|
||||
DBG("Battery charge 'percent':", chargePercent);
|
||||
|
||||
@@ -24,17 +24,16 @@ class TinyGsmBattery {
|
||||
/*
|
||||
* Battery functions
|
||||
*/
|
||||
uint16_t getBattVoltage() {
|
||||
int16_t getBattVoltage() {
|
||||
return thisModem().getBattVoltageImpl();
|
||||
}
|
||||
int8_t getBattPercent() {
|
||||
return thisModem().getBattPercentImpl();
|
||||
}
|
||||
uint8_t getBattChargeState() {
|
||||
int8_t getBattChargeState() {
|
||||
return thisModem().getBattChargeStateImpl();
|
||||
}
|
||||
bool getBattStats(uint8_t& chargeState, int8_t& percent,
|
||||
uint16_t& milliVolts) {
|
||||
bool getBattStats(int8_t& chargeState, int8_t& percent, int16_t& milliVolts) {
|
||||
return thisModem().getBattStatsImpl(chargeState, percent, milliVolts);
|
||||
}
|
||||
|
||||
@@ -61,7 +60,7 @@ class TinyGsmBattery {
|
||||
*/
|
||||
protected:
|
||||
// Use: float vBatt = modem.getBattVoltage() / 1000.0;
|
||||
uint16_t getBattVoltageImpl() {
|
||||
int16_t getBattVoltageImpl() {
|
||||
thisModem().sendAT(GF("+CBC"));
|
||||
if (thisModem().waitResponse(GF("+CBC:")) != 1) { return 0; }
|
||||
thisModem().streamSkipUntil(','); // Skip battery charge status
|
||||
@@ -84,7 +83,7 @@ class TinyGsmBattery {
|
||||
return res;
|
||||
}
|
||||
|
||||
uint8_t getBattChargeStateImpl() {
|
||||
int8_t getBattChargeStateImpl() {
|
||||
thisModem().sendAT(GF("+CBC"));
|
||||
if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; }
|
||||
// Read battery charge status
|
||||
@@ -94,8 +93,8 @@ class TinyGsmBattery {
|
||||
return res;
|
||||
}
|
||||
|
||||
bool getBattStatsImpl(uint8_t& chargeState, int8_t& percent,
|
||||
uint16_t& milliVolts) {
|
||||
bool getBattStatsImpl(int8_t& chargeState, int8_t& percent,
|
||||
int16_t& milliVolts) {
|
||||
thisModem().sendAT(GF("+CBC"));
|
||||
if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; }
|
||||
chargeState = thisModem().streamGetIntBefore(',');
|
||||
|
||||
@@ -435,7 +435,7 @@ class TinyGsmA6 : public TinyGsmModem<TinyGsmA6>,
|
||||
* Battery functions
|
||||
*/
|
||||
protected:
|
||||
uint16_t getBattVoltageImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
int16_t getBattVoltageImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
|
||||
// Needs a '?' after CBC, unlike most
|
||||
int8_t getBattPercentImpl() {
|
||||
@@ -450,8 +450,8 @@ class TinyGsmA6 : public TinyGsmModem<TinyGsmA6>,
|
||||
}
|
||||
|
||||
// Needs a '?' after CBC, unlike most
|
||||
bool getBattStatsImpl(uint8_t& chargeState, int8_t& percent,
|
||||
uint16_t& milliVolts) {
|
||||
bool getBattStatsImpl(int8_t& chargeState, int8_t& percent,
|
||||
int16_t& milliVolts) {
|
||||
sendAT(GF("+CBC?"));
|
||||
if (waitResponse(GF(AT_NL "+CBC:")) != 1) { return false; }
|
||||
chargeState = streamGetIntBefore(',');
|
||||
|
||||
@@ -563,7 +563,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
|
||||
*/
|
||||
protected:
|
||||
// SRGD Note: Returns voltage in VOLTS instead of millivolts
|
||||
uint16_t getBattVoltageImpl() {
|
||||
int16_t getBattVoltageImpl() {
|
||||
sendAT(GF("+CBC"));
|
||||
if (waitResponse(GF(AT_NL "+CBC:")) != 1) { return 0; }
|
||||
streamSkipUntil(','); // Skip battery charge status
|
||||
@@ -578,8 +578,8 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
|
||||
}
|
||||
|
||||
// SRGD Note: Returns voltage in VOLTS instead of millivolts
|
||||
bool getBattStatsImpl(uint8_t& chargeState, int8_t& percent,
|
||||
uint16_t& milliVolts) {
|
||||
bool getBattStatsImpl(int8_t& chargeState, int8_t& percent,
|
||||
int16_t& milliVolts) {
|
||||
sendAT(GF("+CBC"));
|
||||
if (waitResponse(GF(AT_NL "+CBC:")) != 1) { return false; }
|
||||
chargeState = streamGetIntBefore(',');
|
||||
|
||||
@@ -590,7 +590,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
|
||||
*/
|
||||
protected:
|
||||
// returns volts, multiply by 1000 to get mV
|
||||
uint16_t getBattVoltageImpl() {
|
||||
int16_t getBattVoltageImpl() {
|
||||
sendAT(GF("+CBC"));
|
||||
if (waitResponse(GF(AT_NL "+CBC:")) != 1) { return 0; }
|
||||
|
||||
@@ -605,10 +605,10 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
|
||||
|
||||
int8_t getBattPercentImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
|
||||
uint8_t getBattChargeStateImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
int8_t getBattChargeStateImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
|
||||
bool getBattStatsImpl(uint8_t& chargeState, int8_t& percent,
|
||||
uint16_t& milliVolts) {
|
||||
bool getBattStatsImpl(int8_t& chargeState, int8_t& percent,
|
||||
int16_t& milliVolts) {
|
||||
chargeState = 0;
|
||||
percent = 0;
|
||||
milliVolts = getBattVoltage();
|
||||
|
||||
@@ -628,7 +628,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
|
||||
* Battery functions
|
||||
*/
|
||||
protected:
|
||||
uint16_t getBattVoltageImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
int16_t getBattVoltageImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
|
||||
int8_t getBattPercentImpl() {
|
||||
sendAT(GF("+CIND?"));
|
||||
@@ -641,10 +641,10 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
|
||||
return percent;
|
||||
}
|
||||
|
||||
uint8_t getBattChargeStateImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
int8_t getBattChargeStateImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
|
||||
bool getBattStatsImpl(uint8_t& chargeState, int8_t& percent,
|
||||
uint16_t& milliVolts) {
|
||||
bool getBattStatsImpl(int8_t& chargeState, int8_t& percent,
|
||||
int16_t& milliVolts) {
|
||||
chargeState = 0;
|
||||
percent = getBattPercent();
|
||||
milliVolts = 0;
|
||||
|
||||
@@ -621,7 +621,7 @@ class TinyGsmSaraR5 : public TinyGsmModem<TinyGsmSaraR5>,
|
||||
* Battery functions
|
||||
*/
|
||||
protected:
|
||||
uint16_t getBattVoltageImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
int16_t getBattVoltageImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
|
||||
int8_t getBattPercentImpl() {
|
||||
sendAT(GF("+CIND?"));
|
||||
@@ -634,10 +634,10 @@ class TinyGsmSaraR5 : public TinyGsmModem<TinyGsmSaraR5>,
|
||||
return percent;
|
||||
}
|
||||
|
||||
uint8_t getBattChargeStateImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
int8_t getBattChargeStateImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
|
||||
bool getBattStatsImpl(uint8_t& chargeState, int8_t& percent,
|
||||
uint16_t& milliVolts) {
|
||||
bool getBattStatsImpl(int8_t& chargeState, int8_t& percent,
|
||||
int16_t& milliVolts) {
|
||||
chargeState = 0;
|
||||
percent = getBattPercent();
|
||||
milliVolts = 0;
|
||||
|
||||
@@ -609,7 +609,7 @@ class TinyGsmUBLOX : public TinyGsmModem<TinyGsmUBLOX>,
|
||||
* Battery functions
|
||||
*/
|
||||
protected:
|
||||
uint16_t getBattVoltageImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
int16_t getBattVoltageImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
|
||||
int8_t getBattPercentImpl() {
|
||||
sendAT(GF("+CIND?"));
|
||||
@@ -622,10 +622,10 @@ class TinyGsmUBLOX : public TinyGsmModem<TinyGsmUBLOX>,
|
||||
return percent;
|
||||
}
|
||||
|
||||
uint8_t getBattChargeStateImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
int8_t getBattChargeStateImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
|
||||
bool getBattStatsImpl(uint8_t& chargeState, int8_t& percent,
|
||||
uint16_t& milliVolts) {
|
||||
bool getBattStatsImpl(int8_t& chargeState, int8_t& percent,
|
||||
int16_t& milliVolts) {
|
||||
chargeState = 0;
|
||||
percent = getBattPercent();
|
||||
milliVolts = 0;
|
||||
|
||||
@@ -1088,7 +1088,7 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
|
||||
*/
|
||||
protected:
|
||||
// Use: float vBatt = modem.getBattVoltage() / 1000.0;
|
||||
uint16_t getBattVoltageImpl() {
|
||||
int16_t getBattVoltageImpl() {
|
||||
int16_t intRes = 0;
|
||||
XBEE_COMMAND_START_DECORATOR(5, false)
|
||||
if (beeType == XBEE_UNKNOWN) getSeries();
|
||||
@@ -1100,11 +1100,11 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
|
||||
return intRes;
|
||||
}
|
||||
|
||||
int8_t getBattPercentImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
uint8_t getBattChargeStateImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
int8_t getBattPercentImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
int8_t getBattChargeStateImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
|
||||
bool getBattStatsImpl(uint8_t& chargeState, int8_t& percent,
|
||||
uint16_t& milliVolts) {
|
||||
bool getBattStatsImpl(int8_t& chargeState, int8_t& percent,
|
||||
int16_t& milliVolts) {
|
||||
chargeState = 0;
|
||||
percent = 0;
|
||||
milliVolts = getBattVoltage();
|
||||
|
||||
@@ -255,9 +255,9 @@ void loop() {
|
||||
// modem.getBattVoltage(); // Not available for all modems
|
||||
// modem.getBattPercent(); // Not available for all modems
|
||||
// modem.getBattChargeState(); // Not available for all modems
|
||||
uint8_t chargeState = -99;
|
||||
int8_t chargePercent = -99;
|
||||
uint16_t milliVolts = -9999;
|
||||
int8_t chargeState = -99;
|
||||
int8_t chargePercent = -99;
|
||||
int16_t milliVolts = -9999;
|
||||
modem.getBattStats(chargeState, chargePercent, milliVolts);
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user