-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,963 additions
and
2,278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* @file TinyGsmBattery.tpp | ||
* @author Volodymyr Shymanskyy | ||
* @license LGPL-3.0 | ||
* @copyright Copyright (c) 2016 Volodymyr Shymanskyy | ||
* @date Nov 2016 | ||
*/ | ||
|
||
#ifndef SRC_TINYGSMBATTERY_H_ | ||
#define SRC_TINYGSMBATTERY_H_ | ||
|
||
#include "TinyGsmCommon.h" | ||
|
||
#define TINY_GSM_MODEM_HAS_BATTERY | ||
|
||
template <class modemType> | ||
class TinyGsmBattery { | ||
public: | ||
/* | ||
* Battery functions | ||
*/ | ||
uint16_t getBattVoltage() { | ||
return thisModem().getBattVoltageImpl(); | ||
} | ||
int8_t getBattPercent() { | ||
return thisModem().getBattPercentImpl(); | ||
} | ||
uint8_t getBattChargeState() { | ||
return thisModem().getBattChargeStateImpl(); | ||
} | ||
bool getBattStats(uint8_t& chargeState, int8_t& percent, | ||
uint16_t& milliVolts) { | ||
return thisModem().getBattStatsImpl(chargeState, percent, milliVolts); | ||
} | ||
|
||
/* | ||
* CRTP Helper | ||
*/ | ||
protected: | ||
inline const modemType& thisModem() const { | ||
return static_cast<const modemType&>(*this); | ||
} | ||
inline modemType& thisModem() { | ||
return static_cast<modemType&>(*this); | ||
} | ||
|
||
/* | ||
* Battery functions | ||
*/ | ||
protected: | ||
// Use: float vBatt = modem.getBattVoltage() / 1000.0; | ||
uint16_t getBattVoltageImpl() { | ||
thisModem().sendAT(GF("+CBC")); | ||
if (thisModem().waitResponse(GF("+CBC:")) != 1) { return 0; } | ||
thisModem().streamSkipUntil(','); // Skip battery charge status | ||
thisModem().streamSkipUntil(','); // Skip battery charge level | ||
// return voltage in mV | ||
uint16_t res = thisModem().streamGetInt(','); | ||
// Wait for final OK | ||
thisModem().waitResponse(); | ||
return res; | ||
} | ||
|
||
int8_t getBattPercentImpl() { | ||
thisModem().sendAT(GF("+CBC")); | ||
if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; } | ||
thisModem().streamSkipUntil(','); // Skip battery charge status | ||
// Read battery charge level | ||
int res = thisModem().streamGetInt(','); | ||
// Wait for final OK | ||
thisModem().waitResponse(); | ||
return res; | ||
} | ||
|
||
uint8_t getBattChargeStateImpl() { | ||
thisModem().sendAT(GF("+CBC")); | ||
if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; } | ||
// Read battery charge status | ||
int res = thisModem().streamGetInt(','); | ||
// Wait for final OK | ||
thisModem().waitResponse(); | ||
return res; | ||
} | ||
|
||
bool getBattStatsImpl(uint8_t& chargeState, int8_t& percent, | ||
uint16_t& milliVolts) { | ||
thisModem().sendAT(GF("+CBC")); | ||
if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; } | ||
chargeState = thisModem().streamGetInt(','); | ||
percent = thisModem().streamGetInt(','); | ||
milliVolts = thisModem().streamGetInt('\n'); | ||
// Wait for final OK | ||
thisModem().waitResponse(); | ||
return true; | ||
} | ||
}; | ||
|
||
#endif // SRC_TINYGSMBATTERY_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* @file TinyGsmCalling.tpp | ||
* @author Volodymyr Shymanskyy | ||
* @license LGPL-3.0 | ||
* @copyright Copyright (c) 2016 Volodymyr Shymanskyy | ||
* @date Nov 2016 | ||
*/ | ||
|
||
#ifndef SRC_TINYGSMCALLING_H_ | ||
#define SRC_TINYGSMCALLING_H_ | ||
|
||
#include "TinyGsmCommon.h" | ||
|
||
#define TINY_GSM_MODEM_HAS_CALLING | ||
|
||
template <class modemType> | ||
class TinyGsmCalling { | ||
public: | ||
/* | ||
* Phone Call functions | ||
*/ | ||
bool callAnswer() { | ||
return thisModem().callAnswerImpl(); | ||
} | ||
bool callNumber(const String& number) { | ||
return thisModem().callNumberImpl(number); | ||
} | ||
bool callHangup() { | ||
return thisModem().callHangupImpl(); | ||
} | ||
bool dtmfSend(char cmd, int duration_ms = 100) { | ||
return thisModem().dtmfSendImpl(cmd, duration_ms); | ||
} | ||
|
||
/* | ||
* CRTP Helper | ||
*/ | ||
protected: | ||
inline const modemType& thisModem() const { | ||
return static_cast<const modemType&>(*this); | ||
} | ||
inline modemType& thisModem() { | ||
return static_cast<modemType&>(*this); | ||
} | ||
|
||
/* | ||
* Phone Call functions | ||
*/ | ||
protected: | ||
bool callAnswerImpl() { | ||
thisModem().sendAT(GF("A")); | ||
return thisModem().waitResponse() == 1; | ||
} | ||
|
||
// Returns true on pick-up, false on error/busy | ||
bool callNumberImpl(const String& number) { | ||
if (number == GF("last")) { | ||
thisModem().sendAT(GF("DL")); | ||
} else { | ||
thisModem().sendAT(GF("D"), number, ";"); | ||
} | ||
int status = thisModem().waitResponse(60000L, GF("OK"), GF("BUSY"), | ||
GF("NO ANSWER"), GF("NO CARRIER")); | ||
switch (status) { | ||
case 1: return true; | ||
case 2: | ||
case 3: return false; | ||
default: return false; | ||
} | ||
} | ||
|
||
bool callHangupImpl() { | ||
thisModem().sendAT(GF("H")); | ||
return thisModem().waitResponse() == 1; | ||
} | ||
|
||
// 0-9,*,#,A,B,C,D | ||
bool dtmfSendImpl(char cmd, int duration_ms = 100) { | ||
duration_ms = constrain(duration_ms, 100, 1000); | ||
|
||
thisModem().sendAT(GF("+VTD="), | ||
duration_ms / 100); // VTD accepts in 1/10 of a second | ||
thisModem().waitResponse(); | ||
|
||
thisModem().sendAT(GF("+VTS="), cmd); | ||
return thisModem().waitResponse(10000L) == 1; | ||
} | ||
}; | ||
|
||
#endif // SRC_TINYGSMCALLING_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.