Skip to content

Commit 0c8c6ab

Browse files
committed
Move begin functions to separate tab.
1 parent a213409 commit 0c8c6ab

File tree

2 files changed

+203
-200
lines changed

2 files changed

+203
-200
lines changed

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 2 additions & 200 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ void setup()
250250

251251
void loop()
252252
{
253+
myGPS.checkUblox(); //Regularly poll to get latest data and any RTCM
254+
253255
//Update Bluetooth LED status
254256
if (bluetoothState == BT_ON_NOCONNECTION)
255257
{
@@ -421,203 +423,3 @@ void updateDisplay()
421423
}
422424
}
423425
}
424-
425-
void beginSD()
426-
{
427-
pinMode(PIN_MICROSD_CHIP_SELECT, OUTPUT);
428-
digitalWrite(PIN_MICROSD_CHIP_SELECT, HIGH); //Be sure SD is deselected
429-
430-
if (settings.enableSD == true)
431-
{
432-
//Max power up time is 250ms: https://www.kingston.com/datasheets/SDCIT-specsheet-64gb_en.pdf
433-
//Max current is 200mA average across 1s, peak 300mA
434-
delay(10);
435-
436-
if (sd.begin(PIN_MICROSD_CHIP_SELECT, SD_SCK_MHZ(24)) == false) //Standard SdFat
437-
{
438-
printDebug("SD init failed (first attempt). Trying again...\r\n");
439-
//Give SD more time to power up, then try again
440-
delay(250);
441-
if (sd.begin(PIN_MICROSD_CHIP_SELECT, SD_SCK_MHZ(24)) == false) //Standard SdFat
442-
{
443-
Serial.println(F("SD init failed (second attempt). Is card present? Formatted?"));
444-
digitalWrite(PIN_MICROSD_CHIP_SELECT, HIGH); //Be sure SD is deselected
445-
online.microSD = false;
446-
return;
447-
}
448-
}
449-
450-
//Change to root directory. All new file creation will be in root.
451-
if (sd.chdir() == false)
452-
{
453-
Serial.println(F("SD change directory failed"));
454-
online.microSD = false;
455-
return;
456-
}
457-
458-
online.microSD = true;
459-
}
460-
else
461-
{
462-
online.microSD = false;
463-
}
464-
}
465-
466-
void beginDisplay()
467-
{
468-
//0x3D is default on Qwiic board
469-
if (isConnected(0x3D) == true || isConnected(0x3C) == true)
470-
{
471-
online.display = true;
472-
473-
//Init and display splash
474-
oled.begin(); // Initialize the OLED
475-
oled.clear(PAGE); // Clear the display's internal memory
476-
477-
oled.setCursor(10, 2); //x, y
478-
oled.setFontType(0); //Set font to smallest
479-
oled.print("SparkFun");
480-
481-
oled.setCursor(21, 13);
482-
oled.setFontType(1);
483-
oled.print("RTK");
484-
485-
int surveyorTextY = 25;
486-
int surveyorTextX = 2;
487-
int surveyorTextKerning = 8;
488-
oled.setFontType(1);
489-
490-
oled.setCursor(surveyorTextX, surveyorTextY);
491-
oled.print("S");
492-
493-
surveyorTextX += surveyorTextKerning;
494-
oled.setCursor(surveyorTextX, surveyorTextY);
495-
oled.print("u");
496-
497-
surveyorTextX += surveyorTextKerning;
498-
oled.setCursor(surveyorTextX, surveyorTextY);
499-
oled.print("r");
500-
501-
surveyorTextX += surveyorTextKerning;
502-
oled.setCursor(surveyorTextX, surveyorTextY);
503-
oled.print("v");
504-
505-
surveyorTextX += surveyorTextKerning;
506-
oled.setCursor(surveyorTextX, surveyorTextY);
507-
oled.print("e");
508-
509-
surveyorTextX += surveyorTextKerning;
510-
oled.setCursor(surveyorTextX, surveyorTextY);
511-
oled.print("y");
512-
513-
surveyorTextX += surveyorTextKerning;
514-
oled.setCursor(surveyorTextX, surveyorTextY);
515-
oled.print("o");
516-
517-
surveyorTextX += surveyorTextKerning;
518-
oled.setCursor(surveyorTextX, surveyorTextY);
519-
oled.print("r");
520-
521-
oled.setCursor(20, 41);
522-
oled.setFontType(0); //Set font to smallest
523-
oled.printf("v%d.%d", FIRMWARE_VERSION_MAJOR, FIRMWARE_VERSION_MINOR);
524-
oled.display();
525-
}
526-
}
527-
528-
//Connect to and configure ZED-F9P
529-
void beginGNSS()
530-
{
531-
if (myGPS.begin() == false)
532-
{
533-
//Try again with power on delay
534-
delay(1000); //Wait for ZED-F9P to power up before it can respond to ACK
535-
if (myGPS.begin() == false)
536-
{
537-
Serial.println(F("u-blox GNSS not detected at default I2C address. Hard stop."));
538-
blinkError(ERROR_NO_I2C);
539-
}
540-
}
541-
542-
//Check the firmware version of the ZED-F9P. Based on Example21_ModuleInfo.
543-
// if (myGPS.getModuleInfo(1100) == true) // Try to get the module info
544-
// {
545-
// if (strcmp(myGPS.minfo.extension[1], latestZEDFirmware) != 0)
546-
// {
547-
// Serial.print("The ZED-F9P appears to have outdated firmware. Found: ");
548-
// Serial.println(myGPS.minfo.extension[1]);
549-
// Serial.print("The Surveyor works best with ");
550-
// Serial.println(latestZEDFirmware);
551-
// Serial.print("Please upgrade using u-center.");
552-
// Serial.println();
553-
// }
554-
// else
555-
// {
556-
// Serial.println("ZED-F9P firmware is current");
557-
// }
558-
// }
559-
560-
bool response = configureUbloxModule();
561-
if (response == false)
562-
{
563-
//Try once more
564-
Serial.println(F("Failed to configure module. Trying again."));
565-
delay(1000);
566-
response = configureUbloxModule();
567-
568-
if (response == false)
569-
{
570-
Serial.println(F("Failed to configure module. Hard stop."));
571-
blinkError(ERROR_GPS_CONFIG_FAIL);
572-
}
573-
}
574-
Serial.println(F("GNSS configuration complete"));
575-
}
576-
577-
//Get MAC, start radio
578-
void beginBT()
579-
{
580-
//Get unit MAC address
581-
esp_read_mac(unitMACAddress, ESP_MAC_WIFI_STA);
582-
unitMACAddress[5] += 2; //Convert MAC address to Bluetooth MAC (add 2): https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/system.html#mac-address
583-
584-
SerialBT.register_callback(btCallback);
585-
if (startBluetooth() == false)
586-
{
587-
Serial.println("An error occurred initializing Bluetooth");
588-
bluetoothState = BT_OFF;
589-
digitalWrite(bluetoothStatusLED, LOW);
590-
}
591-
else
592-
{
593-
bluetoothState = BT_ON_NOCONNECTION;
594-
digitalWrite(bluetoothStatusLED, HIGH);
595-
lastBluetoothLEDBlink = millis();
596-
}
597-
}
598-
599-
//Set LEDs for output and configure PWM
600-
void beginLEDs()
601-
{
602-
pinMode(positionAccuracyLED_1cm, OUTPUT);
603-
pinMode(positionAccuracyLED_10cm, OUTPUT);
604-
pinMode(positionAccuracyLED_100cm, OUTPUT);
605-
pinMode(baseStatusLED, OUTPUT);
606-
pinMode(bluetoothStatusLED, OUTPUT);
607-
pinMode(baseSwitch, INPUT_PULLUP); //HIGH = rover, LOW = base
608-
609-
digitalWrite(positionAccuracyLED_1cm, LOW);
610-
digitalWrite(positionAccuracyLED_10cm, LOW);
611-
digitalWrite(positionAccuracyLED_100cm, LOW);
612-
digitalWrite(baseStatusLED, LOW);
613-
digitalWrite(bluetoothStatusLED, LOW);
614-
615-
ledcSetup(ledRedChannel, freq, resolution);
616-
ledcSetup(ledGreenChannel, freq, resolution);
617-
618-
ledcAttachPin(batteryLevelLED_Red, ledRedChannel);
619-
ledcAttachPin(batteryLevelLED_Green, ledGreenChannel);
620-
621-
ledcWrite(ledRedChannel, 0);
622-
ledcWrite(ledGreenChannel, 0);
623-
}

0 commit comments

Comments
 (0)