move power management to own module

This commit is contained in:
Peter Buchegger 2020-06-01 11:23:48 +02:00
parent 7545b9f46e
commit f37bba2220
4 changed files with 86 additions and 44 deletions

View file

@ -1,5 +1,5 @@
[platformio]
default_envs = ttgo-lora32-v1
#[platformio]
#default_envs = ttgo-lora32-v1
[env]
platform = espressif32
@ -13,6 +13,7 @@ lib_deps =
APRS-Decoder-Lib
NTPClient
APRS-IS-Lib
AXP202X_Library
check_tool = cppcheck
check_flags =
cppcheck: --suppress=*:*.pio\* --inline-suppr
@ -29,22 +30,7 @@ board = ttgo-lora32-v1
[env:ttgo-t-beam-v1]
board = ttgo-t-beam
lib_deps =
Adafruit GFX Library@1.7.5
Adafruit SSD1306
LoRa
APRS-Decoder-Lib
NTPClient
APRS-IS-Lib
AXP202X_Library
[env:ttgo-t-beam-v0_7]
board = ttgo-t-beam
lib_deps =
Adafruit GFX Library@1.7.5
Adafruit SSD1306
LoRa
APRS-Decoder-Lib
NTPClient
APRS-IS-Lib
build_flags = -DARDUINO_T_Beam_V0_7

View file

@ -6,19 +6,17 @@
#include <LoRa.h>
#include <APRS-IS.h>
#include <APRS-Decoder.h>
#if defined(ARDUINO_T_Beam) && !defined(ARDUINO_T_Beam_V0_7)
#include <axp20x.h>
#endif
#include "settings.h"
#include "display.h"
#include "power_management.h"
WiFiMulti WiFiMulti;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, 60*60);
APRS_IS aprs_is(USER, PASS, TOOL, VERS);
#if defined(ARDUINO_T_Beam) && !defined(ARDUINO_T_Beam_V0_7)
AXP20X_Class axp;
PowerManagement powerManagement;
#endif
int next_update = -1;
@ -27,9 +25,6 @@ void setup_wifi();
void setup_ota();
void setup_lora();
void setup_ntp();
#if defined(ARDUINO_T_Beam) && !defined(ARDUINO_T_Beam_V0_7)
void setup_axp();
#endif
String BeaconMsg;
@ -37,6 +32,20 @@ String BeaconMsg;
void setup()
{
Serial.begin(115200);
#if defined(ARDUINO_T_Beam) && !defined(ARDUINO_T_Beam_V0_7)
Wire.begin(SDA, SCL);
if (!powerManagement.begin(Wire))
{
Serial.println("LoRa-APRS / Init / AXP192 Begin PASS");
} else {
Serial.println("LoRa-APRS / Init / AXP192 Begin FAIL");
}
powerManagement.activateLoRa();
powerManagement.activateOLED();
powerManagement.deactivateGPS();
#endif
setup_display();
delay(500);
@ -47,9 +56,6 @@ void setup()
setup_ota();
setup_lora();
setup_ntp();
#if defined(ARDUINO_T_Beam) && !defined(ARDUINO_T_Beam_V0_7)
setup_axp();
#endif
APRSMessage msg;
msg.setSource(USER);
@ -242,20 +248,3 @@ void setup_ntp()
Serial.println("[INFO] NTP Client init done!");
show_display("INFO", "NTP Client init done!", 2000);
}
#if defined(ARDUINO_T_Beam) && !defined(ARDUINO_T_Beam_V0_7)
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);
}
#endif

42
src/power_management.cpp Normal file
View file

@ -0,0 +1,42 @@
#include "power_management.h"
bool PowerManagement::begin(TwoWire port)
{
bool result = axp.begin(port, AXP192_SLAVE_ADDRESS);
if(!result)
{
axp.setDCDC1Voltage(3300);
}
return result;
}
void PowerManagement::activateLoRa()
{
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON);
}
void PowerManagement::deactivateLoRa()
{
axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
}
void PowerManagement::activateGPS()
{
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON);
}
void PowerManagement::deactivateGPS()
{
axp.setPowerOutPut(AXP192_LDO3, AXP202_OFF);
}
void PowerManagement::activateOLED()
{
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
}
void PowerManagement::decativateOLED()
{
axp.setPowerOutPut(AXP192_DCDC1, AXP202_OFF);
}

25
src/power_management.h Normal file
View file

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