add power management and improve time line on oled

This commit is contained in:
Peter Buchegger 2020-11-08 14:14:56 +01:00
parent f84f3269af
commit 4228ffe235
3 changed files with 149 additions and 63 deletions

View file

@ -2,25 +2,25 @@
#include <LoRa.h>
#include <APRS-Decoder.h>
#include <TinyGPS++.h>
#include <TimeLib.h>
#include <WiFi.h>
#include "settings.h"
#include "display.h"
#include "pins.h"
#include <TimeLib.h>
#include "power_management.h"
#ifdef TTGO_T_Beam_V1_0
#include <axp20x.h>
void setup_axp();
AXP20X_Class axp;
#endif
#include "power_management.h"
PowerManagement powerManagement;
HardwareSerial ss(1);
TinyGPSPlus gps;
void setup_lora();
void setup_gps();
String create_lat_aprs(RawDegrees lat);
String create_long_aprs(RawDegrees lng);
void setup_lora();
String createNowStringTime();
static time_t nowTimeStamp = -1;
static time_t nextBeaconTimeStamp = -1;
@ -31,19 +31,36 @@ static bool send_update = true;
void setup()
{
Serial.begin(115200);
setup_display();
#ifdef TTGO_T_Beam_V1_0
Wire.begin(SDA, SCL);
if (!powerManagement.begin(Wire))
{
Serial.println("[INFO] AXP192 init done!");
}
else
{
Serial.println("[ERROR] AXP192 init failed!");
}
powerManagement.activateLoRa();
powerManagement.activateOLED();
powerManagement.activateGPS();
#endif
delay(500);
Serial.println("[INFO] LoRa APRS Tracker by OE5BPA (Peter Buchegger)");
setup_display();
show_display("OE5BPA", "LoRa APRS Tracker", "by Peter Buchegger", 2000);
#ifdef TTGO_T_Beam_V1_0
setup_axp();
#endif
setup_gps();
setup_lora();
// make sure wifi and bt is off as we don't need it:
WiFi.mode(WIFI_OFF);
btStop();
delay(500);
Serial.println("[INFO] setup done...");
}
String toDoubleInt(int number)
@ -65,11 +82,7 @@ void loop()
gps.encode(c);
}
bool gps_time_update = false;
if(gps.time.isUpdated())
{
gps_time_update = true;
}
bool gps_time_update = gps.time.isUpdated();
if(gps.time.isValid())
{
@ -84,7 +97,7 @@ void loop()
if(send_update && gps.location.isValid() && gps.location.isUpdated())
{
nextBeaconTimeStamp = nowTimeStamp + (BEACON_TIMEOUT * 60);
nextBeaconTimeStamp = nowTimeStamp + (BEACON_TIMEOUT * SECS_PER_MIN);
breakTime(nextBeaconTimeStamp, nextBeaconStruct);
send_update = false;
@ -109,63 +122,27 @@ void loop()
if(gps_time_update)
{
#ifdef TTGO_T_Beam_V1_0
char batteryVoltage[6];
dtostrf(axp.getBattVoltage()/1000, 1, 2, batteryVoltage);
char batteryChargeCurrent[6];
String batteryIndicator;
if(axp.isChargeing())
{
dtostrf(axp.getBattChargeCurrent(), 3, 0, batteryChargeCurrent);
batteryIndicator = "+";
}
else
{
dtostrf(axp.getBattDischargeCurrent(), 3, 0, batteryChargeCurrent);
batteryIndicator = "-";
}
#endif
#ifdef TTGO_T_Beam_V1_0
String batteryVoltage(powerManagement.getBatteryVoltage(), 2);
String batteryChargeCurrent(powerManagement.getBatteryChargeDischargeCurrent(), 0);
#endif
show_display(CALL,
toDoubleInt(gps.date.day()) + String(".") + toDoubleInt(gps.date.month()) + String(".") + gps.date.year() + String(" ") + toDoubleInt(gps.time.hour()) + String(":") + toDoubleInt(gps.time.minute()) + String(":") + toDoubleInt(gps.time.second()),
createNowStringTime(),
String("Sats: ") + gps.satellites.value() + String(" HDOP: ") + gps.hdop.hdop(),
String("Nxt Bcn: ") + toDoubleInt(nextBeaconStruct.Hour) + String(":") + toDoubleInt(nextBeaconStruct.Minute)
#ifdef TTGO_T_Beam_V1_0
, String("Bat: ") + batteryVoltage + String("V ") + batteryIndicator + batteryChargeCurrent + String("mA")
#endif
#ifdef TTGO_T_Beam_V1_0
, String("Bat: ") + batteryVoltage + String("V ") + batteryChargeCurrent + String("mA")
#endif
);
}
if(millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println("No GPS detected!");
}
}
#ifdef TTGO_T_Beam_V1_0
void setup_axp()
{
Wire.begin(SDA, SCL);
if (!axp.begin(Wire, AXP192_SLAVE_ADDRESS))
{
Serial.println("LoRa-APRS / Init / AXP192 Begin PASS");
} else {
Serial.println("LoRa-APRS / Init / AXP192 Begin FAIL");
}
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON); // LORA
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON); // GPS
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON); // OLED
axp.setDCDC1Voltage(3300);
/*Enable AXP ADC function*/
axp.adc1Enable(AXP202_BATT_CUR_ADC1 |
AXP202_BATT_VOL_ADC1,
true);
}
#endif
void setup_lora()
{
Serial.println("[INFO] Set SPI pins!");
@ -221,3 +198,10 @@ String create_long_aprs(RawDegrees lng)
String lng_str(str);
return lng_str;
}
String createNowStringTime()
{
char line[30];
sprintf(line, "%02d.%02d.%04d %02d:%02d:%02d", day(), month(), year(), hour(), minute(), second());
return String(line);
}

