Compare commits

..

No commits in common. "master" and "v22.19.0" have entirely different histories.

12 changed files with 105 additions and 413 deletions

View file

@ -12,7 +12,7 @@ AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
@ -24,8 +24,8 @@ AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: false
BinPackParameters: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
@ -54,7 +54,7 @@ BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 200
ColumnLimit: 500
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false

View file

@ -8,7 +8,6 @@ on:
pull_request:
branches:
- master
merge_group:
jobs:
build:

View file

@ -1,19 +0,0 @@
name: PlatformIO Dependabot
on:
workflow_dispatch:
schedule:
# Runs every day at 00:00
- cron: '0 0 * * *'
jobs:
dependabot:
runs-on: ubuntu-latest
name: run PlatformIO Dependabot
steps:
- name: Checkout
uses: actions/checkout@v3
- name: run PlatformIO Dependabot
uses: peterus/platformio_dependabot@v1
with:
github_token: ${{ secrets.DEPENDABOT_PAT }}

View file

@ -8,4 +8,4 @@
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
}

View file

@ -1,14 +1,3 @@
# Status update September 2025
Over the past year, my focus has shifted to other projects, and Ive decided its time to close the chapter on this one. I will no longer provide updates or support, and the repository will be archived.
This project has been a fun journey, and Id like to thank everyone who used, contributed, or shared feedback along the way. Your interest and support kept it alive far longer than I originally expected.
If youre looking for a great alternative, I recommend [CA2RXU LoRa APRS Tracker/Station](https://github.com/richonguzman/LoRa_APRS_Tracker).
73,
OE5BPA
# LoRa APRS Tracker
The LoRa APRS Tracker will work with very cheep hardware which you can buy from amazon, ebay or aliexpress.
@ -21,8 +10,7 @@ Try it out and be part of the APRS network.
You can use one of the Lora32 boards:
* TTGO T-Beam V0.7 (433MHz SX1278)
* TTGO T-Beam V1.0 and V1.1 (433MHz SX1278)
* TTGO T-Beam V1.2 AXP2101 (433MHz SX1278)
* TTGO T-Beam V1 (433MHz SX1278)
This boards cost around 30 Euros, they are very cheap but perfect for an LoRa iGate.
Keep in minde: you need a 433MHz version!
@ -42,7 +30,6 @@ The best success is to use PlatformIO (and it is the only platform where I can s
* When installed click 'the ant head' on the left and choose import the project on the right.
* Just open the folder and you can compile the Firmware.
### Configuration
* You can find all nessesary settings to change for your configuration in **data/tracker.json**.
@ -50,23 +37,6 @@ The best success is to use PlatformIO (and it is the only platform where I can s
* To upload it to your board you have to do this via **Upload File System image** in PlatformIO!
* To find the 'Upload File System image' click the PlatformIO symbol (the little alien) on the left side, choos your configuration, click on 'Platform' and search for 'Upload File System image'.
#### Step on console
You may not need to use PlatformIO because compilation and configuration can be done via console.
```
# switch to virtual env, for example using pipenv
pipenv shell
# install platformio
pipenv install platformio
# upload to board
pio run -t upload
```
## LoRa iGate
Look at my other project: a [LoRa iGate](https://github.com/peterus/LoRa_APRS_iGate)

View file

@ -2,31 +2,27 @@
default_envs = ttgo-t-beam-v1
[env]
platform = espressif32 @ 6.7.0
platform = espressif32 @ 3.0.0
framework = arduino
lib_ldf_mode = deep+
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
lib_deps =
adafruit/Adafruit GFX Library @ 1.11.9
adafruit/Adafruit SSD1306 @ 2.5.10
bblanchon/ArduinoJson @ 7.0.4
lewisxhe/XPowersLib @ 0.2.4
sandeepmistry/LoRa @ 0.8.0
peterus/APRS-Decoder-Lib @ 0.0.6
mikalhart/TinyGPSPlus @ 1.1.0
adafruit/Adafruit GFX Library @ 1.7.5
adafruit/Adafruit SSD1306 @ 2.4.0
bblanchon/ArduinoJson @ 6.17.0
lewisxhe/AXP202X_Library @ 1.1.2
sandeepmistry/LoRa @ 0.7.2
peterus/APRS-Decoder-Lib @ 0.0.5
mikalhart/TinyGPSPlus @ 1.0.2
paulstoffregen/Time @ 1.6
shaggydog/OneButton @ 1.5.0
peterus/esp-logger @ 1.0.0
peterus/esp-logger @ 0.0.1
check_tool = cppcheck
check_flags =
cppcheck: --suppress=*:*.pio\* --inline-suppr -DCPPCHECK
check_skip_packages = yes
[env:ttgo-t-beam-AXP2101-v1_2]
board = ttgo-t-beam
build_flags = -Werror -Wall -DTTGO_T_Beam_V1_2
[env:ttgo-t-beam-v1]
board = ttgo-t-beam
build_flags = -Werror -Wall -DTTGO_T_Beam_V1_0

View file

@ -13,22 +13,13 @@
#include "pins.h"
#include "power_management.h"
#define VERSION "23.36.01"
logging::Logger logger;
#define VERSION "22.19.0"
Configuration Config;
BeaconManager BeaconMan;
#ifdef TTGO_T_Beam_V1_0
AXP192 axp;
PowerManagement *powerManagement = &axp;
#endif
#ifdef TTGO_T_Beam_V1_2
AXP2101 axp;
PowerManagement *powerManagement = &axp;
#endif
OneButton userButton = OneButton(BUTTON_PIN, true, true);
PowerManagement powerManagement;
OneButton userButton = OneButton(BUTTON_PIN, true, true);
HardwareSerial ss(1);
TinyGPSPlus gps;
@ -71,22 +62,22 @@ static void toggle_display() {
void setup() {
Serial.begin(115200);
#if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_2)
#ifdef TTGO_T_Beam_V1_0
Wire.begin(SDA, SCL);
if (powerManagement->begin(Wire)) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "PMU", "init done!");
if (!powerManagement.begin(Wire)) {
logPrintlnI("AXP192 init done!");
} else {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "PMU", "init failed!");
logPrintlnE("AXP192 init failed!");
}
powerManagement->activateLoRa();
powerManagement->activateOLED();
powerManagement->activateGPS();
powerManagement->activateMeasurement();
powerManagement.activateLoRa();
powerManagement.activateOLED();
powerManagement.activateGPS();
powerManagement.activateMeasurement();
#endif
delay(500);
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "LoRa APRS Tracker by OE5BPA (Peter Buchegger)");
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "Version: " VERSION);
logPrintlnI("LoRa APRS Tracker by OE5BPA (Peter Buchegger)");
logPrintlnI("Version: " VERSION);
setup_display();
show_display("OE5BPA", "LoRa APRS Tracker", "by Peter Buchegger", "Version: " VERSION, 2000);
@ -114,9 +105,9 @@ void setup() {
}
userButton.attachDoubleClick(toggle_display);
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "Smart Beacon is: %s", getSmartBeaconState());
logPrintlnI("Smart Beacon is " + getSmartBeaconState());
show_display("INFO", "Smart Beacon is " + getSmartBeaconState(), 1000);
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "setup done...");
logPrintlnI("setup done...");
delay(500);
}
@ -138,20 +129,9 @@ void loop() {
}
}
bool gps_time_update = gps.time.isUpdated();
bool gps_loc_update = gps.location.isUpdated();
static bool gps_loc_update_valid = false;
static time_t nextBeaconTimeStamp = -1;
if (gps_loc_update != gps_loc_update_valid) {
gps_loc_update_valid = gps_loc_update;
if (gps_loc_update) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Loop", "GPS fix state went to VALID");
} else {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Loop", "GPS fix state went to INVALID");
}
}
bool gps_time_update = gps.time.isUpdated();
bool gps_loc_update = gps.location.isUpdated();
static time_t nextBeaconTimeStamp = -1;
static double currentHeading = 0;
static double previousHeading = 0;
@ -185,14 +165,13 @@ void loop() {
static bool BatteryIsConnected = false;
static String batteryVoltage = "";
static String batteryChargeCurrent = "";
#if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_2)
#ifdef TTGO_T_Beam_V1_0
static unsigned int rate_limit_check_battery = 0;
if (!(rate_limit_check_battery++ % 60)) {
BatteryIsConnected = powerManagement->isBatteryConnect();
}
if (!(rate_limit_check_battery++ % 60))
BatteryIsConnected = powerManagement.isBatteryConnect();
if (BatteryIsConnected) {
batteryVoltage = String(powerManagement->getBatteryVoltage(), 2);
batteryChargeCurrent = String(powerManagement->getBatteryChargeDischargeCurrent(), 0);
batteryVoltage = String(powerManagement.getBatteryVoltage(), 2);
batteryChargeCurrent = String(powerManagement.getBatteryChargeDischargeCurrent(), 0);
}
#endif
@ -224,8 +203,7 @@ void loop() {
if (send_update && gps_loc_update) {
send_update = false;
nextBeaconTimeStamp =
now() + (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active ? BeaconMan.getCurrentBeaconConfig()->smart_beacon.slow_rate : (BeaconMan.getCurrentBeaconConfig()->timeout * SECS_PER_MIN));
nextBeaconTimeStamp = now() + (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active ? BeaconMan.getCurrentBeaconConfig()->smart_beacon.slow_rate : (BeaconMan.getCurrentBeaconConfig()->timeout * SECS_PER_MIN));
APRSMessage msg;
String lat;
@ -289,19 +267,16 @@ void loop() {
aprsmsg += BeaconMan.getCurrentBeaconConfig()->message;
}
if (BatteryIsConnected) {
aprsmsg += " - Bat.: " + batteryVoltage + "V";
#ifdef TTGO_T_Beam_V1_0
aprsmsg += " - Cur.: " + batteryChargeCurrent + "mA";
#endif
aprsmsg += " - _Bat.: " + batteryVoltage + "V - Cur.: " + batteryChargeCurrent + "mA";
}
if (BeaconMan.getCurrentBeaconConfig()->enhance_precision) {
aprsmsg += " " + dao;
}
msg.getBody()->setData(aprsmsg);
msg.getAPRSBody()->setData(aprsmsg);
String data = msg.encode();
logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "Loop", "%s", data.c_str());
logPrintlnD(data);
show_display("<< TX >>", data);
if (Config.ptt.active) {
@ -334,20 +309,7 @@ void loop() {
if (gps_time_update) {
show_display(BeaconMan.getCurrentBeaconConfig()->callsign,
createDateString(now()) + " " + createTimeString(now()),
String("Sats: ") + gps.satellites.value() + " HDOP: " + gps.hdop.hdop(),
String("Next Bcn: ") + (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active ? "~" : "") + createTimeString(nextBeaconTimeStamp),
BatteryIsConnected ? (String("Bat: ") + batteryVoltage + "V, " + batteryChargeCurrent + "mA") : "Powered via USB",
String("Smart Beacon: " + getSmartBeaconState()));
Serial.println(BeaconMan.getCurrentBeaconConfig()->callsign);
Serial.println(createDateString(now()) + " " + createTimeString(now()));
Serial.println(String("Sats: ") + gps.satellites.value() + " HDOP: " + gps.hdop.hdop());
Serial.println(String("Next Bcn: ") + (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active ? "~" : "") + createTimeString(nextBeaconTimeStamp));
Serial.println(BatteryIsConnected ? (String("Bat: ") + batteryVoltage + "V, " + batteryChargeCurrent + "mA") : "Powered via USB");
Serial.println(String("Smart Beacon: " + getSmartBeaconState()));
Serial.println();
show_display(BeaconMan.getCurrentBeaconConfig()->callsign, createDateString(now()) + " " + createTimeString(now()), String("Sats: ") + gps.satellites.value() + " HDOP: " + gps.hdop.hdop(), String("Nxt Bcn: ") + (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active ? "~" : "") + createTimeString(nextBeaconTimeStamp), BatteryIsConnected ? (String("Bat: ") + batteryVoltage + "V, " + batteryChargeCurrent + "mA") : "Powered via USB", String("Smart Beacon: " + getSmartBeaconState()));
if (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active) {
// Change the Tx internal based on the current speed
@ -367,21 +329,14 @@ void loop() {
would lead to decrease of beacon rate in between 5 to 20 km/h. what
is even below the slow speed rate.
*/
if (curr_speed == 0) {
curr_speed = 1;
}
txInterval = min(BeaconMan.getCurrentBeaconConfig()->smart_beacon.slow_rate,
BeaconMan.getCurrentBeaconConfig()->smart_beacon.fast_speed * BeaconMan.getCurrentBeaconConfig()->smart_beacon.fast_rate / curr_speed) *
1000;
txInterval = min(BeaconMan.getCurrentBeaconConfig()->smart_beacon.slow_rate, BeaconMan.getCurrentBeaconConfig()->smart_beacon.fast_speed * BeaconMan.getCurrentBeaconConfig()->smart_beacon.fast_rate / curr_speed) * 1000;
}
}
}
if ((Config.debug == false) && (millis() > 5000 && gps.charsProcessed() < 10)) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR,
"GPS",
"No GPS frames detected! Try to reset the GPS Chip with this "
"firmware: https://github.com/lora-aprs/TTGO-T-Beam_GPS-reset");
logPrintlnE("No GPS frames detected! Try to reset the GPS Chip with this "
"firmware: https://github.com/lora-aprs/TTGO-T-Beam_GPS-reset");
show_display("No GPS frames detected!", "Try to reset the GPS Chip", "https://github.com/lora-aprs/TTGO-T-Beam_GPS-reset", 2000);
}
}
@ -390,29 +345,27 @@ void load_config() {
ConfigurationManagement confmg("/tracker.json");
Config = confmg.readConfiguration();
BeaconMan.loadConfig(Config.beacons);
if (BeaconMan.getCurrentBeaconConfig()->callsign == "NOCALL-7") {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR,
"Config",
"You have to change your settings in 'data/tracker.json' and "
"upload it via \"Upload File System image\"!");
show_display("ERROR",
"You have to change your settings in 'data/tracker.json' and "
"upload it via \"Upload File System image\"!");
if (BeaconMan.getCurrentBeaconConfig()->callsign == "NOCALL-10") {
logPrintlnE("You have to change your settings in 'data/tracker.json' and "
"upload it via \"Upload File System image\"!");
show_display("ERROR", "You have to change your settings in 'data/tracker.json' and "
"upload it via \"Upload File System image\"!");
while (true) {
}
}
}
void setup_lora() {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", "Set SPI pins!");
logPrintlnI("Set SPI pins!");
SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS);
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", "Set LoRa pins!");
logPrintlnI("Set LoRa pins!");
LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ);
long freq = Config.lora.frequencyTx;
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", "frequency: %d", freq);
logPrintI("frequency: ");
logPrintlnI(String(freq));
if (!LoRa.begin(freq)) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "LoRa", "Starting LoRa failed!");
logPrintlnE("Starting LoRa failed!");
show_display("ERROR", "Starting LoRa failed!");
while (true) {
}
@ -423,7 +376,7 @@ void setup_lora() {
LoRa.enableCrc();
LoRa.setTxPower(Config.lora.power);
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", "LoRa init done!");
logPrintlnI("LoRa init done!");
show_display("INFO", "LoRa init done!", 2000);
}
@ -533,7 +486,7 @@ String createDateString(time_t t) {
}
String createTimeString(time_t t) {
return String(padding(hour(t), 2) + ":" + padding(minute(t), 2) + ":" + padding(second(t), 2));
return String(padding(hour(t), 2) + "." + padding(minute(t), 2) + "." + padding(second(t), 2));
}
String getSmartBeaconState() {

View file

@ -7,14 +7,12 @@
#include "configuration.h"
extern logging::Logger logger;
ConfigurationManagement::ConfigurationManagement(String FilePath) : mFilePath(FilePath) {
if (!SPIFFS.begin(true)) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "Configuration", "Mounting SPIFFS was not possible. Trying to format SPIFFS...");
logPrintlnE("Mounting SPIFFS was not possible. Trying to format SPIFFS...");
SPIFFS.format();
if (!SPIFFS.begin()) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "Configuration", "Formatting SPIFFS was not okay!");
logPrintlnE("Formating SPIFFS was not okay!");
}
}
}
@ -23,14 +21,14 @@ ConfigurationManagement::ConfigurationManagement(String FilePath) : mFilePath(Fi
Configuration ConfigurationManagement::readConfiguration() {
File file = SPIFFS.open(mFilePath);
if (!file) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "Configuration", "Failed to open file for reading...");
logPrintlnE("Failed to open file for reading...");
return Configuration();
}
DynamicJsonDocument data(2048);
DeserializationError error = deserializeJson(data, file);
if (error) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "Configuration", "Failed to read file, using default configuration.");
logPrintlnE("Failed to read file, using default configuration.");
}
file.close();
@ -91,7 +89,7 @@ Configuration ConfigurationManagement::readConfiguration() {
void ConfigurationManagement::writeConfiguration(Configuration conf) {
File file = SPIFFS.open(mFilePath, "w");
if (!file) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "Configuration", "Failed to open file for writing...");
logPrintlnE("Failed to open file for writing...");
return;
}
DynamicJsonDocument data(2048);

