Skip to content

Commit

Permalink
mayor code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
richonguzman committed May 14, 2024
1 parent 794cc06 commit 0be60b7
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 66 deletions.
4 changes: 1 addition & 3 deletions data_embed/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,7 @@ <h5>
WiFi Access
</h5>
<small
>Add all Wi-Fi Networks intended to be used,
and their respective coordinates to
georeference the iGate location.</small
>Add all Wi-Fi Networks intended to be used.</small
>
</div>
<div class="col-lg-9 col-sm-12">
Expand Down
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ default_envs = ttgo-lora32-v21

[env]
platform = espressif32 @ 6.3.1
board_build.partitions = min_spiffs.csv
framework = arduino
monitor_speed = 115200
board_build.embed_files =
Expand Down
17 changes: 3 additions & 14 deletions src/LoRa_APRS_iGate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,41 +37,31 @@ ________________________________________________________________________________
#include "A7670_utils.h"
#endif


String versionDate = "2024.05.14";
Configuration Config;
WiFiClient espClient;

String versionDate = "2024.05.13";
uint8_t myWiFiAPIndex = 0;
int myWiFiAPSize = Config.wifiAPs.size();
WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex];

bool isUpdatingOTA = false;
bool statusAfterBoot = true;
bool beaconUpdate = true;
uint32_t lastBeaconTx = 0;
uint32_t previousWiFiMillis = 0;
uint32_t lastScreenOn = millis();

uint32_t lastWiFiCheck = 0;
bool WiFiConnect = true;
bool WiFiConnected = false;

bool WiFiAutoAPStarted = false;
long WiFiAutoAPTime = false;

uint32_t lastBatteryCheck = 0;

String batteryVoltage;

uint32_t lastTxTime = millis();
uint32_t lastRxTime = millis();

std::vector<ReceivedPacket> receivedPackets;

bool modemLoggedToAPRSIS = false;

String firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, iGateBeaconPacket, iGateLoRaBeaconPacket;
String firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine;

//#define STARTUP_DELAY 5 //min

