From 886b661a620363d01cc2271620bb5c89524c5d53 Mon Sep 17 00:00:00 2001 From: richonguzman Date: Sat, 11 May 2024 12:59:07 -0400 Subject: [PATCH] CodeCleaning --- src/A7670_utils.cpp | 332 +++++++++++++++++++++--------------------- src/aprs_is_utils.cpp | 54 +++---- src/bme_utils.cpp | 82 +++++------ src/bme_utils.h | 6 +- src/display.cpp | 32 ++-- src/lora_utils.cpp | 32 ++-- src/pins_config.h | 214 +++++++++++++-------------- src/power_utils.cpp | 156 ++++++++++---------- src/power_utils.h | 4 +- src/utils.cpp | 20 +-- src/wifi_utils.cpp | 6 +- 11 files changed, 469 insertions(+), 469 deletions(-) diff --git a/src/A7670_utils.cpp b/src/A7670_utils.cpp index 7b539821..a9eb0d9f 100644 --- a/src/A7670_utils.cpp +++ b/src/A7670_utils.cpp @@ -7,194 +7,194 @@ #include "utils.h" #if defined(ESP32_DIY_LoRa_A7670) -#define TINY_GSM_MODEM_SIM7600 //The AT instruction of A7670 is compatible with SIM7600 -#define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb -#define SerialAT Serial1 -#include -#include -StreamDebugger debugger(SerialAT, Serial); -TinyGsm modem(debugger); + #define TINY_GSM_MODEM_SIM7600 //The AT instruction of A7670 is compatible with SIM7600 + #define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb + #define SerialAT Serial1 + #include + #include + StreamDebugger debugger(SerialAT, Serial); + TinyGsm modem(debugger); -extern Configuration Config; -extern String firstLine; + extern Configuration Config; + extern String firstLine; -bool modemStartUp = false; -bool serverStartUp = false; -bool userBytesSended = false; -bool beaconBytesSended = false; -bool beaconSended = false; -bool stationBeacon = false; + bool modemStartUp = false; + bool serverStartUp = false; + bool userBytesSended = false; + bool beaconBytesSended = false; + bool beaconSended = false; + bool stationBeacon = false; -extern bool modemLoggedToAPRSIS; + extern bool modemLoggedToAPRSIS; -namespace A7670_Utils { + namespace A7670_Utils { - bool checkModemOn() { - bool modemReady = false; - Serial.print("Starting Modem ... "); - show_display(firstLine, "Starting Modem...", 0); + bool checkModemOn() { + bool modemReady = false; + Serial.print("Starting Modem ... "); + show_display(firstLine, "Starting Modem...", " ", " ", 0); - pinMode(A7670_ResetPin, OUTPUT); //A7670 Reset - digitalWrite(A7670_ResetPin, LOW); - delay(100); - digitalWrite(A7670_ResetPin, HIGH); - delay(3000); - digitalWrite(A7670_ResetPin, LOW); + pinMode(A7670_ResetPin, OUTPUT); //A7670 Reset + digitalWrite(A7670_ResetPin, LOW); + delay(100); + digitalWrite(A7670_ResetPin, HIGH); + delay(3000); + digitalWrite(A7670_ResetPin, LOW); - pinMode(A7670_PWR_PIN, OUTPUT); - digitalWrite(A7670_PWR_PIN, LOW); - delay(100); - digitalWrite(A7670_PWR_PIN, HIGH); - delay(1000); - digitalWrite(A7670_PWR_PIN, LOW); + pinMode(A7670_PWR_PIN, OUTPUT); + digitalWrite(A7670_PWR_PIN, LOW); + delay(100); + digitalWrite(A7670_PWR_PIN, HIGH); + delay(1000); + digitalWrite(A7670_PWR_PIN, LOW); - int i = 20; - while (i) { - SerialAT.println("AT"); - delay(500); - if (SerialAT.available()) { - String r = SerialAT.readString(); - //Serial.println(r); - if ( r.indexOf("OK") >= 0 ) { - modemReady = true; - i = 1; - Serial.println("Modem Ready!\n"); - show_display(firstLine, "Starting Modem...", "---> Modem Ready", 0); - return true; - } - } - if (!modemReady) { + int i = 20; + while (i) { + SerialAT.println("AT"); delay(500); + if (SerialAT.available()) { + String r = SerialAT.readString(); + //Serial.println(r); + if ( r.indexOf("OK") >= 0 ) { + modemReady = true; + i = 1; + Serial.println("Modem Ready!\n"); + show_display(firstLine, "Starting Modem...", "---> Modem Ready", " ", 0); + return true; + } + } + if (!modemReady) { + delay(500); + } + i--; } - i--; + return false; } - return false; - } - void setup() { - SerialAT.begin(115200, SERIAL_8N1, A7670_RX_PIN, A7670_TX_PIN); - if (checkModemOn()) {; - delay(1000); - //setup_gps(); // if gps active / won't be need for now - } else { - show_display(firstLine, "Starting Modem...", "---> Failed !!!", 0); - Serial.println(F("*********** Failed to connect to the modem! ***********")); + void setup() { + SerialAT.begin(115200, SERIAL_8N1, A7670_RX_PIN, A7670_TX_PIN); + if (checkModemOn()) {; + delay(1000); + //setup_gps(); // if gps active / won't be need for now + } else { + show_display(firstLine, "Starting Modem...", "---> Failed !!!", " ", 0); + Serial.println(F("*********** Failed to connect to the modem! ***********")); + } } - } - bool checkATResponse(String ATMessage) { - int delayATMessage = 3000; - bool validAT = false; - //Serial.println(ATMessage); - int i = 10; - while (i) { - if (!validAT) { - SerialAT.println(ATMessage); - } - delay(500); - if (SerialAT.available()) { - String response = SerialAT.readString(); - //Serial.println(response); // DEBUG of Modem AT message - if(response.indexOf("verified") >= 0) { - Serial.println("Logged! (User Validated)\n"); - show_display(firstLine, "Connecting APRS-IS...", "---> Logged!", 1000); - Serial.println("#################### APRS-IS FEED ####################"); - validAT = true; - i = 1; - delayATMessage = 0; - } else if (ATMessage == "AT+NETOPEN" && response.indexOf("OK") >= 0) { - Serial.println("Port Open!"); - show_display(firstLine, "Opening Port...", "---> Port Open", 0); - validAT = true; - i = 1; - delayATMessage = 0; - } else if (ATMessage == "AT+NETOPEN" && response.indexOf("Network is already opened") >= 0) { - Serial.println("Port Open! (was already opened)"); - show_display(firstLine, "Opening Port...", "---> Port Open", 0); - validAT = true; - i = 1; - delayATMessage = 0; - } else if (ATMessage.indexOf("AT+CIPOPEN") == 0 && response.indexOf("PB DONE") >= 0) { - Serial.println("Contacted!"); - show_display(firstLine, "Connecting APRS-IS...", "---> Contacted", 0); - validAT = true; - i = 1; - delayATMessage = 0; - } else if (ATMessage.indexOf("AT+CIPSEND=0,") == 0 && response.indexOf(">") >= 0) { - Serial.print("."); - validAT = true; - i = 1; - delayATMessage = 0; - } else if (ATMessage.indexOf(Config.callsign) >= 3 && !modemLoggedToAPRSIS && response.indexOf("OK") >= 0 && !stationBeacon) { // login info - validAT = true; - delayATMessage = 0; - } else if (ATMessage.indexOf(Config.callsign) == 0 && !beaconSended && response.indexOf("OK") >= 0 && !stationBeacon) { // self beacon or querys - validAT = true; - i = 1; - delayATMessage = 0; - } else if (stationBeacon && response.indexOf("OK") >= 0) { //upload others beacons - validAT = true; - i = 1; - delayATMessage = 0; + bool checkATResponse(String ATMessage) { + int delayATMessage = 3000; + bool validAT = false; + //Serial.println(ATMessage); + int i = 10; + while (i) { + if (!validAT) { + SerialAT.println(ATMessage); } + delay(500); + if (SerialAT.available()) { + String response = SerialAT.readString(); + //Serial.println(response); // DEBUG of Modem AT message + if(response.indexOf("verified") >= 0) { + Serial.println("Logged! (User Validated)\n"); + show_display(firstLine, "Connecting APRS-IS...", "---> Logged!", " ", 1000); + Serial.println("#################### APRS-IS FEED ####################"); + validAT = true; + i = 1; + delayATMessage = 0; + } else if (ATMessage == "AT+NETOPEN" && response.indexOf("OK") >= 0) { + Serial.println("Port Open!"); + show_display(firstLine, "Opening Port...", "---> Port Open", " ", 0); + validAT = true; + i = 1; + delayATMessage = 0; + } else if (ATMessage == "AT+NETOPEN" && response.indexOf("Network is already opened") >= 0) { + Serial.println("Port Open! (was already opened)"); + show_display(firstLine, "Opening Port...", "---> Port Open", " ", 0); + validAT = true; + i = 1; + delayATMessage = 0; + } else if (ATMessage.indexOf("AT+CIPOPEN") == 0 && response.indexOf("PB DONE") >= 0) { + Serial.println("Contacted!"); + show_display(firstLine, "Connecting APRS-IS...", "---> Contacted", " ", 0); + validAT = true; + i = 1; + delayATMessage = 0; + } else if (ATMessage.indexOf("AT+CIPSEND=0,") == 0 && response.indexOf(">") >= 0) { + Serial.print("."); + validAT = true; + i = 1; + delayATMessage = 0; + } else if (ATMessage.indexOf(Config.callsign) >= 3 && !modemLoggedToAPRSIS && response.indexOf("OK") >= 0 && !stationBeacon) { // login info + validAT = true; + delayATMessage = 0; + } else if (ATMessage.indexOf(Config.callsign) == 0 && !beaconSended && response.indexOf("OK") >= 0 && !stationBeacon) { // self beacon or querys + validAT = true; + i = 1; + delayATMessage = 0; + } else if (stationBeacon && response.indexOf("OK") >= 0) { //upload others beacons + validAT = true; + i = 1; + delayATMessage = 0; + } + } + delay(delayATMessage); + i--; } - delay(delayATMessage); - i--; + return validAT; } - return validAT; - } - void APRS_IS_connect() { - String loginInfo = "user " + Config.callsign + " pass " + String(Config.aprs_is.passcode) + " vers CA2RXU_LoRa_iGate 1.3 filter " + Config.aprs_is.filter; - Serial.println("-----> Connecting to APRS IS"); - while (!modemStartUp) { - Serial.print("Opening Port... "); - show_display(firstLine, "Opening Port...", 0); - modemStartUp = checkATResponse("AT+NETOPEN"); - delay(2000); - } while (!serverStartUp) { - Serial.print("Connecting APRS-IS Server... "); - show_display(firstLine, "Connecting APRS-IS...", 0); - serverStartUp = checkATResponse("AT+CIPOPEN=0,\"TCP\",\"" + String(Config.aprs_is.server) + "\"," + String(Config.aprs_is.port)); - delay(2000); - } while (!userBytesSended) { - Serial.print("Writing User Login Data "); - show_display(firstLine, "Connecting APRS-IS...", "---> User Login Data", 0); - userBytesSended = checkATResponse("AT+CIPSEND=0," + String(loginInfo.length()+1)); - delay(2000); - } while (!modemLoggedToAPRSIS) { - Serial.print("."); - modemLoggedToAPRSIS = checkATResponse(loginInfo); - delay(2000); + void APRS_IS_connect() { + String loginInfo = "user " + Config.callsign + " pass " + String(Config.aprs_is.passcode) + " vers CA2RXU_LoRa_iGate 1.3 filter " + Config.aprs_is.filter; + Serial.println("-----> Connecting to APRS IS"); + while (!modemStartUp) { + Serial.print("Opening Port... "); + show_display(firstLine, "Opening Port...", " ", " ", 0); + modemStartUp = checkATResponse("AT+NETOPEN"); + delay(2000); + } while (!serverStartUp) { + Serial.print("Connecting APRS-IS Server... "); + show_display(firstLine, "Connecting APRS-IS...", " ", " ", 0); + serverStartUp = checkATResponse("AT+CIPOPEN=0,\"TCP\",\"" + String(Config.aprs_is.server) + "\"," + String(Config.aprs_is.port)); + delay(2000); + } while (!userBytesSended) { + Serial.print("Writing User Login Data "); + show_display(firstLine, "Connecting APRS-IS...", "---> User Login Data", " ", 0); + userBytesSended = checkATResponse("AT+CIPSEND=0," + String(loginInfo.length()+1)); + delay(2000); + } while (!modemLoggedToAPRSIS) { + Serial.print("."); + modemLoggedToAPRSIS = checkATResponse(loginInfo); + delay(2000); + } } - } - void uploadToAPRSIS(String packet) { - beaconBytesSended = checkATResponse("AT+CIPSEND=0," + String(packet.length()+1)); - delay(2000); - if (beaconBytesSended) { - Serial.print("."); - beaconSended = checkATResponse(packet); - } - if (!beaconSended) { - Serial.println("------------------------------------> UPLOAD FAILED!!!"); - } else { - Serial.println("Packet Uploaded to APRS-IS!"); + void uploadToAPRSIS(String packet) { + beaconBytesSended = checkATResponse("AT+CIPSEND=0," + String(packet.length()+1)); + delay(2000); + if (beaconBytesSended) { + Serial.print("."); + beaconSended = checkATResponse(packet); + } + if (!beaconSended) { + Serial.println("------------------------------------> UPLOAD FAILED!!!"); + } else { + Serial.println("Packet Uploaded to APRS-IS!"); + } + beaconBytesSended = false; + beaconSended = false; } - beaconBytesSended = false; - beaconSended = false; - } - void listenAPRSIS() { - if (SerialAT.available()) { - String packetAPRSIS = SerialAT.readStringUntil('\r'); - packetAPRSIS.trim(); - if (!packetAPRSIS.startsWith("#") && packetAPRSIS.indexOf("+IPD") == -1 && packetAPRSIS.indexOf("RECV") == -1 && packetAPRSIS.length() > 0) { - APRS_IS_Utils::processAPRSISPacket(packetAPRSIS); + void listenAPRSIS() { + if (SerialAT.available()) { + String packetAPRSIS = SerialAT.readStringUntil('\r'); + packetAPRSIS.trim(); + if (!packetAPRSIS.startsWith("#") && packetAPRSIS.indexOf("+IPD") == -1 && packetAPRSIS.indexOf("RECV") == -1 && packetAPRSIS.length() > 0) { + APRS_IS_Utils::processAPRSISPacket(packetAPRSIS); + } } - } - delay(1); - } -} + delay(1); + } + } #endif \ No newline at end of file diff --git a/src/aprs_is_utils.cpp b/src/aprs_is_utils.cpp index bbae6d06..91c58837 100644 --- a/src/aprs_is_utils.cpp +++ b/src/aprs_is_utils.cpp @@ -26,7 +26,7 @@ extern uint32_t lastRxTime; extern bool modemLoggedToAPRSIS; #ifdef ESP32_DIY_LoRa_A7670 -extern bool stationBeacon; + extern bool stationBeacon; #endif @@ -80,17 +80,17 @@ namespace APRS_IS_Utils { aprsisState = "OFF"; } else { #ifdef ESP32_DIY_LoRa_A7670 - if (modemLoggedToAPRSIS) { - aprsisState = "OK"; - } else { - aprsisState = "--"; - } + if (modemLoggedToAPRSIS) { + aprsisState = "OK"; + } else { + aprsisState = "--"; + } #else - if (espClient.connected()) { - aprsisState = "OK"; - } else { - aprsisState = "--"; - } + if (espClient.connected()) { + aprsisState = "OK"; + } else { + aprsisState = "--"; + } #endif if(aprsisState == "--" && !Config.display.alwaysOn && Config.display.timeout != 0) { display_toggle(true); @@ -174,11 +174,11 @@ namespace APRS_IS_Utils { } lastScreenOn = millis(); #ifdef ESP32_DIY_LoRa_A7670 - stationBeacon = true; - A7670_Utils::uploadToAPRSIS(aprsPacket); - stationBeacon = false; + stationBeacon = true; + A7670_Utils::uploadToAPRSIS(aprsPacket); + stationBeacon = false; #else - upload(aprsPacket); + upload(aprsPacket); #endif Utils::println("---> Uploaded to APRS-IS"); show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0); @@ -207,9 +207,9 @@ namespace APRS_IS_Utils { } String ackPacket = Config.callsign + ">APLRG1,TCPIP,qAC::" + Sender + ":" + ackMessage; #ifdef ESP32_DIY_LoRa_A7670 - A7670_Utils::uploadToAPRSIS(ackPacket); + A7670_Utils::uploadToAPRSIS(ackPacket); #else - upload(ackPacket); + upload(ackPacket); #endif receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":") + 1, AddresseeAndMessage.indexOf("{")); } else { @@ -225,9 +225,9 @@ namespace APRS_IS_Utils { lastScreenOn = millis(); delay(500); #ifdef ESP32_DIY_LoRa_A7670 - A7670_Utils::uploadToAPRSIS(queryAnswer); + A7670_Utils::uploadToAPRSIS(queryAnswer); #else - upload(queryAnswer); + upload(queryAnswer); #endif SYSLOG_Utils::log("APRSIS Tx", queryAnswer, 0, 0, 0); fifthLine = "APRS-IS ----> APRS-IS"; @@ -255,16 +255,16 @@ namespace APRS_IS_Utils { void listenAPRSIS() { #ifdef ESP32_DIY_LoRa_A7670 - A7670_Utils::listenAPRSIS(); + A7670_Utils::listenAPRSIS(); #else - if (espClient.connected()) { - if (espClient.available()) { - String aprsisPacket = espClient.readStringUntil('\r'); - // Serial.println(aprsisPacket); - processAPRSISPacket(aprsisPacket); - lastRxTime = millis(); + if (espClient.connected()) { + if (espClient.available()) { + String aprsisPacket = espClient.readStringUntil('\r'); + // Serial.println(aprsisPacket); + processAPRSISPacket(aprsisPacket); + lastRxTime = millis(); + } } - } #endif } diff --git a/src/bme_utils.cpp b/src/bme_utils.cpp index 838aa83c..e17a7c0f 100644 --- a/src/bme_utils.cpp +++ b/src/bme_utils.cpp @@ -19,13 +19,13 @@ bool bmeSensorFound = false; namespace BME_Utils { #ifdef BME280Sensor - Adafruit_BME280 bme; + Adafruit_BME280 bme; #endif #ifdef BMP280Sensor - Adafruit_BMP280 bme; + Adafruit_BMP280 bme; #endif #ifdef BME680Sensor - Adafruit_BME680 bme; + Adafruit_BME680 bme; #endif void setup() { @@ -37,28 +37,28 @@ namespace BME_Utils { show_display("ERROR", "", "BME/BMP sensor active", "but no sensor found...", 2000); } else { #ifdef BME280Sensor - bme.setSampling(Adafruit_BME280::MODE_FORCED, - Adafruit_BME280::SAMPLING_X1, - Adafruit_BME280::SAMPLING_X1, - Adafruit_BME280::SAMPLING_X1, - Adafruit_BME280::FILTER_OFF - ); - Serial.println("init : BME280 Module ... done!"); + bme.setSampling(Adafruit_BME280::MODE_FORCED, + Adafruit_BME280::SAMPLING_X1, + Adafruit_BME280::SAMPLING_X1, + Adafruit_BME280::SAMPLING_X1, + Adafruit_BME280::FILTER_OFF + ); + Serial.println("init : BME280 Module ... done!"); #endif #ifdef BMP280Sensor - bme.setSampling(Adafruit_BMP280::MODE_FORCED, - Adafruit_BMP280::SAMPLING_X1, - Adafruit_BMP280::SAMPLING_X1, - Adafruit_BMP280::FILTER_OFF - ); - Serial.println("init : BMP280 Module ... done!"); + bme.setSampling(Adafruit_BMP280::MODE_FORCED, + Adafruit_BMP280::SAMPLING_X1, + Adafruit_BMP280::SAMPLING_X1, + Adafruit_BMP280::FILTER_OFF + ); + Serial.println("init : BMP280 Module ... done!"); #endif #ifdef BME680Sensor - bme.setTemperatureOversampling(BME680_OS_1X); - bme.setHumidityOversampling(BME680_OS_1X); - bme.setPressureOversampling(BME680_OS_1X); - bme.setIIRFilterSize(BME680_FILTER_SIZE_0); - Serial.println("init : BME680 Module ... done!"); + bme.setTemperatureOversampling(BME680_OS_1X); + bme.setHumidityOversampling(BME680_OS_1X); + bme.setPressureOversampling(BME680_OS_1X); + bme.setIIRFilterSize(BME680_FILTER_SIZE_0); + Serial.println("init : BME680 Module ... done!"); #endif bmeSensorFound = true; } @@ -137,26 +137,26 @@ namespace BME_Utils { uint32_t lastReading = millis() - bmeLastReading; if (lastReading > 60*1000) { #if defined(BME280Sensor) || defined(BMP280Sensor) - bme.takeForcedMeasurement(); - newTemp = bme.readTemperature(); - newPress = (bme.readPressure() / 100.0F); - #ifdef BME280Sensor - newHum = bme.readHumidity(); - #endif - #ifdef BMP280Sensor - newHum = 0; - #endif + bme.takeForcedMeasurement(); + newTemp = bme.readTemperature(); + newPress = (bme.readPressure() / 100.0F); + #ifdef BME280Sensor + newHum = bme.readHumidity(); + #endif + #ifdef BMP280Sensor + newHum = 0; + #endif #endif #ifdef BME680Sensor - bme.performReading(); - delay(50); - if (bme.endReading()) { - newTemp = bme.temperature; - newPress = (bme.pressure / 100.0F); - newHum = bme.humidity; - newGas = bme.gas_resistance / 1000.0; // in Kilo ohms - } + bme.performReading(); + delay(50); + if (bme.endReading()) { + newTemp = bme.temperature; + newPress = (bme.pressure / 100.0F); + newHum = bme.humidity; + newGas = bme.gas_resistance / 1000.0; // in Kilo ohms + } #endif bmeLastReading = millis(); } @@ -169,16 +169,16 @@ namespace BME_Utils { } else { tempStr = generateTempString((newTemp * 1.8) + 32); #if defined(BME280Sensor) || defined(BME680Sensor) - humStr = generateHumString(newHum); + humStr = generateHumString(newHum); #endif #ifdef BMP280Sensor - humStr = ".."; + humStr = ".."; #endif presStr = generatePresString(newPress + (HEIGHT_CORRECTION/CORRECTION_FACTOR)); fifthLine = "BME-> " + String(int(newTemp))+"C " + humStr + "% " + presStr.substring(0,4) + "hPa"; wx = ".../...g...t" + tempStr + "r...p...P...h" + humStr + "b" + presStr; #ifdef BME680Sensor - wx += "Gas: " + String(newGas) + "Kohms "; + wx += "Gas: " + String(newGas) + "Kohms "; #endif return wx; } diff --git a/src/bme_utils.h b/src/bme_utils.h index 3d7a40c7..47a171eb 100644 --- a/src/bme_utils.h +++ b/src/bme_utils.h @@ -9,13 +9,13 @@ //#define BME680Sensor #ifdef BME280Sensor -#include + #include #endif #ifdef BMP280Sensor -#include + #include #endif #ifdef BME680Sensor -#include + #include #endif diff --git a/src/display.cpp b/src/display.cpp index 0000d18e..590f4c01 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -11,9 +11,9 @@ TFT_eSPI tft = TFT_eSPI(); #ifdef HELTEC_WIRELESS_TRACKER - #define bigSizeFont 2 - #define smallSizeFont 1 - #define lineSpacing 9 + #define bigSizeFont 2 + #define smallSizeFont 1 + #define lineSpacing 9 #endif #else #include @@ -74,19 +74,19 @@ void setup_display() { void display_toggle(bool toggle) { #ifdef HAS_DISPLAY - if (toggle) { - #ifdef HAS_TFT - digitalWrite(TFT_BL, HIGH); - #else - display.ssd1306_command(SSD1306_DISPLAYON); - #endif - } else { - #ifdef HAS_TFT - digitalWrite(TFT_BL, LOW); - #else - display.ssd1306_command(SSD1306_DISPLAYOFF); - #endif - } + if (toggle) { + #ifdef HAS_TFT + digitalWrite(TFT_BL, HIGH); + #else + display.ssd1306_command(SSD1306_DISPLAYON); + #endif + } else { + #ifdef HAS_TFT + digitalWrite(TFT_BL, LOW); + #else + display.ssd1306_command(SSD1306_DISPLAYOFF); + #endif + } #endif } diff --git a/src/lora_utils.cpp b/src/lora_utils.cpp index 151b6726..a38c42cc 100644 --- a/src/lora_utils.cpp +++ b/src/lora_utils.cpp @@ -18,19 +18,19 @@ bool ignorePacket = false; bool operationDone = true; #ifdef HAS_SX1262 -SX1262 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN); + SX1262 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN); #endif #ifdef HAS_SX1268 -SX1268 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN); + SX1268 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN); #endif #ifdef HAS_SX1278 -SX1278 radio = new Module(RADIO_CS_PIN, RADIO_BUSY_PIN, RADIO_RST_PIN); + SX1278 radio = new Module(RADIO_CS_PIN, RADIO_BUSY_PIN, RADIO_RST_PIN); #endif #ifdef HAS_SX1276 -SX1276 radio = new Module(RADIO_CS_PIN, RADIO_BUSY_PIN, RADIO_RST_PIN); + SX1276 radio = new Module(RADIO_CS_PIN, RADIO_BUSY_PIN, RADIO_RST_PIN); #endif int rssi, freqError; @@ -53,14 +53,14 @@ namespace LoRa_Utils { while (true); } #if defined(HAS_SX1278) || defined(HAS_SX1276) - radio.setDio0Action(setFlag, RISING); + radio.setDio0Action(setFlag, RISING); #endif #if defined(HAS_SX1262) || defined(HAS_SX1268) - if (!Config.lowPowerMode) { - radio.setDio1Action(setFlag); - } else { - radio.setDIOMapping(1, RADIOLIB_SX126X_IRQ_RX_DONE); - } + if (!Config.lowPowerMode) { + radio.setDio1Action(setFlag); + } else { + radio.setDIOMapping(1, RADIOLIB_SX126X_IRQ_RX_DONE); + } #endif radio.setSpreadingFactor(Config.loramodule.spreadingFactor); float signalBandwidth = Config.loramodule.signalBandwidth/1000; @@ -69,17 +69,17 @@ namespace LoRa_Utils { radio.setCRC(true); #if defined(ESP32_DIY_1W_LoRa) - radio.setRfSwitchPins(RADIO_RXEN, RADIO_TXEN); + radio.setRfSwitchPins(RADIO_RXEN, RADIO_TXEN); #endif #if defined(HAS_SX1278) || defined(HAS_SX1276) || ESP32_DIY_1W_LoRa - state = radio.setOutputPower(Config.loramodule.power); // max value 20dB for 400M30S as it has Low Noise Amp + state = radio.setOutputPower(Config.loramodule.power); // max value 20dB for 400M30S as it has Low Noise Amp #endif #if defined(HELTEC_V3) || defined(HELTEC_WS) || defined(TTGO_T_Beam_V1_0_SX1268) || defined(TTGO_T_Beam_V1_2_SX1262) - state = radio.setOutputPower(Config.loramodule.power + 2); // values available: 10, 17, 22 --> if 20 in tracker_conf.json it will be updated to 22. + state = radio.setOutputPower(Config.loramodule.power + 2); // values available: 10, 17, 22 --> if 20 in tracker_conf.json it will be updated to 22. #endif #if defined(HAS_SX1262) || defined(HAS_SX1268) - radio.setRxBoostedGainMode(true); + radio.setRxBoostedGainMode(true); #endif if (state == RADIOLIB_ERR_NONE) { Utils::println("init : LoRa Module ... done!"); @@ -109,7 +109,7 @@ namespace LoRa_Utils { } #ifdef INTERNAL_LED_PIN - digitalWrite(INTERNAL_LED_PIN, HIGH); + digitalWrite(INTERNAL_LED_PIN, HIGH); #endif int state = radio.transmit("\x3c\xff\x01" + newPacket); transmissionFlag = true; @@ -128,7 +128,7 @@ namespace LoRa_Utils { Utils::println(String(state)); } #ifdef INTERNAL_LED_PIN - digitalWrite(INTERNAL_LED_PIN, LOW); + digitalWrite(INTERNAL_LED_PIN, LOW); #endif if (Config.loramodule.txFreq != Config.loramodule.rxFreq) { changeFreqRx(); diff --git a/src/pins_config.h b/src/pins_config.h index fd00b5c6..1c0bd2ab 100644 --- a/src/pins_config.h +++ b/src/pins_config.h @@ -10,173 +10,173 @@ // LORA MODULES #if defined(TTGO_T_LORA32_V2_1) || defined(HELTEC_V2) || defined(ESP32_DIY_LoRa) || defined(TTGO_T_Beam_V1_2) || defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_LORA32_V2_1_915) -#define RADIO_SCLK_PIN 5 // GPIO5 - SX1278 SCK -#define RADIO_MISO_PIN 19 // GPIO19 - SX1278 MISO -#define RADIO_MOSI_PIN 27 // GPIO27 - SX1278 MOSI -#define RADIO_CS_PIN 18 // GPIO18 - SX1278 CS ---> NSS -#define RADIO_RST_PIN 14 // GPIO14 - SX1278 RST -#define RADIO_BUSY_PIN 26 // GPIO26 - SX1278 IRQ ---->DIO0 + #define RADIO_SCLK_PIN 5 // GPIO5 - SX1278 SCK + #define RADIO_MISO_PIN 19 // GPIO19 - SX1278 MISO + #define RADIO_MOSI_PIN 27 // GPIO27 - SX1278 MOSI + #define RADIO_CS_PIN 18 // GPIO18 - SX1278 CS ---> NSS + #define RADIO_RST_PIN 14 // GPIO14 - SX1278 RST + #define RADIO_BUSY_PIN 26 // GPIO26 - SX1278 IRQ ---->DIO0 #endif #if defined(HELTEC_V3) || defined(HELTEC_WS) -#define RADIO_SCLK_PIN 9 // SX1262 SCK -#define RADIO_MISO_PIN 11 // SX1262 MISO -#define RADIO_MOSI_PIN 10 // SX1262 MOSI -#define RADIO_CS_PIN 8 // SX1262 NSS -#define RADIO_RST_PIN 12 // SX1262 RST -#define RADIO_DIO1_PIN 14 // SX1262 DIO1 -#define RADIO_BUSY_PIN 13 // SX1262 BUSY + #define RADIO_SCLK_PIN 9 // SX1262 SCK + #define RADIO_MISO_PIN 11 // SX1262 MISO + #define RADIO_MOSI_PIN 10 // SX1262 MOSI + #define RADIO_CS_PIN 8 // SX1262 NSS + #define RADIO_RST_PIN 12 // SX1262 RST + #define RADIO_DIO1_PIN 14 // SX1262 DIO1 + #define RADIO_BUSY_PIN 13 // SX1262 BUSY #endif #ifdef ESP32_DIY_1W_LoRa // Ebyte E22 400M30S / SX1268 -#define RADIO_SCLK_PIN 18 -#define RADIO_MISO_PIN 19 -#define RADIO_MOSI_PIN 23 -#define RADIO_CS_PIN 5 -#define RADIO_RST_PIN 27 -#define RADIO_DIO1_PIN 12 -#define RADIO_BUSY_PIN 14 -#define RADIO_RXEN 32 -#define RADIO_TXEN 25 + #define RADIO_SCLK_PIN 18 + #define RADIO_MISO_PIN 19 + #define RADIO_MOSI_PIN 23 + #define RADIO_CS_PIN 5 + #define RADIO_RST_PIN 27 + #define RADIO_DIO1_PIN 12 + #define RADIO_BUSY_PIN 14 + #define RADIO_RXEN 32 + #define RADIO_TXEN 25 #endif #ifdef WEMOS_LOLIN32_OLED_DIY_LoRa -#define RADIO_SCLK_PIN 15 -#define RADIO_MISO_PIN 13 -#define RADIO_MOSI_PIN 12 -#define RADIO_CS_PIN 14 -#define RADIO_RST_PIN 2 -#define RADIO_BUSY_PIN 25 + #define RADIO_SCLK_PIN 15 + #define RADIO_MISO_PIN 13 + #define RADIO_MOSI_PIN 12 + #define RADIO_CS_PIN 14 + #define RADIO_RST_PIN 2 + #define RADIO_BUSY_PIN 25 #endif #if defined(TTGO_T_Beam_V1_0_SX1268) || defined(TTGO_T_Beam_V1_2_SX1262) -#define RADIO_SCLK_PIN 5 -#define RADIO_MISO_PIN 19 -#define RADIO_MOSI_PIN 27 -#define RADIO_CS_PIN 18 -#define RADIO_DIO0_PIN 26 -#define RADIO_RST_PIN 23 -#define RADIO_DIO1_PIN 33 -#define RADIO_BUSY_PIN 32 + #define RADIO_SCLK_PIN 5 + #define RADIO_MISO_PIN 19 + #define RADIO_MOSI_PIN 27 + #define RADIO_CS_PIN 18 + #define RADIO_DIO0_PIN 26 + #define RADIO_RST_PIN 23 + #define RADIO_DIO1_PIN 33 + #define RADIO_BUSY_PIN 32 #endif #if defined(OE5HWN_MeshCom) -#define RADIO_SCLK_PIN 18 -#define RADIO_MISO_PIN 19 -#define RADIO_MOSI_PIN 23 -#define RADIO_CS_PIN 5 -#define RADIO_RST_PIN 27 -#define RADIO_DIO1_PIN 33 -#define RADIO_BUSY_PIN 26 -#define RADIO_RXEN 14 -#define RADIO_TXEN 13 + #define RADIO_SCLK_PIN 18 + #define RADIO_MISO_PIN 19 + #define RADIO_MOSI_PIN 23 + #define RADIO_CS_PIN 5 + #define RADIO_RST_PIN 27 + #define RADIO_DIO1_PIN 33 + #define RADIO_BUSY_PIN 26 + #define RADIO_RXEN 14 + #define RADIO_TXEN 13 #endif #ifdef HELTEC_HTCT62 -#define RADIO_SCLK_PIN 10 // SX1262 SCK -#define RADIO_MISO_PIN 6 // SX1262 MISO -#define RADIO_MOSI_PIN 7 // SX1262 MOSI -#define RADIO_CS_PIN 8 // SX1262 NSS -#define RADIO_RST_PIN 5 // SX1262 RST -#define RADIO_DIO1_PIN 3 // SX1262 DIO1 -#define RADIO_BUSY_PIN 4 // SX1262 BUSY + #define RADIO_SCLK_PIN 10 // SX1262 SCK + #define RADIO_MISO_PIN 6 // SX1262 MISO + #define RADIO_MOSI_PIN 7 // SX1262 MOSI + #define RADIO_CS_PIN 8 // SX1262 NSS + #define RADIO_RST_PIN 5 // SX1262 RST + #define RADIO_DIO1_PIN 3 // SX1262 DIO1 + #define RADIO_BUSY_PIN 4 // SX1262 BUSY #endif #ifdef ESP32_DIY_LoRa_A7670 -#define RADIO_SCLK_PIN 18 -#define RADIO_MISO_PIN 19 -#define RADIO_MOSI_PIN 23 -#define RADIO_CS_PIN 2 -#define RADIO_RST_PIN 0 -#define RADIO_BUSY_PIN 32 -#define A7670_PWR_PIN 4 -#define A7670_ResetPin 5 -#define A7670_TX_PIN 26 -#define A7670_RX_PIN 27 + #define RADIO_SCLK_PIN 18 + #define RADIO_MISO_PIN 19 + #define RADIO_MOSI_PIN 23 + #define RADIO_CS_PIN 2 + #define RADIO_RST_PIN 0 + #define RADIO_BUSY_PIN 32 + #define A7670_PWR_PIN 4 + #define A7670_ResetPin 5 + #define A7670_TX_PIN 26 + #define A7670_RX_PIN 27 #endif #ifdef HELTEC_WIRELESS_TRACKER -#define RADIO_SCLK_PIN 9 -#define RADIO_MISO_PIN 11 -#define RADIO_MOSI_PIN 10 -#define RADIO_CS_PIN 8 -#define RADIO_RST_PIN 12 -#define RADIO_DIO1_PIN 14 // SX1262 IRQ -#define RADIO_BUSY_PIN 13 // SX1262 BUSY + #define RADIO_SCLK_PIN 9 + #define RADIO_MISO_PIN 11 + #define RADIO_MOSI_PIN 10 + #define RADIO_CS_PIN 8 + #define RADIO_RST_PIN 12 + #define RADIO_DIO1_PIN 14 // SX1262 IRQ + #define RADIO_BUSY_PIN 13 // SX1262 BUSY #endif // OLED #if defined(TTGO_T_LORA32_V2_1) || defined(ESP32_DIY_LoRa) || defined(ESP32_DIY_1W_LoRa) || defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_2) || defined(TTGO_T_Beam_V1_0_SX1268) || defined(TTGO_T_Beam_V1_2_SX1262) || defined(OE5HWN_MeshCom) || defined(ESP32_DIY_LoRa_A7670) || defined(TTGO_T_LORA32_V2_1_915) -#define OLED_SDA 21 -#define OLED_SCL 22 -#define OLED_RST -1 // Reset pin # (or -1 if sharing Arduino reset pin) + #define OLED_SDA 21 + #define OLED_SCL 22 + #define OLED_RST -1 // Reset pin # (or -1 if sharing Arduino reset pin) #endif #ifdef HELTEC_V2 -#define OLED_SDA 4 -#define OLED_SCL 15 -#define OLED_RST 16 + #define OLED_SDA 4 + #define OLED_SCL 15 + #define OLED_RST 16 #endif #if defined(HELTEC_V3) || defined(HELTEC_WS) -#define OLED_SDA 17 -#define OLED_SCL 18 -#define OLED_RST 21 + #define OLED_SDA 17 + #define OLED_SCL 18 + #define OLED_RST 21 #endif #ifdef WEMOS_LOLIN32_OLED_DIY_LoRa -#define OLED_SDA 5 -#define OLED_SCL 4 -#define OLED_RST -1 + #define OLED_SDA 5 + #define OLED_SCL 4 + #define OLED_RST -1 #endif #ifndef HELTEC_HTCT62 -#define HAS_DISPLAY + #define HAS_DISPLAY #endif // Leds and other stuff #ifdef HELTEC_HTCT62 -#define BATTERY_PIN 1 + #define BATTERY_PIN 1 #endif #if defined(TTGO_T_LORA32_V2_1) || defined(HELTEC_V2) || defined(TTGO_T_LORA32_V2_1_915) -#define INTERNAL_LED_PIN 25 // Green Led -#define BATTERY_PIN 35 // es 35 el led y 1 bateria? + #define INTERNAL_LED_PIN 25 // Green Led + #define BATTERY_PIN 35 // es 35 el led y 1 bateria? #endif #if defined(HELTEC_V3) || defined(HELTEC_WS) -#define INTERNAL_LED_PIN 35 -#define BATTERY_PIN 1 -#define VEXT_CTRL 36 -#define ADC_CTRL 37 + #define INTERNAL_LED_PIN 35 + #define BATTERY_PIN 1 + #define VEXT_CTRL 36 + #define ADC_CTRL 37 #endif #if defined(ESP32_DIY_LoRa) || defined(ESP32_DIY_1W_LoRa) -#define INTERNAL_LED_PIN 2 + #define INTERNAL_LED_PIN 2 #endif #if defined(ESP32_DIY_LoRa_A7670) -#define INTERNAL_LED_PIN 13 // 13 for V1.1 and 12 for V1.0 -#define BATTERY_PIN 35 + #define INTERNAL_LED_PIN 13 // 13 for V1.1 and 12 for V1.0 + #define BATTERY_PIN 35 #endif #ifdef HELTEC_WIRELESS_TRACKER -#define INTERNAL_LED_PIN 18 -#define BATTERY_PIN 1 -#define ADC_CTRL 2 // HELTEC Wireless Tracker ADC_CTRL = HIGH powers the voltage divider to read BatteryPin. Only on V05 = V1.1 -#define VEXT_CTRL 3 // To turn on GPS and TFT -#define BOARD_I2C_SDA 7 -#define BOARD_I2C_SCL 6 + #define INTERNAL_LED_PIN 18 + #define BATTERY_PIN 1 + #define ADC_CTRL 2 // HELTEC Wireless Tracker ADC_CTRL = HIGH powers the voltage divider to read BatteryPin. Only on V05 = V1.1 + #define VEXT_CTRL 3 // To turn on GPS and TFT + #define BOARD_I2C_SDA 7 + #define BOARD_I2C_SCL 6 #endif #ifdef ESP32_C3_DIY_LoRa -#define OLED_SDA 8 -#define OLED_SCL 9 -#define OLED_RST 10 -#define RADIO_SCLK_PIN 4 -#define RADIO_MISO_PIN 5 -#define RADIO_MOSI_PIN 6 -#define RADIO_CS 7 -#define RADIO_RST_PIN 3 -#define RADIO_IRQ_PIN 2 + #define OLED_SDA 8 + #define OLED_SCL 9 + #define OLED_RST 10 + #define RADIO_SCLK_PIN 4 + #define RADIO_MISO_PIN 5 + #define RADIO_MOSI_PIN 6 + #define RADIO_CS 7 + #define RADIO_RST_PIN 3 + #define RADIO_IRQ_PIN 2 #endif /* (Same pins for LILYGO LoRa32 and ESP32 Wroom Dev ) diff --git a/src/power_utils.cpp b/src/power_utils.cpp index 541176cd..37c88088 100644 --- a/src/power_utils.cpp +++ b/src/power_utils.cpp @@ -3,16 +3,16 @@ #include "pins_config.h" #if defined(HAS_AXP192) || defined(HAS_AXP2101) -#define I2C_SDA 21 -#define I2C_SCL 22 -#define IRQ_PIN 35 + #define I2C_SDA 21 + #define I2C_SCL 22 + #define IRQ_PIN 35 #endif #ifdef HAS_AXP192 -XPowersAXP192 PMU; + XPowersAXP192 PMU; #endif #ifdef HAS_AXP2101 -XPowersAXP2101 PMU; + XPowersAXP2101 PMU; #endif extern Configuration Config; @@ -26,111 +26,111 @@ namespace POWER_Utils { void activateMeasurement() { #if defined(HAS_AXP192) || defined(HAS_AXP2101) - PMU.disableTSPinMeasure(); - PMU.enableBattDetection(); - PMU.enableVbusVoltageMeasure(); - PMU.enableBattVoltageMeasure(); - PMU.enableSystemVoltageMeasure(); + PMU.disableTSPinMeasure(); + PMU.enableBattDetection(); + PMU.enableVbusVoltageMeasure(); + PMU.enableBattVoltageMeasure(); + PMU.enableSystemVoltageMeasure(); #endif } void activateLoRa() { #ifdef HAS_AXP192 - PMU.setLDO2Voltage(3300); - PMU.enableLDO2(); + PMU.setLDO2Voltage(3300); + PMU.enableLDO2(); #endif #ifdef HAS_AXP2101 - PMU.setALDO2Voltage(3300); - PMU.enableALDO2(); + PMU.setALDO2Voltage(3300); + PMU.enableALDO2(); #endif } void deactivateLoRa() { #ifdef HAS_AXP192 - PMU.disableLDO2(); + PMU.disableLDO2(); #endif #ifdef HAS_AXP2101 - PMU.disableALDO2(); + PMU.disableALDO2(); #endif } bool begin(TwoWire &port) { #if defined(HAS_AXP192) - bool result = PMU.begin(Wire, AXP192_SLAVE_ADDRESS, I2C_SDA, I2C_SCL); - if (result) { - PMU.disableDC2(); - PMU.disableLDO2(); - PMU.disableLDO3(); - PMU.setDC1Voltage(3300); - PMU.enableDC1(); - PMU.setProtectedChannel(XPOWERS_DCDC3); - PMU.disableIRQ(XPOWERS_AXP192_ALL_IRQ); - } - return result; + bool result = PMU.begin(Wire, AXP192_SLAVE_ADDRESS, I2C_SDA, I2C_SCL); + if (result) { + PMU.disableDC2(); + PMU.disableLDO2(); + PMU.disableLDO3(); + PMU.setDC1Voltage(3300); + PMU.enableDC1(); + PMU.setProtectedChannel(XPOWERS_DCDC3); + PMU.disableIRQ(XPOWERS_AXP192_ALL_IRQ); + } + return result; #elif defined(HAS_AXP2101) - bool result = PMU.begin(Wire, AXP2101_SLAVE_ADDRESS, I2C_SDA, I2C_SCL); - if (result) { - PMU.disableDC2(); - PMU.disableDC3(); - PMU.disableDC4(); - PMU.disableDC5(); - PMU.disableALDO1(); - PMU.disableALDO4(); - PMU.disableBLDO1(); - PMU.disableBLDO2(); - PMU.disableDLDO1(); - PMU.disableDLDO2(); - PMU.setDC1Voltage(3300); - PMU.enableDC1(); - PMU.setButtonBatteryChargeVoltage(3300); - PMU.enableButtonBatteryCharge(); - PMU.disableIRQ(XPOWERS_AXP2101_ALL_IRQ); - } - return result; + bool result = PMU.begin(Wire, AXP2101_SLAVE_ADDRESS, I2C_SDA, I2C_SCL); + if (result) { + PMU.disableDC2(); + PMU.disableDC3(); + PMU.disableDC4(); + PMU.disableDC5(); + PMU.disableALDO1(); + PMU.disableALDO4(); + PMU.disableBLDO1(); + PMU.disableBLDO2(); + PMU.disableDLDO1(); + PMU.disableDLDO2(); + PMU.setDC1Voltage(3300); + PMU.enableDC1(); + PMU.setButtonBatteryChargeVoltage(3300); + PMU.enableButtonBatteryCharge(); + PMU.disableIRQ(XPOWERS_AXP2101_ALL_IRQ); + } + return result; #else - return true; + return true; #endif } void setup() { #ifdef HAS_AXP192 - Wire.begin(SDA, SCL); - if (begin(Wire)) { - Serial.println("AXP192 init done!"); - } else { - Serial.println("AXP192 init failed!"); - } - activateLoRa(); - activateMeasurement(); - PMU.setChargerTerminationCurr(XPOWERS_AXP192_CHG_ITERM_LESS_10_PERCENT); - PMU.setChargeTargetVoltage(XPOWERS_AXP192_CHG_VOL_4V2); - PMU.setChargerConstantCurr(XPOWERS_AXP192_CHG_CUR_780MA); - PMU.setSysPowerDownVoltage(2600); + Wire.begin(SDA, SCL); + if (begin(Wire)) { + Serial.println("AXP192 init done!"); + } else { + Serial.println("AXP192 init failed!"); + } + activateLoRa(); + activateMeasurement(); + PMU.setChargerTerminationCurr(XPOWERS_AXP192_CHG_ITERM_LESS_10_PERCENT); + PMU.setChargeTargetVoltage(XPOWERS_AXP192_CHG_VOL_4V2); + PMU.setChargerConstantCurr(XPOWERS_AXP192_CHG_CUR_780MA); + PMU.setSysPowerDownVoltage(2600); #endif #ifdef HAS_AXP2101 - Wire.begin(SDA, SCL); - if (begin(Wire)) { - Serial.println("AXP2101 init done!"); - } else { - Serial.println("AXP2101 init failed!"); - } - activateLoRa(); - activateMeasurement(); - PMU.setPrechargeCurr(XPOWERS_AXP2101_PRECHARGE_200MA); - PMU.setChargerTerminationCurr(XPOWERS_AXP2101_CHG_ITERM_25MA); - PMU.setChargeTargetVoltage(XPOWERS_AXP2101_CHG_VOL_4V2); - PMU.setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_800MA); - PMU.setSysPowerDownVoltage(2600); + Wire.begin(SDA, SCL); + if (begin(Wire)) { + Serial.println("AXP2101 init done!"); + } else { + Serial.println("AXP2101 init failed!"); + } + activateLoRa(); + activateMeasurement(); + PMU.setPrechargeCurr(XPOWERS_AXP2101_PRECHARGE_200MA); + PMU.setChargerTerminationCurr(XPOWERS_AXP2101_CHG_ITERM_25MA); + PMU.setChargeTargetVoltage(XPOWERS_AXP2101_CHG_VOL_4V2); + PMU.setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_800MA); + PMU.setSysPowerDownVoltage(2600); #endif #ifdef BATTERY_PIN - pinMode(BATTERY_PIN, INPUT); + pinMode(BATTERY_PIN, INPUT); #endif #ifdef INTERNAL_LED_PIN - pinMode(INTERNAL_LED_PIN, OUTPUT); + pinMode(INTERNAL_LED_PIN, OUTPUT); #endif if (Config.externalVoltageMeasurement) { @@ -138,16 +138,16 @@ namespace POWER_Utils { } #ifdef VEXT_CTRL - pinMode(VEXT_CTRL,OUTPUT); // this is for GPS and TFT screen on Wireless_Tracker and only for Oled in Heltec V3 - digitalWrite(VEXT_CTRL, HIGH); + pinMode(VEXT_CTRL,OUTPUT); // this is for GPS and TFT screen on Wireless_Tracker and only for Oled in Heltec V3 + digitalWrite(VEXT_CTRL, HIGH); #endif #ifdef ADC_CTRL - pinMode(ADC_CTRL, OUTPUT); + pinMode(ADC_CTRL, OUTPUT); #endif #ifdef HELTEC_WIRELESS_TRACKER - Wire.begin(BOARD_I2C_SDA, BOARD_I2C_SCL); + Wire.begin(BOARD_I2C_SDA, BOARD_I2C_SCL); #endif delay(1000); diff --git a/src/power_utils.h b/src/power_utils.h index a8e52b7a..c887834a 100644 --- a/src/power_utils.h +++ b/src/power_utils.h @@ -3,9 +3,9 @@ #include #if defined(HAS_AXP192) || defined(HAS_AXP2101) -#include "XPowersLib.h" + #include "XPowersLib.h" #else -#include + #include #endif diff --git a/src/utils.cpp b/src/utils.cpp index c501ceb3..1801bab9 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -70,12 +70,12 @@ namespace Utils { void setupDisplay() { setup_display(); #ifdef INTERNAL_LED_PIN - digitalWrite(INTERNAL_LED_PIN,HIGH); + digitalWrite(INTERNAL_LED_PIN,HIGH); #endif Serial.println("\nStarting Station: " + Config.callsign + " Version: " + versionDate); show_display(" LoRa APRS", "", " ( iGATE & DIGI )", "", "", "Richonguzman / CA2RXU", " " + versionDate, 4000); #ifdef INTERNAL_LED_PIN - digitalWrite(INTERNAL_LED_PIN,LOW); + digitalWrite(INTERNAL_LED_PIN,LOW); #endif firstLine = Config.callsign; seventhLine = " listening..."; @@ -120,12 +120,12 @@ namespace Utils { secondaryBeaconPacket += Config.beacon.comment; #ifdef BATTERY_PIN - if (Config.sendBatteryVoltage) { - String batteryInfo = "Batt=" + String(BATTERY_Utils::checkBattery(),2) + "V"; - beaconPacket += (" " + batteryInfo); - secondaryBeaconPacket += (" " + batteryInfo); - sixthLine = " ( " + batteryInfo + ")"; - } + if (Config.sendBatteryVoltage) { + String batteryInfo = "Batt=" + String(BATTERY_Utils::checkBattery(),2) + "V"; + beaconPacket += (" " + batteryInfo); + secondaryBeaconPacket += (" " + batteryInfo); + sixthLine = " ( " + batteryInfo + ")"; + } #endif if (Config.externalVoltageMeasurement) { @@ -138,9 +138,9 @@ namespace Utils { show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING IGATE BEACON", 0); seventhLine = " listening..."; #ifdef ESP32_DIY_LoRa_A7670 - A7670_Utils::uploadToAPRSIS(beaconPacket); + A7670_Utils::uploadToAPRSIS(beaconPacket); #else - APRS_IS_Utils::upload(beaconPacket); + APRS_IS_Utils::upload(beaconPacket); #endif } diff --git a/src/wifi_utils.cpp b/src/wifi_utils.cpp index d0be9947..cbb47c9b 100644 --- a/src/wifi_utils.cpp +++ b/src/wifi_utils.cpp @@ -53,12 +53,12 @@ namespace WIFI_Utils { while (WiFi.status() != WL_CONNECTED && wifiCounter 10000){ delay(1000); @@ -79,7 +79,7 @@ namespace WIFI_Utils { } } #ifdef INTERNAL_LED_PIN - digitalWrite(INTERNAL_LED_PIN,LOW); + digitalWrite(INTERNAL_LED_PIN,LOW); #endif if (WiFi.status() == WL_CONNECTED) { Serial.print("Connected as ");