Made battery return types signed

Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
This commit is contained in:
Sara Damiano
2024-05-24 13:17:00 -04:00
parent b982d17b94
commit 6ea2d44594
11 changed files with 41 additions and 41 deletions

View File

@@ -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. - 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. - 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. - Cleaned up code for getting modem names.
- Made battery return types signed.
### Added ### 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) - 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)

View File

@@ -479,9 +479,9 @@ void loop() {
// Test Battery functions // Test Battery functions
#if TINY_GSM_TEST_BATTERY && defined TINY_GSM_MODEM_HAS_BATTERY #if TINY_GSM_TEST_BATTERY && defined TINY_GSM_MODEM_HAS_BATTERY
uint8_t chargeState = -99; int8_t chargeState = -99;
int8_t chargePercent = -99; int8_t chargePercent = -99;
uint16_t milliVolts = -9999; int16_t milliVolts = -9999;
modem.getBattStats(chargeState, chargePercent, milliVolts); modem.getBattStats(chargeState, chargePercent, milliVolts);
DBG("Battery charge state:", chargeState); DBG("Battery charge state:", chargeState);
DBG("Battery charge 'percent':", chargePercent); DBG("Battery charge 'percent':", chargePercent);

View File

@@ -24,17 +24,16 @@ class TinyGsmBattery {
/* /*
* Battery functions * Battery functions
*/ */
uint16_t getBattVoltage() { int16_t getBattVoltage() {
return thisModem().getBattVoltageImpl(); return thisModem().getBattVoltageImpl();
} }
int8_t getBattPercent() { int8_t getBattPercent() {
return thisModem().getBattPercentImpl(); return thisModem().getBattPercentImpl();
} }
uint8_t getBattChargeState() { int8_t getBattChargeState() {
return thisModem().getBattChargeStateImpl(); return thisModem().getBattChargeStateImpl();
} }
bool getBattStats(uint8_t& chargeState, int8_t& percent, bool getBattStats(int8_t& chargeState, int8_t& percent, int16_t& milliVolts) {
uint16_t& milliVolts) {
return thisModem().getBattStatsImpl(chargeState, percent, milliVolts); return thisModem().getBattStatsImpl(chargeState, percent, milliVolts);
} }
@@ -61,7 +60,7 @@ class TinyGsmBattery {
*/ */
protected: protected:
// Use: float vBatt = modem.getBattVoltage() / 1000.0; // Use: float vBatt = modem.getBattVoltage() / 1000.0;
uint16_t getBattVoltageImpl() { int16_t getBattVoltageImpl() {
thisModem().sendAT(GF("+CBC")); thisModem().sendAT(GF("+CBC"));
if (thisModem().waitResponse(GF("+CBC:")) != 1) { return 0; } if (thisModem().waitResponse(GF("+CBC:")) != 1) { return 0; }
thisModem().streamSkipUntil(','); // Skip battery charge status thisModem().streamSkipUntil(','); // Skip battery charge status
@@ -84,7 +83,7 @@ class TinyGsmBattery {
return res; return res;
} }
uint8_t getBattChargeStateImpl() { int8_t getBattChargeStateImpl() {
thisModem().sendAT(GF("+CBC")); thisModem().sendAT(GF("+CBC"));
if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; } if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; }
// Read battery charge status // Read battery charge status
@@ -94,8 +93,8 @@ class TinyGsmBattery {
return res; return res;
} }
bool getBattStatsImpl(uint8_t& chargeState, int8_t& percent, bool getBattStatsImpl(int8_t& chargeState, int8_t& percent,
uint16_t& milliVolts) { int16_t& milliVolts) {
thisModem().sendAT(GF("+CBC")); thisModem().sendAT(GF("+CBC"));
if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; } if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; }
chargeState = thisModem().streamGetIntBefore(','); chargeState = thisModem().streamGetIntBefore(',');

View File

@@ -435,7 +435,7 @@ class TinyGsmA6 : public TinyGsmModem<TinyGsmA6>,
* Battery functions * Battery functions
*/ */
protected: protected:
uint16_t getBattVoltageImpl() TINY_GSM_ATTR_NOT_AVAILABLE; int16_t getBattVoltageImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
// Needs a '?' after CBC, unlike most // Needs a '?' after CBC, unlike most
int8_t getBattPercentImpl() { int8_t getBattPercentImpl() {
@@ -450,8 +450,8 @@ class TinyGsmA6 : public TinyGsmModem<TinyGsmA6>,
} }
// Needs a '?' after CBC, unlike most // Needs a '?' after CBC, unlike most
bool getBattStatsImpl(uint8_t& chargeState, int8_t& percent, bool getBattStatsImpl(int8_t& chargeState, int8_t& percent,
uint16_t& milliVolts) { int16_t& milliVolts) {
sendAT(GF("+CBC?")); sendAT(GF("+CBC?"));
if (waitResponse(GF(AT_NL "+CBC:")) != 1) { return false; } if (waitResponse(GF(AT_NL "+CBC:")) != 1) { return false; }
chargeState = streamGetIntBefore(','); chargeState = streamGetIntBefore(',');

View File

@@ -563,7 +563,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
*/ */
protected: protected:
// SRGD Note: Returns voltage in VOLTS instead of millivolts // SRGD Note: Returns voltage in VOLTS instead of millivolts
uint16_t getBattVoltageImpl() { int16_t getBattVoltageImpl() {
sendAT(GF("+CBC")); sendAT(GF("+CBC"));
if (waitResponse(GF(AT_NL "+CBC:")) != 1) { return 0; } if (waitResponse(GF(AT_NL "+CBC:")) != 1) { return 0; }
streamSkipUntil(','); // Skip battery charge status streamSkipUntil(','); // Skip battery charge status
@@ -578,8 +578,8 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
} }
// SRGD Note: Returns voltage in VOLTS instead of millivolts // SRGD Note: Returns voltage in VOLTS instead of millivolts
bool getBattStatsImpl(uint8_t& chargeState, int8_t& percent, bool getBattStatsImpl(int8_t& chargeState, int8_t& percent,
uint16_t& milliVolts) { int16_t& milliVolts) {
sendAT(GF("+CBC")); sendAT(GF("+CBC"));
if (waitResponse(GF(AT_NL "+CBC:")) != 1) { return false; } if (waitResponse(GF(AT_NL "+CBC:")) != 1) { return false; }
chargeState = streamGetIntBefore(','); chargeState = streamGetIntBefore(',');

View File

@@ -590,7 +590,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
*/ */
protected: protected:
// returns volts, multiply by 1000 to get mV // returns volts, multiply by 1000 to get mV
uint16_t getBattVoltageImpl() { int16_t getBattVoltageImpl() {
sendAT(GF("+CBC")); sendAT(GF("+CBC"));
if (waitResponse(GF(AT_NL "+CBC:")) != 1) { return 0; } 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; 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, bool getBattStatsImpl(int8_t& chargeState, int8_t& percent,
uint16_t& milliVolts) { int16_t& milliVolts) {
chargeState = 0; chargeState = 0;
percent = 0; percent = 0;
milliVolts = getBattVoltage(); milliVolts = getBattVoltage();

View File

@@ -628,7 +628,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
* Battery functions * Battery functions
*/ */
protected: protected:
uint16_t getBattVoltageImpl() TINY_GSM_ATTR_NOT_AVAILABLE; int16_t getBattVoltageImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
int8_t getBattPercentImpl() { int8_t getBattPercentImpl() {
sendAT(GF("+CIND?")); sendAT(GF("+CIND?"));
@@ -641,10 +641,10 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
return percent; 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, bool getBattStatsImpl(int8_t& chargeState, int8_t& percent,
uint16_t& milliVolts) { int16_t& milliVolts) {
chargeState = 0; chargeState = 0;
percent = getBattPercent(); percent = getBattPercent();
milliVolts = 0; milliVolts = 0;

View File

@@ -621,7 +621,7 @@ class TinyGsmSaraR5 : public TinyGsmModem<TinyGsmSaraR5>,
* Battery functions * Battery functions
*/ */
protected: protected:
uint16_t getBattVoltageImpl() TINY_GSM_ATTR_NOT_AVAILABLE; int16_t getBattVoltageImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
int8_t getBattPercentImpl() { int8_t getBattPercentImpl() {
sendAT(GF("+CIND?")); sendAT(GF("+CIND?"));
@@ -634,10 +634,10 @@ class TinyGsmSaraR5 : public TinyGsmModem<TinyGsmSaraR5>,
return percent; 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, bool getBattStatsImpl(int8_t& chargeState, int8_t& percent,
uint16_t& milliVolts) { int16_t& milliVolts) {
chargeState = 0; chargeState = 0;
percent = getBattPercent(); percent = getBattPercent();
milliVolts = 0; milliVolts = 0;

View File

@@ -609,7 +609,7 @@ class TinyGsmUBLOX : public TinyGsmModem<TinyGsmUBLOX>,
* Battery functions * Battery functions
*/ */
protected: protected:
uint16_t getBattVoltageImpl() TINY_GSM_ATTR_NOT_AVAILABLE; int16_t getBattVoltageImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
int8_t getBattPercentImpl() { int8_t getBattPercentImpl() {
sendAT(GF("+CIND?")); sendAT(GF("+CIND?"));
@@ -622,10 +622,10 @@ class TinyGsmUBLOX : public TinyGsmModem<TinyGsmUBLOX>,
return percent; 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, bool getBattStatsImpl(int8_t& chargeState, int8_t& percent,
uint16_t& milliVolts) { int16_t& milliVolts) {
chargeState = 0; chargeState = 0;
percent = getBattPercent(); percent = getBattPercent();
milliVolts = 0; milliVolts = 0;

View File

@@ -1088,7 +1088,7 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
*/ */
protected: protected:
// Use: float vBatt = modem.getBattVoltage() / 1000.0; // Use: float vBatt = modem.getBattVoltage() / 1000.0;
uint16_t getBattVoltageImpl() { int16_t getBattVoltageImpl() {
int16_t intRes = 0; int16_t intRes = 0;
XBEE_COMMAND_START_DECORATOR(5, false) XBEE_COMMAND_START_DECORATOR(5, false)
if (beeType == XBEE_UNKNOWN) getSeries(); if (beeType == XBEE_UNKNOWN) getSeries();
@@ -1100,11 +1100,11 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
return intRes; return intRes;
} }
int8_t getBattPercentImpl() TINY_GSM_ATTR_NOT_AVAILABLE; 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, bool getBattStatsImpl(int8_t& chargeState, int8_t& percent,
uint16_t& milliVolts) { int16_t& milliVolts) {
chargeState = 0; chargeState = 0;
percent = 0; percent = 0;
milliVolts = getBattVoltage(); milliVolts = getBattVoltage();

View File

@@ -255,9 +255,9 @@ void loop() {
// modem.getBattVoltage(); // Not available for all modems // modem.getBattVoltage(); // Not available for all modems
// modem.getBattPercent(); // Not available for all modems // modem.getBattPercent(); // Not available for all modems
// modem.getBattChargeState(); // Not available for all modems // modem.getBattChargeState(); // Not available for all modems
uint8_t chargeState = -99; int8_t chargeState = -99;
int8_t chargePercent = -99; int8_t chargePercent = -99;
uint16_t milliVolts = -9999; int16_t milliVolts = -9999;
modem.getBattStats(chargeState, chargePercent, milliVolts); modem.getBattStats(chargeState, chargePercent, milliVolts);
#endif #endif