Expand All @@ -82,8 +72,7 @@ void setup() {
Config.check();
LoRa_Utils::setup();
Utils::validateFreqs();
iGateBeaconPacket = GPS_Utils::generateBeacon();
iGateLoRaBeaconPacket = GPS_Utils::generateiGateLoRaBeacon();
GPS_Utils::generateBeacons();

#ifdef STARTUP_DELAY // (TEST) just to wait for WiFi init of Routers
show_display("", " STARTUP DELAY ...", "", "", 0);
Expand Down
6 changes: 2 additions & 4 deletions src/aprs_is_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ extern String fourthLine;
extern String fifthLine;
extern String sixthLine;
extern String seventhLine;

extern std::vector<String> outputPacketBuffer;
extern uint32_t lastRxTime;

extern bool modemLoggedToAPRSIS;

uint32_t lastRxTime = millis();

#ifdef ESP32_DIY_LoRa_A7670
extern bool stationBeacon;
#endif
Expand Down
10 changes: 5 additions & 5 deletions src/bme_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
#define SEALEVELPRESSURE_HPA (1013.25)
#define CORRECTION_FACTOR (8.2296) // for meters

extern Configuration Config;
extern String fifthLine;

float newHum, newTemp, newPress, newGas;
extern Configuration Config;
extern String fifthLine;

int wxModuleType = 0;
uint8_t wxModuleAddress = 0x00;

float newHum, newTemp, newPress, newGas;


Adafruit_BME280 bme280;
Adafruit_BME680 bme680;
#ifdef HELTEC_V3_GPS
Expand All @@ -23,7 +24,6 @@ Adafruit_BMP280 bmp280;
#endif



namespace BME_Utils {

void getWxModuleAddres() {
Expand Down
1 change: 1 addition & 0 deletions src/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "configuration.h"
#include "display.h"


void Configuration::check() {
if (reload) {
show_display("------- UPDATE ------", "config is old", "device will update", "and then reboot", 1000);
Expand Down
2 changes: 0 additions & 2 deletions src/digi_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ extern String fifthLine;
extern String sixthLine;
extern String seventhLine;

extern std::vector<String> outputPacketBuffer;


namespace DIGI_Utils {

Expand Down
21 changes: 9 additions & 12 deletions src/gps_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

extern Configuration Config;
extern WiFiClient espClient;
String distance;
String distance, iGateBeaconPacket, iGateLoRaBeaconPacket;


namespace GPS_Utils {
Expand Down Expand Up @@ -47,17 +47,14 @@ namespace GPS_Utils {
return encodedData;
}

String generateBeacon() {
String beaconPacket = Config.callsign + ">APLRG1," + Config.beacon.path;

if (Config.aprs_is.active && Config.digi.mode == 0) { // If APRSIS enabled and Digi disabled
beaconPacket += ",qAC";
}
return beaconPacket + ":!" + encodeGPS(Config.beacon.latitude, Config.beacon.longitude, Config.beacon.overlay, Config.beacon.symbol);;
}

String generateiGateLoRaBeacon() {
return Config.callsign + ">APLRG1," + Config.beacon.path + ":!" + encodeGPS(Config.beacon.latitude, Config.beacon.longitude, Config.beacon.overlay, Config.beacon.symbol);
void generateBeacons() {
String beaconPacket = Config.callsign + ">APLRG1";
if (Config.beacon.path != "") {
beaconPacket += "," + Config.beacon.path;
}
String encodedGPS = encodeGPS(Config.beacon.latitude, Config.beacon.longitude, Config.beacon.overlay, Config.beacon.symbol);
iGateBeaconPacket = beaconPacket + ",qAC:!" + encodedGPS;
iGateLoRaBeaconPacket = beaconPacket + ":!" + encodedGPS;
}

double calculateDistanceTo(double latitude, double longitude) {
Expand Down
3 changes: 1 addition & 2 deletions src/gps_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ namespace GPS_Utils {

char *ax25_base91enc(char *s, uint8_t n, uint32_t v);
String encodeGPS(float latitude, float longitude, String overlay, String symbol);
String generateBeacon();
String generateiGateLoRaBeacon();
void generateBeacons();
double calculateDistanceCourse(double latitude, double longitude);
String decodeEncodedGPS(String packet);
String getReceivedGPS(String packet);
Expand Down
1 change: 0 additions & 1 deletion src/lora_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
extern Configuration Config;
extern uint32_t lastRxTime;


extern std::vector<ReceivedPacket> receivedPackets;

bool transmissionFlag = true;
Expand Down
6 changes: 1 addition & 5 deletions src/power_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ extern Configuration Config;

namespace POWER_Utils {

bool BatteryIsConnected = false;
String batteryVoltage = "";
String batteryChargeDischargeCurrent = "";

void activateMeasurement() {
#if defined(HAS_AXP192) || defined(HAS_AXP2101)
PMU.disableTSPinMeasure();
Expand Down Expand Up @@ -138,7 +134,7 @@ 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
pinMode(VEXT_CTRL,OUTPUT); // GPS + TFT on HELTEC Wireless_Tracker and only for Oled in HELTEC V3
digitalWrite(VEXT_CTRL, HIGH);
#endif

Expand Down
9 changes: 4 additions & 5 deletions src/station_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#include "utils.h"
#include <vector>

extern Configuration Config;
extern uint32_t lastTxTime;
extern uint32_t lastRxTime;
extern String fourthLine;
extern Configuration Config;
extern uint32_t lastRxTime;
extern String fourthLine;

uint32_t lastTxTime = millis();
std::vector<String> lastHeardStation;
std::vector<String> outputPacketBuffer;
std::vector<String> packet25SegBuffer;
Expand Down Expand Up @@ -70,7 +70,6 @@ namespace STATION_Utils {
String deltaTimeString = packet25SegBuffer[0].substring(0, packet25SegBuffer[0].indexOf(","));
uint32_t deltaTime = deltaTimeString.toInt();
if ((millis() - deltaTime) > 25 * 1000) {
//Serial.print("Borrando : "); Serial.println(packet25SegBuffer[0]);
packet25SegBuffer.erase(packet25SegBuffer.begin());
}
}
Expand Down
1 change: 0 additions & 1 deletion src/tnc_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "utils.h"

extern Configuration Config;
extern std::vector<String> outputPacketBuffer;

#define MAX_CLIENTS 4
#define INPUT_BUFFER_SIZE (2 + MAX_CLIENTS)
Expand Down
21 changes: 11 additions & 10 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@
#include "display.h"
#include "utils.h"

extern WiFiClient espClient;
extern Configuration Config;
extern WiFiClient espClient;
extern String versionDate;
extern bool statusAfterBoot;
extern String firstLine;
extern String secondLine;
extern String thirdLine;
extern String fourthLine;
extern String fifthLine;
extern String sixthLine;
extern String seventhLine;
extern uint32_t lastBeaconTx;
extern uint32_t lastScreenOn;
extern bool beaconUpdate;
extern String iGateBeaconPacket;
extern String iGateLoRaBeaconPacket;
extern std::vector<String> lastHeardStation;
Expand All @@ -38,6 +35,10 @@ extern bool WiFiConnect;
extern bool WiFiConnected;
extern int wxModuleType;

bool statusAfterBoot = true;
bool beaconUpdate = true;
uint32_t lastBeaconTx = 0;


namespace Utils {

Expand Down Expand Up @@ -169,14 +170,14 @@ namespace Utils {

void checkWiFiInterval() {
uint32_t WiFiCheck = millis() - lastWiFiCheck;
if (WiFi.status() != WL_CONNECTED && WiFiCheck >= 15*60*1000) {
WiFiConnect = true;
if (WiFi.status() != WL_CONNECTED && WiFiCheck >= 15 * 60 * 1000) {
WiFiConnect = true;
}
if (WiFiConnect) {
Serial.println("\nConnecting to WiFi ...");
WIFI_Utils::startWiFi();
lastWiFiCheck = millis();
WiFiConnect = false;
Serial.println("\nConnecting to WiFi ...");
WIFI_Utils::startWiFi();
lastWiFiCheck = millis();
WiFiConnect = false;
}
}

Expand Down
1 change: 0 additions & 1 deletion src/web_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "utils.h"

extern Configuration Config;

extern uint32_t lastBeaconTx;
extern std::vector<ReceivedPacket> receivedPackets;

Expand Down
2 changes: 1 addition & 1 deletion src/wifi_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extern bool WiFiAutoAPStarted;
namespace WIFI_Utils {

void checkWiFi() {
if ((WiFi.status() != WL_CONNECTED) && ((millis() - previousWiFiMillis) >= 30*1000) && !WiFiAutoAPStarted) {
if ((WiFi.status() != WL_CONNECTED) && ((millis() - previousWiFiMillis) >= 30 * 1000) && !WiFiAutoAPStarted) {
Serial.print(millis());
Serial.println("Reconnecting to WiFi...");
WiFi.disconnect();
Expand Down

0 comments on commit 0be60b7

Please sign in to comment.