Skip to content

Commit

Permalink
CodeCleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
richonguzman committed May 11, 2024
1 parent 53461f2 commit 886b661
Show file tree
Hide file tree
Showing 11 changed files with 469 additions and 469 deletions.
332 changes: 166 additions & 166 deletions src/A7670_utils.cpp

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions src/aprs_is_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern uint32_t lastRxTime;
extern bool modemLoggedToAPRSIS;

#ifdef ESP32_DIY_LoRa_A7670
extern bool stationBeacon;
extern bool stationBeacon;
#endif


Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -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";
Expand Down Expand Up @@ -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
}

Expand Down
82 changes: 41 additions & 41 deletions src/bme_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/bme_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
//#define BME680Sensor

#ifdef BME280Sensor
#include <Adafruit_BME280.h>
#include <Adafruit_BME280.h>
#endif
#ifdef BMP280Sensor
#include <Adafruit_BMP280.h>
#include <Adafruit_BMP280.h>
#endif
#ifdef BME680Sensor
#include <Adafruit_BME680.h>
#include <Adafruit_BME680.h>
#endif


Expand Down
32 changes: 16 additions & 16 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Adafruit_GFX.h>
Expand Down Expand Up @@ -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
}

Expand Down
32 changes: 16 additions & 16 deletions src/lora_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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!");
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Loading

0 comments on commit 886b661

Please sign in to comment.