|
43 | 43 | If more than 1Hz, turn off SV sentences. |
44 | 44 | */ |
45 | 45 |
|
| 46 | +const int FIRMWARE_VERSION_MAJOR = 1; |
| 47 | +const int FIRMWARE_VERSION_MINOR = 6; |
| 48 | + |
| 49 | +#include "settings.h" |
| 50 | + |
| 51 | +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 52 | +//Hardware connections v11 |
| 53 | +const int positionAccuracyLED_1cm = 2; |
| 54 | +const int baseStatusLED = 4; |
| 55 | +const int baseSwitch = 5; |
| 56 | +const int bluetoothStatusLED = 12; |
| 57 | +const int positionAccuracyLED_100cm = 13; |
| 58 | +const int positionAccuracyLED_10cm = 15; |
| 59 | +const byte PIN_MICROSD_CHIP_SELECT = 25; |
| 60 | +const int zed_tx_ready = 26; |
| 61 | +const int zed_reset = 27; |
| 62 | +const int batteryLevelLED_Red = 32; |
| 63 | +const int batteryLevelLED_Green = 33; |
| 64 | +const int batteryLevel_alert = 36; |
| 65 | +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 66 | + |
| 67 | +//microSD Interface |
| 68 | +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
| 69 | +#include <SPI.h> |
| 70 | +#include <SdFat.h> //SdFat (FAT32) by Bill Greiman: http://librarymanager/All#SdFat |
| 71 | +SdFat sd; |
| 72 | +SdFile sensorDataFile; //File that all sensor data is written to |
| 73 | +SdFile serialDataFile; //File that all incoming serial data is written to |
| 74 | +//#define PRINT_LAST_WRITE_TIME // Uncomment this line to enable the 'measure the time between writes' diagnostic |
| 75 | + |
| 76 | +char sensorDataFileName[30] = ""; //We keep a record of this file name so that we can re-open it upon wakeup from sleep |
| 77 | +char serialDataFileName[30] = ""; //We keep a record of this file name so that we can re-open it upon wakeup from sleep |
| 78 | +const int sdPowerDownDelay = 100; //Delay for this many ms before turning off the SD card power |
| 79 | +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
| 80 | + |
46 | 81 | #include <Wire.h> //Needed for I2C to GPS |
47 | 82 |
|
48 | 83 | //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
@@ -104,22 +139,6 @@ uint8_t rBuffer[SERIAL_SIZE_RX]; //Buffer for reading F9P |
104 | 139 | uint8_t wBuffer[SERIAL_SIZE_RX]; //Buffer for writing to F9P |
105 | 140 | //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
106 | 141 |
|
107 | | -//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
108 | | -//Hardware connections v11 |
109 | | -const int positionAccuracyLED_1cm = 2; |
110 | | -const int baseStatusLED = 4; |
111 | | -const int baseSwitch = 5; |
112 | | -const int bluetoothStatusLED = 12; |
113 | | -const int positionAccuracyLED_100cm = 13; |
114 | | -const int positionAccuracyLED_10cm = 15; |
115 | | -const int sd_cs = 25; |
116 | | -const int zed_tx_ready = 26; |
117 | | -const int zed_reset = 27; |
118 | | -const int batteryLevelLED_Red = 32; |
119 | | -const int batteryLevelLED_Green = 33; |
120 | | -const int batteryLevel_alert = 36; |
121 | | -//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
122 | | - |
123 | 142 | //Freeze and blink LEDs if we hit a bad error |
124 | 143 | typedef enum |
125 | 144 | { |
@@ -149,19 +168,30 @@ volatile BaseState baseState = BASE_OFF; |
149 | 168 | unsigned long baseStateBlinkTime = 0; |
150 | 169 | const unsigned long maxSurveyInWait_s = 60L * 15L; //Re-start survey-in after X seconds |
151 | 170 |
|
| 171 | +//Return values for getByteChoice() |
| 172 | +enum returnStatus { |
| 173 | + STATUS_GETBYTE_TIMEOUT = 255, |
| 174 | + STATUS_GETNUMBER_TIMEOUT = -123455555, |
| 175 | + STATUS_PRESSED_X, |
| 176 | +}; |
| 177 | + |
| 178 | +//Global variables |
| 179 | +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
| 180 | +const byte menuTimeout = 15; //Menus will exit/timeout after this number of seconds |
152 | 181 | uint32_t lastBluetoothLEDBlink = 0; |
153 | 182 | uint32_t lastRoverUpdate = 0; |
154 | 183 | uint32_t lastBaseUpdate = 0; |
155 | 184 | uint32_t lastBattUpdate = 0; |
156 | 185 |
|
157 | 186 | uint32_t lastTime = 0; |
| 187 | +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
158 | 188 |
|
159 | 189 | void setup() |
160 | 190 | { |
161 | 191 | Serial.begin(115200); //UART0 for programming and debugging |
162 | 192 | Serial.setRxBufferSize(SERIAL_SIZE_RX); |
163 | 193 | Serial.setTimeout(1); |
164 | | - |
| 194 | + |
165 | 195 | GPS.begin(115200); //UART2 on pins 16/17 for SPP. The ZED-F9P will be configured to output NMEA over its UART1 at 115200bps. |
166 | 196 | GPS.setRxBufferSize(SERIAL_SIZE_RX); |
167 | 197 | GPS.setTimeout(1); |
@@ -258,6 +288,8 @@ void setup() |
258 | 288 | } |
259 | 289 | Serial.println(F("GPS configuration complete")); |
260 | 290 |
|
| 291 | + beginSD(); //Test if SD is present |
| 292 | + |
261 | 293 | danceLEDs(); //Turn on LEDs like a car dashboard |
262 | 294 |
|
263 | 295 | //myGPS.enableDebugging(); //Enable debug messages over Serial (default) |
@@ -321,6 +353,63 @@ void loop() |
321 | 353 | } |
322 | 354 |
|
323 | 355 | updateBattLEDs(); |
| 356 | + |
| 357 | + //Menu system via ESP32 USB connection |
| 358 | + if (Serial.available()) menuMain(); //Present user menu |
| 359 | + |
324 | 360 | delay(10); //Required if no other I2C or functions are called |
325 | 361 |
|
326 | 362 | } |
| 363 | + |
| 364 | +void beginSD() |
| 365 | +{ |
| 366 | + pinMode(PIN_MICROSD_CHIP_SELECT, OUTPUT); |
| 367 | + digitalWrite(PIN_MICROSD_CHIP_SELECT, HIGH); //Be sure SD is deselected |
| 368 | + |
| 369 | + if (settings.enableSD == true) |
| 370 | + { |
| 371 | + // For reasons I don't understand, we seem to have to wait for at least 1ms after SPI.begin before we call microSDPowerOn. |
| 372 | + // If you comment the next line, the Artemis resets at microSDPowerOn when beginSD is called from wakeFromSleep... |
| 373 | + // But only on one of my V10 red boards. The second one I have doesn't seem to need the delay!? |
| 374 | + delay(1); |
| 375 | + |
| 376 | + // microSDPowerOn(); |
| 377 | + |
| 378 | + //Max power up time is 250ms: https://www.kingston.com/datasheets/SDCIT-specsheet-64gb_en.pdf |
| 379 | + //Max current is 200mA average across 1s, peak 300mA |
| 380 | + for (int i = 0; i < 10; i++) //Wait |
| 381 | + { |
| 382 | + delay(1); |
| 383 | + } |
| 384 | + |
| 385 | + if (sd.begin(PIN_MICROSD_CHIP_SELECT, SD_SCK_MHZ(24)) == false) //Standard SdFat |
| 386 | + { |
| 387 | + printDebug("SD init failed (first attempt). Trying again...\r\n"); |
| 388 | + for (int i = 0; i < 250; i++) //Give SD more time to power up, then try again |
| 389 | + { |
| 390 | + delay(1); |
| 391 | + } |
| 392 | + if (sd.begin(PIN_MICROSD_CHIP_SELECT, SD_SCK_MHZ(24)) == false) //Standard SdFat |
| 393 | + { |
| 394 | + Serial.println(F("SD init failed (second attempt). Is card present? Formatted?")); |
| 395 | + digitalWrite(PIN_MICROSD_CHIP_SELECT, HIGH); //Be sure SD is deselected |
| 396 | + online.microSD = false; |
| 397 | + return; |
| 398 | + } |
| 399 | + } |
| 400 | + |
| 401 | + //Change to root directory. All new file creation will be in root. |
| 402 | + if (sd.chdir() == false) |
| 403 | + { |
| 404 | + Serial.println(F("SD change directory failed")); |
| 405 | + online.microSD = false; |
| 406 | + return; |
| 407 | + } |
| 408 | + |
| 409 | + online.microSD = true; |
| 410 | + } |
| 411 | + else |
| 412 | + { |
| 413 | + online.microSD = false; |
| 414 | + } |
| 415 | +} |
0 commit comments