diff --git a/src/multi-tracker.cpp b/src/multi-tracker.cpp index 950566f..a986929 100644 --- a/src/multi-tracker.cpp +++ b/src/multi-tracker.cpp @@ -24,7 +24,6 @@ RH_RF95 rf95(RFM9X_CS, RFM9X_INT); // Radio instance. // Variables -static int prevHeading = -1; // Store previous heading to avoid frequent updates unsigned long lastUpdate = 0; // Time tracking for updates const int updateInterval = 500; // Update interval in milliseconds (500ms = 0.5s) @@ -38,6 +37,7 @@ typedef struct MSG{ double longitude; }MSG; +const uint8_t MSG_Size = sizeof(MSG); enum result { Ok = 0, @@ -91,7 +91,7 @@ uint8_t Radio_Setup(void) { uint8_t Radio_Configure(void) { // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM - if(!rf95.setFrequency(RF95_FREQ)) { + if(!rf95.setFrequency(RF9X_FREQ)) { //Serial.println("Radio_Configure(): failed to set frequency"); return Err; } @@ -126,7 +126,7 @@ uint8_t Radio_CheckForMsg(MSG *msg) { //Now we wait for an packet. if (rf95.waitAvailableTimeout(1000)) { // Should be a reply message for us now - if (rf95.recv(buffer, sizeof(MSG))) { + if (rf95.recv(buffer, (uint8_t *) &MSG_Size)) { //Serial.print("Received reply: "); msg->id = (uint8_t) buffer[0]; @@ -190,15 +190,6 @@ void setup(void) { TFT_Init(); - // Magnetometer Setup - if (!lis2mdl.begin()) { // Initialize the magnetometer -//Serial.println("Error: LIS2MDL not detected. Check your wiring!"); - while (1) delay(10); // Stop the program if the sensor isn't detected - } - - // LED Ring Setup - FastLED.addLeds(leds, NUM_LEDS); - // GPS Setup gpsSerial.begin(GPS_BUADRATE); @@ -222,28 +213,7 @@ void setup(void) { } void loop() { - unsigned long currentTime = millis(); // Get the current time - - // Magnetometer Readings - sensors_event_t event; // Create an event to store magnetometer readings - lis2mdl.getEvent(&event); // Get magnetic field data - int correctedX = event.magnetic.x + 18; // Apply corrections to X-axis data - int correctedY = event.magnetic.y + 59; // Apply corrections to Y-axis data - - // Calculate the heading (bearing) from the magnetometer data - - //NEED TO ADD TILT COMPENSATION - - int heading = (atan2(correctedX, correctedY) * 180) / PI; // Calculate heading in degrees - heading = heading - 90; // Adjust to align with compass directions - if (heading < 0) heading += 360; // Ensure the heading is within the 0-360 range - - // Update LED ring and display every 500ms to avoid flickering - if (currentTime - lastUpdate > updateInterval) { - updateLEDs(heading); // Update the LED ring based on the current heading - updateDisplay(); // Placeholder: Update the central TFT display with GPS data - lastUpdate = currentTime; // Reset the last update time - } + //unsigned long currentTime = millis(); // Get the current time //Handle the Radio data. sendGPSData(); @@ -262,7 +232,7 @@ void TFT_UpdateDistance(uint16_t meters) { tft.setTextWrap(true); tft.println(" Distance"); tft.print(" "); - tft.print(distance); + tft.print(meters); tft.print("m"); } @@ -274,7 +244,7 @@ void TFT_UpdateDirection(uint16_t degrees) { tft.setCursor(0, 150); tft.setTextColor(ST77XX_WHITE); tft.setTextSize(3); - tft.print(meters); + tft.print(degrees); tft.println(" Degrees"); } @@ -312,6 +282,8 @@ uint8_t TFT_Reset() { //Serial.println("TFT_Reset()"); tft.fillScreen(ST77XX_BLACK); // Set the screen background to black //Can add default startup logo/screen here for later. + + return Ok; } // Initalizes the Screen with default startup screen. @@ -325,6 +297,8 @@ uint8_t TFT_Init(void) { TFT_UpdateDistance(0); TFT_UpdateDirection(0); TFT_UpdateBatteryState(100); + + return Ok; } @@ -401,5 +375,5 @@ void handleEdgeCases() { // - GPS signal is lost: Display a message on the screen or flash the LED ring // - Devices are too close: Display a warning if the GPS data is unreliable due to proximity // - LoRa communication is lost: Display a notification or error on the screen - } +