Removed all other sensors and libraries besides needed for MVP

- removed globals for LEDS
- removed no longer needed setup lines.
- removed no longer needed loop lines.

Checked space of compiled program at 87% of program memory in current
state.
This commit is contained in:
Jake Goodwin 2024-10-06 12:48:05 -07:00
parent 90baed96e3
commit 6374bbf01f
1 changed files with 11 additions and 37 deletions

View File

@ -24,7 +24,6 @@ RH_RF95 rf95(RFM9X_CS, RFM9X_INT); // Radio instance.
// Variables // Variables
static int prevHeading = -1; // Store previous heading to avoid frequent updates
unsigned long lastUpdate = 0; // Time tracking for updates unsigned long lastUpdate = 0; // Time tracking for updates
const int updateInterval = 500; // Update interval in milliseconds (500ms = 0.5s) const int updateInterval = 500; // Update interval in milliseconds (500ms = 0.5s)
@ -38,6 +37,7 @@ typedef struct MSG{
double longitude; double longitude;
}MSG; }MSG;
const uint8_t MSG_Size = sizeof(MSG);
enum result { enum result {
Ok = 0, Ok = 0,
@ -91,7 +91,7 @@ uint8_t Radio_Setup(void) {
uint8_t Radio_Configure(void) { uint8_t Radio_Configure(void) {
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM // 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"); //Serial.println("Radio_Configure(): failed to set frequency");
return Err; return Err;
} }
@ -126,7 +126,7 @@ uint8_t Radio_CheckForMsg(MSG *msg) {
//Now we wait for an packet. //Now we wait for an packet.
if (rf95.waitAvailableTimeout(1000)) { if (rf95.waitAvailableTimeout(1000)) {
// Should be a reply message for us now // 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: "); //Serial.print("Received reply: ");
msg->id = (uint8_t) buffer[0]; msg->id = (uint8_t) buffer[0];
@ -190,15 +190,6 @@ void setup(void) {
TFT_Init(); 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<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
// GPS Setup // GPS Setup
gpsSerial.begin(GPS_BUADRATE); gpsSerial.begin(GPS_BUADRATE);
@ -222,28 +213,7 @@ void setup(void) {
} }
void loop() { void loop() {
unsigned long currentTime = millis(); // Get the current time //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
}
//Handle the Radio data. //Handle the Radio data.
sendGPSData(); sendGPSData();
@ -262,7 +232,7 @@ void TFT_UpdateDistance(uint16_t meters) {
tft.setTextWrap(true); tft.setTextWrap(true);
tft.println(" Distance"); tft.println(" Distance");
tft.print(" "); tft.print(" ");
tft.print(distance); tft.print(meters);
tft.print("m"); tft.print("m");
} }
@ -274,7 +244,7 @@ void TFT_UpdateDirection(uint16_t degrees) {
tft.setCursor(0, 150); tft.setCursor(0, 150);
tft.setTextColor(ST77XX_WHITE); tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(3); tft.setTextSize(3);
tft.print(meters); tft.print(degrees);
tft.println(" Degrees"); tft.println(" Degrees");
} }
@ -312,6 +282,8 @@ uint8_t TFT_Reset() {
//Serial.println("TFT_Reset()"); //Serial.println("TFT_Reset()");
tft.fillScreen(ST77XX_BLACK); // Set the screen background to black tft.fillScreen(ST77XX_BLACK); // Set the screen background to black
//Can add default startup logo/screen here for later. //Can add default startup logo/screen here for later.
return Ok;
} }
// Initalizes the Screen with default startup screen. // Initalizes the Screen with default startup screen.
@ -325,6 +297,8 @@ uint8_t TFT_Init(void) {
TFT_UpdateDistance(0); TFT_UpdateDistance(0);
TFT_UpdateDirection(0); TFT_UpdateDirection(0);
TFT_UpdateBatteryState(100); 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 // - 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 // - 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 // - LoRa communication is lost: Display a notification or error on the screen
} }