From f37bba2220e36d0bf0a3b28e6177f4fbc0570905 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Mon, 1 Jun 2020 11:23:48 +0200 Subject: [PATCH] move power management to own module --- platformio.ini | 20 +++---------------- src/LoRa_APRS_iGate.cpp | 43 +++++++++++++++------------------------- src/power_management.cpp | 42 +++++++++++++++++++++++++++++++++++++++ src/power_management.h | 25 +++++++++++++++++++++++ 4 files changed, 86 insertions(+), 44 deletions(-) create mode 100644 src/power_management.cpp create mode 100644 src/power_management.h diff --git a/platformio.ini b/platformio.ini index 4c8a2e8..e10e4ce 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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 diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 57ad79f..01d66c2 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -6,19 +6,17 @@ #include #include #include -#if defined(ARDUINO_T_Beam) && !defined(ARDUINO_T_Beam_V0_7) -#include -#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 diff --git a/src/power_management.cpp b/src/power_management.cpp new file mode 100644 index 0000000..97b31ac --- /dev/null +++ b/src/power_management.cpp @@ -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); +} diff --git a/src/power_management.h b/src/power_management.h new file mode 100644 index 0000000..f64b02c --- /dev/null +++ b/src/power_management.h @@ -0,0 +1,25 @@ +#ifndef POWER_MANAGEMENT_H_ +#define POWER_MANAGEMENT_H_ + +#include +#include + +class PowerManagement +{ +public: + bool begin(TwoWire port); + + void activateLoRa(); + void deactivateLoRa(); + + void activateGPS(); + void deactivateGPS(); + + void activateOLED(); + void decativateOLED(); + +private: + AXP20X_Class axp; +}; + +#endif