73
src/power_management.cpp Normal file
View file

@ -0,0 +1,73 @@
#include "power_management.h"
// cppcheck-suppress uninitMemberVar
PowerManagement::PowerManagement()
{
}
// cppcheck-suppress unusedFunction
bool PowerManagement::begin(TwoWire & port)
{
bool result = axp.begin(port, AXP192_SLAVE_ADDRESS);
if(!result)
{
axp.setDCDC1Voltage(3300);
// Enable AXP ADC function
axp.adc1Enable(AXP202_BATT_CUR_ADC1 |
AXP202_BATT_VOL_ADC1,
true);
}
return result;
}
// cppcheck-suppress unusedFunction
void PowerManagement::activateLoRa()
{
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON);
}
// cppcheck-suppress unusedFunction
void PowerManagement::deactivateLoRa()
{
axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
}
// cppcheck-suppress unusedFunction
void PowerManagement::activateGPS()
{
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON);
}
// cppcheck-suppress unusedFunction
void PowerManagement::deactivateGPS()
{
axp.setPowerOutPut(AXP192_LDO3, AXP202_OFF);
}
// cppcheck-suppress unusedFunction
void PowerManagement::activateOLED()
{
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
}
// cppcheck-suppress unusedFunction
void PowerManagement::decativateOLED()
{
axp.setPowerOutPut(AXP192_DCDC1, AXP202_OFF);
}
double PowerManagement::getBatteryVoltage()
{
return axp.getBattVoltage() / 1000.0;
}
double PowerManagement::getBatteryChargeDischargeCurrent()
{
if(axp.isChargeing())
{
return axp.getBattChargeCurrent();
}
return -1.0 * axp.getBattDischargeCurrent();
}

29
src/power_management.h Normal file
View file

@ -0,0 +1,29 @@
#ifndef POWER_MANAGEMENT_H_
#define POWER_MANAGEMENT_H_
#include <Arduino.h>
#include <axp20x.h>
class PowerManagement
{
public:
PowerManagement();
bool begin(TwoWire & port);
void activateLoRa();
void deactivateLoRa();
void activateGPS();
void deactivateGPS();
void activateOLED();
void decativateOLED();
double getBatteryVoltage();
double getBatteryChargeDischargeCurrent();
private:
AXP20X_Class axp;
};
#endif