removed now redundant code(GPS lines in loop func).

This commit is contained in:
jakeg00dwin 2024-10-04 03:02:28 -07:00
parent 37664251df
commit 0d506bc2f1
1 changed files with 15 additions and 17 deletions

View File

@ -223,23 +223,6 @@ void setup(void) {
void loop() {
unsigned long currentTime = millis(); // Get the current time
// GPS Data Handling
if (gpsSerial.available() > 0) { // Check if data is available from the GPS module
gps.encode(gpsSerial.read()); // Decode the GPS data
if (gps.location.isValid()) { // Check if GPS location data is valid
//double latitude = gps.location.lat(); // Get latitude
//double longitude = gps.location.lng(); // Get longitude
msg_out.latitude = gps.location.lat();
msg_out.longitude = gps.location.lat();
Serial.print("Lat: "); // Output latitude for debugging
Serial.println(msg_out.latitude, 6); // Print latitude with 6 decimal places
Serial.print("Lon: "); // Output longitude for debugging
Serial.println(msg_out.longitude, 6); // Print longitude with 6 decimal places
} else {
Serial.println("Waiting for valid GPS data..."); // GPS signal lost or invalid
}
}
// Magnetometer Readings
sensors_event_t event; // Create an event to store magnetometer readings
lis2mdl.getEvent(&event); // Get magnetic field data
@ -390,6 +373,21 @@ void sendGPSData() {
// - Use the LoRa library to send the data to the paired device
// Example: LoRa.beginPacket(); LoRa.print(latitude); LoRa.print(longitude); LoRa.endPacket();
//Don't waste cpu cycles if no new gps data.
if(GPS_GetCoordinates() == NoReply){
return;
}
for(db = RF9X_MIN_DB; db <= RF9X_MAX_DB; db++) {
Radio_SendMsg(&msg_out);
if(Radio_CheckForMsg(&msg_in) == Ok) {
break;
}
else{
Serial.print("TX Power set to:");
Serial.println(db);
}
}
}
// Future function to receive GPS data from the other device via LoRa - See adafruit LORA code examples