View file

@ -7,8 +7,6 @@
#include "display.h"
#include "pins.h"
extern logging::Logger logger;
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RST);
// cppcheck-suppress unusedFunction
@ -20,7 +18,7 @@ void setup_display() {
Wire.begin(OLED_SDA, OLED_SCL);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "SSD1306", "allocation failed!");
logPrintlnE("SSD1306 allocation failed");
while (true) {
}
}
@ -37,9 +35,12 @@ void setup_display() {
// cppcheck-suppress unusedFunction
void display_toggle(bool toggle) {
logPrintI("Toggling display: ");
if (toggle) {
logPrintlnI("On");
display.ssd1306_command(SSD1306_DISPLAYON);
} else {
logPrintlnI("Off");
display.ssd1306_command(SSD1306_DISPLAYOFF);
}
}

View file

@ -16,7 +16,7 @@
#define GPS_TX 12
#endif
#if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_2)
#ifdef TTGO_T_Beam_V1_0
#define GPS_RX 12
#define GPS_TX 34
#endif

View file

@ -1,218 +1,72 @@
#include <XPowersAXP192.tpp>
#include <XPowersAXP2101.tpp>
#include "power_management.h"
AXP192::AXP192() {
// cppcheck-suppress uninitMemberVar
PowerManagement::PowerManagement() {
}
// cppcheck-suppress unusedFunction
bool AXP192::begin(TwoWire &port) {
_pmu = new XPowersAXP192(port);
if (!_pmu->init()) {
delete _pmu;
_pmu = 0;
return false;
bool PowerManagement::begin(TwoWire &port) {
bool result = axp.begin(port, AXP192_SLAVE_ADDRESS);
if (!result) {
axp.setDCDC1Voltage(3300);
}
// lora radio power channel
_pmu->setPowerChannelVoltage(XPOWERS_LDO2, 3300);
// oled module power channel,
// disable it will cause abnormal communication between boot and AXP power supply,
// do not turn it off
_pmu->setPowerChannelVoltage(XPOWERS_DCDC1, 3300);
// gnss module power channel - now turned on in setGpsPower
_pmu->setPowerChannelVoltage(XPOWERS_LDO3, 3300);
// protected oled power source
//_pmu->setProtectedChannel(XPOWERS_DCDC1);
// protected esp32 power source
_pmu->setProtectedChannel(XPOWERS_DCDC3);
// disable not use channel
_pmu->disablePowerOutput(XPOWERS_DCDC2);
// disable all axp chip interrupt
_pmu->disableIRQ(XPOWERS_AXP192_ALL_IRQ);
// Set constant current charging current
_pmu->setChargerConstantCurr(XPOWERS_AXP192_CHG_CUR_780MA);
// Set up the charging voltage
_pmu->setChargeTargetVoltage(XPOWERS_AXP192_CHG_VOL_4V2);
_pmu->setChargingLedMode(XPOWERS_CHG_LED_CTRL_CHG);
return true;
return result;
}
// cppcheck-suppress unusedFunction
void AXP192::activateLoRa() {
_pmu->enablePowerOutput(XPOWERS_LDO2);
void PowerManagement::activateLoRa() {
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON);
}
// cppcheck-suppress unusedFunction
void AXP192::deactivateLoRa() {
_pmu->disablePowerOutput(XPOWERS_LDO2);
void PowerManagement::deactivateLoRa() {
axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
}
// cppcheck-suppress unusedFunction
void AXP192::activateGPS() {
_pmu->enablePowerOutput(XPOWERS_LDO3);
void PowerManagement::activateGPS() {
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON);
}
// cppcheck-suppress unusedFunction
void AXP192::deactivateGPS() {
_pmu->disablePowerOutput(XPOWERS_LDO3);
void PowerManagement::deactivateGPS() {
axp.setPowerOutPut(AXP192_LDO3, AXP202_OFF);
}
// cppcheck-suppress unusedFunction
void AXP192::activateOLED() {
_pmu->enablePowerOutput(XPOWERS_DCDC1);
void PowerManagement::activateOLED() {
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
}
// cppcheck-suppress unusedFunction
void AXP192::deactivateOLED() {
_pmu->disablePowerOutput(XPOWERS_DCDC1);
void PowerManagement::decativateOLED() {
axp.setPowerOutPut(AXP192_DCDC1, AXP202_OFF);
}
// cppcheck-suppress unusedFunction
void AXP192::activateMeasurement() {
_pmu->enableBattVoltageMeasure();
void PowerManagement::activateMeasurement() {
axp.adc1Enable(AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, true);
}
// cppcheck-suppress unusedFunction
void AXP192::deactivateMeasurement() {
_pmu->disableBattVoltageMeasure();
void PowerManagement::deactivateMeasurement() {
axp.adc1Enable(AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, false);
}
// cppcheck-suppress unusedFunction
double AXP192::getBatteryVoltage() {
return _pmu->getBattVoltage() / 1000.0;
double PowerManagement::getBatteryVoltage() {
return axp.getBattVoltage() / 1000.0;
}
// cppcheck-suppress unusedFunction
double AXP192::getBatteryChargeDischargeCurrent() {
if (isCharging()) {
return ((XPowersAXP192 *)_pmu)->getBatteryChargeCurrent();
double PowerManagement::getBatteryChargeDischargeCurrent() {
if (axp.isChargeing()) {
return axp.getBattChargeCurrent();
}
return -1.0 * ((XPowersAXP192 *)_pmu)->getBattDischargeCurrent();
return -1.0 * axp.getBattDischargeCurrent();
}
bool AXP192::isBatteryConnect() {
return _pmu->isBatteryConnect();
}
bool AXP192::isCharging() {
return _pmu->isCharging();
}
AXP2101::AXP2101() {
}
// cppcheck-suppress unusedFunction
bool AXP2101::begin(TwoWire &port) {
_pmu = new XPowersAXP2101(port);
if (!_pmu->init()) {
delete _pmu;
_pmu = 0;
return false;
}
// Unuse power channel
_pmu->disablePowerOutput(XPOWERS_DCDC2);
_pmu->disablePowerOutput(XPOWERS_DCDC3);
_pmu->disablePowerOutput(XPOWERS_DCDC4);
_pmu->disablePowerOutput(XPOWERS_DCDC5);
_pmu->disablePowerOutput(XPOWERS_ALDO1);
_pmu->disablePowerOutput(XPOWERS_ALDO4);
_pmu->disablePowerOutput(XPOWERS_BLDO1);
_pmu->disablePowerOutput(XPOWERS_BLDO2);
_pmu->disablePowerOutput(XPOWERS_DLDO1);
_pmu->disablePowerOutput(XPOWERS_DLDO2);
// GNSS RTC PowerVDD 3300mV
_pmu->setPowerChannelVoltage(XPOWERS_VBACKUP, 3300);
_pmu->enablePowerOutput(XPOWERS_VBACKUP);
// LoRa VDD 3300mV
_pmu->setPowerChannelVoltage(XPOWERS_ALDO2, 3300);
_pmu->enablePowerOutput(XPOWERS_ALDO2);
// GNSS VDD 3300mV
_pmu->setPowerChannelVoltage(XPOWERS_ALDO3, 3300);
_pmu->enablePowerOutput(XPOWERS_ALDO3);
// disable all axp chip interrupt
_pmu->disableIRQ(XPOWERS_AXP2101_ALL_IRQ);
// Set constant current charging current
_pmu->setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_800MA);
// Set up the charging voltage
_pmu->setChargeTargetVoltage(XPOWERS_AXP2101_CHG_VOL_4V2);
_pmu->setChargingLedMode(XPOWERS_CHG_LED_CTRL_CHG);
return true;
}
// cppcheck-suppress unusedFunction
void AXP2101::activateLoRa() {
_pmu->enablePowerOutput(XPOWERS_ALDO2);
}
// cppcheck-suppress unusedFunction
void AXP2101::deactivateLoRa() {
_pmu->disablePowerOutput(XPOWERS_ALDO2);
}
// cppcheck-suppress unusedFunction
void AXP2101::activateGPS() {
_pmu->enablePowerOutput(XPOWERS_ALDO3);
}
// cppcheck-suppress unusedFunction
void AXP2101::deactivateGPS() {
_pmu->disablePowerOutput(XPOWERS_ALDO3);
}
// cppcheck-suppress unusedFunction
void AXP2101::activateOLED() {
_pmu->enablePowerOutput(XPOWERS_DCDC1);
}
// cppcheck-suppress unusedFunction
void AXP2101::deactivateOLED() {
_pmu->disablePowerOutput(XPOWERS_DCDC1);
}
// cppcheck-suppress unusedFunction
void AXP2101::activateMeasurement() {
_pmu->enableBattVoltageMeasure();
}
// cppcheck-suppress unusedFunction
void AXP2101::deactivateMeasurement() {
_pmu->disableBattVoltageMeasure();
}
// cppcheck-suppress unusedFunction
double AXP2101::getBatteryVoltage() {
return _pmu->getBattVoltage() / 1000.0;
}
// cppcheck-suppress unusedFunction
double AXP2101::getBatteryChargeDischargeCurrent() {
return 0.0;
}
bool AXP2101::isBatteryConnect() {
return _pmu->isBatteryConnect();
}
bool AXP2101::isCharging() {
return _pmu->isCharging();
bool PowerManagement::isBatteryConnect() {
return axp.isBatteryConnect();
}

View file

@ -1,43 +1,12 @@
#ifndef POWER_MANAGEMENT_H_
#define POWER_MANAGEMENT_H_
#include <Wire.h>
#include <XPowersLibInterface.hpp>
#include <Arduino.h>
#include <axp20x.h>
class PowerManagement {
public:
~PowerManagement() {
}
virtual bool begin(TwoWire &port) = 0;
virtual void activateLoRa() = 0;
virtual void deactivateLoRa() = 0;
virtual void activateGPS() = 0;
virtual void deactivateGPS() = 0;
virtual void activateOLED() = 0;
virtual void deactivateOLED() = 0;
virtual void activateMeasurement() = 0;
virtual void deactivateMeasurement() = 0;
virtual double getBatteryVoltage() = 0;
virtual double getBatteryChargeDischargeCurrent() = 0;
virtual bool isBatteryConnect() = 0;
virtual bool isCharging() = 0;
protected:
XPowersLibInterface *_pmu = 0;
};
class AXP192 : public PowerManagement {
public:
AXP192();
PowerManagement();
bool begin(TwoWire &port);
void activateLoRa();
@ -47,10 +16,7 @@ public:
void deactivateGPS();
void activateOLED();
void deactivateOLED();
void enableChgLed();
void disableChgLed();
void decativateOLED();
void activateMeasurement();
void deactivateMeasurement();
@ -59,35 +25,9 @@ public:
double getBatteryChargeDischargeCurrent();
bool isBatteryConnect();
bool isCharging();
};
class AXP2101 : public PowerManagement {
public:
AXP2101();
bool begin(TwoWire &port);
void activateLoRa();
void deactivateLoRa();
void activateGPS();
void deactivateGPS();
void activateOLED();
void deactivateOLED();
void enableChgLed();
void disableChgLed();
void activateMeasurement();
void deactivateMeasurement();
double getBatteryVoltage();
double getBatteryChargeDischargeCurrent();
bool isBatteryConnect();
bool isCharging();
private:
AXP20X_Class axp;
};
#endif