diff --git a/Binaries/OpenLog_Artemis-V10-v19.bin b/Binaries/OpenLog_Artemis-V10-v19.bin new file mode 100644 index 0000000..07decad Binary files /dev/null and b/Binaries/OpenLog_Artemis-V10-v19.bin differ diff --git a/Binaries/OpenLog_Artemis-X04-v19.bin b/Binaries/OpenLog_Artemis-X04-v19.bin new file mode 100644 index 0000000..22c68bf Binary files /dev/null and b/Binaries/OpenLog_Artemis-X04-v19.bin differ diff --git a/CHANGELOG.md b/CHANGELOG.md index 74bca50..7237ced 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,23 @@ Change Log ====================== +v1.9 +--------- + +* Allows the TX and RX pins to be used for the serial terminal / console + * This is very cool as it means you can now connect the OLA to your choice of (e.g.) Bluetooth or radio modem and access your data over that instead of USB + * File transfer using ZMODEM is possible on both USB and TX/RX +* Added support for the SGP40 air quality sensor - which provides a robust VOC Index for indoor air quality +* Added support for the SDP3X differential pressure sensor - opening up possibilities for air flow and air speed measurement +* Added support for the MS5837 depth / pressure sensor - as used in the BlueRobotics Bar02 +* Corrects an issue which was corrupting data when using multiple MS8607s [62]https://github.com/sparkfun/OpenLog_Artemis/issues/62 +* Adds serial logging timestamps with a configurable timestamp token [63](https://github.com/sparkfun/OpenLog_Artemis/issues/63) - thank you @DennisMelamed +* Adds a _slow logging_ feature to extend battery life + * Pin11 can be used to enter slow logging mode [60](https://github.com/sparkfun/OpenLog_Artemis/issues/60) - thank you @ryanneve + * Slow logging can be entered once per day, with configurable start and end time [46](https://github.com/sparkfun/OpenLog_Artemis/issues/46) +* Adds improved support for the SCD30 [67](https://github.com/sparkfun/OpenLog_Artemis/issues/67) - thank you @paulvha +* Corrects a bug in logMicroseconds [57](https://github.com/sparkfun/OpenLog_Artemis/issues/57) + v1.8 --------- diff --git a/Firmware/OpenLog_Artemis/OpenLog_Artemis.ino b/Firmware/OpenLog_Artemis/OpenLog_Artemis.ino index 6c714b6..40a2205 100644 --- a/Firmware/OpenLog_Artemis/OpenLog_Artemis.ino +++ b/Firmware/OpenLog_Artemis/OpenLog_Artemis.ino @@ -13,6 +13,9 @@ The Board should be set to SparkFun Apollo3 \ SparkFun RedBoard Artemis ATP. + Please note: this firmware currently only compiles on v1.2.1 of the Apollo3 boards. + It does not yet work with the new Mbed version (v2.0) of the core. + v1.0 Power Consumption: Sleep between reads, RTC fully charged, no Qwiic, SD, no USB, no Power LED: 260uA 10Hz logging IMU, no Qwiic, SD, no USB, no Power LED: 9-27mA @@ -74,10 +77,19 @@ (done) Add a fix to make sure the MS8607 is detected correctly: https://github.com/sparkfun/OpenLog_Artemis/issues/54 (done) Add logMicroseconds: https://github.com/sparkfun/OpenLog_Artemis/issues/49 (done) Add an option to use autoPVT when logging GNSS data: https://github.com/sparkfun/OpenLog_Artemis/issues/50 + (done) Corrected an issue when using multiple MS8607's: https://github.com/sparkfun/OpenLog_Artemis/issues/62 + (done) Add a feature to use the TX and RX pins as a duplicate Terminal + (done) Add serial log timestamps with a token (as suggested by @DennisMelamed in PR https://github.com/sparkfun/OpenLog_Artemis/pull/70 and Issue https://github.com/sparkfun/OpenLog_Artemis/issues/63) + (done) Add "sleep on pin" functionality based @ryanneve's PR https://github.com/sparkfun/OpenLog_Artemis/pull/64 and Issue https://github.com/sparkfun/OpenLog_Artemis/issues/46 + (done) Add "wake at specified times" functionality based on Issue https://github.com/sparkfun/OpenLog_Artemis/issues/46 + (done) Add corrections for the SCD30 based on Forum post by paulvha: https://forum.sparkfun.com/viewtopic.php?p=222455#p222455 + (done) Add support for the SGP40 VOC Index sensor + (done) Add support for the SDP3X Differential Pressure sensor + (done) Add support for the MS5837 - as used in the BlueRobotics BAR02 and BAR30 water pressure sensors */ const int FIRMWARE_VERSION_MAJOR = 1; -const int FIRMWARE_VERSION_MINOR = 8; +const int FIRMWARE_VERSION_MINOR = 9; //Define the OLA board identifier: // This is an int which is unique to this variant of the OLA and which allows us @@ -87,7 +99,7 @@ const int FIRMWARE_VERSION_MINOR = 8; // the variant * 0x100 (OLA = 1; GNSS_LOGGER = 2; GEOPHONE_LOGGER = 3) // the major firmware version * 0x10 // the minor firmware version -#define OLA_IDENTIFIER 0x118 // Stored as 280 decimal in OLA_settings.txt +#define OLA_IDENTIFIER 0x119 // Stored as 281 decimal in OLA_settings.txt #include "settings.h" @@ -198,7 +210,7 @@ ICM_20948_SPI myICM; #include "SparkFun_VCNL4040_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_VCNL4040 #include "SparkFun_MS5637_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_MS5637 #include "SparkFun_TMP117.h" //Click here to get the library: http://librarymanager/All#SparkFun_TMP117 -#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS +#include "SparkFun_u-blox_GNSS_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS #include "SparkFun_Qwiic_Scale_NAU7802_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_NAU7802 #include "SparkFun_SCD30_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD30 #include "SparkFun_Qwiic_Humidity_AHT20.h" //Click here to get the library: http://librarymanager/All#Qwiic_Humidity_AHT20 by SparkFun @@ -206,6 +218,9 @@ ICM_20948_SPI myICM; #include "SparkFun_ADS122C04_ADC_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_ADS122C04 #include "SparkFun_MicroPressure.h" // Click here to get the library: http://librarymanager/All#SparkFun_MicroPressure #include "SparkFun_Particle_Sensor_SN-GCJA5_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_Particle_Sensor_SN-GCJA5 +#include "SparkFun_SGP40_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP40 +#include "SparkFun_SDP3x_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SDP3x +#include "MS5837.h" // Click here to download the library: https://github.com/sparkfunX/BlueRobotics_MS5837_Library //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- @@ -228,11 +243,34 @@ unsigned long qwiicPowerOnDelayMillis; //Wait for this many milliseconds after t int lowBatteryReadings = 0; // Count how many times the battery voltage has read low const int lowBatteryReadingsLimit = 10; // Don't declare the battery voltage low until we have had this many consecutive low readings (to reject sampling noise) volatile static bool triggerEdgeSeen = false; //Flag to indicate if a trigger interrupt has been seen +char serialTimestamp[40]; //Buffer to store serial timestamp, if needed //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- +uint8_t getByteChoice(int numberOfSeconds, bool updateDZSERIAL = false); // Header + +// gfvalvo's flash string helper code: https://forum.arduino.cc/index.php?topic=533118.msg3634809#msg3634809 +void SerialPrint(const char *); +void SerialPrint(const __FlashStringHelper *); +void SerialPrintln(const char *); +void SerialPrintln(const __FlashStringHelper *); +void DoSerialPrint(char (*)(const char *), const char *, bool newLine = false); + //unsigned long startTime = 0; -#define DUMP(varname) {Serial.printf("%s: %llu\r\n", #varname, varname);} +#define DUMP( varname ) {Serial.printf("%s: %llu\r\n", #varname, varname); if (settings.useTxRxPinsForTerminal == true) SerialLog.printf("%s: %llu\r\n", #varname, varname);} +#define SerialPrintf1( var ) {Serial.printf( var ); if (settings.useTxRxPinsForTerminal == true) SerialLog.printf( var );} +#define SerialPrintf2( var1, var2 ) {Serial.printf( var1, var2 ); if (settings.useTxRxPinsForTerminal == true) SerialLog.printf( var1, var2 );} +#define SerialPrintf3( var1, var2, var3 ) {Serial.printf( var1, var2, var3 ); if (settings.useTxRxPinsForTerminal == true) SerialLog.printf( var1, var2, var3 );} +#define SerialPrintf4( var1, var2, var3, var4 ) {Serial.printf( var1, var2, var3, var4 ); if (settings.useTxRxPinsForTerminal == true) SerialLog.printf( var1, var2, var3, var4 );} +#define SerialPrintf5( var1, var2, var3, var4, var5 ) {Serial.printf( var1, var2, var3, var4, var5 ); if (settings.useTxRxPinsForTerminal == true) SerialLog.printf( var1, var2, var3, var4, var5 );} + +// The Serial port for the Zmodem connection +// must not be the same as DSERIAL unless all +// debugging output to DSERIAL is removed +Stream *ZSERIAL; + +// Serial output for debugging info for Zmodem +Stream *DSERIAL; void setup() { //If 3.3V rail drops below 3V, system will power down and maintain RTC @@ -249,7 +287,8 @@ void setup() { digitalWrite(PIN_STAT_LED, HIGH); // Turn the STAT LED on while we configure everything Serial.begin(115200); //Default for initial debug messages if necessary - Serial.println(); + SerialLog.begin(115200); //Default for initial debug messages if necessary + SerialPrintln(F("")); SPI.begin(); //Needed if SD is disabled @@ -270,13 +309,23 @@ void setup() { loadSettings(); //50 - 250ms + if (settings.useTxRxPinsForTerminal == true) + { + SerialLog.begin(settings.serialTerminalBaudRate); // Restart the serial port + } + else + { + SerialLog.end(); // Stop the SerialLog port + } + Serial.flush(); //Complete any previous prints Serial.begin(settings.serialTerminalBaudRate); - Serial.printf("Artemis OpenLog v%d.%d\r\n", FIRMWARE_VERSION_MAJOR, FIRMWARE_VERSION_MINOR); + + SerialPrintf3("Artemis OpenLog v%d.%d\r\n", FIRMWARE_VERSION_MAJOR, FIRMWARE_VERSION_MINOR); if (settings.useGPIO32ForStopLogging == true) { - Serial.println(F("Stop Logging is enabled. Pull GPIO pin 32 to GND to stop logging.")); + SerialPrintln(F("Stop Logging is enabled. Pull GPIO pin 32 to GND to stop logging.")); pinMode(PIN_STOP_LOGGING, INPUT_PULLUP); delay(1); // Let the pin stabilize attachInterrupt(digitalPinToInterrupt(PIN_STOP_LOGGING), stopLoggingISR, FALLING); // Enable the interrupt @@ -289,12 +338,12 @@ void setup() { delay(1); // Let the pin stabilize if (settings.fallingEdgeTrigger == true) { - Serial.println(F("Falling-edge triggering is enabled. Sensor data will be logged on a falling edge on GPIO pin 11.")); + SerialPrintln(F("Falling-edge triggering is enabled. Sensor data will be logged on a falling edge on GPIO pin 11.")); attachInterrupt(digitalPinToInterrupt(PIN_TRIGGER), triggerPinISR, FALLING); // Enable the interrupt } else { - Serial.println(F("Rising-edge triggering is enabled. Sensor data will be logged on a rising edge on GPIO pin 11.")); + SerialPrintln(F("Rising-edge triggering is enabled. Sensor data will be logged on a rising edge on GPIO pin 11.")); attachInterrupt(digitalPinToInterrupt(PIN_TRIGGER), triggerPinISR, RISING); // Enable the interrupt } triggerEdgeSeen = false; // Make sure the flag is clear @@ -305,52 +354,72 @@ void setup() { beginDataLogging(); //180ms lastSDFileNameChangeTime = rtcMillis(); // Record the time of the file name change - beginSerialLogging(); //20 - 99ms - beginSerialOutput(); // Begin serial data output on the TX pin + serialTimestamp[0] = '\0'; // Empty the serial timestamp buffer + + if (settings.useTxRxPinsForTerminal == false) + { + beginSerialLogging(); //20 - 99ms + beginSerialOutput(); // Begin serial data output on the TX pin + } beginIMU(); //61ms - if (online.microSD == true) Serial.println(F("SD card online")); - else Serial.println(F("SD card offline")); + if (online.microSD == true) SerialPrintln(F("SD card online")); + else SerialPrintln(F("SD card offline")); - if (online.dataLogging == true) Serial.println(F("Data logging online")); - else Serial.println(F("Datalogging offline")); + if (online.dataLogging == true) SerialPrintln(F("Data logging online")); + else SerialPrintln(F("Datalogging offline")); - if (online.serialLogging == true) Serial.println(F("Serial logging online")); - else Serial.println(F("Serial logging offline")); + if (online.serialLogging == true) SerialPrintln(F("Serial logging online")); + else SerialPrintln(F("Serial logging offline")); - if (online.IMU == true) Serial.println(F("IMU online")); - else Serial.println(F("IMU offline")); + if (online.IMU == true) SerialPrintln(F("IMU online")); + else SerialPrintln(F("IMU offline")); - if (settings.logMaxRate == true) Serial.println(F("Logging analog pins at max data rate")); + if (settings.logMaxRate == true) SerialPrintln(F("Logging analog pins at max data rate")); - if (settings.enableTerminalOutput == false && settings.logData == true) Serial.println(F("Logging to microSD card with no terminal output")); + if (settings.enableTerminalOutput == false && settings.logData == true) SerialPrintln(F("Logging to microSD card with no terminal output")); if (detectQwiicDevices() == true) //159 - 865ms but varies based on number of devices attached { beginQwiicDevices(); //Begin() each device in the node list loadDeviceSettingsFromFile(); //Load config settings into node list configureQwiicDevices(); //Apply config settings to each device in the node list - printOnlineDevice(); + int deviceCount = printOnlineDevice(); // Pretty-print the online devices + + if ((deviceCount == 0) && (settings.resetOnZeroDeviceCount == true)) // Check for resetOnZeroDeviceCount + { + if ((Serial.available()) || ((settings.useTxRxPinsForTerminal == true) && (SerialLog.available()))) + menuMain(); //Present user menu - in case the user wants to disable resetOnZeroDeviceCount + else + { + SerialPrintln(F("*** Zero Qwiic Devices Found! Resetting... ***")); + SerialFlush(); + resetArtemis(); //Thank you and goodnight... + } + } } else - Serial.println(F("No Qwiic devices detected")); + SerialPrintln(F("No Qwiic devices detected")); if (settings.showHelperText == true) printHelperText(false); //printHelperText to terminal and sensor file - //If we are sleeping between readings then we cannot rely on millis() as it is powered down. Used RTC instead. - if (settings.usBetweenReadings >= maxUsBeforeSleep) + //If we are sleeping between readings then we cannot rely on millis() as it is powered down + //Use RTC instead + if (((settings.useGPIO11ForTrigger == false) && (settings.usBetweenReadings >= maxUsBeforeSleep)) + || (settings.useGPIO11ForFastSlowLogging == true) + || (settings.useRTCForFastSlowLogging == true)) measurementStartTime = rtcMillis(); else measurementStartTime = millis(); - //Serial.printf("Setup time: %.02f ms\r\n", (micros() - startTime) / 1000.0); + //SerialPrintf2("Setup time: %.02f ms\r\n", (micros() - startTime) / 1000.0); digitalWrite(PIN_STAT_LED, LOW); // Turn the STAT LED off now that everything is configured //If we are immediately going to go to sleep after the first reading then //first present the user with the config menu in case they need to change something - if (settings.usBetweenReadings >= maxUsBeforeSleep) + if (checkIfItIsTimeToSleep()) menuMain(); } @@ -358,15 +427,44 @@ void loop() { checkBattery(); // Check for low battery - if (Serial.available()) menuMain(); //Present user menu + if ((Serial.available()) || ((settings.useTxRxPinsForTerminal == true) && (SerialLog.available()))) + menuMain(); //Present user menu - if (settings.logSerial == true && online.serialLogging == true) + if (settings.logSerial == true && online.serialLogging == true && settings.useTxRxPinsForTerminal == false) { - if (SerialLog.available()) + size_t timestampCharsLeftToWrite = strlen(serialTimestamp); + //SerialPrintf2("timestampCharsLeftToWrite is %d\r\n", timestampCharsLeftToWrite); + //SerialFlush(); + + if (SerialLog.available() || (timestampCharsLeftToWrite > 0)) { - while (SerialLog.available()) + while (SerialLog.available() || (timestampCharsLeftToWrite > 0)) { - incomingBuffer[incomingBufferSpot++] = SerialLog.read(); + if (timestampCharsLeftToWrite > 0) // Based on code written by @DennisMelamed in PR #70 + { + incomingBuffer[incomingBufferSpot++] = serialTimestamp[0]; // Add a timestamp character to incomingBuffer + + for (size_t i = 0; i < timestampCharsLeftToWrite; i++) + { + serialTimestamp[i] = serialTimestamp[i+1]; // Shuffle the remaining chars along by one + } + + timestampCharsLeftToWrite -= 1; + } + else + { + incomingBuffer[incomingBufferSpot++] = SerialLog.read(); + + //Get the RTC timestamp if we just received the timestamp token + if (settings.timestampSerial && (incomingBuffer[incomingBufferSpot-1] == settings.timeStampToken)) + { + getTimeString(&serialTimestamp[2]); + serialTimestamp[0] = 0x0A; // Add Line Feed at the start of the timestamp + serialTimestamp[1] = '^'; // Add an up-arrow to indicate the timestamp relates to the preceeding data + serialTimestamp[strlen(serialTimestamp) - 1] = 0x0A; // Change the final comma of the timestamp to a Line Feed + } + } + if (incomingBufferSpot == sizeof(incomingBuffer)) { digitalWrite(PIN_STAT_LED, HIGH); //Toggle stat LED to indicating log recording @@ -471,7 +569,7 @@ void loop() { //Print to terminal if (settings.enableTerminalOutput == true) - Serial.print(outputData); //Print to terminal + SerialPrint(outputData); //Print to terminal //Output to TX pin if ((settings.outputSerial == true) && (online.serialOutput == true)) @@ -487,7 +585,9 @@ void loop() { if (recordLength != strlen(outputData)) //Record the buffer to the card { if (settings.printDebugMessages == true) - Serial.printf("*** sensorDataFile.write data length mismatch! *** recordLength: %d, outputDataLength: %d\r\n", recordLength, strlen(outputData)); + { + SerialPrintf3("*** sensorDataFile.write data length mismatch! *** recordLength: %d, outputDataLength: %d\r\n", recordLength, strlen(outputData)); + } } //Force sync every 500ms @@ -537,14 +637,120 @@ void loop() { triggerEdgeSeen = false; // Clear the trigger seen flag here - just in case another trigger was received while we were logging data to SD card - //Go to sleep if the time between readings is greater than maxUsBeforeSleep (2 seconds) and triggering is not enabled - if ((settings.useGPIO11ForTrigger == false) && (settings.usBetweenReadings >= maxUsBeforeSleep)) + // Code changes here are based on suggestions by @ryanneve in Issue #46 and PR #64 + if (checkIfItIsTimeToSleep()) { - goToSleep(); + goToSleep(howLongToSleepFor()); } } } +uint32_t howLongToSleepFor(void) +{ + //Counter/Timer 6 will use the 32kHz clock + //Calculate how many 32768Hz system ticks we need to sleep for: + //sysTicksToSleep = msToSleep * 32768L / 1000 + //We need to be careful with the multiply as we will overflow uint32_t if msToSleep is > 131072 + + uint32_t msToSleep; + + if (checkSleepOnFastSlowPin()) + msToSleep = (uint32_t)(settings.slowLoggingIntervalSeconds * 1000UL); + else if (checkSleepOnRTCTime()) + { + // checkSleepOnRTCTime has returned true, so we know that we are between slowLoggingStartMOD and slowLoggingStopMOD + // We need to check how long it is until slowLoggingStopMOD (accounting for midnight!) and adjust the sleep duration + // if slowLoggingStopMOD occurs before slowLoggingIntervalSeconds + + msToSleep = (uint32_t)(settings.slowLoggingIntervalSeconds * 1000UL); // Default to this + + myRTC.getTime(); // Get the RTC time + long secondsOfDay = (myRTC.hour * 60 * 60) + (myRTC.minute * 60) + myRTC.seconds; + + long slowLoggingStopSOD = settings.slowLoggingStopMOD * 60; // Convert slowLoggingStop to seconds-of-day + + long secondsUntilStop = slowLoggingStopSOD - secondsOfDay; // Calculate how long it is until slowLoggingStop + + // If secondsUntilStop is negative then we know that now is before midnight and slowLoggingStop is after midnight + if (secondsUntilStop < 0) secondsUntilStop += 24 * 60 * 60; // Add a day's worth of seconds if required to make secondsUntilStop positive + + if (secondsUntilStop < settings.slowLoggingIntervalSeconds) // If we need to sleep for less than slowLoggingIntervalSeconds + msToSleep = (secondsUntilStop + 1) * 1000UL; // Adjust msToSleep, adding one extra second to make sure the next wake is > slowLoggingStop + } + else // checkSleepOnUsBetweenReadings + msToSleep = (uint32_t)(settings.usBetweenReadings / 1000ULL); + + uint32_t sysTicksToSleep; + if (msToSleep < 131000) + { + sysTicksToSleep = msToSleep * 32768L; // Do the multiply first for short intervals + sysTicksToSleep = sysTicksToSleep / 1000L; // Now do the divide + } + else + { + sysTicksToSleep = msToSleep / 1000L; // Do the division first for long intervals (to avoid an overflow) + sysTicksToSleep = sysTicksToSleep * 32768L; // Now do the multiply + } + + return (sysTicksToSleep); +} + +bool checkIfItIsTimeToSleep(void) +{ + + if (checkSleepOnUsBetweenReadings() + || checkSleepOnRTCTime() + || checkSleepOnFastSlowPin()) + return(true); + else + return(false); +} + +//Go to sleep if the time between readings is greater than maxUsBeforeSleep (2 seconds) and triggering is not enabled +bool checkSleepOnUsBetweenReadings(void) +{ + if ((settings.useGPIO11ForTrigger == false) && (settings.usBetweenReadings >= maxUsBeforeSleep)) + return (true); + else + return (false); +} + +//Go to sleep if Fast/Slow logging on Pin 11 is enabled and Pin 11 is in the correct state +bool checkSleepOnFastSlowPin(void) +{ + if ((settings.useGPIO11ForFastSlowLogging == true) && (digitalRead(PIN_TRIGGER) == settings.slowLoggingWhenPin11Is)) + return (true); + else + return (false); +} + +// Go to sleep if useRTCForFastSlowLogging is enabled and RTC time is between the start and stop times +bool checkSleepOnRTCTime(void) +{ + // Check if we should be sleeping based on useGPIO11ForFastSlowLogging and slowLoggingStartMOD + slowLoggingStopMOD + bool sleepOnRTCTime = false; + if (settings.useRTCForFastSlowLogging == true) + { + if (settings.slowLoggingStartMOD != settings.slowLoggingStopMOD) // Only perform the check if the start and stop times are not equal + { + myRTC.getTime(); // Get the RTC time + int minutesOfDay = (myRTC.hour * 60) + myRTC.minute; + + if (settings.slowLoggingStartMOD > settings.slowLoggingStopMOD) // If slow logging starts later than the stop time (i.e. slow over midnight) + { + if ((minutesOfDay >= settings.slowLoggingStartMOD) || (minutesOfDay < settings.slowLoggingStopMOD)) + sleepOnRTCTime = true; + } + else // Slow logging starts earlier than the stop time + { + if ((minutesOfDay >= settings.slowLoggingStartMOD) && (minutesOfDay < settings.slowLoggingStopMOD)) + sleepOnRTCTime = true; + } + } + } + return(sleepOnRTCTime); +} + void beginQwiic() { pinMode(PIN_QWIIC_POWER, OUTPUT); @@ -578,7 +784,7 @@ void beginSD() if (sd.begin(PIN_MICROSD_CHIP_SELECT, SD_SCK_MHZ(24)) == false) //Standard SdFat { - printDebug("SD init failed (first attempt). Trying again...\r\n"); + printDebug(F("SD init failed (first attempt). Trying again...\r\n")); for (int i = 0; i < 250; i++) //Give SD more time to power up, then try again { checkBattery(); @@ -586,7 +792,7 @@ void beginSD() } if (sd.begin(PIN_MICROSD_CHIP_SELECT, SD_SCK_MHZ(24)) == false) //Standard SdFat { - Serial.println(F("SD init failed (second attempt). Is card present? Formatted?")); + SerialPrintln(F("SD init failed (second attempt). Is card present? Formatted?")); digitalWrite(PIN_MICROSD_CHIP_SELECT, HIGH); //Be sure SD is deselected online.microSD = false; return; @@ -596,7 +802,7 @@ void beginSD() //Change to root directory. All new file creation will be in root. if (sd.chdir() == false) { - Serial.println(F("SD change directory failed")); + SerialPrintln(F("SD change directory failed")); online.microSD = false; return; } @@ -622,7 +828,7 @@ void enableCIPOpullUp() cipoPinCfg.ePullup = AM_HAL_GPIO_PIN_PULLUP_1_5K; padMode(MISO, cipoPinCfg, &retval); if (retval != AP3_OK) - printDebug("Setting CIPO padMode failed!"); + printDebug(F("Setting CIPO padMode failed!")); } void beginIMU() @@ -672,7 +878,7 @@ void beginIMU() { printDebug("beginIMU: second attempt at myICM.begin failed. myICM.status = " + (String)myICM.status + "\r\n"); digitalWrite(PIN_IMU_CHIP_SELECT, HIGH); //Be sure IMU is deselected - Serial.println(F("ICM-20948 failed to init.")); + SerialPrintln(F("ICM-20948 failed to init.")); imuPowerOff(); online.IMU = false; return; @@ -691,12 +897,12 @@ void beginIMU() ICM_20948_Status_e retval = myICM.enableDLPF(ICM_20948_Internal_Acc, settings.imuAccDLPF); if (retval != ICM_20948_Stat_Ok) { - Serial.println(F("Error: Could not configure the IMU Accelerometer DLPF!")); + SerialPrintln(F("Error: Could not configure the IMU Accelerometer DLPF!")); } retval = myICM.enableDLPF(ICM_20948_Internal_Gyr, settings.imuGyroDLPF); if (retval != ICM_20948_Stat_Ok) { - Serial.println(F("Error: Could not configure the IMU Gyro DLPF!")); + SerialPrintln(F("Error: Could not configure the IMU Gyro DLPF!")); } ICM_20948_dlpcfg_t dlpcfg; dlpcfg.a = settings.imuAccDLPFBW; @@ -704,7 +910,7 @@ void beginIMU() retval = myICM.setDLPFcfg((ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), dlpcfg); if (retval != ICM_20948_Stat_Ok) { - Serial.println(F("Error: Could not configure the IMU DLPF BW!")); + SerialPrintln(F("Error: Could not configure the IMU DLPF BW!")); } ICM_20948_fss_t FSS; FSS.a = settings.imuAccFSS; @@ -712,7 +918,7 @@ void beginIMU() retval = myICM.setFullScale((ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), FSS); if (retval != ICM_20948_Stat_Ok) { - Serial.println(F("Error: Could not configure the IMU Full Scale!")); + SerialPrintln(F("Error: Could not configure the IMU Full Scale!")); } online.IMU = true; @@ -738,7 +944,7 @@ void beginDataLogging() // O_WRITE - open for write if (sensorDataFile.open(sensorDataFileName, O_CREAT | O_APPEND | O_WRITE) == false) { - Serial.println(F("Failed to create sensor data file")); + SerialPrintln(F("Failed to create sensor data file")); online.dataLogging = false; return; } @@ -761,7 +967,7 @@ void beginSerialLogging() if (serialDataFile.open(serialDataFileName, O_CREAT | O_APPEND | O_WRITE) == false) { - Serial.println(F("Failed to create serial log file")); + SerialPrintln(F("Failed to create serial log file")); //systemError(ERROR_FILE_OPEN); online.serialLogging = false; return; @@ -825,3 +1031,55 @@ void triggerPinISR(void) { triggerEdgeSeen = true; } + +void SerialFlush(void) +{ + Serial.flush(); + if (settings.useTxRxPinsForTerminal == true) + { + SerialLog.flush(); + } +} + +// gfvalvo's flash string helper code: https://forum.arduino.cc/index.php?topic=533118.msg3634809#msg3634809 + +void SerialPrint(const char *line) +{ + DoSerialPrint([](const char *ptr) {return *ptr;}, line); +} + +void SerialPrint(const __FlashStringHelper *line) +{ + DoSerialPrint([](const char *ptr) {return (char) pgm_read_byte_near(ptr);}, + (const char*) line); +} + +void SerialPrintln(const char *line) +{ + DoSerialPrint([](const char *ptr) {return *ptr;}, line, true); +} + +void SerialPrintln(const __FlashStringHelper *line) +{ + DoSerialPrint([](const char *ptr) {return (char) pgm_read_byte_near(ptr);}, + (const char*) line, true); +} + +void DoSerialPrint(char (*funct)(const char *), const char *string, bool newLine) +{ + char ch; + + while ((ch = funct(string++))) + { + Serial.print(ch); + if (settings.useTxRxPinsForTerminal == true) + SerialLog.print(ch); + } + + if (newLine) + { + Serial.println(); + if (settings.useTxRxPinsForTerminal == true) + SerialLog.println(); + } +} diff --git a/Firmware/OpenLog_Artemis/Sensors.ino b/Firmware/OpenLog_Artemis/Sensors.ino index 3b110ff..5ccc542 100644 --- a/Firmware/OpenLog_Artemis/Sensors.ino +++ b/Firmware/OpenLog_Artemis/Sensors.ino @@ -9,44 +9,10 @@ void getData() if (settings.logRTC) { - //Decide if we are using the internal RTC or GPS for timestamps - if (settings.getRTCfromGPS == false) - { - myRTC.getTime(); - - if (settings.logDate) - { - char rtcDate[12]; //10/12/2019, - if (settings.americanDateStyle == true) - sprintf(rtcDate, "%02d/%02d/20%02d,", myRTC.month, myRTC.dayOfMonth, myRTC.year); - else - sprintf(rtcDate, "%02d/%02d/20%02d,", myRTC.dayOfMonth, myRTC.month, myRTC.year); - strcat(outputData, rtcDate); - } - - if (settings.logTime) - { - char rtcTime[13]; //09:14:37.41, - int adjustedHour = myRTC.hour; - if (settings.hour24Style == false) - { - if (adjustedHour > 12) adjustedHour -= 12; - } - sprintf(rtcTime, "%02d:%02d:%02d.%02d,", adjustedHour, myRTC.minute, myRTC.seconds, myRTC.hundredths); - strcat(outputData, rtcTime); - } - - if (settings.logMicroseconds) - { - char microseconds[11]; // - sprintf(microseconds, "%d,", micros()); - strcat(outputData, microseconds); - } - } //end if use RTC for timestamp - else //Use GPS for timestamp - { - Serial.println(F("Print GPS Timestamp / not yet implemented")); - } + //Code written by @DennisMelamed in PR #70 + char timeString[37]; + getTimeString(timeString); // getTimeString is in timeStamp.ino + strcat(outputData, timeString); } if (settings.logA11) @@ -161,8 +127,10 @@ void getData() uint64_t currentMillis; //If we are sleeping between readings then we cannot rely on millis() as it is powered down - //Used RTC instead - if (settings.usBetweenReadings >= maxUsBeforeSleep) + //Use RTC instead + if (((settings.useGPIO11ForTrigger == false) && (settings.usBetweenReadings >= maxUsBeforeSleep)) + || (settings.useGPIO11ForFastSlowLogging == true) + || (settings.useRTCForFastSlowLogging == true)) { currentMillis = rtcMillis(); } @@ -254,7 +222,7 @@ void gatherDeviceValues() { qwiic.setPullups(0); //Disable pullups to minimize CRC issues - SFE_UBLOX_GPS *nodeDevice = (SFE_UBLOX_GPS *)temp->classPtr; + SFE_UBLOX_GNSS *nodeDevice = (SFE_UBLOX_GNSS *)temp->classPtr; struct_uBlox *nodeSetting = (struct_uBlox *)temp->configPtr; if (nodeSetting->log == true) @@ -803,8 +771,81 @@ void gatherDeviceValues() } } break; + case DEVICE_VOC_SGP40: + { + SGP40 *nodeDevice = (SGP40 *)temp->classPtr; + struct_SGP40 *nodeSetting = (struct_SGP40 *)temp->configPtr; + if (nodeSetting->log == true) + { + if (nodeSetting->logVOC) + { + sprintf(tempData, "%d,", nodeDevice->getVOCindex(nodeSetting->RH, nodeSetting->T)); + strcat(outputData, tempData); + } + } + } + break; + case DEVICE_PRESSURE_SDP3X: + { + SDP3X *nodeDevice = (SDP3X *)temp->classPtr; + struct_SDP3X *nodeSetting = (struct_SDP3X *)temp->configPtr; + if (nodeSetting->log == true) + { + float pressure; + float temperature; + if ((nodeSetting->logPressure) || (nodeSetting->logTemperature)) + { + nodeDevice->triggeredMeasurement(nodeSetting->massFlow, nodeSetting->clockStretching); + nodeDevice->readMeasurement(&pressure, &temperature); + } + if (nodeSetting->logPressure) + { + sprintf(tempData, "%.02f,", pressure); + strcat(outputData, tempData); + } + if (nodeSetting->logTemperature) + { + sprintf(tempData, "%.02f,", temperature); + strcat(outputData, tempData); + } + } + } + break; + case DEVICE_PRESSURE_MS5837: + { + MS5837 *nodeDevice = (MS5837 *)temp->classPtr; + struct_MS5837 *nodeSetting = (struct_MS5837 *)temp->configPtr; + if (nodeSetting->log == true) + { + if ((nodeSetting->logPressure) || (nodeSetting->logTemperature) || (nodeSetting->logDepth) || (nodeSetting->logAltitude)) + { + nodeDevice->read(); + } + if (nodeSetting->logPressure) + { + sprintf(tempData, "%.02f,", nodeDevice->pressure(nodeSetting->conversion)); + strcat(outputData, tempData); + } + if (nodeSetting->logTemperature) + { + sprintf(tempData, "%.02f,", nodeDevice->temperature()); + strcat(outputData, tempData); + } + if (nodeSetting->logDepth) + { + sprintf(tempData, "%.03f,", nodeDevice->depth()); + strcat(outputData, tempData); + } + if (nodeSetting->logAltitude) + { + sprintf(tempData, "%.02f,", nodeDevice->altitude()); + strcat(outputData, tempData); + } + } + } + break; default: - Serial.printf("printDeviceValue unknown device type: %s\r\n", getDeviceName(temp->deviceType)); + SerialPrintf2("printDeviceValue unknown device type: %s\r\n", getDeviceName(temp->deviceType)); break; } @@ -821,19 +862,12 @@ void printHelperText(bool terminalOnly) if (settings.logRTC) { - //Decide if we are using the internal RTC or GPS for timestamps - if (settings.getRTCfromGPS == false) - { - if (settings.logDate) - strcat(helperText, "rtcDate,"); - if (settings.logTime) - strcat(helperText, "rtcTime,"); - if (settings.logMicroseconds) - strcat(helperText, "micros,"); - } - } //end if use RTC for timestamp - else //Use GPS for timestamp - { + if (settings.logDate) + strcat(helperText, "rtcDate,"); + if (settings.logTime) + strcat(helperText, "rtcTime,"); + if (settings.logMicroseconds) + strcat(helperText, "micros,"); } if (settings.logA11) @@ -962,7 +996,7 @@ void printHelperText(bool terminalOnly) if (nodeSetting->logPressure) strcat(helperText, "pressure_hPa,"); if (nodeSetting->logTemperature) - strcat(helperText, "pressure_degC,"); + strcat(helperText, "temperature_degC,"); } } break; @@ -1172,8 +1206,46 @@ void printHelperText(bool terminalOnly) } } break; + case DEVICE_VOC_SGP40: + { + struct_SGP40 *nodeSetting = (struct_SGP40 *)temp->configPtr; + if (nodeSetting->log) + { + if (nodeSetting->logVOC) + strcat(helperText, "VOCindex,"); + } + } + break; + case DEVICE_PRESSURE_SDP3X: + { + struct_SDP3X *nodeSetting = (struct_SDP3X *)temp->configPtr; + if (nodeSetting->log) + { + if (nodeSetting->logPressure) + strcat(helperText, "Pa,"); + if (nodeSetting->logTemperature) + strcat(helperText, "degC,"); + } + } + break; + case DEVICE_PRESSURE_MS5837: + { + struct_MS5837 *nodeSetting = (struct_MS5837 *)temp->configPtr; + if (nodeSetting->log) + { + if (nodeSetting->logPressure) + strcat(helperText, "mbar,"); + if (nodeSetting->logTemperature) + strcat(helperText, "degC,"); + if (nodeSetting->logDepth) + strcat(helperText, "depth_m,"); + if (nodeSetting->logAltitude) + strcat(helperText, "alt_m,"); + } + } + break; default: - Serial.printf("\nprinterHelperText device not found: %d\r\n", temp->deviceType); + SerialPrintf2("\nprinterHelperText device not found: %d\r\n", temp->deviceType); break; } } @@ -1188,7 +1260,7 @@ void printHelperText(bool terminalOnly) strcat(helperText, "\r\n"); - Serial.print(helperText); + SerialPrint(helperText); if ((terminalOnly == false) && (settings.logData == true) && (online.microSD) && (settings.enableSD && online.microSD)) sensorDataFile.print(helperText); } diff --git a/Firmware/OpenLog_Artemis/autoDetect.ino b/Firmware/OpenLog_Artemis/autoDetect.ino index ea7a6c0..a7aeeda 100644 --- a/Firmware/OpenLog_Artemis/autoDetect.ino +++ b/Firmware/OpenLog_Artemis/autoDetect.ino @@ -137,7 +137,7 @@ bool addDevice(deviceType_e deviceType, uint8_t address, uint8_t muxAddress, uin break; case DEVICE_GPS_UBLOX: { - temp->classPtr = new SFE_UBLOX_GPS; + temp->classPtr = new SFE_UBLOX_GNSS; temp->configPtr = new struct_uBlox; } break; @@ -237,8 +237,26 @@ bool addDevice(deviceType_e deviceType, uint8_t address, uint8_t muxAddress, uin temp->configPtr = new struct_SNGCJA5; } break; + case DEVICE_VOC_SGP40: + { + temp->classPtr = new SGP40; + temp->configPtr = new struct_SGP40; + } + break; + case DEVICE_PRESSURE_SDP3X: + { + temp->classPtr = new SDP3X; + temp->configPtr = new struct_SDP3X; + } + break; + case DEVICE_PRESSURE_MS5837: + { + temp->classPtr = new MS5837; + temp->configPtr = new struct_MS5837; + } + break; default: - Serial.printf("addDevice Device type not found: %d\r\n", deviceType); + SerialPrintf2("addDevice Device type not found: %d\r\n", deviceType); break; } @@ -268,6 +286,8 @@ bool beginQwiicDevices() qwiicPowerOnDelayMillis = settings.qwiicBusPowerUpDelayMs; // Set qwiicPowerOnDelayMillis to the _minimum_ defined by settings.qwiicBusPowerUpDelayMs. It will be increased if required. + int numberOfSCD30s = 0; // Keep track of how many SCD30s we begin so we can delay before starting the second and subsequent ones + //Step through the list node *temp = head; @@ -283,8 +303,8 @@ bool beginQwiicDevices() if (settings.printDebugMessages == true) { - Serial.printf("beginQwiicDevices: attempting to begin deviceType %s", getDeviceName(temp->deviceType)); - Serial.printf(" at address 0x%02X using mux address 0x%02X and port number %d\r\n", temp->address, temp->muxAddress, temp->portNumber); + SerialPrintf2("beginQwiicDevices: attempting to begin deviceType %s", getDeviceName(temp->deviceType)); + SerialPrintf4(" at address 0x%02X using mux address 0x%02X and port number %d\r\n", temp->address, temp->muxAddress, temp->portNumber); } //Attempt to begin the device @@ -318,7 +338,7 @@ bool beginQwiicDevices() case DEVICE_GPS_UBLOX: { qwiic.setPullups(0); //Disable pullups for u-blox comms. - SFE_UBLOX_GPS *tempDevice = (SFE_UBLOX_GPS *)temp->classPtr; + SFE_UBLOX_GNSS *tempDevice = (SFE_UBLOX_GNSS *)temp->classPtr; struct_uBlox *nodeSetting = (struct_uBlox *)temp->configPtr; //Create a local pointer that points to same spot as node does if (nodeSetting->powerOnDelayMillis > qwiicPowerOnDelayMillis) qwiicPowerOnDelayMillis = nodeSetting->powerOnDelayMillis; // Increase qwiicPowerOnDelayMillis if required temp->online = tempDevice->begin(qwiic, temp->address); //Wire port, Address @@ -395,6 +415,14 @@ bool beginQwiicDevices() SCD30 *tempDevice = (SCD30 *)temp->classPtr; struct_SCD30 *nodeSetting = (struct_SCD30 *)temp->configPtr; //Create a local pointer that points to same spot as node does if (nodeSetting->powerOnDelayMillis > qwiicPowerOnDelayMillis) qwiicPowerOnDelayMillis = nodeSetting->powerOnDelayMillis; // Increase qwiicPowerOnDelayMillis if required + numberOfSCD30s++; // Keep track of how many SCD30s we begin + // Delay before starting the second and subsequent SCD30s to try and stagger the measurements and the peak current draw + if (numberOfSCD30s >= 2) + { + printDebug(F("beginQwiicDevices: found more than one SCD30. Delaying for 375ms to stagger the peak current draw...\r\n")); + delay(375); + } + if(settings.printDebugMessages == true) tempDevice->enableDebugging(); // Enable debug messages if required temp->online = tempDevice->begin(qwiic); //Wire port } break; @@ -459,18 +487,45 @@ bool beginQwiicDevices() temp->online = true; } break; + case DEVICE_VOC_SGP40: + { + SGP40 *tempDevice = (SGP40 *)temp->classPtr; + struct_SGP40 *nodeSetting = (struct_SGP40 *)temp->configPtr; //Create a local pointer that points to same spot as node does + if (nodeSetting->powerOnDelayMillis > qwiicPowerOnDelayMillis) qwiicPowerOnDelayMillis = nodeSetting->powerOnDelayMillis; // Increase qwiicPowerOnDelayMillis if required + if (tempDevice->begin(qwiic) == true) //Wire port. Returns true on success. + temp->online = true; + } + break; + case DEVICE_PRESSURE_SDP3X: + { + SDP3X *tempDevice = (SDP3X *)temp->classPtr; + struct_SDP3X *nodeSetting = (struct_SDP3X *)temp->configPtr; //Create a local pointer that points to same spot as node does + if (nodeSetting->powerOnDelayMillis > qwiicPowerOnDelayMillis) qwiicPowerOnDelayMillis = nodeSetting->powerOnDelayMillis; // Increase qwiicPowerOnDelayMillis if required + if (tempDevice->begin(temp->address, qwiic) == true) //Address, Wire port. Returns true on success. + temp->online = true; + } + break; + case DEVICE_PRESSURE_MS5837: + { + MS5837 *tempDevice = (MS5837 *)temp->classPtr; + struct_MS5837 *nodeSetting = (struct_MS5837 *)temp->configPtr; //Create a local pointer that points to same spot as node does + if (nodeSetting->powerOnDelayMillis > qwiicPowerOnDelayMillis) qwiicPowerOnDelayMillis = nodeSetting->powerOnDelayMillis; // Increase qwiicPowerOnDelayMillis if required + if (tempDevice->begin(qwiic) == true) //Wire port. Returns true on success. + temp->online = true; + } + break; default: - Serial.printf("beginQwiicDevices: device type not found: %d\r\n", temp->deviceType); + SerialPrintf2("beginQwiicDevices: device type not found: %d\r\n", temp->deviceType); break; } if (temp->online == true) { - printDebug("beginQwiicDevices: device is online\r\n"); + printDebug(F("beginQwiicDevices: device is online\r\n")); } else { - printDebug("beginQwiicDevices: device is **NOT** online\r\n"); + printDebug(F("beginQwiicDevices: device is **NOT** online\r\n")); everythingStarted = false; } @@ -481,7 +536,7 @@ bool beginQwiicDevices() } //Pretty print all the online devices -void printOnlineDevice() +int printOnlineDevice() { int deviceCount = 0; @@ -491,7 +546,7 @@ void printOnlineDevice() if (temp == NULL) { printDebug(F("printOnlineDevice: No devices detected\r\n")); - return; + return (0); } while (temp != NULL) @@ -510,13 +565,17 @@ void printOnlineDevice() { sprintf(sensorOnlineText, "%s failed to respond\r\n", getDeviceName(temp->deviceType)); } - Serial.print(sensorOnlineText); + SerialPrint(sensorOnlineText); temp = temp->next; } if (settings.printDebugMessages == true) - Serial.printf("Device count: %d\r\n", deviceCount); + { + SerialPrintf2("Device count: %d\r\n", deviceCount); + } + + return (deviceCount); } //Given the node number, apply the node's configuration settings to the device @@ -569,7 +628,7 @@ void configureDevice(node * temp) { qwiic.setPullups(0); //Disable pullups for u-blox comms. - SFE_UBLOX_GPS *sensor = (SFE_UBLOX_GPS *)temp->classPtr; + SFE_UBLOX_GNSS *sensor = (SFE_UBLOX_GNSS *)temp->classPtr; struct_uBlox *nodeSetting = (struct_uBlox *)temp->configPtr; sensor->setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) @@ -705,8 +764,24 @@ void configureDevice(node * temp) case DEVICE_PARTICLE_SNGCJA5: //Nothing to configure break; + case DEVICE_VOC_SGP40: + //Nothing to configure + break; + case DEVICE_PRESSURE_SDP3X: + //Nothing to configure + break; + case DEVICE_PRESSURE_MS5837: + { + MS5837 *sensor = (MS5837 *)temp->classPtr; + struct_MS5837 *sensorSetting = (struct_MS5837 *)temp->configPtr; + + //sensor->setModel(sensorSetting->model); + sensorSetting->model = sensor->getModel(); + sensor->setFluidDensity(sensorSetting->fluidDensity); + } + break; default: - Serial.printf("configureDevice: Unknown device type %d: %s\r\n", deviceType, getDeviceName((deviceType_e)deviceType)); + SerialPrintf3("configureDevice: Unknown device type %d: %s\r\n", deviceType, getDeviceName((deviceType_e)deviceType)); break; } } @@ -795,9 +870,18 @@ FunctionPointer getConfigFunctionPtr(uint8_t nodeNumber) case DEVICE_PARTICLE_SNGCJA5: ptr = (FunctionPointer)menuConfigure_SNGCJA5; break; + case DEVICE_VOC_SGP40: + ptr = (FunctionPointer)menuConfigure_SGP40; + break; + case DEVICE_PRESSURE_SDP3X: + ptr = (FunctionPointer)menuConfigure_SDP3X; + break; + case DEVICE_PRESSURE_MS5837: + ptr = (FunctionPointer)menuConfigure_MS5837; + break; default: - Serial.println(F("getConfigFunctionPtr: Unknown device type")); - Serial.flush(); + SerialPrintln(F("getConfigFunctionPtr: Unknown device type")); + SerialFlush(); break; } @@ -840,7 +924,7 @@ bool openConnection(uint8_t muxAddress, uint8_t portNumber) { if (head == NULL) { - Serial.println(F("OpenConnection Error: No devices in list")); + SerialPrintln(F("OpenConnection Error: No devices in list")); return false; } @@ -924,6 +1008,7 @@ void swap(struct node * a, struct node * b) //We no longer use defines in the search table. These are just here for reference. #define ADR_VEML6075 0x10 #define ADR_MPR0025PA1 0x18 +#define ADR_SDP3X 0x21 //Alternates: 0x22, 0x23 #define ADR_NAU7802 0x2A #define ADR_VL53L1X 0x29 #define ADR_SNGCJA5 0x33 @@ -933,6 +1018,7 @@ void swap(struct node * a, struct node * b) #define ADR_ADS122C04 0x45 //Alternates: 0x44, 0x41 and 0x40 #define ADR_TMP117 0x48 //Alternates: 0x49, 0x4A, and 0x4B #define ADR_SGP30 0x58 +#define ADR_SGP40 0x59 #define ADR_CCS811 0x5B //Alternates: 0x5A #define ADR_LPS25HB 0x5D //Alternates: 0x5C #define ADR_VCNL4040 0x60 @@ -941,6 +1027,7 @@ void swap(struct node * a, struct node * b) #define ADR_MULTIPLEXER 0x70 //0x70 to 0x77 #define ADR_SHTC3 0x70 #define ADR_MS5637 0x76 +#define ADR_MS5837 0x76 //#define ADR_MS8607 0x76 //Pressure portion of the MS8607 sensor. We'll catch the 0x40 first #define ADR_BME280 0x77 //Alternates: 0x76 @@ -967,6 +1054,30 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb return (DEVICE_PRESSURE_MPR0025PA1); } break; + case 0x21: + { + //Confidence: Medium - .begin reads the product ID + SDP3X sensor; + if (sensor.begin(i2cAddress, qwiic) == true) //Address, Wire port + return (DEVICE_PRESSURE_SDP3X); + } + break; + case 0x22: + { + //Confidence: Medium - .begin reads the product ID + SDP3X sensor; + if (sensor.begin(i2cAddress, qwiic) == true) //Address, Wire port + return (DEVICE_PRESSURE_SDP3X); + } + break; + case 0x23: + { + //Confidence: Medium - .begin reads the product ID + SDP3X sensor; + if (sensor.begin(i2cAddress, qwiic) == true) //Address, Wire port + return (DEVICE_PRESSURE_SDP3X); + } + break; case 0x2A: { //Confidence: High - Checks 8 bit revision code (0x0F) @@ -1026,7 +1137,7 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb { //Confidence: High - Sends/receives CRC checked data response qwiic.setPullups(0); //Disable pullups to minimize CRC issues - SFE_UBLOX_GPS sensor; + SFE_UBLOX_GNSS sensor; if(settings.printDebugMessages == true) sensor.enableDebugging(); // Enable debug messages if required if (sensor.begin(qwiic, i2cAddress) == true) //Wire port, address { @@ -1084,6 +1195,13 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb return (DEVICE_VOC_SGP30); } break; + case 0x59: + { + SGP40 sensor; + if (sensor.begin(qwiic) == true) //Wire port + return (DEVICE_VOC_SGP40); + } + break; case 0x5A: case 0x5B: { @@ -1122,11 +1240,12 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb if (sensor.begin(i2cAddress, qwiic) == true) //Address, Wire port return (DEVICE_TEMPERATURE_MCP9600); - //Confidence: Medium - Begin doesn't confirm anything, but a readMeasurement() must pass CRC check + //Confidence: High - begin now checks FW Ver CRC SCD30 sensor1; - if (sensor1.begin(qwiic) == true) //Wire port - if (sensor1.readMeasurement() == true) //This reads the measurement register and calculates a CRC on the interchange - return (DEVICE_CO2_SCD30); + if(settings.printDebugMessages == true) sensor1.enableDebugging(); // Enable debug messages if required + // Set measBegin to false. beginQwiicDevices will call begin with measBegin set true. + if (sensor1.begin(qwiic, true, false) == true) //Wire port, autoCalibrate, measBegin + return (DEVICE_CO2_SCD30); } break; case 0x62: @@ -1229,7 +1348,12 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb //Ignore devices we've already recorded. This was causing the mux to get tested, a begin() would happen, and the mux would be reset. if (deviceExists(DEVICE_MULTIPLEXER, i2cAddress, muxAddress, portNumber) == true) return (DEVICE_MULTIPLEXER); - //Confidence: High - does CRC on internal EEPROM read + //Confidence: High - does CRC on internal EEPROM read and checks sensor version + MS5837 sensor2; + if (sensor2.begin(qwiic) == true) //Wire port + return (DEVICE_PRESSURE_MS5837); + + //Confidence: High - does CRC on internal EEPROM read - but do this second as a MS5837 will appear as a MS5637 MS5637 sensor; if (sensor.begin(qwiic) == true) //Wire port return (DEVICE_PRESSURE_MS5637); @@ -1260,14 +1384,18 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb default: { if (muxAddress == 0) - Serial.printf("Unknown device at address (0x%02X)\r\n", i2cAddress); + { + SerialPrintf2("Unknown device at address (0x%02X)\r\n", i2cAddress); + } else - Serial.printf("Unknown device at address (0x%02X)(Mux:0x%02X Port:%d)\r\n", i2cAddress, muxAddress, portNumber); + { + SerialPrintf4("Unknown device at address (0x%02X)(Mux:0x%02X Port:%d)\r\n", i2cAddress, muxAddress, portNumber); + } return DEVICE_UNKNOWN_DEVICE; } break; } - Serial.printf("Known I2C address but device failed identification at address 0x%02X\r\n", i2cAddress); + SerialPrintf2("Known I2C address but device failed identification at address 0x%02X\r\n", i2cAddress); return DEVICE_UNKNOWN_DEVICE; } @@ -1344,9 +1472,13 @@ deviceType_e testMuxDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portN default: { if (muxAddress == 0) - Serial.printf("Unknown device at address (0x%02X)\r\n", i2cAddress); + { + SerialPrintf2("Unknown device at address (0x%02X)\r\n", i2cAddress); + } else - Serial.printf("Unknown device at address (0x%02X)(Mux:0x%02X Port:%d)\r\n", i2cAddress, muxAddress, portNumber); + { + SerialPrintf4("Unknown device at address (0x%02X)(Mux:0x%02X Port:%d)\r\n", i2cAddress, muxAddress, portNumber); + } return DEVICE_UNKNOWN_DEVICE; } break; @@ -1470,6 +1602,15 @@ const char* getDeviceName(deviceType_e deviceNumber) case DEVICE_PARTICLE_SNGCJA5: return "Particle-SNGCJA5"; break; + case DEVICE_VOC_SGP40: + return "VOC-SGP40"; + break; + case DEVICE_PRESSURE_SDP3X: + return "Pressure-SDP3X"; + break; + case DEVICE_PRESSURE_MS5837: + return "Pressure-MS5837"; + break; case DEVICE_UNKNOWN_DEVICE: return "Unknown device"; diff --git a/Firmware/OpenLog_Artemis/logging.ino b/Firmware/OpenLog_Artemis/logging.ino index 10e0169..1135815 100644 --- a/Firmware/OpenLog_Artemis/logging.ino +++ b/Firmware/OpenLog_Artemis/logging.ino @@ -1,7 +1,7 @@ //Print a message both to terminal and to log void msg(const char * message) { - Serial.println(message); + SerialPrintln(message); if (online.microSD) sensorDataFile.println(message); } @@ -15,8 +15,8 @@ char* findNextAvailableLog(int &newFileNumber, const char *fileLeader) if (newFileNumber < 2) //If the settings have been reset, let's warn the user that this could take a while! { - Serial.println(F("Finding the next available log file.")); - Serial.println(F("This could take a long time if the SD card contains many existing log files.")); + SerialPrintln(F("Finding the next available log file.")); + SerialPrintln(F("This could take a long time if the SD card contains many existing log files.")); } if (newFileNumber > 0) @@ -46,15 +46,15 @@ char* findNextAvailableLog(int &newFileNumber, const char *fileLeader) if (newFileNumber >= 100000) // Have we hit the maximum number of files? { - Serial.print(F("***** WARNING! File number limit reached! (Overwriting ")); - Serial.print(newFileName); - Serial.println(F(") *****")); + SerialPrint(F("***** WARNING! File number limit reached! (Overwriting ")); + SerialPrint(newFileName); + SerialPrintln(F(") *****")); newFileNumber = 100000; // This will overwrite Log99999.TXT next time thanks to the newFileNumber-- above } else { - Serial.print(F("Logging to: ")); - Serial.println(newFileName); + SerialPrint(F("Logging to: ")); + SerialPrintln(newFileName); } //Record new file number to EEPROM and to config file diff --git a/Firmware/OpenLog_Artemis/lowerPower.ino b/Firmware/OpenLog_Artemis/lowerPower.ino index ad6fdd3..820561a 100644 --- a/Firmware/OpenLog_Artemis/lowerPower.ino +++ b/Firmware/OpenLog_Artemis/lowerPower.ino @@ -30,10 +30,10 @@ void checkBattery(void) delay(sdPowerDownDelay); // Give the SD card time to finish writing ***** THIS IS CRITICAL ***** - Serial.println(F("*** LOW BATTERY VOLTAGE DETECTED! GOING INTO POWERDOWN ***")); - Serial.println(F("*** PLEASE CHANGE THE POWER SOURCE AND RESET THE OLA TO CONTINUE ***")); + SerialPrintln(F("*** LOW BATTERY VOLTAGE DETECTED! GOING INTO POWERDOWN ***")); + SerialPrintln(F("*** PLEASE CHANGE THE POWER SOURCE AND RESET THE OLA TO CONTINUE ***")); - Serial.flush(); //Finish any prints + SerialFlush(); //Finish any prints powerDown(); // power down and wait for reset } @@ -82,7 +82,7 @@ void powerDown() // serialDataFile.close(); // } - //Serial.flush(); //Don't waste time waiting for prints to finish + //SerialFlush(); //Don't waste time waiting for prints to finish // Wire.end(); //Power down I2C qwiic.end(); //Power down I2C @@ -153,26 +153,80 @@ void powerDown() } } -//Power everything down and wait for interrupt wakeup -void goToSleep() +//Reset the Artemis +void resetArtemis(void) { - //Counter/Timer 6 will use the 32kHz clock - //Calculate how many 32768Hz system ticks we need to sleep for: - //sysTicksToSleep = msToSleep * 32768L / 1000 - //We need to be careful with the multiply as we will overflow uint32_t if msToSleep is > 131072 - uint32_t msToSleep = (uint32_t)(settings.usBetweenReadings / 1000ULL); - uint32_t sysTicksToSleep; - if (msToSleep < 131000) + //Save files before resetting + if (online.dataLogging == true) { - sysTicksToSleep = msToSleep * 32768L; // Do the multiply first for short intervals - sysTicksToSleep = sysTicksToSleep / 1000L; // Now do the divide + sensorDataFile.sync(); + updateDataFileAccess(&sensorDataFile); // Update the file access time & date + sensorDataFile.close(); //No need to close files. https://forum.arduino.cc/index.php?topic=149504.msg1125098#msg1125098 } - else + if (online.serialLogging == true) { - sysTicksToSleep = msToSleep / 1000L; // Do the division first for long intervals (to avoid an overflow) - sysTicksToSleep = sysTicksToSleep * 32768L; // Now do the multiply + serialDataFile.sync(); + updateDataFileAccess(&serialDataFile); // Update the file access time & date + serialDataFile.close(); + } + + delay(sdPowerDownDelay); // Give the SD card time to finish writing ***** THIS IS CRITICAL ***** + + SerialFlush(); //Finish any prints + + // Wire.end(); //Power down I2C + qwiic.end(); //Power down I2C + + SPI.end(); //Power down SPI + + power_adc_disable(); //Power down ADC. It it started by default before setup(). + + Serial.end(); //Power down UART + SerialLog.end(); + + //Force the peripherals off + am_hal_pwrctrl_periph_disable(AM_HAL_PWRCTRL_PERIPH_IOM0); + am_hal_pwrctrl_periph_disable(AM_HAL_PWRCTRL_PERIPH_IOM1); + am_hal_pwrctrl_periph_disable(AM_HAL_PWRCTRL_PERIPH_IOM2); + am_hal_pwrctrl_periph_disable(AM_HAL_PWRCTRL_PERIPH_IOM3); + am_hal_pwrctrl_periph_disable(AM_HAL_PWRCTRL_PERIPH_IOM4); + am_hal_pwrctrl_periph_disable(AM_HAL_PWRCTRL_PERIPH_IOM5); + am_hal_pwrctrl_periph_disable(AM_HAL_PWRCTRL_PERIPH_ADC); + am_hal_pwrctrl_periph_disable(AM_HAL_PWRCTRL_PERIPH_UART0); + am_hal_pwrctrl_periph_disable(AM_HAL_PWRCTRL_PERIPH_UART1); + + //Disable pads + for (int x = 0; x < 50; x++) + { + if ((x != ap3_gpio_pin2pad(PIN_POWER_LOSS)) && + //(x != ap3_gpio_pin2pad(PIN_LOGIC_DEBUG)) && + (x != ap3_gpio_pin2pad(PIN_MICROSD_POWER)) && + (x != ap3_gpio_pin2pad(PIN_QWIIC_POWER)) && + (x != ap3_gpio_pin2pad(PIN_IMU_POWER))) + { + am_hal_gpio_pinconfig(x, g_AM_HAL_GPIO_DISABLE); + } } + //We can't leave these power control pins floating + imuPowerOff(); + microSDPowerOff(); + + //Disable power for the Qwiic bus + qwiicPowerOff(); + + //Disable the power LED + powerLEDOff(); + + //Enable the Watchdog so it can reset the Artemis + startWatchdog(); + while (1) // That's all folks! Artemis will reset in 1.25 seconds + ; +} + +//Power everything down and wait for interrupt wakeup +void goToSleep(uint32_t sysTicksToSleep) +{ //printDebug("goToSleep: sysTicksToSleep = " + (String)sysTicksToSleep + "\r\n"); //printDebug("goToSleep: online.IMU = " + (String)online.IMU + "\r\n"); @@ -211,7 +265,7 @@ void goToSleep() delay(sdPowerDownDelay); // Give the SD card time to finish writing ***** THIS IS CRITICAL ***** - Serial.flush(); //Finish any prints + SerialFlush(); //Finish any prints // Wire.end(); //Power down I2C qwiic.end(); //Power down I2C @@ -360,6 +414,11 @@ void wakeFromSleep() triggerEdgeSeen = false; // Make sure the flag is clear } + if (settings.useGPIO11ForFastSlowLogging == true) + { + pinMode(PIN_TRIGGER, INPUT_PULLUP); + } + pinMode(PIN_STAT_LED, OUTPUT); digitalWrite(PIN_STAT_LED, LOW); @@ -367,11 +426,16 @@ void wakeFromSleep() Serial.begin(settings.serialTerminalBaudRate); - printDebug("wakeFromSleep: I'm awake!\r\n"); + if (settings.useTxRxPinsForTerminal == true) + { + SerialLog.begin(settings.serialTerminalBaudRate); // Start the serial port + } + + printDebug(F("wakeFromSleep: I'm awake!\r\n")); printDebug("wakeFromSleep: adcError is " + (String)adcError + "."); if (adcError > 0) - printDebug(" This indicates an error was returned by ap3_adc_setup or one of the calls to ap3_set_pin_to_analog."); - printDebug("\r\n"); + printDebug(F(" This indicates an error was returned by ap3_adc_setup or one of the calls to ap3_set_pin_to_analog.")); + printDebug(F("\r\n")); beginQwiic(); //Power up Qwiic bus as early as possible @@ -383,7 +447,10 @@ void wakeFromSleep() beginDataLogging(); //180ms - beginSerialLogging(); //20 - 99ms + if (settings.useTxRxPinsForTerminal == false) + { + beginSerialLogging(); //20 - 99ms + } beginIMU(); //61ms //printDebug("wakeFromSleep: online.IMU = " + (String)online.IMU + "\r\n"); @@ -396,7 +463,7 @@ void wakeFromSleep() configureQwiicDevices(); //Apply config settings to each device in the node list } - //Serial.printf("Wake up time: %.02f ms\r\n", (micros() - startTime) / 1000.0); + //SerialPrintf2("Wake up time: %.02f ms\r\n", (micros() - startTime) / 1000.0); //When we wake up micros has been reset to zero so we need to let the main loop know to take a reading takeReading = true; @@ -420,9 +487,11 @@ void stopLogging(void) serialDataFile.close(); } - Serial.print(F("Logging is stopped. Please reset OpenLog Artemis and open a terminal at ")); + SerialPrint(F("Logging is stopped. Please reset OpenLog Artemis and open a terminal at ")); Serial.print((String)settings.serialTerminalBaudRate); - Serial.println(F("bps...")); + if (settings.useTxRxPinsForTerminal == true) + SerialLog.print((String)settings.serialTerminalBaudRate); + SerialPrintln(F("bps...")); delay(sdPowerDownDelay); // Give the SD card time to shut down powerDown(); } @@ -562,3 +631,46 @@ int calculateDayOfYear(int day, int month, int year) doy += day; return doy; } + +//WatchDog Timer code by Adam Garbo: +//https://forum.sparkfun.com/viewtopic.php?f=169&t=52431&p=213296#p213296 + +// Watchdog timer configuration structure. +am_hal_wdt_config_t g_sWatchdogConfig = { + + // Configuration values for generated watchdog timer event. + .ui32Config = AM_HAL_WDT_LFRC_CLK_16HZ | AM_HAL_WDT_ENABLE_RESET | AM_HAL_WDT_ENABLE_INTERRUPT, + + // Number of watchdog timer ticks allowed before a watchdog interrupt event is generated. + .ui16InterruptCount = 16, // Set WDT interrupt timeout for 1 second. + + // Number of watchdog timer ticks allowed before the watchdog will issue a system reset. + .ui16ResetCount = 20 // Set WDT reset timeout for 1.25 seconds. +}; + +void startWatchdog() +{ + // LFRC must be turned on for this example as the watchdog only runs off of the LFRC. + am_hal_clkgen_control(AM_HAL_CLKGEN_CONTROL_LFRC_START, 0); + + // Configure the watchdog. + am_hal_wdt_init(&g_sWatchdogConfig); + + // Enable the interrupt for the watchdog in the NVIC. + NVIC_EnableIRQ(WDT_IRQn); + //NVIC_SetPriority(WDT_IRQn, 0); // Set the interrupt priority to 0 = highest (255 = lowest) + //am_hal_interrupt_master_enable(); // ap3_initialization.cpp does this - no need to do it here + + // Enable the watchdog. + am_hal_wdt_start(); +} + +// Interrupt handler for the watchdog. +extern "C++" void am_watchdog_isr(void) +{ + // Clear the watchdog interrupt. + am_hal_wdt_int_clear(); + + // DON'T Restart the watchdog. + //am_hal_wdt_restart(); // "Pet" the dog. +} diff --git a/Firmware/OpenLog_Artemis/menuAnalogLogging.ino b/Firmware/OpenLog_Artemis/menuAnalogLogging.ino index f50b2ae..f8298f8 100644 --- a/Firmware/OpenLog_Artemis/menuAnalogLogging.ino +++ b/Firmware/OpenLog_Artemis/menuAnalogLogging.ino @@ -3,37 +3,39 @@ void menuAnalogLogging() while (1) { #if(HARDWARE_VERSION_MAJOR == 0) - Serial.println(); - Serial.println(F("Note: VIN logging is only supported on V10+ hardware. X04 will show 0.0V.")); + SerialPrintln(F("")); + SerialPrintln(F("Note: VIN logging is only supported on V10+ hardware. X04 will show 0.0V.")); #endif - Serial.println(); - Serial.println(F("Menu: Configure Analog Logging")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure Analog Logging")); - Serial.print(F("1) Log analog pin 11 (2V Max): ")); - if (settings.logA11 == true) Serial.println(F("Enabled. (Triggering is disabled)")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Log analog pin 11 (2V Max): ")); + if (settings.logA11 == true) SerialPrintln(F("Enabled. (Triggering is disabled)")); + else SerialPrintln(F("Disabled")); - Serial.print(F("2) Log analog pin 12 (TX) (2V Max): ")); - if (settings.logA12 == true) Serial.println(F("Enabled. (Serial output is disabled)")); - else Serial.println(F("Disabled")); + SerialPrint(F("2) Log analog pin 12 (TX) (2V Max): ")); + if (settings.useTxRxPinsForTerminal == true) SerialPrintln(F("Disabled. (TX and RX pins are being used for the Terminal)")); + else if (settings.logA12 == true) SerialPrintln(F("Enabled. (Serial output is disabled)")); + else SerialPrintln(F("Disabled")); - Serial.print(F("3) Log analog pin 13 (RX) (2V Max): ")); - if (settings.logA13 == true) Serial.println(F("Enabled. (Serial logging is disabled)")); - else Serial.println(F("Disabled")); + SerialPrint(F("3) Log analog pin 13 (RX) (2V Max): ")); + if (settings.useTxRxPinsForTerminal == true) SerialPrintln(F("Disabled. (TX and RX pins are being used for the Terminal)")); + else if (settings.logA13 == true) SerialPrintln(F("Enabled. (Serial logging is disabled)")); + else SerialPrintln(F("Disabled")); - Serial.print(F("4) Log analog pin 32 (2V Max): ")); - if (settings.logA32 == true) Serial.println(F("Enabled. (Stop logging is disabled)")); - else Serial.println(F("Disabled")); + SerialPrint(F("4) Log analog pin 32 (2V Max): ")); + if (settings.logA32 == true) SerialPrintln(F("Enabled. (Stop logging is disabled)")); + else SerialPrintln(F("Disabled")); - Serial.print(F("5) Log output type: ")); - if (settings.logAnalogVoltages == true) Serial.println(F("Calculated Voltage")); - else Serial.println(F("Raw ADC reading")); + SerialPrint(F("5) Log output type: ")); + if (settings.logAnalogVoltages == true) SerialPrintln(F("Calculated Voltage")); + else SerialPrintln(F("Raw ADC reading")); - Serial.print(F("6) Log VIN (battery) voltage (6V Max): ")); - if (settings.logVIN == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("6) Log VIN (battery) voltage (6V Max): ")); + if (settings.logVIN == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds @@ -55,9 +57,18 @@ void menuAnalogLogging() { if(settings.logA12 == false) { - online.serialOutput = false; // Disable serial output - settings.outputSerial = false; - settings.logA12 = true; + if (settings.useTxRxPinsForTerminal == true) + { + SerialPrintln(F("")); + SerialPrintln(F("Analog logging on pin 12 is not possible. TX and RX pins are being used for the Terminal.")); + SerialPrintln(F("")); + } + else + { + online.serialOutput = false; // Disable serial output + settings.outputSerial = false; + settings.logA12 = true; + } } else settings.logA12 = false; @@ -66,9 +77,18 @@ void menuAnalogLogging() { if(settings.logA13 == false) { - online.serialLogging = false; //Disable serial logging - settings.logSerial = false; - settings.logA13 = true; + if (settings.useTxRxPinsForTerminal == true) + { + SerialPrintln(F("")); + SerialPrintln(F("Analog logging on pin 13 is not possible. TX and RX pins are being used for the Terminal.")); + SerialPrintln(F("")); + } + else + { + online.serialLogging = false; //Disable serial logging + settings.logSerial = false; + settings.logA13 = true; + } } else settings.logA13 = false; diff --git a/Firmware/OpenLog_Artemis/menuAttachedDevices.ino b/Firmware/OpenLog_Artemis/menuAttachedDevices.ino index 53f3fa5..8ad45d6 100644 --- a/Firmware/OpenLog_Artemis/menuAttachedDevices.ino +++ b/Firmware/OpenLog_Artemis/menuAttachedDevices.ino @@ -30,7 +30,7 @@ //Returns true if devices detected > 0 bool detectQwiicDevices() { - printDebug("detectQwiicDevices started\r\n"); + printDebug(F("detectQwiicDevices started\r\n")); bool somethingDetected = false; qwiic.setClock(100000); //During detection, go slow @@ -47,7 +47,7 @@ bool detectQwiicDevices() // lock up the I2C bus if you don't discover it and then begin it in one go... // The following code has been restructured to try and keep the MCP9600 happy. - Serial.println(F("Identifying Qwiic Muxes...")); + SerialPrintln(F("Identifying Qwiic Muxes...")); //First scan for Muxes. Valid addresses are 0x70 to 0x77 (112 to 119). //If any are found, they will be begin()'d causing their ports to turn off @@ -65,19 +65,25 @@ bool detectQwiicDevices() //} somethingDetected = true; if (settings.printDebugMessages == true) - Serial.printf("detectQwiicDevices: something detected at address 0x%02X\r\n", address); + { + SerialPrintf2("detectQwiicDevices: something detected at address 0x%02X\r\n", address); + } deviceType_e foundType = testMuxDevice(address, 0, 0); //No mux or port numbers for this test if (foundType == DEVICE_MULTIPLEXER) { addDevice(foundType, address, 0, 0); //Add this device to our map if (settings.printDebugMessages == true) - Serial.printf("detectQwiicDevices: multiplexer found at address 0x%02X\r\n", address); + { + SerialPrintf2("detectQwiicDevices: multiplexer found at address 0x%02X\r\n", address); + } muxCount++; } else if (foundType == DEVICE_PRESSURE_MS5637) { if (settings.printDebugMessages == true) - Serial.printf("detectQwiicDevices: MS8607/MS5637 found at address 0x%02X. Ignoring it for now...\r\n", address); + { + SerialPrintf2("detectQwiicDevices: MS8607/MS5637 found at address 0x%02X. Ignoring it for now...\r\n", address); + } } } } @@ -86,17 +92,17 @@ bool detectQwiicDevices() { if (settings.printDebugMessages == true) { - Serial.printf("detectQwiicDevices: found %d", muxCount); + SerialPrintf2("detectQwiicDevices: found %d", muxCount); if (muxCount == 1) - Serial.println(F(" multiplexer")); + SerialPrintln(F(" multiplexer")); else - Serial.println(F(" multiplexers")); + SerialPrintln(F(" multiplexers")); } beginQwiicDevices(); //begin() the muxes to disable their ports } //Before going into mux sub branches, scan the main branch for all remaining devices - Serial.println(F("Identifying Qwiic Devices...")); + SerialPrintln(F("Identifying Qwiic Devices...")); bool foundMS8607 = false; // The MS8607 appears as two devices (MS8607 and MS5637). We need to skip the MS5637 if we have found a MS8607. for (uint8_t address = 1 ; address < 127 ; address++) { @@ -105,7 +111,9 @@ bool detectQwiicDevices() { somethingDetected = true; if (settings.printDebugMessages == true) - Serial.printf("detectQwiicDevices: something detected at address 0x%02X\r\n", address); + { + SerialPrintf2("detectQwiicDevices: something detected at address 0x%02X\r\n", address); + } deviceType_e foundType = testDevice(address, 0, 0); //No mux or port numbers for this test if (foundType != DEVICE_UNKNOWN_DEVICE) { @@ -118,7 +126,9 @@ bool detectQwiicDevices() if (addDevice(foundType, address, 0, 0) == true) //Records this device. //Returns false if mux/device was already recorded. { if (settings.printDebugMessages == true) - Serial.printf("detectQwiicDevices: added %s at address 0x%02X\r\n", getDeviceName(foundType), address); + { + SerialPrintf3("detectQwiicDevices: added %s at address 0x%02X\r\n", getDeviceName(foundType), address); + } } } if (foundType == DEVICE_PHT_MS8607) @@ -134,7 +144,7 @@ bool detectQwiicDevices() //If we have muxes, begin scanning their sub nets if (muxCount > 0) { - Serial.println(F("Multiplexers found. Scanning sub nets...")); + SerialPrintln(F("Multiplexers found. Scanning sub nets...")); //Step into first mux and begin stepping through ports for (int muxNumber = 0 ; muxNumber < muxCount ; muxNumber++) @@ -144,7 +154,7 @@ bool detectQwiicDevices() QWIICMUX *myMux = (QWIICMUX *)muxNode->classPtr; printDebug("detectQwiicDevices: scanning the ports of multiplexer " + (String)muxNumber); - printDebug("\r\n"); + printDebug(F("\r\n")); for (int portNumber = 0 ; portNumber < 8 ; portNumber++) //Assumes we are using a mux with 8 ports max { @@ -153,7 +163,7 @@ bool detectQwiicDevices() printDebug("detectQwiicDevices: scanning port number " + (String)portNumber); printDebug(" on multiplexer " + (String)muxNumber); - printDebug("\r\n"); + printDebug(F("\r\n")); //Scan this new bus for new addresses for (uint8_t address = 1 ; address < 127 ; address++) @@ -162,7 +172,9 @@ bool detectQwiicDevices() if (deviceExists(DEVICE_TOTAL_DEVICES, address, 0, 0)) // Check if we found any type of device with this address on the main branch { if (settings.printDebugMessages == true) - Serial.printf("detectQwiicDevices: skipping device address 0x%02X because we found one on the main branch\r\n", address); + { + SerialPrintf2("detectQwiicDevices: skipping device address 0x%02X because we found one on the main branch\r\n", address); + } } else { @@ -186,14 +198,14 @@ bool detectQwiicDevices() if (foundType == DEVICE_MULTIPLEXER) // Let's ignore multiplexers hanging off multiplexer ports. (Multiple muxes on the main branch is OK.) { if (settings.printDebugMessages == true) - Serial.printf("detectQwiicDevices: ignoring %s at address 0x%02X.0x%02X.%d\r\n", getDeviceName(foundType), address, muxNode->address, portNumber); + SerialPrintf5("detectQwiicDevices: ignoring %s at address 0x%02X.0x%02X.%d\r\n", getDeviceName(foundType), address, muxNode->address, portNumber); } else { if (addDevice(foundType, address, muxNode->address, portNumber) == true) //Record this device, with mux port specifics. { if (settings.printDebugMessages == true) - Serial.printf("detectQwiicDevices: added %s at address 0x%02X.0x%02X.%d\r\n", getDeviceName(foundType), address, muxNode->address, portNumber); + SerialPrintf5("detectQwiicDevices: added %s at address 0x%02X.0x%02X.%d\r\n", getDeviceName(foundType), address, muxNode->address, portNumber); } } } @@ -219,7 +231,7 @@ bool detectQwiicDevices() setMaxI2CSpeed(); //Try for 400kHz but reduce to 100kHz or low if certain devices are attached - Serial.println(F("Autodetect complete")); + SerialPrintln(F("Autodetect complete")); return (true); } // /detectQwiicDevices @@ -228,8 +240,8 @@ void menuAttachedDevices() { while (1) { - Serial.println(); - Serial.println(F("Menu: Configure Attached Devices")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure Attached Devices")); int availableDevices = 0; @@ -237,7 +249,7 @@ void menuAttachedDevices() node *temp = head; if (temp == NULL) - Serial.println(F("**No devices detected on Qwiic bus**")); + SerialPrintln(F("**No devices detected on Qwiic bus**")); while (temp != NULL) { @@ -256,67 +268,76 @@ void menuAttachedDevices() switch (temp->deviceType) { case DEVICE_MULTIPLEXER: - //Serial.printf("%s Multiplexer %s\r\n", strDeviceMenu, strAddress); + //SerialPrintf3("%s Multiplexer %s\r\n", strDeviceMenu, strAddress); break; case DEVICE_LOADCELL_NAU7802: - Serial.printf("%s NAU7802 Weight Sensor %s\r\n", strDeviceMenu, strAddress); + SerialPrintf3("%s NAU7802 Weight Sensor %s\r\n", strDeviceMenu, strAddress); break; case DEVICE_DISTANCE_VL53L1X: - Serial.printf("%s VL53L1X Distance Sensor %s\r\n", strDeviceMenu, strAddress); + SerialPrintf3("%s VL53L1X Distance Sensor %s\r\n", strDeviceMenu, strAddress); break; case DEVICE_GPS_UBLOX: - Serial.printf("%s u-blox GPS Receiver %s\r\n", strDeviceMenu, strAddress); + SerialPrintf3("%s u-blox GPS Receiver %s\r\n", strDeviceMenu, strAddress); break; case DEVICE_PROXIMITY_VCNL4040: - Serial.printf("%s VCNL4040 Proximity Sensor %s\r\n", strDeviceMenu, strAddress); + SerialPrintf3("%s VCNL4040 Proximity Sensor %s\r\n", strDeviceMenu, strAddress); break; case DEVICE_TEMPERATURE_TMP117: - Serial.printf("%s TMP117 High Precision Temperature Sensor %s\r\n", strDeviceMenu, strAddress); + SerialPrintf3("%s TMP117 High Precision Temperature Sensor %s\r\n", strDeviceMenu, strAddress); break; case DEVICE_PRESSURE_MS5637: - Serial.printf("%s MS5637 Pressure Sensor %s\r\n", strDeviceMenu, strAddress); + SerialPrintf3("%s MS5637 Pressure Sensor %s\r\n", strDeviceMenu, strAddress); break; case DEVICE_PRESSURE_LPS25HB: - Serial.printf("%s LPS25HB Pressure Sensor %s\r\n", strDeviceMenu, strAddress); + SerialPrintf3("%s LPS25HB Pressure Sensor %s\r\n", strDeviceMenu, strAddress); break; case DEVICE_PHT_BME280: - Serial.printf("%s BME280 Pressure/Humidity/Temp (PHT) Sensor %s\r\n", strDeviceMenu, strAddress); + SerialPrintf3("%s BME280 Pressure/Humidity/Temp (PHT) Sensor %s\r\n", strDeviceMenu, strAddress); break; case DEVICE_UV_VEML6075: - Serial.printf("%s VEML6075 UV Sensor %s\r\n", strDeviceMenu, strAddress); + SerialPrintf3("%s VEML6075 UV Sensor %s\r\n", strDeviceMenu, strAddress); break; case DEVICE_VOC_CCS811: - Serial.printf("%s CCS811 tVOC and CO2 Sensor %s\r\n", strDeviceMenu, strAddress); + SerialPrintf3("%s CCS811 tVOC and CO2 Sensor %s\r\n", strDeviceMenu, strAddress); break; case DEVICE_VOC_SGP30: - Serial.printf("%s SGP30 tVOC and CO2 Sensor %s\r\n", strDeviceMenu, strAddress); + SerialPrintf3("%s SGP30 tVOC and CO2 Sensor %s\r\n", strDeviceMenu, strAddress); break; case DEVICE_CO2_SCD30: - Serial.printf("%s SCD30 CO2 Sensor %s\r\n", strDeviceMenu, strAddress); + SerialPrintf3("%s SCD30 CO2 Sensor %s\r\n", strDeviceMenu, strAddress); break; case DEVICE_PHT_MS8607: - Serial.printf("%s MS8607 Pressure/Humidity/Temp (PHT) Sensor %s\r\n", strDeviceMenu, strAddress); + SerialPrintf3("%s MS8607 Pressure/Humidity/Temp (PHT) Sensor %s\r\n", strDeviceMenu, strAddress); break; case DEVICE_TEMPERATURE_MCP9600: - Serial.printf("%s MCP9600 Thermocouple Sensor %s\r\n", strDeviceMenu, strAddress); + SerialPrintf3("%s MCP9600 Thermocouple Sensor %s\r\n", strDeviceMenu, strAddress); break; case DEVICE_HUMIDITY_AHT20: - Serial.printf("%s AHT20 Humidity Sensor %s\r\n", strDeviceMenu, strAddress); + SerialPrintf3("%s AHT20 Humidity Sensor %s\r\n", strDeviceMenu, strAddress); break; case DEVICE_HUMIDITY_SHTC3: - Serial.printf("%s SHTC3 Humidity Sensor %s\r\n", strDeviceMenu, strAddress); + SerialPrintf3("%s SHTC3 Humidity Sensor %s\r\n", strDeviceMenu, strAddress); break; case DEVICE_ADC_ADS122C04: - Serial.printf("%s ADS122C04 ADC (Qwiic PT100) %s\r\n", strDeviceMenu, strAddress); + SerialPrintf3("%s ADS122C04 ADC (Qwiic PT100) %s\r\n", strDeviceMenu, strAddress); break; case DEVICE_PRESSURE_MPR0025PA1: - Serial.printf("%s MPR MicroPressure Sensor %s\r\n", strDeviceMenu, strAddress); + SerialPrintf3("%s MPR MicroPressure Sensor %s\r\n", strDeviceMenu, strAddress); break; case DEVICE_PARTICLE_SNGCJA5: - Serial.printf("%s SN-GCJA5 Particle Sensor %s\r\n", strDeviceMenu, strAddress); + SerialPrintf3("%s SN-GCJA5 Particle Sensor %s\r\n", strDeviceMenu, strAddress); + break; + case DEVICE_VOC_SGP40: + SerialPrintf3("%s SGP40 VOC Sensor %s\r\n", strDeviceMenu, strAddress); + break; + case DEVICE_PRESSURE_SDP3X: + SerialPrintf3("%s SDP3X Differential Pressure Sensor %s\r\n", strDeviceMenu, strAddress); + break; + case DEVICE_PRESSURE_MS5837: + SerialPrintf3("%s MS5837 (BAR30 / BAR02) Pressure Sensor %s\r\n", strDeviceMenu, strAddress); break; default: - Serial.printf("Unknown device type %d in menuAttachedDevices\r\n", temp->deviceType); + SerialPrintf2("Unknown device type %d in menuAttachedDevices\r\n", temp->deviceType); break; } } @@ -324,9 +345,9 @@ void menuAttachedDevices() temp = temp->next; } - Serial.printf("%d) Configure Qwiic Settings\r\n", availableDevices++ + 1); + SerialPrintf2("%d) Configure Qwiic Settings\r\n", availableDevices++ + 1); - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); int nodeNumber = getNumber(menuTimeout); //Timeout after x seconds if (nodeNumber > 0 && nodeNumber < availableDevices) @@ -357,30 +378,30 @@ void menuConfigure_QwiicBus() { while (1) { - Serial.println(); - Serial.println(F("Menu: Configure Qwiic Bus")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure Qwiic Bus")); - Serial.print(F("1) Turn off bus power between readings (>2s): ")); - if (settings.powerDownQwiicBusBetweenReads == true) Serial.println(F("Yes")); - else Serial.println(F("No")); + SerialPrint(F("1) Turn off bus power between readings (>2s): ")); + if (settings.powerDownQwiicBusBetweenReads == true) SerialPrintln(F("Yes")); + else SerialPrintln(F("No")); - Serial.printf("2) Set Max Qwiic Bus Speed: %d Hz\r\n", settings.qwiicBusMaxSpeed); + SerialPrintf2("2) Set Max Qwiic Bus Speed: %d Hz\r\n", settings.qwiicBusMaxSpeed); - Serial.printf("3) Set minimum Qwiic bus power up delay: %d ms\r\n", settings.qwiicBusPowerUpDelayMs); + SerialPrintf2("3) Set minimum Qwiic bus power up delay: %d ms\r\n", settings.qwiicBusPowerUpDelayMs); - Serial.print(F("4) Qwiic bus pull-ups (internal to the Artemis): ")); + SerialPrint(F("4) Qwiic bus pull-ups (internal to the Artemis): ")); if (settings.qwiicBusPullUps == 1) - Serial.println(F("1.5k")); + SerialPrintln(F("1.5k")); else if (settings.qwiicBusPullUps == 6) - Serial.println(F("6k")); + SerialPrintln(F("6k")); else if (settings.qwiicBusPullUps == 12) - Serial.println(F("12k")); + SerialPrintln(F("12k")); else if (settings.qwiicBusPullUps == 24) - Serial.println(F("24k")); + SerialPrintln(F("24k")); else - Serial.println(F("None")); + SerialPrintln(F("None")); - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds @@ -388,32 +409,32 @@ void menuConfigure_QwiicBus() settings.powerDownQwiicBusBetweenReads ^= 1; else if (incoming == '2') { - Serial.print(F("Enter max frequency to run Qwiic bus: (100000 or 400000): ")); + SerialPrint(F("Enter max frequency to run Qwiic bus: (100000 or 400000): ")); uint32_t amt = getNumber(menuTimeout); if ((amt == 100000) || (amt == 400000)) settings.qwiicBusMaxSpeed = amt; else - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); } else if (incoming == '3') { // 60 seconds is more than long enough for a ZED-F9P to do a warm start after being powered cycled, so that seems a sensible maximum // minimumQwiicPowerOnDelay is defined in settings.h - Serial.printf("Enter the minimum number of milliseconds to wait for Qwiic VCC to stabilize before communication: (%d to 60000): ", minimumQwiicPowerOnDelay); + SerialPrintf2("Enter the minimum number of milliseconds to wait for Qwiic VCC to stabilize before communication: (%d to 60000): ", minimumQwiicPowerOnDelay); unsigned long amt = getNumber(menuTimeout); if ((amt >= minimumQwiicPowerOnDelay) && (amt <= 60000)) settings.qwiicBusPowerUpDelayMs = amt; else - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); } else if (incoming == '4') { - Serial.print(F("Enter the Artemis pull-up resistance (0 = None; 1 = 1.5k; 6 = 6k; 12 = 12k; 24 = 24k): ")); + SerialPrint(F("Enter the Artemis pull-up resistance (0 = None; 1 = 1.5k; 6 = 6k; 12 = 12k; 24 = 24k): ")); uint32_t pur = (uint32_t)getNumber(menuTimeout); if ((pur == 0) || (pur == 1) || (pur == 6) || (pur == 12) || (pur == 24)) settings.qwiicBusPullUps = pur; else - Serial.println(F("Error: Invalid resistance. Possible values are 0,1,6,12,24.")); + SerialPrintln(F("Error: Invalid resistance. Possible values are 0,1,6,12,24.")); } else if (incoming == 'x') break; @@ -428,10 +449,10 @@ void menuConfigure_Multiplexer(void *configPtr) { //struct_multiplexer *sensor = (struct_multiplexer*)configPtr; - Serial.println(); - Serial.println(F("Menu: Configure Multiplexer")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure Multiplexer")); - Serial.println(F("There are currently no configurable options for this device.")); + SerialPrintln(F("There are currently no configurable options for this device.")); for (int i = 0; i < 500; i++) { checkBattery(); @@ -449,39 +470,39 @@ void menuConfigure_VL53L1X(void *configPtr) while (1) { - Serial.println(); - Serial.println(F("Menu: Configure VL53L1X Distance Sensor")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure VL53L1X Distance Sensor")); - Serial.print(F("1) Sensor Logging: ")); - if (sensorSetting->log == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (sensorSetting->log == true) { - Serial.print(F("2) Log Distance: ")); - if (sensorSetting->logDistance == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("2) Log Distance: ")); + if (sensorSetting->logDistance == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("3) Log Range Status: ")); - if (sensorSetting->logRangeStatus == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("3) Log Range Status: ")); + if (sensorSetting->logRangeStatus == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("4) Log Signal Rate: ")); - if (sensorSetting->logSignalRate == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("4) Log Signal Rate: ")); + if (sensorSetting->logSignalRate == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("5) Set Distance Mode: ")); + SerialPrint(F("5) Set Distance Mode: ")); if (sensorSetting->distanceMode == VL53L1X_DISTANCE_MODE_SHORT) - Serial.print(F("Short")); + SerialPrint(F("Short")); else - Serial.print(F("Long")); - Serial.println(); + SerialPrint(F("Long")); + SerialPrintln(F("")); - Serial.printf("6) Set Intermeasurement Period: %d ms\r\n", sensorSetting->intermeasurementPeriod); - Serial.printf("7) Set Offset: %d mm\r\n", sensorSetting->offset); - Serial.printf("8) Set Cross Talk (counts per second): %d cps\r\n", sensorSetting->crosstalk); + SerialPrintf2("6) Set Intermeasurement Period: %d ms\r\n", sensorSetting->intermeasurementPeriod); + SerialPrintf2("7) Set Offset: %d mm\r\n", sensorSetting->offset); + SerialPrintf2("8) Set Cross Talk (counts per second): %d cps\r\n", sensorSetting->crosstalk); } - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds @@ -506,7 +527,7 @@ void menuConfigure_VL53L1X(void *configPtr) if (sensorSetting->distanceMode == VL53L1X_DISTANCE_MODE_LONG && sensorSetting->intermeasurementPeriod < 140) { sensorSetting->intermeasurementPeriod = 140; - Serial.println(F("Intermeasurement Period increased to 140ms")); + SerialPrintln(F("Intermeasurement Period increased to 140ms")); } } else if (incoming == '6') @@ -516,28 +537,28 @@ void menuConfigure_VL53L1X(void *configPtr) min = 140; - Serial.printf("Set timing budget (%d to 1000ms): ", min); + SerialPrintf2("Set timing budget (%d to 1000ms): ", min); int amt = getNumber(menuTimeout); //x second timeout if (amt < min || amt > 1000) - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); else sensorSetting->intermeasurementPeriod = amt; } else if (incoming == '7') { - Serial.print(F("Set Offset in mm (0 to 4000mm): ")); + SerialPrint(F("Set Offset in mm (0 to 4000mm): ")); int amt = getNumber(menuTimeout); //x second timeout if (amt < 0 || amt > 4000) - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); else sensorSetting->offset = amt; } else if (incoming == '8') { - Serial.print(F("Set Crosstalk in Counts Per Second: ")); + SerialPrint(F("Set Crosstalk in Counts Per Second: ")); int amt = getNumber(menuTimeout); //x second timeout if (amt < 0 || amt > 4000) - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); else sensorSetting->crosstalk = amt; } @@ -564,32 +585,32 @@ void menuConfigure_BME280(void *configPtr) while (1) { - Serial.println(); - Serial.println(F("Menu: Configure BME280 Pressure/Humidity/Temperature Sensor")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure BME280 Pressure/Humidity/Temperature Sensor")); - Serial.print(F("1) Sensor Logging: ")); - if (sensorSetting->log == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (sensorSetting->log == true) { - Serial.print(F("2) Log Pressure: ")); - if (sensorSetting->logPressure == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("2) Log Pressure: ")); + if (sensorSetting->logPressure == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("3) Log Humidity: ")); - if (sensorSetting->logHumidity == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("3) Log Humidity: ")); + if (sensorSetting->logHumidity == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("4) Log Altitude: ")); - if (sensorSetting->logAltitude == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("4) Log Altitude: ")); + if (sensorSetting->logAltitude == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("5) Log Temperature: ")); - if (sensorSetting->logTemperature == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("5) Log Temperature: ")); + if (sensorSetting->logTemperature == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); } - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds @@ -627,24 +648,24 @@ void menuConfigure_CCS811(void *configPtr) while (1) { - Serial.println(); - Serial.println(F("Menu: Configure CCS811 tVOC and CO2 Sensor")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure CCS811 tVOC and CO2 Sensor")); - Serial.print(F("1) Sensor Logging: ")); - if (sensorSetting->log == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (sensorSetting->log == true) { - Serial.print(F("2) Log tVOC: ")); - if (sensorSetting->logTVOC == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("2) Log tVOC: ")); + if (sensorSetting->logTVOC == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("3) Log CO2: ")); - if (sensorSetting->logCO2 == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("3) Log CO2: ")); + if (sensorSetting->logCO2 == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); } - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds @@ -677,24 +698,24 @@ void menuConfigure_LPS25HB(void *configPtr) struct_LPS25HB *sensorSetting = (struct_LPS25HB*)configPtr; while (1) { - Serial.println(); - Serial.println(F("Menu: Configure LPS25HB Pressure Sensor")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure LPS25HB Pressure Sensor")); - Serial.print(F("1) Sensor Logging: ")); - if (sensorSetting->log == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (sensorSetting->log == true) { - Serial.print(F("2) Log Pressure: ")); - if (sensorSetting->logPressure == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("2) Log Pressure: ")); + if (sensorSetting->logPressure == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("3) Log Temperature: ")); - if (sensorSetting->logTemperature == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("3) Log Temperature: ")); + if (sensorSetting->logTemperature == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); } - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds @@ -736,7 +757,7 @@ void menuConfigure_NAU7802(void *configPtr) } if (temp == NULL) { - Serial.println(F("NAU7802 node not found. Returning.")); + SerialPrintln(F("NAU7802 node not found. Returning.")); for (int i = 0; i < 1000; i++) { checkBattery(); @@ -750,27 +771,27 @@ void menuConfigure_NAU7802(void *configPtr) while (1) { - Serial.println(); - Serial.println(F("Menu: Configure NAU7802 Load Cell Amplifier")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure NAU7802 Load Cell Amplifier")); - Serial.print(F("1) Sensor Logging: ")); - if (sensorConfig->log == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Sensor Logging: ")); + if (sensorConfig->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (sensorConfig->log == true) { - Serial.println(F("2) Calibrate Scale")); - Serial.printf("\tScale calibration factor: %f\r\n", sensorConfig->calibrationFactor); - Serial.printf("\tScale zero offset: %d\r\n", sensorConfig->zeroOffset); - Serial.printf("\tWeight currently on scale: %f\r\n", sensor->getWeight()); + SerialPrintln(F("2) Calibrate Scale")); + SerialPrintf2("\tScale calibration factor: %f\r\n", sensorConfig->calibrationFactor); + SerialPrintf2("\tScale zero offset: %d\r\n", sensorConfig->zeroOffset); + SerialPrintf2("\tWeight currently on scale: %f\r\n", sensor->getWeight()); - Serial.printf("3) Number of decimal places: %d\r\n", sensorConfig->decimalPlaces); - Serial.printf("4) Average number of readings to take per weight read: %d\r\n", sensorConfig->averageAmount); + SerialPrintf2("3) Number of decimal places: %d\r\n", sensorConfig->decimalPlaces); + SerialPrintf2("4) Average number of readings to take per weight read: %d\r\n", sensorConfig->averageAmount); } - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); - byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds + byte incoming = getByteChoice(menuTimeout, true); //Timeout after x seconds and set DSERIAL & ZSERIAL if (incoming == '1') { @@ -781,38 +802,40 @@ void menuConfigure_NAU7802(void *configPtr) if (incoming == '2') { //Gives user the ability to set a known weight on the scale and calculate a calibration factor - Serial.println(); - Serial.println(F("Scale calibration")); + SerialPrintln(F("")); + SerialPrintln(F("Scale calibration")); - Serial.println(F("Setup scale with no weight on it. Press a key when ready.")); + SerialPrintln(F("Setup scale with no weight on it. Press a key when ready.")); waitForInput(); sensor->calculateZeroOffset(64); //Zero or Tare the scale. Average over 64 readings. - Serial.print(F("New zero offset: ")); + SerialPrint(F("New zero offset: ")); Serial.println(sensor->getZeroOffset()); + if (settings.useTxRxPinsForTerminal == true) + SerialLog.println(sensor->getZeroOffset()); - Serial.println(F("Place known weight on scale. Press a key when weight is in place and stable.")); + SerialPrintln(F("Place known weight on scale. Press a key when weight is in place and stable.")); waitForInput(); - Serial.print(F("Please enter the weight, without units, currently sitting on the scale (for example '4.25'): ")); + SerialPrint(F("Please enter the weight, without units, currently sitting on the scale (for example '4.25'): ")); waitForInput(); //Read user input - float weightOnScale = Serial.parseFloat(); + float weightOnScale = DSERIAL->parseFloat(); sensor->calculateCalibrationFactor(weightOnScale, 64); //Tell the library how much weight is currently on it. Average over 64 readings. sensorConfig->calibrationFactor = sensor->getCalibrationFactor(); sensorConfig->zeroOffset = sensor->getZeroOffset(); - Serial.println(); + SerialPrintln(F("")); } else if (incoming == '3') { - Serial.print(F("Enter number of decimal places to print (1 to 10): ")); + SerialPrint(F("Enter number of decimal places to print (1 to 10): ")); int places = getNumber(menuTimeout); if (places < 1 || places > 10) { - Serial.println(F("Error: Decimal places out of range")); + SerialPrintln(F("Error: Decimal places out of range")); } else { @@ -821,11 +844,11 @@ void menuConfigure_NAU7802(void *configPtr) } else if (incoming == '4') { - Serial.print(F("Enter number of readings to take per weight read (1 to 10): ")); + SerialPrint(F("Enter number of readings to take per weight read (1 to 10): ")); int amt = getNumber(menuTimeout); if (amt < 1 || amt > 10) { - Serial.println(F("Error: Average number of readings out of range")); + SerialPrintln(F("Error: Average number of readings out of range")); } else { @@ -854,72 +877,72 @@ void menuConfigure_uBlox(void *configPtr) while (1) { - Serial.println(); - Serial.println(F("Menu: Configure uBlox GPS Receiver")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure uBlox GPS Receiver")); - Serial.print(F("1) Sensor Logging: ")); - if (sensorSetting->log == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (sensorSetting->log == true) { - Serial.print(F("2) Log GPS Date: ")); - if (sensorSetting->logDate == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("2) Log GPS Date: ")); + if (sensorSetting->logDate == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("3) Log GPS Time: ")); - if (sensorSetting->logTime == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("3) Log GPS Time: ")); + if (sensorSetting->logTime == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("4) Log Longitude/Latitude: ")); - if (sensorSetting->logPosition == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("4) Log Longitude/Latitude: ")); + if (sensorSetting->logPosition == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("5) Log Altitude: ")); - if (sensorSetting->logAltitude == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("5) Log Altitude: ")); + if (sensorSetting->logAltitude == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("6) Log Altitude Mean Sea Level: ")); - if (sensorSetting->logAltitudeMSL == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("6) Log Altitude Mean Sea Level: ")); + if (sensorSetting->logAltitudeMSL == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("7) Log Satellites In View: ")); - if (sensorSetting->logSIV == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("7) Log Satellites In View: ")); + if (sensorSetting->logSIV == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("8) Log Fix Type: ")); - if (sensorSetting->logFixType == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("8) Log Fix Type: ")); + if (sensorSetting->logFixType == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("9) Log Carrier Solution: ")); - if (sensorSetting->logCarrierSolution == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("9) Log Carrier Solution: ")); + if (sensorSetting->logCarrierSolution == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("10) Log Ground Speed: ")); - if (sensorSetting->logGroundSpeed == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("10) Log Ground Speed: ")); + if (sensorSetting->logGroundSpeed == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("11) Log Heading of Motion: ")); - if (sensorSetting->logHeadingOfMotion == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("11) Log Heading of Motion: ")); + if (sensorSetting->logHeadingOfMotion == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("12) Log Position Dilution of Precision (pDOP): ")); - if (sensorSetting->logpDOP == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("12) Log Position Dilution of Precision (pDOP): ")); + if (sensorSetting->logpDOP == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("13) Log Interval Time Of Week (iTOW): ")); - if (sensorSetting->logiTOW == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("13) Log Interval Time Of Week (iTOW): ")); + if (sensorSetting->logiTOW == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.printf("14) Set I2C Interface Speed (u-blox modules have pullups built in. Remove *all* I2C pullups to achieve 400kHz): %d\r\n", sensorSetting->i2cSpeed); + SerialPrintf2("14) Set I2C Interface Speed (u-blox modules have pullups built in. Remove *all* I2C pullups to achieve 400kHz): %d\r\n", sensorSetting->i2cSpeed); - Serial.print(F("15) Use autoPVT: ")); - if (sensorSetting->useAutoPVT == true) Serial.println(F("Yes")); - else Serial.println(F("No")); + SerialPrint(F("15) Use autoPVT: ")); + if (sensorSetting->useAutoPVT == true) SerialPrintln(F("Yes")); + else SerialPrintln(F("No")); - Serial.flush(); + SerialFlush(); } - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); int incoming = getNumber(menuTimeout); //Timeout after 10 seconds @@ -1010,7 +1033,7 @@ void getUbloxDateTime(int &year, int &month, int &day, int &hour, int &minute, i { qwiic.setPullups(0); //Disable pullups to minimize CRC issues - SFE_UBLOX_GPS *nodeDevice = (SFE_UBLOX_GPS *)temp->classPtr; + SFE_UBLOX_GNSS *nodeDevice = (SFE_UBLOX_GNSS *)temp->classPtr; struct_uBlox *nodeSetting = (struct_uBlox *)temp->configPtr; //Get latested date/time from GPS @@ -1037,24 +1060,24 @@ void menuConfigure_MCP9600(void *configPtr) struct_MCP9600 *sensorSetting = (struct_MCP9600*)configPtr; while (1) { - Serial.println(); - Serial.println(F("Menu: Configure MCP9600 Thermocouple Sensor")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure MCP9600 Thermocouple Sensor")); - Serial.print(F("1) Sensor Logging: ")); - if (sensorSetting->log == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (sensorSetting->log == true) { - Serial.print(F("2) Log Thermocouple Temperature: ")); - if (sensorSetting->logTemperature == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("2) Log Thermocouple Temperature: ")); + if (sensorSetting->logTemperature == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("3) Log Ambient Temperature: ")); - if (sensorSetting->logAmbientTemperature == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("3) Log Ambient Temperature: ")); + if (sensorSetting->logAmbientTemperature == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); } - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds @@ -1088,30 +1111,30 @@ void menuConfigure_VCNL4040(void *configPtr) struct_VCNL4040 *sensorSetting = (struct_VCNL4040*)configPtr; while (1) { - Serial.println(); - Serial.println(F("Menu: Configure VCNL4040 Proximity Sensor")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure VCNL4040 Proximity Sensor")); - Serial.print(F("1) Sensor Logging: ")); - if (sensorSetting->log == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (sensorSetting->log == true) { - Serial.print(F("2) Log Proximity: ")); - if (sensorSetting->logProximity == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); - - Serial.print(F("3) Log Ambient Light: ")); - if (sensorSetting->logAmbientLight == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); - - Serial.printf("4) Set LED Current: %d\r\n", sensorSetting->LEDCurrent); - Serial.printf("5) Set IR Duty Cycle: %d\r\n", sensorSetting->IRDutyCycle); - Serial.printf("6) Set Proximity Integration Time: %d\r\n", sensorSetting->proximityIntegrationTime); - Serial.printf("7) Set Ambient Integration Time: %d\r\n", sensorSetting->ambientIntegrationTime); - Serial.printf("8) Set Resolution (bits): %d\r\n", sensorSetting->resolution); + SerialPrint(F("2) Log Proximity: ")); + if (sensorSetting->logProximity == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); + + SerialPrint(F("3) Log Ambient Light: ")); + if (sensorSetting->logAmbientLight == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); + + SerialPrintf2("4) Set LED Current: %d\r\n", sensorSetting->LEDCurrent); + SerialPrintf2("5) Set IR Duty Cycle: %d\r\n", sensorSetting->IRDutyCycle); + SerialPrintf2("6) Set Proximity Integration Time: %d\r\n", sensorSetting->proximityIntegrationTime); + SerialPrintf2("7) Set Ambient Integration Time: %d\r\n", sensorSetting->ambientIntegrationTime); + SerialPrintf2("8) Set Resolution (bits): %d\r\n", sensorSetting->resolution); } - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds @@ -1125,48 +1148,48 @@ void menuConfigure_VCNL4040(void *configPtr) sensorSetting->logAmbientLight ^= 1; else if (incoming == '4') { - Serial.print(F("Enter current (mA) for IR LED drive (50 to 200mA): ")); + SerialPrint(F("Enter current (mA) for IR LED drive (50 to 200mA): ")); int amt = getNumber(menuTimeout); //x second timeout if (amt < 50 || amt > 200) - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); else sensorSetting->LEDCurrent = amt; } else if (incoming == '5') { - Serial.print(F("Enter IR Duty Cycle (40 to 320): ")); + SerialPrint(F("Enter IR Duty Cycle (40 to 320): ")); int amt = getNumber(menuTimeout); //x second timeout if (amt < 40 || amt > 320) - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); else sensorSetting->IRDutyCycle = amt; } else if (incoming == '6') { - Serial.print(F("Enter Proximity Integration Time (1 to 8): ")); + SerialPrint(F("Enter Proximity Integration Time (1 to 8): ")); int amt = getNumber(menuTimeout); //x second timeout if (amt < 1 || amt > 8) - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); else sensorSetting->proximityIntegrationTime = amt; } else if (incoming == '7') { - Serial.print(F("Enter Ambient Light Integration Time (80 to 640ms): ")); + SerialPrint(F("Enter Ambient Light Integration Time (80 to 640ms): ")); int amt = getNumber(menuTimeout); //x second timeout if (amt < 80 || amt > 640) - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); else sensorSetting->ambientIntegrationTime = amt; } else if (incoming == '8') { - Serial.print(F("Enter Proximity Resolution (12 or 16 bit): ")); + SerialPrint(F("Enter Proximity Resolution (12 or 16 bit): ")); int amt = getNumber(menuTimeout); //x second timeout if (amt == 12 || amt == 16) sensorSetting->resolution = amt; else - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); } else if (incoming == 'x') break; @@ -1190,14 +1213,14 @@ void menuConfigure_TMP117(void *configPtr) struct_TMP117 *sensorSetting = (struct_TMP117*)configPtr; while (1) { - Serial.println(); - Serial.println(F("Menu: Configure TMP117 Precision Temperature Sensor")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure TMP117 Precision Temperature Sensor")); - Serial.print(F("1) Sensor Logging: ")); - if (sensorSetting->log == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds @@ -1219,32 +1242,32 @@ void menuConfigure_SGP30(void *configPtr) struct_SGP30 *sensorSetting = (struct_SGP30*)configPtr; while (1) { - Serial.println(); - Serial.println(F("Menu: Configure SGP30 tVOC and CO2 Sensor")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure SGP30 tVOC and CO2 Sensor")); - Serial.print(F("1) Sensor Logging: ")); - if (sensorSetting->log == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (sensorSetting->log == true) { - Serial.print(F("2) Log tVOC: ")); - if (sensorSetting->logTVOC == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("2) Log tVOC: ")); + if (sensorSetting->logTVOC == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("3) Log CO2: ")); - if (sensorSetting->logCO2 == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("3) Log CO2: ")); + if (sensorSetting->logCO2 == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("4) Log H2: ")); - if (sensorSetting->logH2 == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("4) Log H2: ")); + if (sensorSetting->logH2 == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("5) Log Ethanol: ")); - if (sensorSetting->logEthanol == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("5) Log Ethanol: ")); + if (sensorSetting->logEthanol == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); } - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds @@ -1281,28 +1304,28 @@ void menuConfigure_VEML6075(void *configPtr) struct_VEML6075 *sensorSetting = (struct_VEML6075*)configPtr; while (1) { - Serial.println(); - Serial.println(F("Menu: Configure VEML6075 UV Index Sensor")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure VEML6075 UV Index Sensor")); - Serial.print(F("1) Sensor Logging: ")); - if (sensorSetting->log == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (sensorSetting->log == true) { - Serial.print(F("2) Log UVA: ")); - if (sensorSetting->logUVA == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("2) Log UVA: ")); + if (sensorSetting->logUVA == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("3) Log UVB: ")); - if (sensorSetting->logUVB == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("3) Log UVB: ")); + if (sensorSetting->logUVB == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("4) Log UV Index: ")); - if (sensorSetting->logUVIndex == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("4) Log UV Index: ")); + if (sensorSetting->logUVIndex == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); } - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds @@ -1339,24 +1362,24 @@ void menuConfigure_MS5637(void *configPtr) struct_MS5637 *sensorSetting = (struct_MS5637*)configPtr; while (1) { - Serial.println(); - Serial.println(F("Menu: Configure MS5637 Pressure Sensor")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure MS5637 Pressure Sensor")); - Serial.print(F("1) Sensor Logging: ")); - if (sensorSetting->log == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (sensorSetting->log == true) { - Serial.print(F("2) Log Pressure: ")); - if (sensorSetting->logPressure == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("2) Log Pressure: ")); + if (sensorSetting->logPressure == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("3) Log Temperature: ")); - if (sensorSetting->logTemperature == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("3) Log Temperature: ")); + if (sensorSetting->logTemperature == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); } - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds @@ -1399,7 +1422,7 @@ void menuConfigure_SCD30(void *configPtr) } if (temp == NULL) { - Serial.println(F("SCD30 node not found. Returning.")); + SerialPrintln(F("SCD30 node not found. Returning.")); for (int i = 0; i < 1000; i++) { checkBattery(); @@ -1413,33 +1436,33 @@ void menuConfigure_SCD30(void *configPtr) while (1) { - Serial.println(); - Serial.println(F("Menu: Configure SCD30 CO2 and Humidity Sensor")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure SCD30 CO2 and Humidity Sensor")); - Serial.print(F("1) Sensor Logging: ")); - if (sensorSetting->log == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (sensorSetting->log == true) { - Serial.print(F("2) Log CO2: ")); - if (sensorSetting->logCO2 == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); - - Serial.print(F("3) Log Humidity: ")); - if (sensorSetting->logHumidity == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); - - Serial.print(F("4) Log Temperature: ")); - if (sensorSetting->logTemperature == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); - - Serial.printf("5) Set Measurement Interval: %d\r\n", sensorSetting->measurementInterval); - Serial.printf("6) Set Altitude Compensation: %d\r\n", sensorSetting->altitudeCompensation); - Serial.printf("7) Set Ambient Pressure: %d\r\n", sensorSetting->ambientPressure); - Serial.printf("8) Set Temperature Offset: %d\r\n", sensorSetting->temperatureOffset); + SerialPrint(F("2) Log CO2: ")); + if (sensorSetting->logCO2 == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); + + SerialPrint(F("3) Log Humidity: ")); + if (sensorSetting->logHumidity == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); + + SerialPrint(F("4) Log Temperature: ")); + if (sensorSetting->logTemperature == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); + + SerialPrintf2("5) Set Measurement Interval: %d\r\n", sensorSetting->measurementInterval); + SerialPrintf2("6) Set Altitude Compensation: %d\r\n", sensorSetting->altitudeCompensation); + SerialPrintf2("7) Set Ambient Pressure: %d\r\n", sensorSetting->ambientPressure); + SerialPrintf2("8) Set Temperature Offset: %d\r\n", sensorSetting->temperatureOffset); } - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds @@ -1455,42 +1478,44 @@ void menuConfigure_SCD30(void *configPtr) sensorSetting->logTemperature ^= 1; else if (incoming == '5') { - Serial.print(F("Enter the seconds between measurements (2 to 1800): ")); + SerialPrint(F("Enter the seconds between measurements (2 to 1800): ")); int amt = getNumber(menuTimeout); //x second timeout if (amt < 2 || amt > 1800) - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); else sensorSetting->measurementInterval = amt; } else if (incoming == '6') { - Serial.print(F("Enter the Altitude Compensation in meters (0 to 10000): ")); + SerialPrint(F("Enter the Altitude Compensation in meters (0 to 10000): ")); int amt = getNumber(menuTimeout); //x second timeout if (amt < 0 || amt > 10000) - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); else sensorSetting->altitudeCompensation = amt; } else if (incoming == '7') { - Serial.print(F("Enter Ambient Pressure in mBar (700 to 1200): ")); + SerialPrint(F("Enter Ambient Pressure in mBar (700 to 1200): ")); int amt = getNumber(menuTimeout); //x second timeout if (amt < 700 || amt > 1200) - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); else sensorSetting->ambientPressure = amt; } else if (incoming == '8') { - Serial.print(F("The current temperature offset read from the sensor is: ")); + SerialPrint(F("The current temperature offset read from the sensor is: ")); Serial.print(sensor->getTemperatureOffset(), 2); - Serial.println(F("C")); - Serial.print(F("Enter new temperature offset in C (-50 to 50): ")); + if (settings.useTxRxPinsForTerminal == true) + SerialLog.print(sensor->getTemperatureOffset(), 2); + SerialPrintln(F("C")); + SerialPrint(F("Enter new temperature offset in C (-50 to 50): ")); int amt = getNumber(menuTimeout); //x second timeout if (amt < -50 || amt > 50) sensorSetting->temperatureOffset = amt; else - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); } else if (incoming == 'x') break; @@ -1515,58 +1540,58 @@ void menuConfigure_MS8607(void *configPtr) struct_MS8607 *sensorSetting = (struct_MS8607*)configPtr; while (1) { - Serial.println(); - Serial.println(F("Menu: Configure MS8607 Pressure Humidity Temperature (PHT) Sensor")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure MS8607 Pressure Humidity Temperature (PHT) Sensor")); - Serial.print(F("1) Sensor Logging: ")); - if (sensorSetting->log == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (sensorSetting->log == true) { - Serial.print(F("2) Log Pressure: ")); - if (sensorSetting->logPressure == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("2) Log Pressure: ")); + if (sensorSetting->logPressure == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("3) Log Humidity: ")); - if (sensorSetting->logHumidity == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("3) Log Humidity: ")); + if (sensorSetting->logHumidity == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("4) Log Temperature: ")); - if (sensorSetting->logTemperature == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("4) Log Temperature: ")); + if (sensorSetting->logTemperature == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("5) Heater: ")); - if (sensorSetting->enableHeater == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("5) Heater: ")); + if (sensorSetting->enableHeater == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("6) Set Pressure Resolution: ")); + SerialPrint(F("6) Set Pressure Resolution: ")); if (sensorSetting->pressureResolution == MS8607_pressure_resolution_osr_256) - Serial.print(F("0.11")); + SerialPrint(F("0.11")); else if (sensorSetting->pressureResolution == MS8607_pressure_resolution_osr_512) - Serial.print(F("0.062")); + SerialPrint(F("0.062")); else if (sensorSetting->pressureResolution == MS8607_pressure_resolution_osr_1024) - Serial.print(F("0.039")); + SerialPrint(F("0.039")); else if (sensorSetting->pressureResolution == MS8607_pressure_resolution_osr_2048) - Serial.print(F("0.028")); + SerialPrint(F("0.028")); else if (sensorSetting->pressureResolution == MS8607_pressure_resolution_osr_4096) - Serial.print(F("0.021")); + SerialPrint(F("0.021")); else if (sensorSetting->pressureResolution == MS8607_pressure_resolution_osr_8192) - Serial.print(F("0.016")); - Serial.println(F(" mbar")); + SerialPrint(F("0.016")); + SerialPrintln(F(" mbar")); - Serial.print(F("7) Set Humidity Resolution: ")); + SerialPrint(F("7) Set Humidity Resolution: ")); if (sensorSetting->humidityResolution == MS8607_humidity_resolution_8b) - Serial.print(F("8")); + SerialPrint(F("8")); else if (sensorSetting->humidityResolution == MS8607_humidity_resolution_10b) - Serial.print(F("10")); + SerialPrint(F("10")); else if (sensorSetting->humidityResolution == MS8607_humidity_resolution_11b) - Serial.print(F("11")); + SerialPrint(F("11")); else if (sensorSetting->humidityResolution == MS8607_humidity_resolution_12b) - Serial.print(F("12")); - Serial.println(F(" bits")); + SerialPrint(F("12")); + SerialPrintln(F(" bits")); } - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds @@ -1584,26 +1609,26 @@ void menuConfigure_MS8607(void *configPtr) sensorSetting->enableHeater ^= 1; else if (incoming == '6') { - Serial.println(F("Set Pressure Resolution:")); - Serial.println(F("1) 0.11 mbar")); - Serial.println(F("2) 0.062 mbar")); - Serial.println(F("3) 0.039 mbar")); - Serial.println(F("4) 0.028 mbar")); - Serial.println(F("5) 0.021 mbar")); - Serial.println(F("6) 0.016 mbar")); + SerialPrintln(F("Set Pressure Resolution:")); + SerialPrintln(F("1) 0.11 mbar")); + SerialPrintln(F("2) 0.062 mbar")); + SerialPrintln(F("3) 0.039 mbar")); + SerialPrintln(F("4) 0.028 mbar")); + SerialPrintln(F("5) 0.021 mbar")); + SerialPrintln(F("6) 0.016 mbar")); int amt = getNumber(menuTimeout); //x second timeout if (amt >= 1 && amt <= 6) sensorSetting->pressureResolution = (MS8607_pressure_resolution)(amt - 1); else - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); } else if (incoming == '7') { - Serial.println(F("Set Humidity Resolution:")); - Serial.println(F("1) 8 bit")); - Serial.println(F("2) 10 bit")); - Serial.println(F("3) 11 bit")); - Serial.println(F("4) 12 bit")); + SerialPrintln(F("Set Humidity Resolution:")); + SerialPrintln(F("1) 8 bit")); + SerialPrintln(F("2) 10 bit")); + SerialPrintln(F("3) 11 bit")); + SerialPrintln(F("4) 12 bit")); int amt = getNumber(menuTimeout); //x second timeout if (amt >= 1 && amt <= 4) { @@ -1614,7 +1639,7 @@ void menuConfigure_MS8607(void *configPtr) if (amt == 4) sensorSetting->humidityResolution = MS8607_humidity_resolution_12b; } else - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); } else if (incoming == 'x') break; @@ -1638,24 +1663,24 @@ void menuConfigure_AHT20(void *configPtr) while (1) { - Serial.println(); - Serial.println(F("Menu: Configure AHT20 Humidity Sensor")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure AHT20 Humidity Sensor")); - Serial.print(F("1) Sensor Logging: ")); - if (sensorSetting->log == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (sensorSetting->log == true) { - Serial.print(F("2) Log Humidity: ")); - if (sensorSetting->logHumidity == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("2) Log Humidity: ")); + if (sensorSetting->logHumidity == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("3) Log Temperature: ")); - if (sensorSetting->logTemperature == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("3) Log Temperature: ")); + if (sensorSetting->logTemperature == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); } - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds @@ -1689,24 +1714,24 @@ void menuConfigure_SHTC3(void *configPtr) while (1) { - Serial.println(); - Serial.println(F("Menu: Configure SHTC3 Humidity Sensor")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure SHTC3 Humidity Sensor")); - Serial.print(F("1) Sensor Logging: ")); - if (sensorSetting->log == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (sensorSetting->log == true) { - Serial.print(F("2) Log Humidity: ")); - if (sensorSetting->logHumidity == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("2) Log Humidity: ")); + if (sensorSetting->logHumidity == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("3) Log Temperature: ")); - if (sensorSetting->logTemperature == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("3) Log Temperature: ")); + if (sensorSetting->logTemperature == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); } - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds @@ -1740,56 +1765,56 @@ void menuConfigure_ADS122C04(void *configPtr) while (1) { - Serial.println(); - Serial.println(F("Menu: Configure ADS122C04 ADC (Qwiic PT100)")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure ADS122C04 ADC (Qwiic PT100)")); - Serial.print(F("1) Sensor Logging: ")); - if (sensorSetting->log == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (sensorSetting->log == true) { - Serial.print(F("2) Log Centigrade: ")); - if (sensorSetting->logCentigrade == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("2) Log Centigrade: ")); + if (sensorSetting->logCentigrade == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("3) Log Fahrenheit: ")); - if (sensorSetting->logFahrenheit == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("3) Log Fahrenheit: ")); + if (sensorSetting->logFahrenheit == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("4) Log Internal Temperature: ")); - if (sensorSetting->logInternalTemperature == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("4) Log Internal Temperature: ")); + if (sensorSetting->logInternalTemperature == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("5) Log Raw Voltage: ")); - if (sensorSetting->logRawVoltage == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("5) Log Raw Voltage: ")); + if (sensorSetting->logRawVoltage == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("6) Use 4-Wire Mode: ")); - if (sensorSetting->useFourWireMode == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("6) Use 4-Wire Mode: ")); + if (sensorSetting->useFourWireMode == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("7) Use 3-Wire Mode: ")); - if (sensorSetting->useThreeWireMode == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("7) Use 3-Wire Mode: ")); + if (sensorSetting->useThreeWireMode == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("8) Use 2-Wire Mode: ")); - if (sensorSetting->useTwoWireMode == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("8) Use 2-Wire Mode: ")); + if (sensorSetting->useTwoWireMode == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("9) Use 4-Wire High Temperature Mode: ")); - if (sensorSetting->useFourWireHighTemperatureMode == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("9) Use 4-Wire High Temperature Mode: ")); + if (sensorSetting->useFourWireHighTemperatureMode == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("10) Use 3-Wire High Temperature Mode: ")); - if (sensorSetting->useThreeWireHighTemperatureMode == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("10) Use 3-Wire High Temperature Mode: ")); + if (sensorSetting->useThreeWireHighTemperatureMode == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("11) Use 2-Wire High Temperature Mode: ")); - if (sensorSetting->useTwoWireHighTemperatureMode == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("11) Use 2-Wire High Temperature Mode: ")); + if (sensorSetting->useTwoWireHighTemperatureMode == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); } - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); int incoming = getNumber(menuTimeout); //Timeout after x seconds @@ -1881,49 +1906,49 @@ void menuConfigure_MPR0025PA1(void *configPtr) while (1) { - Serial.println(); - Serial.println(F("Menu: Configure MPR MicroPressure Sensor")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure MPR MicroPressure Sensor")); - Serial.print(F("1) Sensor Logging: ")); - if (sensorSetting->log == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (sensorSetting->log == true) { - Serial.printf("2) Minimum PSI: %d\r\n", sensorSetting->minimumPSI); + SerialPrintf2("2) Minimum PSI: %d\r\n", sensorSetting->minimumPSI); - Serial.printf("3) Maximum PSI: %d\r\n", sensorSetting->maximumPSI); + SerialPrintf2("3) Maximum PSI: %d\r\n", sensorSetting->maximumPSI); - Serial.print(F("4) Use PSI: ")); - if (sensorSetting->usePSI == true) Serial.println(F("Yes")); - else Serial.println(F("No")); + SerialPrint(F("4) Use PSI: ")); + if (sensorSetting->usePSI == true) SerialPrintln(F("Yes")); + else SerialPrintln(F("No")); - Serial.print(F("5) Use Pa: ")); - if (sensorSetting->usePA == true) Serial.println(F("Yes")); - else Serial.println(F("No")); + SerialPrint(F("5) Use Pa: ")); + if (sensorSetting->usePA == true) SerialPrintln(F("Yes")); + else SerialPrintln(F("No")); - Serial.print(F("6) Use kPa: ")); - if (sensorSetting->useKPA == true) Serial.println(F("Yes")); - else Serial.println(F("No")); + SerialPrint(F("6) Use kPa: ")); + if (sensorSetting->useKPA == true) SerialPrintln(F("Yes")); + else SerialPrintln(F("No")); - Serial.print(F("7) Use torr: ")); - if (sensorSetting->useTORR == true) Serial.println(F("Yes")); - else Serial.println(F("No")); + SerialPrint(F("7) Use torr: ")); + if (sensorSetting->useTORR == true) SerialPrintln(F("Yes")); + else SerialPrintln(F("No")); - Serial.print(F("8) Use inHg: ")); - if (sensorSetting->useINHG == true) Serial.println(F("Yes")); - else Serial.println(F("No")); + SerialPrint(F("8) Use inHg: ")); + if (sensorSetting->useINHG == true) SerialPrintln(F("Yes")); + else SerialPrintln(F("No")); - Serial.print(F("9) Use atm: ")); - if (sensorSetting->useATM == true) Serial.println(F("Yes")); - else Serial.println(F("No")); + SerialPrint(F("9) Use atm: ")); + if (sensorSetting->useATM == true) SerialPrintln(F("Yes")); + else SerialPrintln(F("No")); - Serial.print(F("10) Use bar: ")); - if (sensorSetting->useBAR == true) Serial.println(F("Yes")); - else Serial.println(F("No")); + SerialPrint(F("10) Use bar: ")); + if (sensorSetting->useBAR == true) SerialPrintln(F("Yes")); + else SerialPrintln(F("No")); } - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); int incoming = getNumber(menuTimeout); //Timeout after x seconds @@ -1933,19 +1958,19 @@ void menuConfigure_MPR0025PA1(void *configPtr) { if (incoming == 2) { - Serial.print(F("Enter the sensor minimum pressure in PSI (this should be 0 for the MPR0025PA): ")); + SerialPrint(F("Enter the sensor minimum pressure in PSI (this should be 0 for the MPR0025PA): ")); int minPSI = getNumber(menuTimeout); //x second timeout if (minPSI < 0 || minPSI > 30) - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); else sensorSetting->minimumPSI = minPSI; } else if (incoming == 3) { - Serial.print(F("Enter the sensor maximum pressure in PSI (this should be 25 for the MPR0025PA): ")); + SerialPrint(F("Enter the sensor maximum pressure in PSI (this should be 25 for the MPR0025PA): ")); int maxPSI = getNumber(menuTimeout); //x second timeout if (maxPSI < 0 || maxPSI > 30) - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); else sensorSetting->maximumPSI = maxPSI; } @@ -2041,68 +2066,68 @@ void menuConfigure_SNGCJA5(void *configPtr) while (1) { - Serial.println(); - Serial.println(F("Menu: Configure SNGCJA5 Particle Sensor")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure SNGCJA5 Particle Sensor")); - Serial.print(F("1) Sensor Logging: ")); - if (sensorSetting->log == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (sensorSetting->log == true) { - Serial.print(F("2) Log Particle Mass Density 1.0um (ug/m^3): ")); - if (sensorSetting->logPM1 == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("2) Log Particle Mass Density 1.0um (ug/m^3): ")); + if (sensorSetting->logPM1 == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("3) Log Particle Mass Density 2.5um (ug/m^3): ")); - if (sensorSetting->logPM25 == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("3) Log Particle Mass Density 2.5um (ug/m^3): ")); + if (sensorSetting->logPM25 == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("4) Log Particle Mass Density 10.0um (ug/m^3): ")); - if (sensorSetting->logPM10 == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("4) Log Particle Mass Density 10.0um (ug/m^3): ")); + if (sensorSetting->logPM10 == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("5) Log Particle Count 0.5um: ")); - if (sensorSetting->logPC05 == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("5) Log Particle Count 0.5um: ")); + if (sensorSetting->logPC05 == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("6) Log Particle Count 1.0um: ")); - if (sensorSetting->logPC1 == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("6) Log Particle Count 1.0um: ")); + if (sensorSetting->logPC1 == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("7) Log Particle Count 2.5um: ")); - if (sensorSetting->logPC25 == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("7) Log Particle Count 2.5um: ")); + if (sensorSetting->logPC25 == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("8) Log Particle Count 5.0um: ")); - if (sensorSetting->logPC50 == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("8) Log Particle Count 5.0um: ")); + if (sensorSetting->logPC50 == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("9) Log Particle Count 7.5um: ")); - if (sensorSetting->logPC75 == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("9) Log Particle Count 7.5um: ")); + if (sensorSetting->logPC75 == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("10) Log Particle Count 10.0um: ")); - if (sensorSetting->logPC10 == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("10) Log Particle Count 10.0um: ")); + if (sensorSetting->logPC10 == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("11) Log Combined Sensor Status: ")); - if (sensorSetting->logSensorStatus == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("11) Log Combined Sensor Status: ")); + if (sensorSetting->logSensorStatus == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("12) Log PhotoDiode Status: ")); - if (sensorSetting->logPDStatus == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("12) Log PhotoDiode Status: ")); + if (sensorSetting->logPDStatus == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("13) Log LaserDiode Status: ")); - if (sensorSetting->logLDStatus == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("13) Log LaserDiode Status: ")); + if (sensorSetting->logLDStatus == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("14) Log Fan Status: ")); - if (sensorSetting->logFanStatus == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("14) Log Fan Status: ")); + if (sensorSetting->logFanStatus == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); } - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); int incoming = getNumber(menuTimeout); //Timeout after x seconds @@ -2151,3 +2176,216 @@ void menuConfigure_SNGCJA5(void *configPtr) printUnknown(incoming); } } + +void menuConfigure_SGP40(void *configPtr) +{ + struct_SGP40 *sensorSetting = (struct_SGP40*)configPtr; + + while (1) + { + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure SGP40 VOC Sensor")); + + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); + + if (sensorSetting->log == true) + { + SerialPrint(F("2) Log VOC: ")); + if (sensorSetting->logVOC == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); + + SerialPrintf2("3) Sensor Compensation: Relative Humidity (%): %d\r\n", sensorSetting->RH); + + SerialPrintf2("4) Sensor Compensation: Temperature (C): %d\r\n", sensorSetting->T); + } + SerialPrintln(F("x) Exit")); + + int incoming = getNumber(menuTimeout); //Timeout after x seconds + + if (incoming == 1) + sensorSetting->log ^= 1; + else if (sensorSetting->log == true) + { + if (incoming == 2) + sensorSetting->logVOC ^= 1; + else if (incoming == 3) + { + SerialPrint(F("Enter the %RH for sensor compensation (0 to 100): ")); + int RH = getNumber(menuTimeout); //x second timeout + if (RH < 0 || RH > 100) + SerialPrintln(F("Error: Out of range")); + else + sensorSetting->RH = RH; + } + else if (incoming == 4) + { + SerialPrint(F("Enter the temperature (C) for sensor compensation (-45 to 130): ")); + int T = getNumber(menuTimeout); //x second timeout + if (T < -45 || T > 130) + SerialPrintln(F("Error: Out of range")); + else + sensorSetting->T = T; + } + else if (incoming == STATUS_PRESSED_X) + break; + else if (incoming == STATUS_GETNUMBER_TIMEOUT) + break; + else + printUnknown(incoming); + } + else if (incoming == STATUS_PRESSED_X) + break; + else if (incoming == STATUS_GETNUMBER_TIMEOUT) + break; + else + printUnknown(incoming); + } +} + +void menuConfigure_SDP3X(void *configPtr) +{ + struct_SDP3X *sensorSetting = (struct_SDP3X*)configPtr; + + while (1) + { + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure SDP3X Differential Pressure Sensor")); + + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); + + if (sensorSetting->log == true) + { + SerialPrint(F("2) Log Pressure: ")); + if (sensorSetting->logPressure == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); + + SerialPrint(F("3) Log Temperature: ")); + if (sensorSetting->logTemperature == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); + + SerialPrint(F("4) Temperature Compensation: ")); + if (sensorSetting->massFlow == true) SerialPrintln(F("Mass Flow")); + else SerialPrintln(F("Differential Pressure")); + + SerialPrint(F("5) Use Clock Stretching: ")); + if (sensorSetting->clockStretching == true) SerialPrintln(F("Yes")); + else SerialPrintln(F("No")); + } + SerialPrintln(F("x) Exit")); + + int incoming = getNumber(menuTimeout); //Timeout after x seconds + + if (incoming == 1) + sensorSetting->log ^= 1; + else if (sensorSetting->log == true) + { + if (incoming == 2) + sensorSetting->logPressure ^= 1; + else if (incoming == 3) + sensorSetting->logTemperature ^= 1; + else if (incoming == 4) + sensorSetting->massFlow ^= 1; + else if (incoming == 5) + sensorSetting->clockStretching ^= 1; + else if (incoming == STATUS_PRESSED_X) + break; + else if (incoming == STATUS_GETNUMBER_TIMEOUT) + break; + else + printUnknown(incoming); + } + else if (incoming == STATUS_PRESSED_X) + break; + else if (incoming == STATUS_GETNUMBER_TIMEOUT) + break; + else + printUnknown(incoming); + } +} + +void menuConfigure_MS5837(void *configPtr) +{ + struct_MS5837 *sensorSetting = (struct_MS5837*)configPtr; + + while (1) + { + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure MS5837 Pressure Sensor")); + + SerialPrint(F("Sensor Model: ")); + if (sensorSetting->model == true) SerialPrintln(F("MS5837-02BA / BlueRobotics Bar02: 2 Bar Absolute / 10m Depth")); + else SerialPrintln(F("MS5837-30BA / BlueRobotics Bar30: 30 Bar Absolute / 300m Depth")); + + SerialPrint(F("1) Sensor Logging: ")); + if (sensorSetting->log == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); + + if (sensorSetting->log == true) + { + SerialPrint(F("2) Log Pressure: ")); + if (sensorSetting->logPressure == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); + + SerialPrint(F("3) Log Temperature: ")); + if (sensorSetting->logTemperature == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); + + SerialPrint(F("4) Log Depth: ")); + if (sensorSetting->logDepth == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); + + SerialPrint(F("5) Log Altitude: ")); + if (sensorSetting->logAltitude == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); + + SerialPrintf2("6) Fluid Density (kg/m^3): %f\r\n", sensorSetting->fluidDensity); + + SerialPrintf2("7) Pressure Conversion Factor: %.02f\r\n", sensorSetting->conversion); + } + SerialPrintln(F("x) Exit")); + + int incoming = getNumber(menuTimeout); //Timeout after x seconds + + if (incoming == 1) + sensorSetting->log ^= 1; + else if (sensorSetting->log == true) + { + if (incoming == 2) + sensorSetting->logPressure ^= 1; + else if (incoming == 3) + sensorSetting->logTemperature ^= 1; + else if (incoming == 4) + sensorSetting->logDepth ^= 1; + else if (incoming == 5) + sensorSetting->logAltitude ^= 1; + else if (incoming == 6) + { + SerialPrint(F("Enter the Fluid Density (kg/m^3): ")); + double FD = getDouble(menuTimeout); //x second timeout + sensorSetting->fluidDensity = (float)FD; + } + else if (incoming == 7) + { + SerialPrint(F("Enter the Pressure Conversion Factor: ")); + double PCF = getDouble(menuTimeout); //x second timeout + sensorSetting->conversion = (float)PCF; + } + else if (incoming == STATUS_PRESSED_X) + break; + else if (incoming == STATUS_GETNUMBER_TIMEOUT) + break; + else + printUnknown(incoming); + } + else if (incoming == STATUS_PRESSED_X) + break; + else if (incoming == STATUS_GETNUMBER_TIMEOUT) + break; + else + printUnknown(incoming); + } +} diff --git a/Firmware/OpenLog_Artemis/menuDebug.ino b/Firmware/OpenLog_Artemis/menuDebug.ino index 18869fe..1a63549 100644 --- a/Firmware/OpenLog_Artemis/menuDebug.ino +++ b/Firmware/OpenLog_Artemis/menuDebug.ino @@ -2,14 +2,18 @@ void menuDebug() { while (1) { - Serial.println(); - Serial.println(F("Menu: Configure Debug Settings")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure Debug Settings")); - Serial.print(F("1) Debug Messages: ")); - if (settings.printDebugMessages == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Debug Messages: ")); + if (settings.printDebugMessages == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.println(F("x) Exit")); + SerialPrint(F("2) Reset on Zero Device Count: ")); + if (settings.resetOnZeroDeviceCount == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); + + SerialPrintln(F("x) Exit")); byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds @@ -17,6 +21,27 @@ void menuDebug() { settings.printDebugMessages ^= 1; } + else if (incoming == '2') + { + if (settings.resetOnZeroDeviceCount == false) + { + SerialPrintln(F("")); + SerialPrintln(F("Enabling resetOnZeroDeviceCount will cause the OLA to completely reset if no devices are found on the Qwiic bus.")); + SerialPrintln(F("Do not enable this option if you are only logging IMU or Serial data.")); + SerialPrintln(F("Are you sure? Press 'y' to confirm: ")); + byte bContinue = getByteChoice(menuTimeout); + if (bContinue == 'y') + { + settings.resetOnZeroDeviceCount ^= 1; + } + else + SerialPrintln(F("\"resetOnZeroDeviceCount\" aborted")); + } + else + { + settings.resetOnZeroDeviceCount ^= 1; + } + } else if (incoming == 'x') break; else if (incoming == STATUS_GETBYTE_TIMEOUT) diff --git a/Firmware/OpenLog_Artemis/menuIMU.ino b/Firmware/OpenLog_Artemis/menuIMU.ino index c88fae4..c91af34 100644 --- a/Firmware/OpenLog_Artemis/menuIMU.ino +++ b/Firmware/OpenLog_Artemis/menuIMU.ino @@ -2,158 +2,158 @@ void menuIMU() { while (1) { - Serial.println(); - Serial.println(F("Menu: Configure IMU")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure IMU")); - Serial.print(F("1) Sensor Logging: ")); - if (settings.enableIMU == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Sensor Logging: ")); + if (settings.enableIMU == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (settings.enableIMU == true) { - Serial.print(F("2) Accelerometer Logging: ")); - if (settings.logIMUAccel) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("2) Accelerometer Logging: ")); + if (settings.logIMUAccel) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("3) Gyro Logging: ")); - if (settings.logIMUGyro) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("3) Gyro Logging: ")); + if (settings.logIMUGyro) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("4) Magnotometer Logging: ")); - if (settings.logIMUMag) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("4) Magnetometer Logging: ")); + if (settings.logIMUMag) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("5) Temperature Logging: ")); - if (settings.logIMUTemp) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("5) Temperature Logging: ")); + if (settings.logIMUTemp) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (online.IMU == true) { - Serial.print(F("6) Accelerometer Full Scale: +/- ")); + SerialPrint(F("6) Accelerometer Full Scale: +/- ")); switch (settings.imuAccFSS) { case 0: - Serial.println(F("2g")); + SerialPrintln(F("2g")); break; case 1: - Serial.println(F("4g")); + SerialPrintln(F("4g")); break; case 2: - Serial.println(F("8g")); + SerialPrintln(F("8g")); break; case 3: - Serial.println(F("16g")); + SerialPrintln(F("16g")); break; default: - Serial.println(F("UNKNOWN")); + SerialPrintln(F("UNKNOWN")); break; } - Serial.print(F("7) Accelerometer Digital Low Pass Filter: ")); + SerialPrint(F("7) Accelerometer Digital Low Pass Filter: ")); if (settings.imuAccDLPF) { - Serial.println(F("Enabled")); - Serial.print(F("8) Accelerometer DLPF Bandwidth (Hz): ")); + SerialPrintln(F("Enabled")); + SerialPrint(F("8) Accelerometer DLPF Bandwidth (Hz): ")); switch (settings.imuAccDLPFBW) { case 0: - Serial.println(F("246.0 (3dB) 265.0 (Nyquist)")); + SerialPrintln(F("246.0 (3dB) 265.0 (Nyquist)")); break; case 1: - Serial.println(F("246.0 (3dB) 265.0 (Nyquist)")); + SerialPrintln(F("246.0 (3dB) 265.0 (Nyquist)")); break; case 2: - Serial.println(F("111.4 (3dB) 136.0 (Nyquist)")); + SerialPrintln(F("111.4 (3dB) 136.0 (Nyquist)")); break; case 3: - Serial.println(F("50.4 (3dB) 68.8 (Nyquist)")); + SerialPrintln(F("50.4 (3dB) 68.8 (Nyquist)")); break; case 4: - Serial.println(F("23.9 (3dB) 34.4 (Nyquist)")); + SerialPrintln(F("23.9 (3dB) 34.4 (Nyquist)")); break; case 5: - Serial.println(F("11.5 (3dB) 17.0 (Nyquist)")); + SerialPrintln(F("11.5 (3dB) 17.0 (Nyquist)")); break; case 6: - Serial.println(F("5.7 (3dB) 8.3 (Nyquist)")); + SerialPrintln(F("5.7 (3dB) 8.3 (Nyquist)")); break; case 7: - Serial.println(F("473 (3dB) 499 (Nyquist)")); + SerialPrintln(F("473 (3dB) 499 (Nyquist)")); break; default: - Serial.println(F("UNKNOWN")); + SerialPrintln(F("UNKNOWN")); break; } } else { - Serial.println(F("Disabled (Bandwidth is 1209 Hz (3dB) 1248 Hz (Nyquist))")); + SerialPrintln(F("Disabled (Bandwidth is 1209 Hz (3dB) 1248 Hz (Nyquist))")); } - Serial.print(F("9) Gyro Full Scale: +/- ")); + SerialPrint(F("9) Gyro Full Scale: +/- ")); switch (settings.imuGyroFSS) { case 0: - Serial.println(F("250dps")); + SerialPrintln(F("250dps")); break; case 1: - Serial.println(F("500dps")); + SerialPrintln(F("500dps")); break; case 2: - Serial.println(F("1000dps")); + SerialPrintln(F("1000dps")); break; case 3: - Serial.println(F("2000dps")); + SerialPrintln(F("2000dps")); break; default: - Serial.println(F("UNKNOWN")); + SerialPrintln(F("UNKNOWN")); break; } - Serial.print(F("10) Gyro Digital Low Pass Filter: ")); + SerialPrint(F("10) Gyro Digital Low Pass Filter: ")); if (settings.imuGyroDLPF) { - Serial.println(F("Enabled")); - Serial.print(F("11) Gyro DLPF Bandwidth (Hz): ")); + SerialPrintln(F("Enabled")); + SerialPrint(F("11) Gyro DLPF Bandwidth (Hz): ")); switch (settings.imuGyroDLPFBW) { case 0: - Serial.println(F("196.6 (3dB) 229.8 (Nyquist)")); + SerialPrintln(F("196.6 (3dB) 229.8 (Nyquist)")); break; case 1: - Serial.println(F("151.8 (3dB) 187.6 (Nyquist)")); + SerialPrintln(F("151.8 (3dB) 187.6 (Nyquist)")); break; case 2: - Serial.println(F("119.5 (3dB) 154.3 (Nyquist)")); + SerialPrintln(F("119.5 (3dB) 154.3 (Nyquist)")); break; case 3: - Serial.println(F("51.2 (3dB) 73.3 (Nyquist)")); + SerialPrintln(F("51.2 (3dB) 73.3 (Nyquist)")); break; case 4: - Serial.println(F("23.9 (3dB) 35.9 (Nyquist)")); + SerialPrintln(F("23.9 (3dB) 35.9 (Nyquist)")); break; case 5: - Serial.println(F("11.6 (3dB) 17.8 (Nyquist)")); + SerialPrintln(F("11.6 (3dB) 17.8 (Nyquist)")); break; case 6: - Serial.println(F("5.7 (3dB) 8.9 (Nyquist)")); + SerialPrintln(F("5.7 (3dB) 8.9 (Nyquist)")); break; case 7: - Serial.println(F("361.4 (3dB) 376.5 (Nyquist)")); + SerialPrintln(F("361.4 (3dB) 376.5 (Nyquist)")); break; default: - Serial.println(F("UNKNOWN")); + SerialPrintln(F("UNKNOWN")); break; } } else { - Serial.println(F("Disabled (Bandwidth is 12106 Hz (3dB) 12316 Hz (Nyquist))")); + SerialPrintln(F("Disabled (Bandwidth is 12106 Hz (3dB) 12316 Hz (Nyquist))")); } } } - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); int incoming = getNumber(menuTimeout); //Timeout after x seconds @@ -175,14 +175,14 @@ void menuIMU() settings.logIMUTemp ^= 1; else if ((incoming == 6) && (online.IMU == true)) { - Serial.println(F("Enter Accelerometer Full Scale (0 to 3): ")); - Serial.println(F("0: +/- 2g")); - Serial.println(F("1: +/- 4g")); - Serial.println(F("2: +/- 8g")); - Serial.println(F("3: +/- 16g")); + SerialPrintln(F("Enter Accelerometer Full Scale (0 to 3): ")); + SerialPrintln(F("0: +/- 2g")); + SerialPrintln(F("1: +/- 4g")); + SerialPrintln(F("2: +/- 8g")); + SerialPrintln(F("3: +/- 16g")); int afs = getNumber(menuTimeout); //x second timeout if (afs < 0 || afs > 3) - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); else { settings.imuAccFSS = afs; @@ -192,7 +192,7 @@ void menuIMU() ICM_20948_Status_e retval = myICM.setFullScale((ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), FSS); if (retval != ICM_20948_Stat_Ok) { - Serial.println(F("Error: Could not configure the IMU!")); + SerialPrintln(F("Error: Could not configure the IMU!")); } } } @@ -202,23 +202,23 @@ void menuIMU() ICM_20948_Status_e retval = myICM.enableDLPF(ICM_20948_Internal_Acc, settings.imuAccDLPF); if (retval != ICM_20948_Stat_Ok) { - Serial.println(F("Error: Could not configure the IMU!")); + SerialPrintln(F("Error: Could not configure the IMU!")); } } else if ((incoming == 8) && (online.IMU == true) && (settings.imuAccDLPF == true)) { - Serial.println(F("Enter Accelerometer DLPF Bandwidth (0 to 7): ")); - Serial.println(F("0: 246.0 (3dB) 265.0 (Nyquist) (Hz)")); - Serial.println(F("1: 246.0 (3dB) 265.0 (Nyquist) (Hz)")); - Serial.println(F("2: 111.4 (3dB) 136.0 (Nyquist) (Hz)")); - Serial.println(F("3: 50.4 (3dB) 68.8 (Nyquist) (Hz)")); - Serial.println(F("4: 23.9 (3dB) 34.4 (Nyquist) (Hz)")); - Serial.println(F("5: 11.5 (3dB) 17.0 (Nyquist) (Hz)")); - Serial.println(F("6: 5.7 (3dB) 8.3 (Nyquist) (Hz)")); - Serial.println(F("7: 473 (3dB) 499 (Nyquist) (Hz)")); + SerialPrintln(F("Enter Accelerometer DLPF Bandwidth (0 to 7): ")); + SerialPrintln(F("0: 246.0 (3dB) 265.0 (Nyquist) (Hz)")); + SerialPrintln(F("1: 246.0 (3dB) 265.0 (Nyquist) (Hz)")); + SerialPrintln(F("2: 111.4 (3dB) 136.0 (Nyquist) (Hz)")); + SerialPrintln(F("3: 50.4 (3dB) 68.8 (Nyquist) (Hz)")); + SerialPrintln(F("4: 23.9 (3dB) 34.4 (Nyquist) (Hz)")); + SerialPrintln(F("5: 11.5 (3dB) 17.0 (Nyquist) (Hz)")); + SerialPrintln(F("6: 5.7 (3dB) 8.3 (Nyquist) (Hz)")); + SerialPrintln(F("7: 473 (3dB) 499 (Nyquist) (Hz)")); int afbw = getNumber(menuTimeout); //x second timeout if (afbw < 0 || afbw > 7) - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); else { settings.imuAccDLPFBW = afbw; @@ -228,20 +228,20 @@ void menuIMU() ICM_20948_Status_e retval = myICM.setDLPFcfg((ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), dlpcfg); if (retval != ICM_20948_Stat_Ok) { - Serial.println(F("Error: Could not configure the IMU!")); + SerialPrintln(F("Error: Could not configure the IMU!")); } } } else if ((incoming == 9) && (online.IMU == true)) { - Serial.println(F("Enter Gyro Full Scale (0 to 3): ")); - Serial.println(F("0: +/- 250dps")); - Serial.println(F("1: +/- 500dps")); - Serial.println(F("2: +/- 1000dps")); - Serial.println(F("3: +/- 2000dps")); + SerialPrintln(F("Enter Gyro Full Scale (0 to 3): ")); + SerialPrintln(F("0: +/- 250dps")); + SerialPrintln(F("1: +/- 500dps")); + SerialPrintln(F("2: +/- 1000dps")); + SerialPrintln(F("3: +/- 2000dps")); int gfs = getNumber(menuTimeout); //x second timeout if (gfs < 0 || gfs > 3) - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); else { settings.imuGyroFSS = gfs; @@ -251,7 +251,7 @@ void menuIMU() ICM_20948_Status_e retval = myICM.setFullScale((ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), FSS); if (retval != ICM_20948_Stat_Ok) { - Serial.println(F("Error: Could not configure the IMU!")); + SerialPrintln(F("Error: Could not configure the IMU!")); } } } @@ -261,23 +261,23 @@ void menuIMU() ICM_20948_Status_e retval = myICM.enableDLPF(ICM_20948_Internal_Gyr, settings.imuGyroDLPF); if (retval != ICM_20948_Stat_Ok) { - Serial.println(F("Error: Could not configure the IMU!")); + SerialPrintln(F("Error: Could not configure the IMU!")); } } else if ((incoming == 11) && (online.IMU == true) && (settings.imuGyroDLPF == true)) { - Serial.println(F("Enter Gyro DLPF Bandwidth (0 to 7): ")); - Serial.println(F("0: 196.6 (3dB) 229.8 (Nyquist) (Hz)")); - Serial.println(F("1: 151.8 (3dB) 187.6 (Nyquist) (Hz)")); - Serial.println(F("2: 119.5 (3dB) 154.3 (Nyquist) (Hz)")); - Serial.println(F("3: 51.2 (3dB) 73.3 (Nyquist) (Hz)")); - Serial.println(F("4: 23.9 (3dB) 35.9 (Nyquist) (Hz)")); - Serial.println(F("5: 11.6 (3dB) 17.8 (Nyquist) (Hz)")); - Serial.println(F("6: 5.7 (3dB) 8.9 (Nyquist) (Hz)")); - Serial.println(F("7: 361.4 (3dB) 376.5 (Nyquist) (Hz)")); + SerialPrintln(F("Enter Gyro DLPF Bandwidth (0 to 7): ")); + SerialPrintln(F("0: 196.6 (3dB) 229.8 (Nyquist) (Hz)")); + SerialPrintln(F("1: 151.8 (3dB) 187.6 (Nyquist) (Hz)")); + SerialPrintln(F("2: 119.5 (3dB) 154.3 (Nyquist) (Hz)")); + SerialPrintln(F("3: 51.2 (3dB) 73.3 (Nyquist) (Hz)")); + SerialPrintln(F("4: 23.9 (3dB) 35.9 (Nyquist) (Hz)")); + SerialPrintln(F("5: 11.6 (3dB) 17.8 (Nyquist) (Hz)")); + SerialPrintln(F("6: 5.7 (3dB) 8.9 (Nyquist) (Hz)")); + SerialPrintln(F("7: 361.4 (3dB) 376.5 (Nyquist) (Hz)")); int gfbw = getNumber(menuTimeout); //x second timeout if (gfbw < 0 || gfbw > 7) - Serial.println(F("Error: Out of range")); + SerialPrintln(F("Error: Out of range")); else { settings.imuGyroDLPFBW = gfbw; @@ -287,7 +287,7 @@ void menuIMU() ICM_20948_Status_e retval = myICM.setDLPFcfg((ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), dlpcfg); if (retval != ICM_20948_Stat_Ok) { - Serial.println(F("Error: Could not configure the IMU!")); + SerialPrintln(F("Error: Could not configure the IMU!")); } } } diff --git a/Firmware/OpenLog_Artemis/menuMain.ino b/Firmware/OpenLog_Artemis/menuMain.ino index bee9a82..0cc2202 100644 --- a/Firmware/OpenLog_Artemis/menuMain.ino +++ b/Firmware/OpenLog_Artemis/menuMain.ino @@ -4,37 +4,38 @@ void menuMain() { while (1) { - Serial.println(); - Serial.println(F("Menu: Main Menu")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Main Menu")); - Serial.println(F("1) Configure Terminal Output")); + SerialPrintln(F("1) Configure Terminal Output")); - Serial.println(F("2) Configure Time Stamp")); + SerialPrintln(F("2) Configure Time Stamp")); - Serial.println(F("3) Configure IMU Logging")); + SerialPrintln(F("3) Configure IMU Logging")); - Serial.println(F("4) Configure Serial Logging")); + if (settings.useTxRxPinsForTerminal == false) + SerialPrintln(F("4) Configure Serial Logging")); - Serial.println(F("5) Configure Analog Logging")); + SerialPrintln(F("5) Configure Analog Logging")); - Serial.println(F("6) Detect / Configure Attached Devices")); + SerialPrintln(F("6) Detect / Configure Attached Devices")); - Serial.println(F("7) Configure Power Options")); + SerialPrintln(F("7) Configure Power Options")); - Serial.println(F("h) Print Sensor Helper Text (and return to logging)")); + SerialPrintln(F("h) Print Sensor Helper Text (and return to logging)")); if (settings.enableSD && online.microSD) - Serial.println(F("s) SD Card File Transfer")); + SerialPrintln(F("s) SD Card File Transfer")); - Serial.println(F("r) Reset all settings to default")); + SerialPrintln(F("r) Reset all settings to default")); - Serial.println(F("q) Quit: Close log files and power down")); + SerialPrintln(F("q) Quit: Close log files and power down")); - //Serial.println(F("d) Debug Menu")); + //SerialPrintln(F("d) Debug Menu")); - Serial.println(F("x) Return to logging")); + SerialPrintln(F("x) Return to logging")); - byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds + byte incoming = getByteChoice(menuTimeout, true); //Get byte choice and set DSERIAL & ZSERIAL if (incoming == '1') menuLogRate(); @@ -42,7 +43,7 @@ void menuMain() menuTimeStamp(); else if (incoming == '3') menuIMU(); - else if (incoming == '4') + else if ((incoming == '4') && (settings.useTxRxPinsForTerminal == false)) menuSerialLogging(); else if (incoming == '5') menuAnalogLogging(); @@ -75,11 +76,11 @@ void menuMain() serialDataFile.close(); } - Serial.println(); - Serial.println(); + SerialPrintln(F("")); + SerialPrintln(F("")); sdCardMenu(); // Located in zmodem.ino - Serial.println(); - Serial.println(); + SerialPrintln(F("")); + SerialPrintln(F("")); if (online.dataLogging == true) { @@ -96,7 +97,7 @@ void menuMain() } else if (incoming == 'r') { - Serial.println(F("\r\nResetting to factory defaults. Press 'y' to confirm:")); + SerialPrintln(F("\r\nResetting to factory defaults. Press 'y' to confirm: ")); byte bContinue = getByteChoice(menuTimeout); if (bContinue == 'y') { @@ -106,17 +107,19 @@ void menuMain() if (sd.exists("OLA_deviceSettings.txt")) sd.remove("OLA_deviceSettings.txt"); - Serial.print(F("Settings erased. Please reset OpenLog Artemis and open a terminal at ")); + SerialPrint(F("Settings erased. Please reset OpenLog Artemis and open a terminal at ")); Serial.print((String)settings.serialTerminalBaudRate); - Serial.println(F("bps...")); + if (settings.useTxRxPinsForTerminal == true) + SerialLog.print((String)settings.serialTerminalBaudRate); + SerialPrintln(F("bps...")); while (1); } else - Serial.println(F("Reset aborted")); + SerialPrintln(F("Reset aborted")); } else if (incoming == 'q') { - Serial.println(F("\r\nQuit? Press 'y' to confirm:")); + SerialPrintln(F("\r\nQuit? Press 'y' to confirm:")); byte bContinue = getByteChoice(menuTimeout); if (bContinue == 'y') { @@ -133,14 +136,16 @@ void menuMain() updateDataFileAccess(&serialDataFile); // Update the file access time & date serialDataFile.close(); } - Serial.print(F("Log files are closed. Please reset OpenLog Artemis and open a terminal at ")); + SerialPrint(F("Log files are closed. Please reset OpenLog Artemis and open a terminal at ")); Serial.print((String)settings.serialTerminalBaudRate); - Serial.println(F("bps...")); + if (settings.useTxRxPinsForTerminal == true) + SerialLog.print((String)settings.serialTerminalBaudRate); + SerialPrintln(F("bps...")); delay(sdPowerDownDelay); // Give the SD card time to shut down powerDown(); } else - Serial.println(F("Quit aborted")); + SerialPrintln(F("Quit aborted")); } else if (incoming == 'x') break; @@ -158,11 +163,17 @@ void menuMain() while (Serial.available()) Serial.read(); //Empty buffer of any newline chars + if (settings.useTxRxPinsForTerminal == true) + while (SerialLog.available()) SerialLog.read(); //Empty buffer of any newline chars + //Reset measurements measurementCount = 0; totalCharactersPrinted = 0; - //If we are sleeping between readings then we cannot rely on millis() as it is powered down. Used RTC instead. - if (settings.usBetweenReadings >= maxUsBeforeSleep) + //If we are sleeping between readings then we cannot rely on millis() as it is powered down + //Use RTC instead + if (((settings.useGPIO11ForTrigger == false) && (settings.usBetweenReadings >= maxUsBeforeSleep)) + || (settings.useGPIO11ForFastSlowLogging == true) + || (settings.useRTCForFastSlowLogging == true)) measurementStartTime = rtcMillis(); else measurementStartTime = millis(); diff --git a/Firmware/OpenLog_Artemis/menuPower.ino b/Firmware/OpenLog_Artemis/menuPower.ino index 870895f..f3721da 100644 --- a/Firmware/OpenLog_Artemis/menuPower.ino +++ b/Firmware/OpenLog_Artemis/menuPower.ino @@ -2,34 +2,34 @@ void menuPower() { while (1) { - Serial.println(); - Serial.println(F("Menu: Configure Power Options")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure Power Options")); - Serial.print(F("1) Turn off Qwiic bus power between readings (>2s): ")); - if (settings.powerDownQwiicBusBetweenReads == true) Serial.println(F("Yes")); - else Serial.println(F("No")); + SerialPrint(F("1) Turn off Qwiic bus power between readings (>2s): ")); + if (settings.powerDownQwiicBusBetweenReads == true) SerialPrintln(F("Yes")); + else SerialPrintln(F("No")); - Serial.print(F("2) Use pin 32 to Stop Logging: ")); - if (settings.useGPIO32ForStopLogging == true) Serial.println(F("Yes")); - else Serial.println(F("No")); + SerialPrint(F("2) Use pin 32 to Stop Logging: ")); + if (settings.useGPIO32ForStopLogging == true) SerialPrintln(F("Yes")); + else SerialPrintln(F("No")); #if(HARDWARE_VERSION_MAJOR >= 1) - Serial.print(F("3) Power LED During Sleep: ")); - if (settings.enablePwrLedDuringSleep == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("3) Power LED During Sleep: ")); + if (settings.enablePwrLedDuringSleep == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("4) Low Battery Voltage Detection: ")); - if (settings.enableLowBatteryDetection == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("4) Low Battery Voltage Detection: ")); + if (settings.enableLowBatteryDetection == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("5) Low Battery Threshold (V): ")); - Serial.printf("%.2f\r\n", settings.lowBatteryThreshold); + SerialPrint(F("5) Low Battery Threshold (V): ")); + SerialPrintf2("%.2f\r\n", settings.lowBatteryThreshold); - Serial.print(F("6) VIN measurement correction factor: ")); - Serial.printf("%.3f\r\n", settings.vinCorrectionFactor); + SerialPrint(F("6) VIN measurement correction factor: ")); + SerialPrintf2("%.3f\r\n", settings.vinCorrectionFactor); #endif - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds @@ -69,22 +69,22 @@ void menuPower() } else if (incoming == '5') { - Serial.println(F("Please enter the new low battery threshold:")); + SerialPrintln(F("Please enter the new low battery threshold:")); float tempBT = (float)getDouble(menuTimeout); //Timeout after x seconds if ((tempBT < 3.0) || (tempBT > 6.0)) - Serial.println(F("Error: Threshold out of range")); + SerialPrintln(F("Error: Threshold out of range")); else settings.lowBatteryThreshold = tempBT; } else if (incoming == '6') { - Serial.println(F("Please measure the voltage on the MEAS pin and enter it here:")); + SerialPrintln(F("Please measure the voltage on the MEAS pin and enter it here:")); float tempCF = (float)getDouble(menuTimeout); //Timeout after x seconds int div3 = analogRead(PIN_VIN_MONITOR); //Read VIN across a 1/3 resistor divider float vin = (float)div3 * 3.0 * 2.0 / 16384.0; //Convert 1/3 VIN to VIN (14-bit resolution) tempCF = tempCF / vin; //Calculate the new correction factor if ((tempCF < 1.0) || (tempCF > 2.0)) - Serial.println(F("Error: Correction factor out of range")); + SerialPrintln(F("Error: Correction factor out of range")); else settings.vinCorrectionFactor = tempCF; } diff --git a/Firmware/OpenLog_Artemis/menuSerialLogging.ino b/Firmware/OpenLog_Artemis/menuSerialLogging.ino index af80f14..350bcea 100644 --- a/Firmware/OpenLog_Artemis/menuSerialLogging.ino +++ b/Firmware/OpenLog_Artemis/menuSerialLogging.ino @@ -4,29 +4,67 @@ void menuSerialLogging() { while (1) { - Serial.println(); - Serial.println(F("Menu: Configure Serial Logging")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure Serial Logging")); - Serial.print(F("1) Log serial data: ")); - if (settings.logSerial == true) Serial.println(F("Enabled, analog logging on RX/A13 pin disabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Log serial data: ")); + if (settings.logSerial == true) SerialPrintln(F("Enabled, analog logging on RX/A13 pin disabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("2) Output serial data to TX pin: ")); - if (settings.outputSerial == true) Serial.println(F("Enabled, analog logging on TX/A12 pin disabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("2) Output serial data to TX pin: ")); + if (settings.outputSerial == true) SerialPrintln(F("Enabled, analog logging on TX/A12 pin disabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("3) zmodem start delay: ")); + SerialPrint(F("3) zmodem start delay: ")); Serial.print(settings.zmodemStartDelay); - Serial.println(F(" seconds")); + if (settings.useTxRxPinsForTerminal == true) + SerialLog.print(settings.zmodemStartDelay); + SerialPrintln(F(" seconds")); if ((settings.logSerial == true) || (settings.outputSerial == true)) { - Serial.print(F("4) Set serial baud rate: ")); + SerialPrint(F("4) Set serial baud rate: ")); Serial.print(settings.serialLogBaudRate); - Serial.println(F(" bps")); + if (settings.useTxRxPinsForTerminal == true) + SerialLog.print(settings.zmodemStartDelay); + SerialPrintln(F(" bps")); } - Serial.println(F("x) Exit")); + if (settings.logSerial == true) // Suggested by @DennisMelamed in Issue #63 + { + SerialPrint(F("5) Add RTC timestamp when token is received: ")); + if (settings.timestampSerial == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); + + SerialPrint(F("6) Timestamp token: ")); + Serial.print(settings.timeStampToken); + if (settings.useTxRxPinsForTerminal == true) + SerialLog.print(settings.timeStampToken); + SerialPrint(F(" (Decimal)")); + switch (settings.timeStampToken) + { + case 0x00: + SerialPrintln(F(" = NULL")); + break; + case 0x03: + SerialPrintln(F(" = End of Text")); + break; + case 0x0A: + SerialPrintln(F(" = Line Feed")); + break; + case 0x0D: + SerialPrintln(F(" = Carriage Return")); + break; + case 0x1B: + SerialPrintln(F(" = Escape")); + break; + default: + SerialPrintln(F("")); + break; + } + } + + SerialPrintln(F("x) Exit")); byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds @@ -69,11 +107,11 @@ void menuSerialLogging() } else if (incoming == '3') { - Serial.print(F("Enter zmodem start delay (5 to 60): ")); + SerialPrint(F("Enter zmodem start delay (5 to 60): ")); int newDelay = getNumber(menuTimeout); //Timeout after x seconds if (newDelay < 5 || newDelay > 60) { - Serial.println(F("Error: start delay out of range")); + SerialPrintln(F("Error: start delay out of range")); } else { @@ -84,11 +122,11 @@ void menuSerialLogging() { if (incoming == '4') { - Serial.print(F("Enter baud rate (1200 to 500000): ")); + SerialPrint(F("Enter baud rate (1200 to 500000): ")); int newBaud = getNumber(menuTimeout); //Timeout after x seconds if (newBaud < 1200 || newBaud > 500000) { - Serial.println(F("Error: baud rate out of range")); + SerialPrintln(F("Error: baud rate out of range")); } else { @@ -96,6 +134,21 @@ void menuSerialLogging() SerialLog.begin(settings.serialLogBaudRate); } } + else if (incoming == '5') + settings.timestampSerial ^= 1; + else if (incoming == '6') + { + SerialPrint(F("Enter the timestamp token in decimal (0 to 255): ")); + int newToken = getNumber(menuTimeout); //Timeout after x seconds + if (newToken < 0 || newToken > 255) + { + SerialPrintln(F("Error: token out of range")); + } + else + { + settings.timeStampToken = (uint8_t)newToken; + } + } else if (incoming == 'x') return; else if (incoming == STATUS_GETBYTE_TIMEOUT) diff --git a/Firmware/OpenLog_Artemis/menuTerminal.ino b/Firmware/OpenLog_Artemis/menuTerminal.ino index 6b9775d..da2059e 100644 --- a/Firmware/OpenLog_Artemis/menuTerminal.ino +++ b/Firmware/OpenLog_Artemis/menuTerminal.ino @@ -2,92 +2,137 @@ void menuLogRate() { while (1) { - Serial.println(); - Serial.println(F("Menu: Configure Terminal Output")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure Terminal Output")); - Serial.print(F("1) Log to microSD: ")); - if (settings.logData == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Log to microSD: ")); + if (settings.logData == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("2) Log to Terminal: ")); - if (settings.enableTerminalOutput == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("2) Log to Terminal: ")); + if (settings.enableTerminalOutput == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("3) Set Serial Baud Rate: ")); + SerialPrint(F("3) Set Serial Terminal Baud Rate: ")); Serial.print(settings.serialTerminalBaudRate); - Serial.println(F(" bps")); + if (settings.useTxRxPinsForTerminal == true) + SerialLog.print(settings.serialTerminalBaudRate); + SerialPrintln(F(" bps")); if (settings.useGPIO11ForTrigger == false) { - Serial.print(F("4) Set Log Rate in Hz: ")); - if (settings.logMaxRate == true) Serial.println(F("Max rate enabled")); + SerialPrint(F("4) Set Log Rate in Hz: ")); + if (settings.logMaxRate == true) SerialPrintln(F("Max rate enabled")); else { if (settings.usBetweenReadings < 1000000ULL) //Take more than one measurement per second { //Display Integer Hertz int logRate = (int)(1000000ULL / settings.usBetweenReadings); - Serial.printf("%d\r\n", logRate); + SerialPrintf2("%d\r\n", logRate); } else { //Display fractional Hertz uint32_t logRateSeconds = (uint32_t)(settings.usBetweenReadings / 1000000ULL); - Serial.printf("%.06lf\r\n", 1.0 / logRateSeconds); + SerialPrintf2("%.06lf\r\n", 1.0 / logRateSeconds); } } - Serial.print(F("5) Set Log Rate in seconds between readings: ")); - if (settings.logMaxRate == true) Serial.println(F("Max rate enabled")); + SerialPrint(F("5) Set Log Rate in seconds between readings: ")); + if (settings.logMaxRate == true) SerialPrintln(F("Max rate enabled")); else { if (settings.usBetweenReadings > 1000000ULL) //Take more than one measurement per second { uint32_t interval = (uint32_t)(settings.usBetweenReadings / 1000000ULL); - Serial.printf("%d\r\n", interval); + SerialPrintf2("%d\r\n", interval); } else { float rate = (float)(settings.usBetweenReadings / 1000000.0); - Serial.printf("%.06f\r\n", rate); + SerialPrintf2("%.06f\r\n", rate); } } - Serial.print(F("6) Enable maximum logging: ")); - if (settings.logMaxRate == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("6) Enable maximum logging: ")); + if (settings.logMaxRate == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); } - Serial.print(F("7) Output Actual Hertz: ")); - if (settings.logHertz == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("7) Output Actual Hertz: ")); + if (settings.logHertz == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("8) Output Column Titles: ")); - if (settings.showHelperText == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("8) Output Column Titles: ")); + if (settings.showHelperText == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("9) Output Measurement Count: ")); - if (settings.printMeasurementCount == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("9) Output Measurement Count: ")); + if (settings.printMeasurementCount == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("10) Open New Log Files After (s): ")); - Serial.printf("%d", settings.openNewLogFilesAfter); - if (settings.openNewLogFilesAfter == 0) Serial.println(F(" (Never)")); - else Serial.println(); + SerialPrint(F("10) Open New Log Files After (s): ")); + SerialPrintf2("%d", settings.openNewLogFilesAfter); + if (settings.openNewLogFilesAfter == 0) SerialPrintln(F(" (Never)")); + else SerialPrintln(F("")); - Serial.print(F("11) Frequent log file access timestamps: ")); - if (settings.frequentFileAccessTimestamps == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("11) Frequent log file access timestamps: ")); + if (settings.frequentFileAccessTimestamps == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("12) Use pin 11 to trigger logging: ")); - if (settings.useGPIO11ForTrigger == true) Serial.println(F("Yes")); - else Serial.println(F("No")); + SerialPrint(F("12) Use pin 11 to trigger logging: ")); + if (settings.useGPIO11ForTrigger == true) SerialPrintln(F("Yes")); + else SerialPrintln(F("No")); - Serial.print(F("13) Logging is triggered when the signal on pin 11 is: ")); - if (settings.fallingEdgeTrigger == true) Serial.println(F("Falling")); - else Serial.println(F("Rising")); + SerialPrint(F("13) Logging is triggered when the signal on pin 11 is: ")); + if (settings.fallingEdgeTrigger == true) SerialPrintln(F("Falling")); + else SerialPrintln(F("Rising")); - Serial.println(F("x) Exit")); + SerialPrint(F("14) Use TX and RX pins for Terminal: ")); + if (settings.useTxRxPinsForTerminal == true) + { + SerialPrintln(F("Enabled")); + SerialPrintln(F(" Analog logging on TX/A12 and RX/A13 is permanently disabled")); + SerialPrintln(F(" Serial logging on RX/A13 is permanently disabled")); + } + else SerialPrintln(F("Disabled")); + + SerialPrint(F("15) Use Pin 11 to control fast/slow logging: ")); + if (settings.useGPIO11ForFastSlowLogging == true) SerialPrintln(F("Yes")); + else SerialPrintln(F("No")); + + if (settings.useGPIO11ForFastSlowLogging == true) + { + SerialPrint(F("16) Log slowly when Pin 11 is: ")); + if (settings.slowLoggingWhenPin11Is == true) SerialPrintln(F("High")); + else SerialPrintln(F("Low")); + } + + SerialPrint(F("17) Use RTC to control fast/slow logging: ")); + if (settings.useRTCForFastSlowLogging == true) SerialPrintln(F("Yes")); + else SerialPrintln(F("No")); + + if ((settings.useGPIO11ForFastSlowLogging == true) || (settings.useRTCForFastSlowLogging == true)) + { + SerialPrint(F("18) Slow logging interval (seconds): ")); + SerialPrintf2("%d\r\n", settings.slowLoggingIntervalSeconds); + } + + if (settings.useRTCForFastSlowLogging == true) + { + SerialPrint(F("19) Slow logging starts at: ")); + int slowHour = settings.slowLoggingStartMOD / 60; + int slowMin = settings.slowLoggingStartMOD % 60; + SerialPrintf3("%02d:%02d\r\n", slowHour, slowMin); + + SerialPrint(F("20) Slow logging ends at: ")); + slowHour = settings.slowLoggingStopMOD / 60; + slowMin = settings.slowLoggingStopMOD % 60; + SerialPrintf3("%02d:%02d\r\n", slowHour, slowMin); + } + + SerialPrintln(F("x) Exit")); int incoming = getNumber(menuTimeout); //Timeout after x seconds @@ -97,18 +142,18 @@ void menuLogRate() settings.enableTerminalOutput ^= 1; else if (incoming == 3) { - Serial.print(F("Enter baud rate (1200 to 500000): ")); + SerialPrint(F("Enter baud rate (1200 to 500000): ")); int newBaud = getNumber(menuTimeout); //Timeout after x seconds if (newBaud < 1200 || newBaud > 500000) { - Serial.println(F("Error: baud rate out of range")); + SerialPrintln(F("Error: baud rate out of range")); } else { settings.serialTerminalBaudRate = newBaud; recordSystemSettings(); //Normally recorded upon all menu exits recordDeviceSettingsToFile(); //Normally recorded upon all menu exits - Serial.printf("Terminal now set at %dbps. Please reset device and open terminal at new baud rate. Freezing...\r\n", settings.serialTerminalBaudRate); + SerialPrintf2("Terminal now set at %dbps. Please reset device and open terminal at new baud rate. Freezing...\r\n", settings.serialTerminalBaudRate); while (1); } } @@ -121,10 +166,10 @@ void menuLogRate() if (maxOutputRate < 10) maxOutputRate = 10; //TODO this is forced. Needed when multi seconds between readings. - Serial.printf("How many readings per second would you like to log? (Current max is %d): ", maxOutputRate); + SerialPrintf2("How many readings per second would you like to log? (Current max is %d): ", maxOutputRate); int tempRPS = getNumber(menuTimeout); //Timeout after x seconds if (tempRPS < 1 || tempRPS > maxOutputRate) - Serial.println(F("Error: Readings Per Second out of range")); + SerialPrintln(F("Error: Readings Per Second out of range")); else settings.usBetweenReadings = 1000000ULL / ((uint64_t)tempRPS); } @@ -136,10 +181,10 @@ void menuLogRate() //The Deep Sleep duration is set with am_hal_stimer_compare_delta_set, the duration of which is uint32_t //So the maximum we can sleep for is 2^32 / 32768 = 131072 seconds = 36.4 hours //Let's limit this to 36 hours = 129600 seconds - Serial.println(F("How many seconds would you like to sleep between readings? (1 to 129,600):")); + SerialPrintln(F("How many seconds would you like to wait between readings? (1 to 129,600):")); int64_t tempSeconds = getNumber(menuTimeout); //Timeout after x seconds if (tempSeconds < 1 || tempSeconds > 129600) - Serial.println(F("Error: Readings Per Second out of range")); + SerialPrintln(F("Error: logging interval out of range")); else settings.usBetweenReadings = 1000000ULL * ((uint64_t)tempSeconds); } @@ -150,7 +195,7 @@ void menuLogRate() { if (settings.logMaxRate == false) { - Serial.println(F("\r\nEnabling max log rate will disable the IMU, \r\nterminal output, and serial logging. \r\nOnly analog values will be logged. Continue?")); + SerialPrintln(F("\r\nEnabling max log rate will disable the IMU, \r\nterminal output, and serial logging. \r\nOnly analog values will be logged. Continue?")); byte bContinue = getByteChoice(menuTimeout); if (bContinue == 'y') { @@ -168,7 +213,7 @@ void menuLogRate() recordSystemSettings(); //Normally recorded upon all menu exits recordDeviceSettingsToFile(); //Normally recorded upon all menu exits - Serial.println(F("OpenLog Artemis configured for max data rate. Please reset. Freezing...")); + SerialPrintln(F("OpenLog Artemis configured for max data rate. Please reset. Freezing...")); while (1); } } @@ -187,10 +232,10 @@ void menuLogRate() settings.printMeasurementCount ^= 1; else if (incoming == 10) { - Serial.println(F("Open new log files after this many seconds (0 or 10 to 129,600) (0 = Never):")); + SerialPrintln(F("Open new log files after this many seconds (0 or 10 to 129,600) (0 = Never):")); int64_t tempSeconds = getNumber(menuTimeout); //Timeout after x seconds if ((tempSeconds < 0) || ((tempSeconds > 0) && (tempSeconds < 10)) || (tempSeconds > 129600ULL)) - Serial.println(F("Error: Invalid interval")); + SerialPrintln(F("Error: Invalid interval")); else settings.openNewLogFilesAfter = tempSeconds; } @@ -219,6 +264,8 @@ void menuLogRate() triggerEdgeSeen = false; // Make sure the flag is clear settings.logA11 = false; // Disable analog logging on pin 11 settings.logMaxRate = false; // Disable max rate logging + settings.useGPIO11ForFastSlowLogging = false; + settings.useRTCForFastSlowLogging = false; } } else if (incoming == 13) @@ -236,6 +283,154 @@ void menuLogRate() else settings.fallingEdgeTrigger ^= 1; // Interrupt is not currently enabled so simply invert the flag } + else if (incoming == 14) + { + if (settings.useTxRxPinsForTerminal == false) + { + SerialPrintln(F("")); + SerialPrintln(F("\"Use TX and RX pins for terminal\" can only be disabled by \"Reset all settings to default\".")); + SerialPrintln(F("Analog logging on TX/A12 and RX/A13 will be disabled.")); + SerialPrintln(F("Serial logging will be disabled.")); + SerialPrintln(F("Are you sure? Press 'y' to confirm: ")); + byte bContinue = getByteChoice(menuTimeout); + if (bContinue == 'y') + { + settings.useTxRxPinsForTerminal = true; + if (online.serialLogging == true) + { + serialDataFile.sync(); + updateDataFileAccess(&serialDataFile); // Update the file access time & date + serialDataFile.close(); + } + online.serialLogging = false; + settings.logSerial = false; + settings.outputSerial = false; + online.serialOutput = false; + settings.logA12 = false; + settings.logA13 = false; + SerialLog.begin(settings.serialTerminalBaudRate); // (Re)Start the serial port + } + else + SerialPrintln(F("\"Use TX and RX pins for terminal\" aborted")); + } + else + { + SerialPrintln(F("")); + SerialPrintln(F("\"Use TX and RX pins for terminal\" can not be disabled.")); + SerialPrintln(F("You need to use \"Reset all settings to default\" from the main menu.")); + SerialPrintln(F("")); + } + } + else if (incoming == 15) + { + if (settings.useGPIO11ForFastSlowLogging == false) // If the user is trying to enable Pin 11 fast / slow logging + { + settings.useGPIO11ForFastSlowLogging = true; + settings.useRTCForFastSlowLogging = false; + settings.logA11 = false; // Disable analog logging on pin 11 + pinMode(PIN_TRIGGER, INPUT_PULLUP); + delay(1); // Let the pin stabilize + // Disable triggering + if (settings.useGPIO11ForTrigger == true) + { + detachInterrupt(digitalPinToInterrupt(PIN_TRIGGER)); // Disable the interrupt + triggerEdgeSeen = false; // Make sure the flag is clear + } + settings.useGPIO11ForTrigger = false; + } + else // If the user is trying to disable Pin 11 fast / slow logging + { + settings.useGPIO11ForFastSlowLogging = false; + pinMode(PIN_TRIGGER, INPUT); // Remove the pull-up + } + } + else if (incoming == 16) + { + if (settings.useGPIO11ForFastSlowLogging == true) + { + settings.slowLoggingWhenPin11Is ^= 1; + } + } + else if (incoming == 17) + { + if (settings.useRTCForFastSlowLogging == false) // If the user is trying to enable RTC fast / slow logging + { + settings.useRTCForFastSlowLogging = true; + if (settings.useGPIO11ForFastSlowLogging == true) + { + pinMode(PIN_TRIGGER, INPUT); // Remove the pull-up + } + settings.useGPIO11ForFastSlowLogging = false; + settings.logA11 = false; // Disable analog logging on pin 11 + // Disable triggering + if (settings.useGPIO11ForTrigger == true) + { + detachInterrupt(digitalPinToInterrupt(PIN_TRIGGER)); // Disable the interrupt + pinMode(PIN_TRIGGER, INPUT); // Remove the pull-up + triggerEdgeSeen = false; // Make sure the flag is clear + } + settings.useGPIO11ForTrigger = false; + } + else // If the user is trying to disable RTC fast / slow logging + { + settings.useRTCForFastSlowLogging = false; + } + } + else if (incoming == 18) + { + if ((settings.useGPIO11ForFastSlowLogging == true) || (settings.useRTCForFastSlowLogging == true)) + { + //The Deep Sleep duration is set with am_hal_stimer_compare_delta_set, the duration of which is uint32_t + //So the maximum we can sleep for is 2^32 / 32768 = 131072 seconds = 36.4 hours + //Let's limit this to 36 hours = 129600 seconds + SerialPrintln(F("How many seconds would you like to sleep between readings? (5 to 129,600):")); + int64_t tempSeconds = getNumber(menuTimeout); //Timeout after x seconds + if (tempSeconds < 5 || tempSeconds > 129600) + SerialPrintln(F("Error: sleep interval out of range")); + else + settings.slowLoggingIntervalSeconds = (int)tempSeconds; + } + } + else if (incoming == 19) + { + if (settings.useRTCForFastSlowLogging == true) + { + SerialPrintln(F("Enter the Hour slow logging should start (0 to 23):")); + int64_t tempMOD = getNumber(menuTimeout); //Timeout after x seconds + if (tempMOD < 0 || tempMOD > 23) + SerialPrintln(F("Error: time out of range")); + else + { + settings.slowLoggingStartMOD = (int)tempMOD * 60; // Convert to minutes + SerialPrintln(F("\r\nEnter the Minute slow logging should start (0 to 59):")); + tempMOD = getNumber(menuTimeout); //Timeout after x seconds + if (tempMOD < 0 || tempMOD > 59) + SerialPrintln(F("Error: time out of range")); + else + settings.slowLoggingStartMOD += (int)tempMOD; + } + } + } + else if (incoming == 20) + { + if (settings.useRTCForFastSlowLogging == true) + { + SerialPrintln(F("Enter the Hour slow logging should end (0 to 23):")); + int64_t tempMOD = getNumber(menuTimeout); //Timeout after x seconds + if (tempMOD < 0 || tempMOD > 23) + SerialPrintln(F("Error: time out of range")); + else + { + settings.slowLoggingStopMOD = (int)tempMOD * 60; // Convert to minutes + SerialPrintln(F("\r\nEnter the Minute slow logging should end (0 to 59):")); + tempMOD = getNumber(menuTimeout); //Timeout after x seconds + if (tempMOD < 0 || tempMOD > 59) + SerialPrintln(F("Error: time out of range")); + else + settings.slowLoggingStopMOD += (int)tempMOD; + } + } + } else if (incoming == STATUS_PRESSED_X) return; else if (incoming == STATUS_GETNUMBER_TIMEOUT) diff --git a/Firmware/OpenLog_Artemis/menuTimeStamp.ino b/Firmware/OpenLog_Artemis/menuTimeStamp.ino index 14c58d0..6082b69 100644 --- a/Firmware/OpenLog_Artemis/menuTimeStamp.ino +++ b/Firmware/OpenLog_Artemis/menuTimeStamp.ino @@ -2,9 +2,9 @@ void menuTimeStamp() { while (1) { - Serial.println(); - Serial.println(F("Menu: Configure Time Stamp")); - Serial.print(F("Current date/time: ")); + SerialPrintln(F("")); + SerialPrintln(F("Menu: Configure Time Stamp")); + SerialPrint(F("Current date/time: ")); myRTC.getTime(); char rtcDate[11]; //10/12/2019 @@ -13,8 +13,8 @@ void menuTimeStamp() else sprintf(rtcDate, "%02d/%02d/20%02d", myRTC.dayOfMonth, myRTC.month, myRTC.year); - Serial.print(rtcDate); - Serial.print(F(" ")); + SerialPrint(rtcDate); + SerialPrint(F(" ")); char rtcTime[12]; //09:14:37.41 int adjustedHour = myRTC.hour; @@ -23,55 +23,56 @@ void menuTimeStamp() if (adjustedHour > 12) adjustedHour -= 12; } sprintf(rtcTime, "%02d:%02d:%02d.%02d", adjustedHour, myRTC.minute, myRTC.seconds, myRTC.hundredths); - Serial.println(rtcTime); + SerialPrintln(rtcTime); - Serial.print(F("1) Log Date: ")); - if (settings.logDate == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("1) Log Date: ")); + if (settings.logDate == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.print(F("2) Log Time: ")); - if (settings.logTime == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("2) Log Time: ")); + if (settings.logTime == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); if (settings.logDate == true || settings.logTime == true) { - Serial.println(F("3) Set RTC to compiler macro time")); + SerialPrintln(F("3) Set RTC to compiler macro time")); } if (settings.logDate == true) { - Serial.println(F("4) Manually set RTC date")); + SerialPrintln(F("4) Manually set RTC date")); - Serial.print(F("5) Toggle date style: ")); - if (settings.americanDateStyle == true) Serial.println(F("mm/dd/yyyy")); - else Serial.println(F("dd/mm/yyyy")); + SerialPrint(F("5) Toggle date style: ")); + if (settings.americanDateStyle == true) SerialPrintln(F("mm/dd/yyyy")); + else SerialPrintln(F("dd/mm/yyyy")); } if (settings.logTime == true) { - Serial.println(F("6) Manually set RTC time")); + SerialPrintln(F("6) Manually set RTC time")); - Serial.print(F("7) Toggle time style: ")); - if (settings.hour24Style == true) Serial.println(F("24 hour")); - else Serial.println(F("12 hour")); + SerialPrint(F("7) Toggle time style: ")); + if (settings.hour24Style == true) SerialPrintln(F("24 hour")); + else SerialPrintln(F("12 hour")); } if (settings.logDate == true || settings.logTime == true) { if (isUbloxAttached() == true) { - Serial.println(F("8) Synchronize RTC to GPS")); + SerialPrintln(F("8) Synchronize RTC to GPS")); } - Serial.print(F("9) Local offset from UTC: ")); + SerialPrint(F("9) Local offset from UTC: ")); Serial.println(settings.localUTCOffset); - + if (settings.useTxRxPinsForTerminal == true) + SerialLog.println(settings.localUTCOffset); } - Serial.print(F("10) Log Microseconds: ")); - if (settings.logMicroseconds == true) Serial.println(F("Enabled")); - else Serial.println(F("Disabled")); + SerialPrint(F("10) Log Microseconds: ")); + if (settings.logMicroseconds == true) SerialPrintln(F("Enabled")); + else SerialPrintln(F("Disabled")); - Serial.println(F("x) Exit")); + SerialPrintln(F("x) Exit")); int incoming = getNumber(menuTimeout); //Timeout after x seconds @@ -92,7 +93,7 @@ void menuTimeStamp() if (incoming == 3) { myRTC.setToCompilerTime(); //Set RTC using the system __DATE__ and __TIME__ macros from compiler - Serial.println(F("RTC set to compiler time")); + SerialPrintln(F("RTC set to compiler time")); } else if ((incoming == 8) && (isUbloxAttached() == true)) { @@ -102,18 +103,18 @@ void menuTimeStamp() getGPSDateTime(yy, mm, dd, h, m, s, ms, dateValid, timeValid); // Get the GPS date and time, corrected for localUTCOffset myRTC.setTime(h, m, s, (ms / 10), dd, mm, (yy - 2000)); //Manually set RTC lastSDFileNameChangeTime = rtcMillis(); // Record the time of the file name change - Serial.println(F("RTC set to GPS (UTC) time")); + SerialPrintln(F("RTC set to GPS (UTC) time")); if ((dateValid == false) || (timeValid == false)) { - Serial.println(F("\r\nWarning: the GPS time or date was not valid. Please try again.\r\n")); + SerialPrintln(F("\r\nWarning: the GPS time or date was not valid. Please try again.\r\n")); } } else if (incoming == 9) { - Serial.print(F("Enter the local hour offset from UTC (-12 to 14): ")); + SerialPrint(F("Enter the local hour offset from UTC (-12 to 14): ")); int offset = getNumber(menuTimeout); //Timeout after x seconds if (offset < -12 || offset > 14) - Serial.println(F("Error: Offset is out of range")); + SerialPrintln(F("Error: Offset is out of range")); else settings.localUTCOffset = offset; } @@ -127,14 +128,14 @@ void menuTimeStamp() myRTC.getTime(); int dd = myRTC.dayOfMonth, mm = myRTC.month, yy = myRTC.year, h = myRTC.hour, m = myRTC.minute, s = myRTC.seconds; - Serial.print(F("Enter current two digit year: ")); + SerialPrint(F("Enter current two digit year: ")); yy = getNumber(menuTimeout); //Timeout after x seconds if (yy > 2000 && yy < 2100) yy -= 2000; - Serial.print(F("Enter current month (1 to 12): ")); + SerialPrint(F("Enter current month (1 to 12): ")); mm = getNumber(menuTimeout); //Timeout after x seconds - Serial.print(F("Enter current day (1 to 31): ")); + SerialPrint(F("Enter current day (1 to 31): ")); dd = getNumber(menuTimeout); //Timeout after x seconds myRTC.setTime(h, m, s, 0, dd, mm, yy); //Manually set RTC @@ -154,13 +155,13 @@ void menuTimeStamp() myRTC.getTime(); int dd = myRTC.dayOfMonth, mm = myRTC.month, yy = myRTC.year, h = myRTC.hour, m = myRTC.minute, s = myRTC.seconds; - Serial.print(F("Enter current hour (0 to 23): ")); + SerialPrint(F("Enter current hour (0 to 23): ")); h = getNumber(menuTimeout); //Timeout after x seconds - Serial.print(F("Enter current minute (0 to 59): ")); + SerialPrint(F("Enter current minute (0 to 59): ")); m = getNumber(menuTimeout); //Timeout after x seconds - Serial.print(F("Enter current second (0 to 59): ")); + SerialPrint(F("Enter current second (0 to 59): ")); s = getNumber(menuTimeout); //Timeout after x seconds myRTC.setTime(h, m, s, 0, dd, mm, yy); //Manually set RTC diff --git a/Firmware/OpenLog_Artemis/nvm.ino b/Firmware/OpenLog_Artemis/nvm.ino index 7226341..226c677 100644 --- a/Firmware/OpenLog_Artemis/nvm.ino +++ b/Firmware/OpenLog_Artemis/nvm.ino @@ -8,7 +8,7 @@ void loadSettings() uint32_t testRead = 0; if (EEPROM.get(0, testRead) == 0xFFFFFFFF) { - Serial.println(F("EEPROM is blank. Default settings applied")); + SerialPrintln(F("EEPROM is blank. Default settings applied")); recordSystemSettings(); //Record default settings to EEPROM and config file. At power on, settings are in default state } @@ -18,7 +18,7 @@ void loadSettings() EEPROM.get(0, tempSize); //Load the sizeOfSettings if (tempSize != sizeof(settings)) { - Serial.println(F("Settings wrong size. Default settings applied")); + SerialPrintln(F("Settings wrong size. Default settings applied")); recordSystemSettings(); //Record default settings to EEPROM and config file. At power on, settings are in default state } @@ -28,7 +28,7 @@ void loadSettings() EEPROM.get(sizeof(int), tempIdentifier); //Load the identifier from the EEPROM location after sizeOfSettings (int) if (tempIdentifier != OLA_IDENTIFIER) { - Serial.println(F("Settings are not valid for this variant of the OLA. Default settings applied")); + SerialPrintln(F("Settings are not valid for this variant of the OLA. Default settings applied")); recordSystemSettings(); //Record default settings to EEPROM and config file. At power on, settings are in default state } @@ -60,7 +60,7 @@ void recordSystemSettingsToFile() SdFile settingsFile; //FAT32 if (settingsFile.open("OLA_settings.txt", O_CREAT | O_APPEND | O_WRITE) == false) { - Serial.println(F("Failed to create settings file")); + SerialPrintln(F("Failed to create settings file")); return; } @@ -98,9 +98,9 @@ void recordSystemSettingsToFile() settingsFile.println("usBetweenReadings=" + (String)tempTime); - //printDebug("Saving usBetweenReadings to SD card: "); + //printDebug(F("Saving usBetweenReadings to SD card: ")); //printDebug((String)tempTime); - //printDebug("\r\n"); + //printDebug(F("\r\n")); settingsFile.println("logMaxRate=" + (String)settings.logMaxRate); settingsFile.println("enableRTC=" + (String)settings.enableRTC); @@ -117,7 +117,6 @@ void recordSystemSettingsToFile() settingsFile.println("logIMUTemp=" + (String)settings.logIMUTemp); settingsFile.println("logRTC=" + (String)settings.logRTC); settingsFile.println("logHertz=" + (String)settings.logHertz); - settingsFile.println("getRTCfromGPS=" + (String)settings.getRTCfromGPS); settingsFile.println("correctForDST=" + (String)settings.correctForDST); settingsFile.println("americanDateStyle=" + (String)settings.americanDateStyle); settingsFile.println("hour24Style=" + (String)settings.hour24Style); @@ -155,6 +154,16 @@ void recordSystemSettingsToFile() settingsFile.println("imuGyroFSS=" + (String)settings.imuGyroFSS); settingsFile.println("imuGyroDLPFBW=" + (String)settings.imuGyroDLPFBW); settingsFile.println("logMicroseconds=" + (String)settings.logMicroseconds); + settingsFile.println("useTxRxPinsForTerminal=" + (String)settings.useTxRxPinsForTerminal); + settingsFile.println("timestampSerial=" + (String)settings.timestampSerial); + settingsFile.println("timeStampToken=" + (String)settings.timeStampToken); + settingsFile.println("useGPIO11ForFastSlowLogging=" + (String)settings.useGPIO11ForFastSlowLogging); + settingsFile.println("slowLoggingWhenPin11Is=" + (String)settings.slowLoggingWhenPin11Is); + settingsFile.println("useRTCForFastSlowLogging=" + (String)settings.useRTCForFastSlowLogging); + settingsFile.println("slowLoggingIntervalSeconds=" + (String)settings.slowLoggingIntervalSeconds); + settingsFile.println("slowLoggingStartMOD=" + (String)settings.slowLoggingStartMOD); + settingsFile.println("slowLoggingStopMOD=" + (String)settings.slowLoggingStopMOD); + settingsFile.println("resetOnZeroDeviceCount=" + (String)settings.resetOnZeroDeviceCount); updateDataFileAccess(&settingsFile); // Update the file access time & date settingsFile.close(); } @@ -173,7 +182,7 @@ bool loadSystemSettingsFromFile() SdFile settingsFile; //FAT32 if (settingsFile.open("OLA_settings.txt", O_READ) == false) { - Serial.println(F("Failed to open settings file")); + SerialPrintln(F("Failed to open settings file")); return (false); } @@ -183,23 +192,23 @@ bool loadSystemSettingsFromFile() while (settingsFile.available()) { int n = settingsFile.fgets(line, sizeof(line)); if (n <= 0) { - Serial.printf("Failed to read line %d from settings file\r\n", lineNumber); + SerialPrintf2("Failed to read line %d from settings file\r\n", lineNumber); } else if (line[n - 1] != '\n' && n == (sizeof(line) - 1)) { - Serial.printf("Settings line %d too long\r\n", lineNumber); + SerialPrintf2("Settings line %d too long\r\n", lineNumber); if (lineNumber == 0) { //If we can't read the first line of the settings file, give up - Serial.println(F("Giving up on settings file")); + SerialPrintln(F("Giving up on settings file")); return (false); } } else if (parseLine(line) == false) { - Serial.printf("Failed to parse line %d: %s\r\n", lineNumber, line); + SerialPrintf3("Failed to parse line %d: %s\r\n", lineNumber, line); if (lineNumber == 0) { //If we can't read the first line of the settings file, give up - Serial.println(F("Giving up on settings file")); + SerialPrintln(F("Giving up on settings file")); return (false); } } @@ -207,19 +216,19 @@ bool loadSystemSettingsFromFile() lineNumber++; } - //Serial.println(F("Config file read complete")); + //SerialPrintln(F("Config file read complete")); settingsFile.close(); return (true); } else { - Serial.println(F("No config file found. Using settings from EEPROM.")); + SerialPrintln(F("No config file found. Using settings from EEPROM.")); //The defaults of the struct will be recorded to a file later on. return (false); } } - Serial.println(F("Config file read failed: SD offline")); + SerialPrintln(F("Config file read failed: SD offline")); return (false); //SD offline } @@ -235,8 +244,8 @@ bool parseLine(char* str) { char* ptr; //Debug - //Serial.printf("Line contents: %s", str); - //Serial.flush(); + //SerialPrintf2("Line contents: %s", str); + //SerialFlush(); // Set strtok start of line. str = strtok(str, "="); @@ -250,15 +259,15 @@ bool parseLine(char* str) { str = strtok(nullptr, "\n"); if (!str) return false; - //Serial.printf("s = %s\r\n", str); - //Serial.flush(); + //SerialPrintf2("s = %s\r\n", str); + //SerialFlush(); // Convert string to double. double d = strtod(str, &ptr); if (str == ptr || *skipSpace(ptr)) return false; - //Serial.printf("d = %lf\r\n", d); - //Serial.flush(); + //SerialPrintf2("d = %lf\r\n", d); + //SerialFlush(); // Get setting name if (strcmp(settingName, "sizeOfSettings") == 0) @@ -269,13 +278,13 @@ bool parseLine(char* str) { { EEPROM.erase(); sd.remove("OLA_settings.txt"); - Serial.println(F("OpenLog Artemis has been factory reset. Freezing. Please restart and open terminal at 115200bps.")); + SerialPrintln(F("OpenLog Artemis has been factory reset. Freezing. Please restart and open terminal at 115200bps.")); while (1); } //Check to see if this setting file is compatible with this version of OLA if (d != sizeof(settings)) - Serial.printf("Warning: Settings size is %d but current firmware expects %d. Attempting to use settings from file.\r\n", d, sizeof(settings)); + SerialPrintf3("Warning: Settings size is %d but current firmware expects %d. Attempting to use settings from file.\r\n", d, sizeof(settings)); } else if (strcmp(settingName, "olaIdentifier") == 0) @@ -287,9 +296,9 @@ bool parseLine(char* str) { else if (strcmp(settingName, "usBetweenReadings") == 0) { settings.usBetweenReadings = d; - //printDebug("Read usBetweenReadings from SD card: "); + //printDebug(F("Read usBetweenReadings from SD card: ")); //printDebug(String(d)); - //printDebug("\r\n"); + //printDebug(F("\r\n")); } else if (strcmp(settingName, "logMaxRate") == 0) settings.logMaxRate = d; @@ -321,8 +330,6 @@ bool parseLine(char* str) { settings.logRTC = d; else if (strcmp(settingName, "logHertz") == 0) settings.logHertz = d; - else if (strcmp(settingName, "getRTCfromGPS") == 0) - settings.getRTCfromGPS = d; else if (strcmp(settingName, "correctForDST") == 0) settings.correctForDST = d; else if (strcmp(settingName, "americanDateStyle") == 0) @@ -397,8 +404,31 @@ bool parseLine(char* str) { settings.imuGyroDLPFBW = d; else if (strcmp(settingName, "logMicroseconds") == 0) settings.logMicroseconds = d; + else if (strcmp(settingName, "useTxRxPinsForTerminal") == 0) + settings.useTxRxPinsForTerminal = d; + else if (strcmp(settingName, "timestampSerial") == 0) + settings.timestampSerial = d; + else if (strcmp(settingName, "timeStampToken") == 0) + settings.timeStampToken = d; + else if (strcmp(settingName, "useGPIO11ForFastSlowLogging") == 0) + settings.useGPIO11ForFastSlowLogging = d; + else if (strcmp(settingName, "slowLoggingWhenPin11Is") == 0) + settings.slowLoggingWhenPin11Is = d; + else if (strcmp(settingName, "useRTCForFastSlowLogging") == 0) + settings.useRTCForFastSlowLogging = d; + else if (strcmp(settingName, "slowLoggingIntervalSeconds") == 0) + settings.slowLoggingIntervalSeconds = d; + else if (strcmp(settingName, "slowLoggingStartMOD") == 0) + settings.slowLoggingStartMOD = d; + else if (strcmp(settingName, "slowLoggingStopMOD") == 0) + settings.slowLoggingStopMOD = d; + else if (strcmp(settingName, "resetOnZeroDeviceCount") == 0) + settings.resetOnZeroDeviceCount = d; else - Serial.printf("Unknown setting %s on line: %s\r\n", settingName, str); + { + SerialPrintf2("Unknown setting %s. Ignoring...\r\n", settingName); + return(false); + } return (true); } @@ -414,7 +444,7 @@ void recordDeviceSettingsToFile() SdFile settingsFile; //FAT32 if (settingsFile.open("OLA_deviceSettings.txt", O_CREAT | O_APPEND | O_WRITE) == false) { - Serial.println(F("Failed to create device settings file")); + SerialPrintln(F("Failed to create device settings file")); return; } @@ -649,8 +679,39 @@ void recordDeviceSettingsToFile() settingsFile.println((String)base + "logFanStatus=" + nodeSetting->logFanStatus); } break; + case DEVICE_VOC_SGP40: + { + struct_SGP40 *nodeSetting = (struct_SGP40 *)temp->configPtr; + settingsFile.println((String)base + "log=" + nodeSetting->log); + settingsFile.println((String)base + "logVOC=" + nodeSetting->logVOC); + settingsFile.println((String)base + "RH=" + nodeSetting->RH); + settingsFile.println((String)base + "T=" + nodeSetting->T); + } + break; + case DEVICE_PRESSURE_SDP3X: + { + struct_SDP3X *nodeSetting = (struct_SDP3X *)temp->configPtr; + settingsFile.println((String)base + "logPressure=" + nodeSetting->logPressure); + settingsFile.println((String)base + "logTemperature=" + nodeSetting->logTemperature); + settingsFile.println((String)base + "massFlow=" + nodeSetting->massFlow); + settingsFile.println((String)base + "clockStretching=" + nodeSetting->clockStretching); + } + break; + case DEVICE_PRESSURE_MS5837: + { + struct_MS5837 *nodeSetting = (struct_MS5837 *)temp->configPtr; + settingsFile.println((String)base + "log=" + nodeSetting->log); + settingsFile.println((String)base + "logPressure=" + nodeSetting->logPressure); + settingsFile.println((String)base + "logTemperature=" + nodeSetting->logTemperature); + settingsFile.println((String)base + "logDepth=" + nodeSetting->logDepth); + settingsFile.println((String)base + "logAltitude=" + nodeSetting->logAltitude); + settingsFile.println((String)base + "model=" + nodeSetting->model); + settingsFile.println((String)base + "fluidDensity=" + nodeSetting->fluidDensity); + settingsFile.println((String)base + "conversion=" + nodeSetting->conversion); + } + break; default: - Serial.printf("recordSettingsToFile Unknown device: %s\r\n", base); + SerialPrintf2("recordSettingsToFile Unknown device: %s\r\n", base); //settingsFile.println((String)base + "=UnknownDeviceSettings"); break; } @@ -674,7 +735,7 @@ bool loadDeviceSettingsFromFile() SdFile settingsFile; //FAT32 if (settingsFile.open("OLA_deviceSettings.txt", O_READ) == false) { - Serial.println(F("Failed to open device settings file")); + SerialPrintln(F("Failed to open device settings file")); return (false); } @@ -684,32 +745,32 @@ bool loadDeviceSettingsFromFile() while (settingsFile.available()) { int n = settingsFile.fgets(line, sizeof(line)); if (n <= 0) { - Serial.printf("Failed to read line %d from settings file\r\n", lineNumber); + SerialPrintf2("Failed to read line %d from settings file\r\n", lineNumber); } else if (line[n - 1] != '\n' && n == (sizeof(line) - 1)) { - Serial.printf("Settings line %d too long\n", lineNumber); + SerialPrintf2("Settings line %d too long\n", lineNumber); } else if (parseDeviceLine(line) == false) { - Serial.printf("Failed to parse line %d: %s\r\n", lineNumber + 1, line); + SerialPrintf3("Failed to parse line %d: %s\r\n", lineNumber + 1, line); } lineNumber++; } - //Serial.println(F("Device config file read complete")); + //SerialPrintln(F("Device config file read complete")); updateDataFileAccess(&settingsFile); // Update the file access time & date settingsFile.close(); return (true); } else { - Serial.println(F("No device config file found. Creating one with device defaults.")); + SerialPrintln(F("No device config file found. Creating one with device defaults.")); recordDeviceSettingsToFile(); //Record the current settings to create the initial file return (false); } } - Serial.println(F("Device config file read failed: SD offline")); + SerialPrintln(F("Device config file read failed: SD offline")); return (false); //SD offline } @@ -719,8 +780,8 @@ bool parseDeviceLine(char* str) { char* ptr; //Debug - //Serial.printf("Line contents: %s", str); - //Serial.flush(); + //SerialPrintf2("Line contents: %s", str); + //SerialFlush(); // Set strtok start of line. str = strtok(str, "="); @@ -734,15 +795,15 @@ bool parseDeviceLine(char* str) { str = strtok(nullptr, "\n"); if (!str) return false; - //Serial.printf("s = %s\r\n", str); - //Serial.flush(); + //SerialPrintf2("s = %s\r\n", str); + //SerialFlush(); // Convert string to double. double d = strtod(str, &ptr); if (str == ptr || *skipSpace(ptr)) return false; - //Serial.printf("d = %lf\r\n", d); - //Serial.flush(); + //SerialPrintf2("d = %lf\r\n", d); + //SerialFlush(); //Break device setting into its constituent parts char deviceSettingName[50]; @@ -772,19 +833,19 @@ bool parseDeviceLine(char* str) { if (count < 5) { - Serial.printf("Incomplete setting: %s\r\n", settingName); + SerialPrintf2("Incomplete setting: %s\r\n", settingName); return false; } - //Serial.printf("%d: %d.%d.%d - %s\r\n", deviceType, address, muxAddress, portNumber, deviceSettingName); - //Serial.flush(); + //SerialPrintf6("%d: %d.%d.%d - %s\r\n", deviceType, address, muxAddress, portNumber, deviceSettingName); + //SerialFlush(); //Find the device in the list that has this device type and address void *deviceConfigPtr = getConfigPointer(deviceType, address, muxAddress, portNumber); if (deviceConfigPtr == NULL) { - //Serial.printf("Setting in file found but no matching device on bus is available: %s\r\n", settingName); - //Serial.flush(); + //SerialPrintf2("Setting in file found but no matching device on bus is available: %s\r\n", settingName); + //SerialFlush(); } else { @@ -792,7 +853,7 @@ bool parseDeviceLine(char* str) { { case DEVICE_MULTIPLEXER: { - Serial.println(F("There are no known settings for a multiplexer to load.")); + SerialPrintln(F("There are no known settings for a multiplexer to load.")); } break; case DEVICE_LOADCELL_NAU7802: @@ -811,7 +872,7 @@ bool parseDeviceLine(char* str) { else if (strcmp(deviceSettingName, "averageAmount") == 0) nodeSetting->averageAmount = d; else - Serial.printf("Unknown device setting: %s\r\n", deviceSettingName); + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); } break; case DEVICE_DISTANCE_VL53L1X: @@ -834,7 +895,7 @@ bool parseDeviceLine(char* str) { else if (strcmp(deviceSettingName, "crosstalk") == 0) nodeSetting->crosstalk = d; else - Serial.printf("Unknown device setting: %s\r\n", deviceSettingName); + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); } break; case DEVICE_GPS_UBLOX: @@ -873,7 +934,7 @@ bool parseDeviceLine(char* str) { else if (strcmp(deviceSettingName, "useAutoPVT") == 0) nodeSetting->useAutoPVT = d; else - Serial.printf("Unknown device setting: %s\r\n", deviceSettingName); + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); } break; case DEVICE_PROXIMITY_VCNL4040: @@ -896,7 +957,7 @@ bool parseDeviceLine(char* str) { else if (strcmp(deviceSettingName, "resolution") == 0) nodeSetting->resolution = d; else - Serial.printf("Unknown device setting: %s\r\n", deviceSettingName); + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); } break; case DEVICE_TEMPERATURE_TMP117: @@ -907,7 +968,7 @@ bool parseDeviceLine(char* str) { else if (strcmp(deviceSettingName, "logTemperature") == 0) nodeSetting->logTemperature = d; else - Serial.printf("Unknown device setting: %s\r\n", deviceSettingName); + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); } break; case DEVICE_PRESSURE_MS5637: @@ -920,7 +981,7 @@ bool parseDeviceLine(char* str) { else if (strcmp(deviceSettingName, "logTemperature") == 0) nodeSetting->logTemperature = d; else - Serial.printf("Unknown device setting: %s\r\n", deviceSettingName); + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); } break; case DEVICE_PRESSURE_LPS25HB: @@ -933,7 +994,7 @@ bool parseDeviceLine(char* str) { else if (strcmp(deviceSettingName, "logTemperature") == 0) nodeSetting->logTemperature = d; else - Serial.printf("Unknown device setting: %s\r\n", deviceSettingName); + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); } break; case DEVICE_PHT_BME280: @@ -950,7 +1011,7 @@ bool parseDeviceLine(char* str) { else if (strcmp(deviceSettingName, "logTemperature") == 0) nodeSetting->logTemperature = d; else - Serial.printf("Unknown device setting: %s\r\n", deviceSettingName); + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); } break; case DEVICE_UV_VEML6075: @@ -965,7 +1026,7 @@ bool parseDeviceLine(char* str) { else if (strcmp(deviceSettingName, "logUVIndex") == 0) nodeSetting->logUVIndex = d; else - Serial.printf("Unknown device setting: %s\r\n", deviceSettingName); + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); } break; case DEVICE_VOC_CCS811: @@ -978,7 +1039,7 @@ bool parseDeviceLine(char* str) { else if (strcmp(deviceSettingName, "logCO2") == 0) nodeSetting->logCO2 = d; else - Serial.printf("Unknown device setting: %s\r\n", deviceSettingName); + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); } break; case DEVICE_VOC_SGP30: @@ -995,7 +1056,7 @@ bool parseDeviceLine(char* str) { else if (strcmp(deviceSettingName, "logEthanol") == 0) nodeSetting->logEthanol = d; else - Serial.printf("Unknown device setting: %s\r\n", deviceSettingName); + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); } break; case DEVICE_CO2_SCD30: @@ -1018,7 +1079,7 @@ bool parseDeviceLine(char* str) { else if (strcmp(deviceSettingName, "temperatureOffset") == 0) nodeSetting->temperatureOffset = d; else - Serial.printf("Unknown device setting: %s\r\n", deviceSettingName); + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); } break; case DEVICE_PHT_MS8607: @@ -1039,7 +1100,7 @@ bool parseDeviceLine(char* str) { else if (strcmp(deviceSettingName, "humidityResolution") == 0) nodeSetting->humidityResolution = (MS8607_humidity_resolution)d; else - Serial.printf("Unknown device setting: %s\r\n", deviceSettingName); + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); } break; case DEVICE_TEMPERATURE_MCP9600: @@ -1052,7 +1113,7 @@ bool parseDeviceLine(char* str) { else if (strcmp(deviceSettingName, "logAmbientTemperature") == 0) nodeSetting->logAmbientTemperature = d; else - Serial.printf("Unknown device setting: %s\r\n", deviceSettingName); + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); } break; case DEVICE_HUMIDITY_AHT20: @@ -1065,7 +1126,7 @@ bool parseDeviceLine(char* str) { else if (strcmp(deviceSettingName, "logTemperature") == 0) nodeSetting->logTemperature = d; else - Serial.printf("Unknown device setting: %s\r\n", deviceSettingName); + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); } break; case DEVICE_HUMIDITY_SHTC3: @@ -1078,7 +1139,7 @@ bool parseDeviceLine(char* str) { else if (strcmp(deviceSettingName, "logTemperature") == 0) nodeSetting->logTemperature = d; else - Serial.printf("Unknown device setting: %s\r\n", deviceSettingName); + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); } break; case DEVICE_ADC_ADS122C04: @@ -1107,7 +1168,7 @@ bool parseDeviceLine(char* str) { else if (strcmp(deviceSettingName, "useTwoWireHighTemperatureMode") == 0) nodeSetting->useTwoWireHighTemperatureMode = d; else - Serial.printf("Unknown device setting: %s\r\n", deviceSettingName); + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); } break; case DEVICE_PRESSURE_MPR0025PA1: @@ -1134,7 +1195,7 @@ bool parseDeviceLine(char* str) { else if (strcmp(deviceSettingName, "useBAR") == 0) nodeSetting->useBAR = d; else - Serial.printf("Unknown device setting: %s\r\n", deviceSettingName); + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); } break; case DEVICE_PARTICLE_SNGCJA5: @@ -1169,12 +1230,67 @@ bool parseDeviceLine(char* str) { else if (strcmp(deviceSettingName, "logFanStatus") == 0) nodeSetting->logFanStatus = d; else - Serial.printf("Unknown device setting: %s\r\n", deviceSettingName); + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); + } + break; + case DEVICE_VOC_SGP40: + { + struct_SGP40 *nodeSetting = (struct_SGP40 *)deviceConfigPtr; //Create a local pointer that points to same spot as node does + if (strcmp(deviceSettingName, "log") == 0) + nodeSetting->log = d; + else if (strcmp(deviceSettingName, "logVOC") == 0) + nodeSetting->logVOC = d; + else if (strcmp(deviceSettingName, "RH") == 0) + nodeSetting->RH = d; + else if (strcmp(deviceSettingName, "T") == 0) + nodeSetting->T = d; + else + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); + } + break; + case DEVICE_PRESSURE_SDP3X: + { + struct_SDP3X *nodeSetting = (struct_SDP3X *)deviceConfigPtr; //Create a local pointer that points to same spot as node does + if (strcmp(deviceSettingName, "log") == 0) + nodeSetting->log = d; + else if (strcmp(deviceSettingName, "logPressure") == 0) + nodeSetting->logPressure = d; + else if (strcmp(deviceSettingName, "logTemperature") == 0) + nodeSetting->logTemperature = d; + else if (strcmp(deviceSettingName, "massFlow") == 0) + nodeSetting->massFlow = d; + else if (strcmp(deviceSettingName, "clockStretching") == 0) + nodeSetting->clockStretching = d; + else + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); + } + break; + case DEVICE_PRESSURE_MS5837: + { + struct_MS5837 *nodeSetting = (struct_MS5837 *)deviceConfigPtr; //Create a local pointer that points to same spot as node does + if (strcmp(deviceSettingName, "log") == 0) + nodeSetting->log = d; + else if (strcmp(deviceSettingName, "logPressure") == 0) + nodeSetting->logPressure = d; + else if (strcmp(deviceSettingName, "logTemperature") == 0) + nodeSetting->logTemperature = d; + else if (strcmp(deviceSettingName, "logDepth") == 0) + nodeSetting->logDepth = d; + else if (strcmp(deviceSettingName, "logAltitude") == 0) + nodeSetting->logAltitude = d; + else if (strcmp(deviceSettingName, "model") == 0) + nodeSetting->model = d; + else if (strcmp(deviceSettingName, "fluidDensity") == 0) + nodeSetting->fluidDensity = d; + else if (strcmp(deviceSettingName, "conversion") == 0) + nodeSetting->conversion = d; + else + SerialPrintf2("Unknown device setting: %s\r\n", deviceSettingName); } break; default: - Serial.printf("Unknown device type: %d\r\n", deviceType); - Serial.flush(); + SerialPrintf2("Unknown device type: %d\r\n", deviceType); + SerialFlush(); break; } } diff --git a/Firmware/OpenLog_Artemis/settings.h b/Firmware/OpenLog_Artemis/settings.h index 465e6ab..c2bea0a 100644 --- a/Firmware/OpenLog_Artemis/settings.h +++ b/Firmware/OpenLog_Artemis/settings.h @@ -23,6 +23,9 @@ typedef enum DEVICE_ADC_ADS122C04, DEVICE_PRESSURE_MPR0025PA1, // 0-25 PSI, I2C Address 0x18 DEVICE_PARTICLE_SNGCJA5, + DEVICE_VOC_SGP40, + DEVICE_PRESSURE_SDP3X, + DEVICE_PRESSURE_MS5837, DEVICE_TOTAL_DEVICES, //Marks the end, used to iterate loops DEVICE_UNKNOWN_DEVICE, @@ -204,7 +207,7 @@ struct struct_SCD30 { bool logTemperature = true; int measurementInterval = 2; //2 seconds int altitudeCompensation = 0; //0 m above sea level - int ambientPressure = 835; //mBar STP + int ambientPressure = 1000; //mBar STP (Toto, I have a feeling we're not in Boulder anymore) int temperatureOffset = 0; //C - Be careful not to overwrite the value on the sensor unsigned long powerOnDelayMillis = 5000; // Wait for at least this many millis before communicating with this device }; @@ -281,6 +284,35 @@ struct struct_SNGCJA5 { unsigned long powerOnDelayMillis = minimumQwiicPowerOnDelay; // Wait for at least this many millis before communicating with this device. Increase if required! }; +struct struct_SGP40 { + bool log = true; + bool logVOC = true; + float RH = 50; + float T = 25; + unsigned long powerOnDelayMillis = minimumQwiicPowerOnDelay; // Wait for at least this many millis before communicating with this device. Increase if required! +}; + +struct struct_SDP3X { + bool log = true; + bool logPressure = true; + bool logTemperature = true; + bool massFlow = true; + bool clockStretching = false; + unsigned long powerOnDelayMillis = minimumQwiicPowerOnDelay; // Wait for at least this many millis before communicating with this device. Increase if required! +}; + +struct struct_MS5837 { + bool log = true; + bool logPressure = true; + bool logTemperature = true; + bool logDepth = true; + bool logAltitude = true; + bool model = true; // Valid options are: 0 (MS5837::MS5837_30BA) and 1 (MS5837::MS5837_02BA) + float fluidDensity = 997; + float conversion = 1.0; + unsigned long powerOnDelayMillis = minimumQwiicPowerOnDelay; // Wait for at least this many millis before communicating with this device. Increase if required! +}; + //This is all the settings that can be set on OpenLog. It's recorded to NVM and the config file. struct struct_settings { @@ -309,7 +341,6 @@ struct struct_settings { bool logIMUTemp = true; bool logRTC = true; bool logHertz = true; - bool getRTCfromGPS = false; bool correctForDST = false; bool americanDateStyle = true; bool hour24Style = true; @@ -351,6 +382,16 @@ struct struct_settings { int imuGyroFSS = 0; // IMU gyro full scale - default to 250 degrees per second (ICM_20948_GYRO_CONFIG_1_FS_SEL_e) int imuGyroDLPFBW = 7; // IMU gyro DLPF bandwidth - default to gyr_d361bw4_n376bw5 (ICM_20948_GYRO_CONFIG_1_DLPCFG_e) bool logMicroseconds = false; // Log micros() + bool useTxRxPinsForTerminal = false; // If true, the terminal is echo'd to the Tx and Rx pins. Note: setting this to true will _permanently_ disable serial logging and analog input on those pins! + bool timestampSerial = false; // If true, the RTC time will be added to the serial log file when timeStampToken is received + uint8_t timeStampToken = 0x0A; // Add RTC time to the serial log when this token is received. Default to Line Feed (0x0A). Suggested by @DennisMelamed in Issue #63 + bool useGPIO11ForFastSlowLogging = false; // If true, Pin 11 will control if readings are taken quickly or slowly. Suggested by @ryanneve in Issue #46 and PR #64 + bool slowLoggingWhenPin11Is = false; // Controls the polarity of Pin 11 for fast / slow logging + bool useRTCForFastSlowLogging = false; // If true, logging will be slow during the specified times + int slowLoggingIntervalSeconds = 300; // Slow logging interval in seconds. Default to 5 mins + int slowLoggingStartMOD = 1260; // Start slow logging at this many Minutes Of Day. Default to 21:00 + int slowLoggingStopMOD = 420; // Stop slow logging at this many Minutes Of Day. Default to 07:00 + bool resetOnZeroDeviceCount = false; // A work-around for I2C bus crashes. Enable this via the debug menu. } settings; //These are the devices on board OpenLog that may be on or offline. diff --git a/Firmware/OpenLog_Artemis/support.ino b/Firmware/OpenLog_Artemis/support.ino index 40eb7db..70f7332 100644 --- a/Firmware/OpenLog_Artemis/support.ino +++ b/Firmware/OpenLog_Artemis/support.ino @@ -2,7 +2,9 @@ void printDebug(String thingToPrint) { if(settings.printDebugMessages == true) { - Serial.print(thingToPrint); + Serial.print(thingToPrint); + if (settings.useTxRxPinsForTerminal == true) + SerialLog.print(thingToPrint); } } @@ -10,15 +12,19 @@ void printDebug(String thingToPrint) //Option not known void printUnknown(uint8_t unknownChoice) { - Serial.print(F("Unknown choice: ")); + SerialPrint(F("Unknown choice: ")); Serial.write(unknownChoice); - Serial.println(); + if (settings.useTxRxPinsForTerminal == true) + SerialLog.write(unknownChoice); + SerialPrintln(F("")); } void printUnknown(int unknownValue) { - Serial.print(F("Unknown value: ")); + SerialPrint(F("Unknown value: ")); Serial.write(unknownValue); - Serial.println(); + if (settings.useTxRxPinsForTerminal == true) + SerialLog.write(unknownValue); + SerialPrintln(F("")); } //Blocking wait for user input @@ -29,9 +35,24 @@ void waitForInput() checkBattery(); delay(1); } + while (Serial.available() > 0) Serial.read(); //Clear buffer - while (Serial.available() == 0) + + if (settings.useTxRxPinsForTerminal == true) + while (SerialLog.available() > 0) SerialLog.read(); //Clear buffer + + bool keepChecking = true; + while (keepChecking) { + if (Serial.available()) + keepChecking = false; + + if (settings.useTxRxPinsForTerminal == true) + { + if (SerialLog.available()) + keepChecking = false; + } + checkBattery(); } } @@ -40,16 +61,21 @@ void waitForInput() //Waits for and returns the character that the user provides //Returns STATUS_GETNUMBER_TIMEOUT if input times out //Returns 'x' if user presses 'x' -uint8_t getByteChoice(int numberOfSeconds) +uint8_t getByteChoice(int numberOfSeconds, bool updateDZSERIAL) { - Serial.flush(); + SerialFlush(); + for (int i = 0; i < 50; i++) //Wait for any incoming chars to hit buffer { checkBattery(); delay(1); } + while (Serial.available() > 0) Serial.read(); //Clear buffer + if (settings.useTxRxPinsForTerminal == true) + while (SerialLog.available() > 0) SerialLog.read(); //Clear buffer + long startTime = millis(); byte incoming; while (1) @@ -57,8 +83,32 @@ uint8_t getByteChoice(int numberOfSeconds) if (Serial.available() > 0) { incoming = Serial.read(); -// Serial.print(F("byte: 0x")); + if (updateDZSERIAL) + { + DSERIAL = &Serial; + ZSERIAL = &Serial; + } +// SerialPrint(F("byte: 0x")); +// Serial.println(incoming, HEX); +// if (settings.useTxRxPinsForTerminal == true) +// SerialLog.println(incoming, HEX); + if (incoming >= 'a' && incoming <= 'z') break; + if (incoming >= 'A' && incoming <= 'Z') break; + if (incoming >= '0' && incoming <= '9') break; + } + + if ((settings.useTxRxPinsForTerminal == true) && (SerialLog.available() > 0)) + { + incoming = SerialLog.read(); + if (updateDZSERIAL) + { + DSERIAL = &SerialLog; + ZSERIAL = &SerialLog; + } +// SerialPrint(F("byte: 0x")); // Serial.println(incoming, HEX); +// if (settings.useTxRxPinsForTerminal == true) +// SerialLog.println(incoming, HEX); if (incoming >= 'a' && incoming <= 'z') break; if (incoming >= 'A' && incoming <= 'Z') break; if (incoming >= '0' && incoming <= '9') break; @@ -66,7 +116,7 @@ uint8_t getByteChoice(int numberOfSeconds) if ( (millis() - startTime) / 1000 >= numberOfSeconds) { - Serial.println(F("No user input received.")); + SerialPrintln(F("No user input received.")); return (STATUS_GETBYTE_TIMEOUT); //Timeout. No user input. } @@ -87,8 +137,12 @@ int64_t getNumber(int numberOfSeconds) checkBattery(); delay(1); } + while (Serial.available() > 0) Serial.read(); //Clear buffer + if (settings.useTxRxPinsForTerminal == true) + while (SerialLog.available() > 0) SerialLog.read(); //Clear buffer + //Get input from user char cleansed[20]; //Good for very large numbers: 123,456,789,012,345,678\0 @@ -96,15 +150,22 @@ int64_t getNumber(int numberOfSeconds) int spot = 0; while (spot < 20 - 1) //Leave room for terminating \0 { - while (Serial.available() == 0) //Wait for user input + bool serialAvailable = false; + while (serialAvailable == false) //Wait for user input { + if (Serial.available()) + serialAvailable = true; + + if ((settings.useTxRxPinsForTerminal == true) && (SerialLog.available())) + serialAvailable = true; + checkBattery(); if ( (millis() - startTime) / 1000 >= numberOfSeconds) { if (spot == 0) { - Serial.println(F("No user input received. Do you have line endings turned on?")); + SerialPrintln(F("No user input received. Do you have line endings turned on?")); return (STATUS_GETNUMBER_TIMEOUT); //Timeout. No user input. } else if (spot > 0) @@ -117,20 +178,31 @@ int64_t getNumber(int numberOfSeconds) //See if we timed out waiting for a line ending if (spot > 0 && (millis() - startTime) / 1000 >= numberOfSeconds) { - Serial.println(F("Do you have line endings turned on?")); + SerialPrintln(F("Do you have line endings turned on?")); break; //Timeout, but we have data } - byte incoming = Serial.read(); + byte incoming; + + if (Serial.available()) + incoming = Serial.read(); + + else + incoming = SerialLog.read(); + if (incoming == '\n' || incoming == '\r') { - Serial.println(); + SerialPrintln(F("")); break; } if ((isDigit(incoming) == true) || ((incoming == '-') && (spot == 0))) // Check for digits and a minus sign { Serial.write(incoming); //Echo user's typing + + if (settings.useTxRxPinsForTerminal == true) + SerialLog.write(incoming); //Echo user's typing + cleansed[spot++] = (char)incoming; } @@ -170,8 +242,12 @@ double getDouble(int numberOfSeconds) checkBattery(); delay(1); } + while (Serial.available() > 0) Serial.read(); //Clear buffer + if (settings.useTxRxPinsForTerminal == true) + while (SerialLog.available() > 0) SerialLog.read(); //Clear buffer + //Get input from user char cleansed[20]; //Good for very large numbers: 123,456,789,012,345,678\0 @@ -180,15 +256,22 @@ double getDouble(int numberOfSeconds) bool dpSeen = false; while (spot < 20 - 1) //Leave room for terminating \0 { - while (Serial.available() == 0) //Wait for user input + bool serialAvailable = false; + while (serialAvailable == false) //Wait for user input { + if (Serial.available()) + serialAvailable = true; + + if ((settings.useTxRxPinsForTerminal == true) && (SerialLog.available())) + serialAvailable = true; + checkBattery(); if ( (millis() - startTime) / 1000 >= numberOfSeconds) { if (spot == 0) { - Serial.println(F("No user input received. Do you have line endings turned on?")); + SerialPrintln(F("No user input received. Do you have line endings turned on?")); return (STATUS_GETNUMBER_TIMEOUT); //Timeout. No user input. } else if (spot > 0) @@ -201,20 +284,31 @@ double getDouble(int numberOfSeconds) //See if we timed out waiting for a line ending if (spot > 0 && (millis() - startTime) / 1000 >= numberOfSeconds) { - Serial.println(F("Do you have line endings turned on?")); + SerialPrintln(F("Do you have line endings turned on?")); break; //Timeout, but we have data } - byte incoming = Serial.read(); + byte incoming; + + if (Serial.available()) + incoming = Serial.read(); + + else + incoming = SerialLog.read(); + if (incoming == '\n' || incoming == '\r') { - Serial.println(); + SerialPrintln(F("")); break; } if ((isDigit(incoming) == true) || ((incoming == '-') && (spot == 0)) || ((incoming == '.') && (dpSeen == false))) // Check for digits/minus/dp { Serial.write(incoming); //Echo user's typing + + if (settings.useTxRxPinsForTerminal == true) + SerialLog.write(incoming); //Echo user's typing + cleansed[spot++] = (char)incoming; } diff --git a/Firmware/OpenLog_Artemis/timeStamp.ino b/Firmware/OpenLog_Artemis/timeStamp.ino index 7786248..e0288f2 100644 --- a/Firmware/OpenLog_Artemis/timeStamp.ino +++ b/Firmware/OpenLog_Artemis/timeStamp.ino @@ -1,54 +1,41 @@ -//Gets the current time from GPS -//Adjust the hour by local hour offset -//Adjust the hour by DST as necessary -//Adjust the date as necessary -//Returns a string according to user's settings -//Leap year is taken into account but does not interact with DST (DST happens later in March) -// -//Note: this function should only be called if we know that a u-blox GNSS is actually connected -// -String getGPSDateTimeAsStr() { - //Get latested date/time from GPS -// int year = gpsSensor_ublox.getYear(); -// int month = gpsSensor_ublox.getMonth(); -// int day = gpsSensor_ublox.getDay(); -// int hour = gpsSensor_ublox.getHour(); -// int minute = gpsSensor_ublox.getMinute(); -// int second = gpsSensor_ublox.getSecond(); - - int year = 19; - int month = 1; - int day = 1; - int hour = 6; - int minute = 14; - int second = 37; - - adjustToLocalDateTime(year, month, day, hour, settings.localUTCOffset); - - if (settings.hour24Style == false) - { - if (hour > 12) hour -= 12; - } +//Query the RTC and put the appropriately formatted (according to settings) +//string into the passed buffer. timeStringBuffer should be at least 37 chars long +//Code modified by @DennisMelamed in PR #70 +void getTimeString(char timeStringBuffer[]) +{ + //reset the buffer + timeStringBuffer[0] = '\0'; - String myTime = ""; + myRTC.getTime(); - if (settings.logDate == true) + if (settings.logDate) { - char gpsDate[11]; //10/12/2019 + char rtcDate[12]; //10/12/2019, if (settings.americanDateStyle == true) - sprintf(gpsDate, "%02d/%02d/20%02d", month, day, year); + sprintf(rtcDate, "%02d/%02d/20%02d,", myRTC.month, myRTC.dayOfMonth, myRTC.year); else - sprintf(gpsDate, "%02d/%02d/20%02d", day, month, year); - myTime += String(gpsDate); - myTime += ","; + sprintf(rtcDate, "%02d/%02d/20%02d,", myRTC.dayOfMonth, myRTC.month, myRTC.year); + strcat(timeStringBuffer, rtcDate); } - char gpsTime[13]; //09:14:37.412 - sprintf(gpsTime, "%02d:%02d:%02d.%03d", hour, minute, second, millis() % 1000); //TODO get GPS hundredths() - myTime += String(gpsTime); - myTime += ","; - - return (myTime); + if (settings.logTime) + { + char rtcTime[13]; //09:14:37.41, + int adjustedHour = myRTC.hour; + if (settings.hour24Style == false) + { + if (adjustedHour > 12) adjustedHour -= 12; + } + sprintf(rtcTime, "%02d:%02d:%02d.%02d,", adjustedHour, myRTC.minute, myRTC.seconds, myRTC.hundredths); + strcat(timeStringBuffer, rtcTime); + } + + if (settings.logMicroseconds) + { + char microseconds[11]; // + sprintf(microseconds, "%lu,", micros()); + strcat(timeStringBuffer, microseconds); + } } //Gets the current time from GPS diff --git a/Firmware/OpenLog_Artemis/zmodem.h b/Firmware/OpenLog_Artemis/zmodem.h index 1815571..073f2d0 100644 --- a/Firmware/OpenLog_Artemis/zmodem.h +++ b/Firmware/OpenLog_Artemis/zmodem.h @@ -185,7 +185,7 @@ int wcrx(); #define CPMEOF 032 #define WANTCRC 0103 /* send C not NAK to get crc not checksum */ #define WANTG 0107 /* Send G not NAK to get nonstop batch xmsn */ -#define TIMEOUT (-2) +//#define TIMEOUT (-2) #define RCDO (-3) #define Tx_RETRYMAX 10 #define Rx_RETRYMAX 5 diff --git a/Firmware/OpenLog_Artemis/zmodem.ino b/Firmware/OpenLog_Artemis/zmodem.ino index 84fdcdf..b46ce74 100644 --- a/Firmware/OpenLog_Artemis/zmodem.ino +++ b/Firmware/OpenLog_Artemis/zmodem.ino @@ -145,29 +145,29 @@ size_t DSERIALprint(const __FlashStringHelper *ifsh) while (1) { unsigned char c = pgm_read_byte(p++); if (c == 0) break; - if (DSERIAL.availableForWrite() > SERIAL_TX_BUFFER_SIZE / 2) DSERIAL.flush(); - if (DSERIAL.write(c)) n++; + if (DSERIAL->availableForWrite() > SERIAL_TX_BUFFER_SIZE / 2) DSERIAL->flush(); + if (DSERIAL->write(c)) n++; else break; } return n; } -#define DSERIALprintln(_p) ({ DSERIALprint(_p); DSERIAL.write("\r\n"); }) +#define DSERIALprintln(_p) ({ DSERIALprint(_p); DSERIAL->write("\r\n"); }) void sdCardHelp(void) { DSERIALprint(F("\r\n")); DSERIALprint(Progname); DSERIALprint(F(" - Transfer rate: ")); - DSERIAL.flush(); DSERIAL.println(settings.serialTerminalBaudRate); DSERIAL.flush(); - DSERIALprintln(F("Available Commands:")); DSERIAL.flush(); - DSERIALprintln(F("HELP - Print this list of commands")); DSERIAL.flush(); - DSERIALprintln(F("DIR - List files in current working directory - alternate LS")); DSERIAL.flush(); - DSERIALprintln(F("DEL file - Delete file - alternate RM")); DSERIAL.flush(); - DSERIALprintln(F("SZ file - Send file from OLA to terminal using ZModem (\"SZ *\" will send all files)")); DSERIAL.flush(); - DSERIALprintln(F("SS file - Send file from OLA using serial TX pin")); DSERIAL.flush(); - DSERIALprintln(F("CAT file - Type file to this terminal - alternate TYPE")); DSERIAL.flush(); - DSERIALprintln(F("X - Exit to OpenLog Artemis Main Menu")); DSERIAL.flush(); + DSERIAL->flush(); DSERIAL->println(settings.serialTerminalBaudRate); DSERIAL->flush(); + DSERIALprintln(F("Available Commands:")); DSERIAL->flush(); + DSERIALprintln(F("HELP - Print this list of commands")); DSERIAL->flush(); + DSERIALprintln(F("DIR - List files in current working directory - alternate LS")); DSERIAL->flush(); + DSERIALprintln(F("DEL file - Delete file - alternate RM")); DSERIAL->flush(); + DSERIALprintln(F("SZ file - Send file from OLA to terminal using ZModem (\"SZ *\" will send all files)")); DSERIAL->flush(); + DSERIALprintln(F("SS file - Send file from OLA using serial TX pin")); DSERIAL->flush(); + DSERIALprintln(F("CAT file - Type file to this terminal - alternate TYPE")); DSERIAL->flush(); + DSERIALprintln(F("X - Exit to OpenLog Artemis Main Menu")); DSERIAL->flush(); DSERIALprint(F("\r\n")); } @@ -214,17 +214,17 @@ void sdCardMenu(void) *cmd = 0; - while (DSERIAL.available()) DSERIAL.read(); + while (DSERIAL->available()) DSERIAL->read(); char c = 0; while(1) { - if (DSERIAL.available() > 0) + if (DSERIAL->available() > 0) { - c = DSERIAL.read(); + c = DSERIAL->read(); if ((c == 8 or c == 127) && strlen(cmd) > 0) cmd[strlen(cmd)-1] = 0; if (c == '\n' || c == '\r') break; - DSERIAL.write(c); + DSERIAL->write(c); if (c != 8 && c != 127) strncat(cmd, &c, 1); } else @@ -251,7 +251,7 @@ void sdCardMenu(void) } strupr(cmd); - DSERIAL.println(); + DSERIAL->println(); // DSERIALprintln(command); // DSERIALprintln(parameter); @@ -264,7 +264,10 @@ void sdCardMenu(void) { DSERIALprintln(F("\r\nRoot Directory Listing:")); - sd.ls("/", LS_DATE | LS_SIZE); // Do a non-recursive LS of the root directory showing file modification dates and sizes + if (DSERIAL == &Serial) + sd.ls("/", LS_DATE | LS_SIZE); // Do a non-recursive LS of the root directory showing file modification dates and sizes + else + sd.ls(&SerialLog, "/", LS_DATE | LS_SIZE); DSERIALprintln(F("End of Directory\r\n")); } @@ -274,13 +277,13 @@ void sdCardMenu(void) if (!sd.remove(param)) { DSERIALprint(F("\r\nFailed to delete file ")); - DSERIAL.flush(); DSERIAL.println(param); DSERIAL.flush(); + DSERIAL->flush(); DSERIAL->println(param); DSERIAL->flush(); DSERIALprintln(F("\r\n")); } else { DSERIALprint(F("\r\nFile ")); - DSERIAL.flush(); DSERIAL.print(param); DSERIAL.flush(); + DSERIAL->flush(); DSERIAL->print(param); DSERIAL->flush(); DSERIALprintln(F(" deleted\r\n")); } } @@ -291,14 +294,14 @@ void sdCardMenu(void) { count_files(&Filesleft, &Totalleft); - DSERIALprint(F("\r\nTransferring ")); DSERIAL.print(Filesleft); DSERIALprint(F(" files (")); DSERIAL.print(Totalleft); DSERIALprintln(F(" bytes)")); + DSERIALprint(F("\r\nTransferring ")); DSERIAL->print(Filesleft); DSERIALprint(F(" files (")); DSERIAL->print(Totalleft); DSERIALprintln(F(" bytes)")); root.open("/"); // (re)open the root directory root.rewind(); // rewind if (Filesleft > 0) { - DSERIALprint(F("Starting zmodem transfer in ")); Serial.print(settings.zmodemStartDelay); DSERIALprintln(F(" seconds...")); + DSERIALprint(F("Starting zmodem transfer in ")); DSERIAL->print(settings.zmodemStartDelay); DSERIALprintln(F(" seconds...")); DSERIALprintln(F("(If you are using Tera Term, you need to start your File\\Transfer\\ZMODEM\\Receive now!)")); if (oneTime == false) { @@ -327,7 +330,7 @@ void sdCardMenu(void) char fname[30]; size_t fsize = 30; fout.getName(fname, fsize); - //Serial.print("fname: "); Serial.println(fname); + //DSERIAL->print("fname: "); DSERIAL->println(fname); if (wcs(fname) == ERROR) { for (int i = 0; i < 500; i++) @@ -367,7 +370,7 @@ void sdCardMenu(void) } else { - DSERIALprint(F("\r\nStarting zmodem transfer in ")); Serial.print(settings.zmodemStartDelay); DSERIALprintln(F(" seconds...")); + DSERIALprint(F("\r\nStarting zmodem transfer in ")); DSERIAL->print(settings.zmodemStartDelay); DSERIALprintln(F(" seconds...")); DSERIALprintln(F("(If you are using Tera Term, you need to start your File\\Transfer\\ZMODEM\\Receive now!)")); if (oneTime == false) { @@ -384,7 +387,7 @@ void sdCardMenu(void) // Start the ZMODEM transfer Filesleft = 1; Totalleft = fout.fileSize(); - //ZSERIAL.print(F("rz\r")); + //ZSERIAL->print(F("rz\r")); sendzrqinit(); for (int i = 0; i < 200; i++) { @@ -408,9 +411,10 @@ void sdCardMenu(void) else { settings.logA12 = false; //Disable analog readings on TX pin - SerialLog.begin(settings.serialLogBaudRate); // (Re)start the serial port + if (settings.useTxRxPinsForTerminal == false) + SerialLog.begin(settings.serialLogBaudRate); // (Re)start the serial port - DSERIALprint(F("\r\nSending ")); Serial.print(param); DSERIALprint(F(" to the TX pin at ")); Serial.print(settings.serialLogBaudRate); DSERIALprintln(F(" baud")); + DSERIALprint(F("\r\nSending ")); DSERIAL->print(param); DSERIALprint(F(" to the TX pin at ")); DSERIAL->print(settings.serialLogBaudRate); DSERIALprintln(F(" baud")); while (fout.available()) { @@ -438,7 +442,7 @@ void sdCardMenu(void) { char ch; if (fout.read(&ch, 1) == 1) // Read a single char - Serial.write(ch); // Send it via SerialLog (TX pin) + DSERIAL->write(ch); // Send it via SerialLog (TX pin) } fout.close(); diff --git a/Firmware/OpenLog_Artemis/zmodem_config.h b/Firmware/OpenLog_Artemis/zmodem_config.h index b96f666..c39244a 100644 --- a/Firmware/OpenLog_Artemis/zmodem_config.h +++ b/Firmware/OpenLog_Artemis/zmodem_config.h @@ -17,13 +17,15 @@ //#endif // Serial output for debugging info -#define DSERIAL Serial +//#define DSERIAL Serial +//Stream *DSERIAL; // The Serial port for the Zmodem connection // must not be the same as DSERIAL unless all // debugging output to DSERIAL is removed //#define ZSERIAL Serial3 -#define ZSERIAL Serial +//#define ZSERIAL Serial +//Stream *ZSERIAL; //#ifdef TEENSYDUINO // #ifndef SERIAL_TX_BUFFER_SIZE diff --git a/Firmware/OpenLog_Artemis/zmodem_fixes.h b/Firmware/OpenLog_Artemis/zmodem_fixes.h index 4155191..b5ec90d 100644 --- a/Firmware/OpenLog_Artemis/zmodem_fixes.h +++ b/Firmware/OpenLog_Artemis/zmodem_fixes.h @@ -19,18 +19,39 @@ extern SdFat sd; #include -// Dylan (monte_carlo_ecm, bitflipper, etc.) - changed serial read/write to macros to try to squeeze +// Dylan (monte_carlo_ecm, bitflipper, etc.) - changed serial read/write to macros to try to squeeze // out higher speed #define READCHECK #define TYPICAL_SERIAL_TIMEOUT 1200 -#define readline(timeout) ({ char _c; ZSERIAL.readBytes(&_c, 1) > 0 ? _c : TIMEOUT; }) -int zdlread2(int); -#define zdlread(void) ({ int _z; ((_z = readline(Rxtimeout)) & 0140) ? _z : zdlread2(_z); }) -//#define sendline(_c) ZSERIAL.write(char(_c)) -#define sendline(_c) ({ if (ZSERIAL.availableForWrite() > SERIAL_TX_BUFFER_SIZE / 2) ZSERIAL.flush(); ZSERIAL.write(char(_c)); }) -#define zsendline(_z) ({ (_z & 0140 ) ? sendline(_z) : zsendline2(_z); }) +extern Stream *ZSERIAL; +extern int Rxtimeout; +#define TIMEOUT (-2) + +//#define readline(timeout) ({ char _c; ZSERIAL->readBytes(&_c, 1) > 0 ? _c : TIMEOUT; }) +//#define zdlread(void) ({ int _z; ((_z = readline(Rxtimeout)) & 0140) ? _z : zdlread2(_z); }) +//#define sendline(_c) ZSERIAL->write(char(_c)) +//#define sendline(_c) ({ if (ZSERIAL->availableForWrite() > SERIAL_TX_BUFFER_SIZE / 2) ZSERIAL->flush(); ZSERIAL->write(char(_c)); }) +//#define zsendline(_z) ({ (_z & 0140 ) ? sendline(_z) : zsendline2(_z); }) + +int readline(int timeout); // Header. Code is in zmodem_zm.cpp + +void sendline(int _c); // Header. Code is in zmodem_zm.cpp +#define xsendline(c) sendline(c) + +//int zdlread2(int); // Header. Code is in zmodem_zm.cpp + +void zsendline(int _z); // Header. Code is in zmodem_zm.cpp + +//int zdlread(void) +//{ +// int _z; +// if ((_z = readline(Rxtimeout)) & 0140) +// return (_z); +// else +// return (zdlread2(_z)); +//} void sendzrqinit(void); int wctxpn(const char *name); @@ -62,7 +83,7 @@ extern int Filcnt; // enter the "if" statement's clause #define setjmp(...) -#define printf(s, ... ) DSERIAL.println(s); +#define printf(s, ... ) DSERIAL->println(s); #define fprintf(...) // fseek(in, Rxpos, 0) diff --git a/Firmware/OpenLog_Artemis/zmodem_rz.cpp b/Firmware/OpenLog_Artemis/zmodem_rz.cpp index b92a85f..c6b06f8 100644 --- a/Firmware/OpenLog_Artemis/zmodem_rz.cpp +++ b/Firmware/OpenLog_Artemis/zmodem_rz.cpp @@ -27,14 +27,14 @@ * Professional-YAM, PowerCom, YAM, IMP, or programs supporting XMODEM. * rz uses Unix buffered input to reduce wasted CPU time. * - * Iff the program is invoked by rzCOMMAND, output is piped to + * Iff the program is invoked by rzCOMMAND, output is piped to * "COMMAND filename" (Unix only) * * Some systems (Venix, Coherent, Regulus) may not support tty raw mode * read(2) the same way as Unix. ONEREAD must be defined to force one * character reads for these systems. Added 7-01-84 CAF * - * Alarm signal handling changed to work with 4.2 BSD 7-15-84 CAF + * Alarm signal handling changed to work with 4.2 BSD 7-15-84 CAF * * BIX added 6-30-87 to support BIX(TM) upload protocol used by the * Byte Information Exchange. @@ -62,8 +62,6 @@ #include -#define xsendline(c) sendline(c) - #include "zmodem.h" #include "zmodem_zm.h" #include "zmodem_crc16.cpp" @@ -222,7 +220,7 @@ void bibi(int n) { if (Zmodem) zmputs(Attn); - canit(); + canit(); mode(0); fprintf(stderr, "rz: caught signal %d; exiting\n", n); cucheck(); @@ -265,47 +263,47 @@ int wcreceive(int argc, char **argp) return OK; } if (c == ERROR) { -//DSERIAL.println(F("fubar 1")); +//DSERIAL->println(F("fubar 1")); goto fubar; } c = rzfiles(); if (c) { -//DSERIAL.println(F("fubar 2")); +//DSERIAL->println(F("fubar 2")); goto fubar; } - } + } else { for (;;) { if (wcrxpn(secbuf)== ERROR) { -//DSERIAL.println(F("fubar 3")); +//DSERIAL->println(F("fubar 3")); goto fubar; } if (secbuf[0]==0) return OK; if (procheader(secbuf) == ERROR) { -//DSERIAL.println(F("fubar 4")); +//DSERIAL->println(F("fubar 4")); goto fubar; } if (wcrx()==ERROR) { -//DSERIAL.println(F("fubar 5")); +//DSERIAL->println(F("fubar 5")); goto fubar; } } } - } + } else { - Bytesleft = DEFBYTL; - //Filemode = 0; + Bytesleft = DEFBYTL; + //Filemode = 0; //Modtime = 0L; - procheader(""); - strcpy(Pathname, *argp); + procheader(""); + strcpy(Pathname, *argp); // if (checkpath(Pathname)) { // canit(); // return ERROR; // } -//DSERIAL.print("rz: ready to receive "); -//DSERIAL.println(Pathname); +//DSERIAL->print("rz: ready to receive "); +//DSERIAL->println(Pathname); #ifndef ARDUINO if ((fout=fopen(Pathname, "w")) == NULL) #else @@ -313,9 +311,9 @@ int wcreceive(int argc, char **argp) #endif return ERROR; rxbytes = fout.fileSize(); - + if (wcrx()==ERROR) { -DSERIAL.println(F("fubar 6")); +//DSERIAL->println(F("fubar 6")); goto fubar; } } @@ -326,7 +324,7 @@ DSERIAL.println(F("fubar 6")); #ifndef ARDUINO #ifndef vax11c if (Topipe && fout) { - pclose(fout); + pclose(fout); return ERROR; } #endif @@ -364,7 +362,7 @@ int wcrxpn(char *rpn) #endif et_tu: - Firstsec=TRUE; + Firstsec=TRUE; Eofseen=FALSE; sendline(Crcflg?WANTCRC:NAK); Lleft=0; /* Do read next time ... */ @@ -378,7 +376,7 @@ int wcrxpn(char *rpn) } return ERROR; - + } sendline(ACK); return OK; @@ -396,7 +394,7 @@ int wcrx() int cblklen; /* bytes to dump this block */ Firstsec=TRUE; - sectnum=0; + sectnum=0; Eofseen=FALSE; sendchar=Crcflg?WANTCRC:NAK; @@ -454,7 +452,7 @@ int wcgetsec(char *rxbuf,int maxtime) for (Lastrx=errors=0; errors=0; ) { if ((firstch=readline(1)) < 0) { -//DSERIAL.println(F("bilge 1")); +//DSERIAL->println(F("bilge 1")); goto bilge; } oldcrc=updcrc(firstch, oldcrc); checksum += (*p++ = firstch); } if ((firstch=readline(1)) < 0) { -//DSERIAL.println(F("bilge 2")); +//DSERIAL->println(F("bilge 2")); goto bilge; } if (Crcflg) { oldcrc=updcrc(firstch, oldcrc); if ((firstch=readline(1)) < 0) { -//DSERIAL.println(F("bilge 3")); +//DSERIAL->println(F("bilge 3")); goto bilge; } @@ -513,7 +511,7 @@ int wcgetsec(char *rxbuf,int maxtime) if (Lastrx==CAN) { zperr( "Sender CANcelled"); return ERROR; - } + } else { Lastrx=CAN; continue; @@ -535,9 +533,9 @@ int wcgetsec(char *rxbuf,int maxtime) if (Firstsec) { sendline(Crcflg?WANTCRC:NAK); Lleft=0; /* Do read next time ... */ - } + } else { - maxtime=40; + maxtime=40; sendline(NAK); Lleft=0; /* Do read next time ... */ } @@ -578,7 +576,7 @@ int procheader(char *name) /* Check for existing file */ #ifndef ARDUINO if (!Rxclob && (zmanag&ZMMASK) != ZMCLOB && (fout=fopen(name, "r"))) { - fclose(fout); + fclose(fout); return ERROR; } #else @@ -588,8 +586,8 @@ int procheader(char *name) #endif #endif - Bytesleft = DEFBYTL; - //Filemode = 0; + Bytesleft = DEFBYTL; + //Filemode = 0; //Modtime = 0L; p = name + 1 + strlen(name); @@ -645,7 +643,7 @@ int procheader(char *name) if ( !(fout = popen(name+1, "w"))) { return ERROR; } - Topipe = -1; + Topipe = -1; return(OK); } #endif @@ -696,10 +694,10 @@ int putsec(char *buf,int n) if ( *p == '\r') continue; if (*p == CPMEOF) { - Eofseen=TRUE; + Eofseen=TRUE; return OK; } -#ifndef ARDUINO +#ifndef ARDUINO putc(*p ,fout); #else fout.write(*p); @@ -748,7 +746,7 @@ int tryz(void) int c, n; int cmdzack1flg; -//DSERIAL.println(F("Entering tryz")); +//DSERIAL->println(F("Entering tryz")); if (Nozmodem) /* Check for "rb" program name */ return 0; @@ -766,7 +764,7 @@ int tryz(void) // This unfortunate piece is a limiting factor. This parameter is supposed to control // the maximum buffer size that the sender expects us to have. It seems most ZModem send implementations // ignore it, with Hyperterminal being the only exception I can find. Without setting this, even -// Hyperterminal outstrips the Arduino's speed and buffer (64 bytes) at 57600 baud. +// Hyperterminal outstrips the Arduino's speed and buffer (64 bytes) at 57600 baud. stohdr(SECBUF_LEN); #endif @@ -786,16 +784,16 @@ int tryz(void) again: switch (zgethdr(Rxhdr, 0)) { case ZRQINIT: -//DSERIAL.println(F("tryz got ZRQINIT")); +//DSERIAL->println(F("tryz got ZRQINIT")); continue; case ZEOF: -//DSERIAL.println(F("tryz got ZEOF")); +//DSERIAL->println(F("tryz got ZEOF")); continue; case TIMEOUT: -//DSERIAL.println(F("tryz got TIMEOUT")); +//DSERIAL->println(F("tryz got TIMEOUT")); continue; case ZFILE: -//DSERIAL.println(F("tryz got ZFILE")); +//DSERIAL->println(F("tryz got ZFILE")); zconv = Rxhdr[ZF0]; zmanag = Rxhdr[ZF1]; @@ -808,7 +806,7 @@ int tryz(void) zshhdr(ZNAK, Txhdr); goto again; case ZSINIT: -//DSERIAL.println(F("tryz got ZSINIT")); +//DSERIAL->println(F("tryz got ZSINIT")); Zctlesc = TESCCTL & Rxhdr[ZF0]; if (zrdata(Attn, ZATTNLEN) == GOTCRCW) { @@ -826,7 +824,7 @@ int tryz(void) #ifdef vax11c return ERROR; #else -//DSERIAL.println(F("tryz got ZCOMMAND")); +//DSERIAL->println(F("tryz got ZCOMMAND")); cmdzack1flg = Rxhdr[ZF0]; if (zrdata(secbuf, SECBUF_LEN) == GOTCRCW) { @@ -844,24 +842,24 @@ int tryz(void) // exec2(secbuf); return ZCOMPL; } - zshhdr(ZNAK, Txhdr); + zshhdr(ZNAK, Txhdr); goto again; #endif case ZCOMPL: -//DSERIAL.println(F("tryz got ZCOMPL")); +//DSERIAL->println(F("tryz got ZCOMPL")); goto again; default: -//DSERIAL.println(F("tryz got default")); - +//DSERIAL->println(F("tryz got default")); + continue; case ZFIN: -//DSERIAL.println(F("tryz got ZFIN")); +//DSERIAL->println(F("tryz got ZFIN")); - ackbibi(); + ackbibi(); return ZCOMPL; case ZCAN: -//DSERIAL.println(F("tryz got ZCAN")); +//DSERIAL->println(F("tryz got ZCAN")); return ERROR; } @@ -911,7 +909,7 @@ int rzfile(void) return (tryzhdrtype = ZSKIP); } - n = 20; + n = 20; // rxbytes = 0l; for (;;) { @@ -949,7 +947,7 @@ int rzfile(void) * a timeout because the eof might have gone * out before we sent our zrpos. */ - errors = 0; + errors = 0; goto nxthdr; } if (closeit()) { @@ -987,7 +985,7 @@ int rzfile(void) putsec(secbuf, chinseg); chinseg = 0; #endif - zmputs(Attn); + zmputs(Attn); continue; } moredata: @@ -1091,14 +1089,14 @@ void zmputs(char *s) while (*s) { switch (c = *s++) { case '\336': -#ifndef ARDUINO - sleep(1); +#ifndef ARDUINO + sleep(1); #else delay(1000); #endif continue; case '\335': - sendbrk(); + sendbrk(); continue; default: sendline(c); diff --git a/Firmware/OpenLog_Artemis/zmodem_sz.cpp b/Firmware/OpenLog_Artemis/zmodem_sz.cpp index 4a8ccd4..d52ec27 100644 --- a/Firmware/OpenLog_Artemis/zmodem_sz.cpp +++ b/Firmware/OpenLog_Artemis/zmodem_sz.cpp @@ -226,7 +226,7 @@ int wctxpn(const char *name) char *p, *q; -//DSERIAL.println("\nwctxpn"); +//DSERIAL->println("\nwctxpn"); strcpy(txbuf,name); p = q = txbuf + strlen(txbuf)+1; @@ -247,10 +247,10 @@ int wctxpn(const char *name) ultoa(Totalleft, q, 10); Totalleft -= fout.fileSize(); -//DSERIAL.print(F("wctxpn sf = ")); -//DSERIAL.print(sf); -//DSERIAL.print(F(" length = ")); -//DSERIAL.println(Totalleft); +//DSERIAL->print(F("wctxpn sf = ")); +//DSERIAL->print(sf); +//DSERIAL->print(F(" length = ")); +//DSERIAL->println(Totalleft); if (--Filesleft <= 0) Totalleft = 0; if (Totalleft < 0) @@ -276,7 +276,7 @@ int wctx(long flen) int sectnum, attempts, firstch; long charssent; -//DSERIAL.println("\nwctx"); +//DSERIAL->println("\nwctx"); charssent = 0; firstsec=TRUE; @@ -412,16 +412,16 @@ int filbuf(char *buf,int count) { int c, m; -//DSERIAL.println("\nfilbuf"); +//DSERIAL->println("\nfilbuf"); if ( !Ascii) { // m = read(fileno(in), buf, count); m = fout.read(buf, count); -//DSERIAL.println(F("filbuf: '")); +//DSERIAL->println(F("filbuf: '")); //for(int i=0;iprint(buf[i]); //} -//DSERIAL.println(F("'")); +//DSERIAL->println(F("'")); if (m <= 0) return 0; while (m < count) @@ -477,7 +477,7 @@ int zsendfile(char *buf, int blen) int c; UNSL long crc; -//DSERIAL.println(F("\nzsendfile")); +//DSERIAL->println(F("\nzsendfile")); for (;;) { Txhdr[ZF0] = Lzconv; /* file conversion request */ @@ -503,7 +503,7 @@ int zsendfile(char *buf, int blen) case TIMEOUT: case ZABORT: case ZFIN: -//DSERIAL.println(F("\nzsendfile - ZFIN")); +//DSERIAL->println(F("\nzsendfile - ZFIN")); return ERROR; case ZCRC: @@ -524,7 +524,7 @@ int zsendfile(char *buf, int blen) case ZSKIP: fout.close(); //fclose(in); -//DSERIAL.println(F("\nzsendfile - ZSKIP")); +//DSERIAL->println(F("\nzsendfile - ZSKIP")); return c; case ZRPOS: /* @@ -537,8 +537,8 @@ int zsendfile(char *buf, int blen) return ERROR; Lastsync = (bytcnt = Txpos = Rxpos) -1; int ret = zsendfdata(); -//DSERIAL.print(F("\nzsendfile - exit - ")); -//DSERIAL.println(ret); +//DSERIAL->print(F("\nzsendfile - exit - ")); +//DSERIAL->println(ret); return(ret); } } @@ -554,11 +554,11 @@ int zsendfdata(void) int newcnt; uint8_t junkcount; /* Counts garbage chars received by TX */ -//DSERIAL.print(F("\nzsendfdata: ")); -//DSERIAL.print(F("number = ")); -//DSERIAL.print(Filesleft+1); -//DSERIAL.print(F(" length = ")); -//DSERIAL.println(Totalleft); +//DSERIAL->print(F("\nzsendfdata: ")); +//DSERIAL->print(F("number = ")); +//DSERIAL->print(Filesleft+1); +//DSERIAL->print(F(" length = ")); +//DSERIAL->println(Totalleft); Lrxpos = 0; junkcount = 0; Beenhereb4 = FALSE; @@ -574,7 +574,7 @@ int zsendfdata(void) case ZCAN: fout.close(); //fclose(in); -//DSERIAL.println(F("zsendfdata - error - 1")); +//DSERIAL->println(F("zsendfdata - error - 1")); return ERROR; case ZSKIP: fout.close(); @@ -593,7 +593,7 @@ int zsendfdata(void) * sent by the receiver, in place of setjmp/longjmp * rdchk(fdes) returns non 0 if a character is available */ - while (ZSERIAL.available()) { + while (ZSERIAL->available()) { #ifdef SV switch (checked) #else @@ -612,7 +612,7 @@ int zsendfdata(void) #endif } -//DSERIAL.println("zsendfdata - 1"); +//DSERIAL->println("zsendfdata - 1"); // if ( !Fromcu) // signal(SIGINT, onintr); @@ -621,12 +621,12 @@ int zsendfdata(void) stohdr(Txpos); zsbhdr(ZDATA, Txhdr); -//DSERIAL.println("zsendfdata - 2"); +//DSERIAL->println("zsendfdata - 2"); do { n = zfilbuf(); // AHA - it reads the 18 chars here -//DSERIAL.println(n); +//DSERIAL->println(n); if (Eofseen) e = ZCRCE; else if (junkcount > 3) @@ -655,7 +655,7 @@ int zsendfdata(void) * rdchk(fdes) returns non 0 if a character is available */ // fflush(stdout); - while (ZSERIAL.available()) { + while (ZSERIAL->available()) { #ifdef SV switch (checked) #else @@ -684,7 +684,7 @@ int zsendfdata(void) } while (!Eofseen); -//DSERIAL.println("zsendfdata - 4"); +//DSERIAL->println("zsendfdata - 4"); // if ( !Fromcu) // signal(SIGINT, SIG_IGN); @@ -694,23 +694,23 @@ int zsendfdata(void) zsbhdr(ZEOF, Txhdr); switch (getinsync(0)) { case ZACK: -//DSERIAL.println(F("zsendfdata - ZAK")); +//DSERIAL->println(F("zsendfdata - ZAK")); continue; case ZRPOS: -//DSERIAL.println(F("zsendfdata - ZRPOS")); +//DSERIAL->println(F("zsendfdata - ZRPOS")); goto somemore; case ZRINIT: -//DSERIAL.println(F("zsendfdata - OK")); +//DSERIAL->println(F("zsendfdata - OK")); return OK; case ZSKIP: fout.close(); //fclose(in); -//DSERIAL.println(F("zsendfdata - ZSKIP")); +//DSERIAL->println(F("zsendfdata - ZSKIP")); return c; default: fout.close(); //fclose(in); -//DSERIAL.println(F("zsendfdata - error - 2")); +//DSERIAL->println(F("zsendfdata - error - 2")); return ERROR; } } @@ -728,7 +728,7 @@ int getinsync(int flag) for (;;) { if (Test) { -//DSERIAL.println(F("***** Signal Caught *****")); +//DSERIAL->println(F("***** Signal Caught *****")); Rxpos = 0; c = ZRPOS; } @@ -739,7 +739,7 @@ int getinsync(int flag) case ZABORT: case ZFIN: case TIMEOUT: -//DSERIAL.println(F("getinsync - timeout")); +//DSERIAL->println(F("getinsync - timeout")); return ERROR; case ZRPOS: /* ************************************* */ @@ -750,7 +750,7 @@ int getinsync(int flag) // if (fseek(in, Rxpos, 0)) { // seekSet returns true on success if(!fout.seekSet(Rxpos)) { -//DSERIAL.println(F("getinsync - fseek")); +//DSERIAL->println(F("getinsync - fseek")); return ERROR; } Eofseen = 0; @@ -792,7 +792,7 @@ int getinsync(int flag) void sendzrqinit(void) { - ZSERIAL.print(ZRQINIT_STR); + ZSERIAL->print(ZRQINIT_STR); } /* Say "bibi" to the receiver, try to do it cleanly */ diff --git a/Firmware/OpenLog_Artemis/zmodem_zm.cpp b/Firmware/OpenLog_Artemis/zmodem_zm.cpp index 0e27c25..1ea66ac 100644 --- a/Firmware/OpenLog_Artemis/zmodem_zm.cpp +++ b/Firmware/OpenLog_Artemis/zmodem_zm.cpp @@ -34,12 +34,16 @@ #endif #endif +int zdlread(void); // Header. Code is below. +int zdlread2(int c); // Header. Code is below. + // Shared globals long Bytesleft; // from rz - Shared with sz bytcnt long rxbytes; // from rz - Shared with sz Lrxpos int Blklen; // from rz - Shared with sz blklen -#define Rxtimeout 100 /* Tenths of seconds to wait for something */ +//#define Rxtimeout 100 /* Tenths of seconds to wait for something */ +int Rxtimeout = 100; /* Tenths of seconds to wait for something */ #define Verbose 0 // This buffer blends Txb (from sz) and secbuf (from rz) into a single buffer, saving 1K @@ -108,8 +112,8 @@ char *frametypes[] = { (char *)"ZCOMMAND", (char *)"ZSTDERR", (char *)"xxxxx" -#define FRTYPES 22 // Total number of frame types in this array - // not including psuedo negative entries +#define FRTYPES 22 // Total number of frame types in this array + // not including psuedo negative entries }; */ #define badcrc F("Bad CRC"); @@ -128,18 +132,18 @@ void zsbhdr(int type, char *hdr) for (n = Znulls; --n >=0; ) xsendline(0); */ - xsendline(ZPAD); + xsendline(ZPAD); xsendline(ZDLE); //Pete (El Supremo) This looks wrong but it is correct - the code fails if == is used if ((Crc32t = Txfcs32)) { int n; UNSL long crc; - - xsendline(ZBIN32); + + xsendline(ZBIN32); zsendline(type); - crc = 0xFFFFFFFFL; + crc = 0xFFFFFFFFL; crc = UPDC32(type, crc); - + for (n=4; --n >= 0; ++hdr) { crc = UPDC32((0377 & *hdr), crc); zsendline(*hdr); @@ -152,9 +156,9 @@ void zsbhdr(int type, char *hdr) } else { int n; unsigned short crc; - - xsendline(ZBIN); - zsendline(type); + + xsendline(ZBIN); + zsendline(type); crc = updcrc(type, 0); for (n=4; --n >= 0; ++hdr) { @@ -177,24 +181,24 @@ void zshhdr(int type,char *hdr) unsigned short crc; vfile(F("zshhdr: %s %lx"), frametypes[type+FTOFFSET], rclhdr(hdr)); - sendline(ZPAD); - sendline(ZPAD); - sendline(ZDLE); + sendline(ZPAD); + sendline(ZPAD); + sendline(ZDLE); sendline(ZHEX); zputhex(type); Crc32t = 0; crc = updcrc(type, 0); for (n=4; --n >= 0; ++hdr) { - zputhex(*hdr); + zputhex(*hdr); crc = updcrc((0377 & *hdr), crc); } crc = updcrc(0,updcrc(0,crc)); - zputhex(crc>>8); + zputhex(crc>>8); zputhex(crc); /* Make it printable on remote machine */ - sendline(015); + sendline(015); sendline(0212); /* * Uncork the remote in case a fake XOFF has stopped data flow @@ -209,8 +213,8 @@ void zshhdr(int type,char *hdr) * Send binary array buf of length length, with ending ZDLE sequence frameend */ /* -static char *Zendnames[] = { - (char *)"ZCRCE", +static char *Zendnames[] = { + (char *)"ZCRCE", (char *)"ZCRCG", (char *)"ZCRCQ", (char *)"ZCRCW" @@ -224,7 +228,7 @@ void zsdata(char *buf,int length,int frameend) if (Crc32t) { int c; UNSL long crc; - + crc = 0xFFFFFFFFL; for (;--length >= 0; ++buf) { c = *buf & 0377; @@ -234,33 +238,33 @@ void zsdata(char *buf,int length,int frameend) zsendline(c); crc = UPDC32(c, crc); } - xsendline(ZDLE); + xsendline(ZDLE); xsendline(frameend); crc = UPDC32(frameend, crc); - + crc = ~crc; for (length=4; --length >= 0;) { - zsendline((int)crc); + zsendline((int)crc); crc >>= 8; } } else { unsigned short crc; - + crc = 0; for (;--length >= 0; ++buf) { - zsendline(*buf); + zsendline(*buf); crc = updcrc((0377 & *buf), crc); } - xsendline(ZDLE); + xsendline(ZDLE); xsendline(frameend); crc = updcrc(frameend, crc); crc = updcrc(0,updcrc(0,crc)); - zsendline(crc>>8); + zsendline(crc>>8); zsendline(crc); } if (frameend == ZCRCW) { - xsendline(XON); + xsendline(XON); flushmo(); } } @@ -278,9 +282,9 @@ int zrdata(char *buf,int length) if (Rxframeind == ZBIN32) { UNSL long crc; - - crc = 0xFFFFFFFFL; - Rxcount = 0; + + crc = 0xFFFFFFFFL; + Rxcount = 0; end = buf + length; while (buf <= end) { if ((c = zdlread()) & ~0377) { @@ -290,7 +294,7 @@ int zrdata(char *buf,int length) case GOTCRCG: case GOTCRCQ: case GOTCRCW: - d = c; + d = c; c &= 0377; crc = UPDC32(c, crc); if ((c = zdlread()) & ~0377) @@ -332,7 +336,7 @@ int zrdata(char *buf,int length) } else { unsigned short crc; - crc = Rxcount = 0; + crc = Rxcount = 0; end = buf + length; while (buf <= end) { if ((c = zdlread()) & ~0377) { @@ -397,10 +401,10 @@ int zgethdr(char *hdr,int eflag) cancount = 5; again: /* Return immediate ERROR if ZCRCW sequence seen */ - ZSERIAL.setTimeout(Rxtimeout * 100); + ZSERIAL->setTimeout(Rxtimeout * 100); c = readline(Rxtimeout); - ZSERIAL.setTimeout(TYPICAL_SERIAL_TIMEOUT); - + ZSERIAL->setTimeout(TYPICAL_SERIAL_TIMEOUT); + switch (c) { case RCDO: case TIMEOUT: @@ -408,7 +412,7 @@ int zgethdr(char *hdr,int eflag) case CAN: gotcan: if (--cancount <= 0) { - c = ZCAN; + c = ZCAN; goto fifi; } switch (c = readline(1)) { @@ -423,7 +427,7 @@ int zgethdr(char *hdr,int eflag) break; case CAN: if (--cancount <= 0) { - c = ZCAN; + c = ZCAN; goto fifi; } goto again; @@ -467,7 +471,7 @@ int zgethdr(char *hdr,int eflag) case TIMEOUT: goto fifi; case ZBIN: - Rxframeind = ZBIN; + Rxframeind = ZBIN; Crc32 = FALSE; c = zrbhdr(hdr); break; @@ -476,7 +480,7 @@ int zgethdr(char *hdr,int eflag) c = zrbhdr32(hdr); break; case ZHEX: - Rxframeind = ZHEX; + Rxframeind = ZHEX; Crc32 = FALSE; c = zrhhdr(hdr); break; @@ -537,7 +541,7 @@ int zrbhdr(char *hdr) if ((c = zdlread()) & ~0377) return c; crc = updcrc(c, crc); - if (crc & 0xFFFF) { + if (crc & 0xFFFF) { zperr(badcrc); return ERROR; } @@ -559,7 +563,7 @@ int zrbhdr32(char *hdr) if ((c = zdlread()) & ~0377) return c; Rxtype = c; - crc = 0xFFFFFFFFL; + crc = 0xFFFFFFFFL; crc = UPDC32(c, crc); #ifdef DEBUGZ vfile(F("zrbhdr32 c=%X crc=%lX"), c, crc); @@ -621,7 +625,7 @@ int zrhhdr(char *hdr) return c; crc = updcrc(c, crc); if (crc & 0xFFFF) { - zperr(badcrc); + zperr(badcrc); return ERROR; } switch ( c = readline(1)) { @@ -638,7 +642,7 @@ int zrhhdr(char *hdr) #ifdef ZMODEM Protocol = ZMODEM; #endif -// Zmodem = 1; +// Zmodem = 1; return Rxtype; } @@ -739,6 +743,16 @@ int zgethex(void) * Read a byte, checking for ZMODEM escape encoding * including CAN*5 which represents a quick abort */ + +int zdlread(void) +{ + int _z; + if ((_z = readline(Rxtimeout)) & 0140) + return (_z); + else + return (zdlread2(_z)); +} + /* int zdlread(void) { @@ -801,6 +815,7 @@ int zdlread(void) return ERROR; } */ + int zdlread2(int c) { again: @@ -814,7 +829,7 @@ int zdlread2(int c) case 021: case 0221: if ((c = readline(Rxtimeout)) & 0140) - return c; + return c; goto again; default: if (Zctlesc && !(c & 0140)) { @@ -921,13 +936,13 @@ long rclhdr(char *hdr) // Why was this called sendline ?? //void sendline(int c) //{ -// ZSERIAL.write(c & 0xFF); -// ZSERIAL.write(char(c)); -// ZSERIAL.flush(); +// ZSERIAL->write(c & 0xFF); +// ZSERIAL->write(char(c)); +// ZSERIAL->flush(); -//DSERIAL.print("SEND: "); -//DSERIAL.print(c, HEX); -//DSERIAL.println(); +//DSERIAL->print("SEND: "); +//DSERIAL->print(c, HEX); +//DSERIAL->println(); //} /* @@ -937,18 +952,18 @@ int readline(int timeout) { long then; unsigned char c; - + then = millis(); - while(ZSERIAL.available() < 1) { + while(ZSERIAL->available() < 1) { if(millis() - then > (unsigned int)timeout*100UL) { -DSERIAL.println("readline - TIMEOUT"); +DSERIAL->println("readline - TIMEOUT"); return(TIMEOUT); } } - c = ZSERIAL.read(); -//DSERIAL.print("READ: "); -//DSERIAL.print(c, HEX); -//DSERIAL.println(); + c = ZSERIAL->read(); +//DSERIAL->print("READ: "); +//DSERIAL->print(c, HEX); +//DSERIAL->println(); return(c); } */ @@ -958,7 +973,7 @@ DSERIAL.println("readline - TIMEOUT"); */ void purgeline(void) { - while(ZSERIAL.available())ZSERIAL.read(); + while(ZSERIAL->available())ZSERIAL->read(); } /* @@ -974,21 +989,43 @@ void bttyout(int c) void flushmo(void) { - ZSERIAL.flush(); + ZSERIAL->flush(); } - - /* send cancel string to get the other end to shut up */ void canit(void) { for (int i=0; i < 10; ++i) { - ZSERIAL.write(24); + ZSERIAL->write(24); } for (int i=0; i < 10; ++i) { - ZSERIAL.write(8); + ZSERIAL->write(8); } - ZSERIAL.flush(); + ZSERIAL->flush(); +} + +int readline(int timeout) +{ + char _c; + if (ZSERIAL->readBytes(&_c, 1) > 0) + return (_c); + else + return (TIMEOUT); +} + +void sendline(int _c) +{ + if (ZSERIAL->availableForWrite() > SERIAL_TX_BUFFER_SIZE / 2) + ZSERIAL->flush(); + ZSERIAL->write(char(_c)); +} + +void zsendline(int _z) +{ + if (_z & 0140) + sendline(_z); + else + zsendline2(_z); } /* End of zm.c */ diff --git a/Firmware/OpenLog_Artemis/zmodem_zm.h b/Firmware/OpenLog_Artemis/zmodem_zm.h index 9dd8a3d..11e3118 100644 --- a/Firmware/OpenLog_Artemis/zmodem_zm.h +++ b/Firmware/OpenLog_Artemis/zmodem_zm.h @@ -42,10 +42,10 @@ extern uint32_t Baudrate; /* #define WHERESTR "[FILE : %s, FUNC : %s, LINE : %d]: " #define WHEREARG __FILE__,__func__,__LINE__ -#define DEBUG(...) {char s[256]; sprintf(s, __VA_ARGS__); DSERIAL.println(s);} +#define DEBUG(...) {char s[256]; sprintf(s, __VA_ARGS__); DSERIAL->println(s);} #define zperr(_fmt, ...) DEBUG(WHERESTR _fmt, WHEREARG,__VA_ARGS__) */ -//#define zperr(...) {char s[256]; sprintf(s, __VA_ARGS__); DSERIAL.println(s);} +//#define zperr(...) {char s[256]; sprintf(s, __VA_ARGS__); DSERIAL->println(s);} #define zperr(...) #endif diff --git a/README.md b/README.md index 3e59633..6aaa4f3 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ The OpenLog Artemis automatically scans, detects, configures, and logs various Q * [LPS25HB Barometric Pressure Sensor](https://www.sparkfun.com/products/14767) * [BME280 Humidity and Barometric Pressure Sensor](https://www.sparkfun.com/products/15440) * [MS5637 Barometric Pressure Sensor](https://www.sparkfun.com/products/14688) +* [MS5837 Depth / Pressure Sensor](https://www.sparkfun.com/products/17709) +* [SDP3X Differential Pressure Sensor](https://www.sparkfun.com/products/nnnnn) * [MS8607 Pressure Humidity Temperature Sensor](https://www.sparkfun.com/products/16298) * [MPR0025PA MicroPressure Sensor](https://www.sparkfun.com/products/16476) * [TMP117 High Precision Temperature Sensor](https://www.sparkfun.com/products/15805) @@ -38,6 +40,7 @@ The OpenLog Artemis automatically scans, detects, configures, and logs various Q * [SHTC3 Humidity and Temperature Sensor](https://www.sparkfun.com/products/16467) * [CCS811 Air Quality Sensor](https://www.sparkfun.com/products/14348) * [SGP30 Air Quality Sensor](https://www.sparkfun.com/products/16531) +* [SGP40 Air Quality Sensor](https://www.sparkfun.com/products/17729) * [SCD30 CO2 and Air Quality Sensor](https://www.sparkfun.com/products/15112) * [SN-GCJA5 Particle Sensor](https://www.sparkfun.com/products/17123) * [VEML6075 UV Sensor](https://www.sparkfun.com/products/15089) diff --git a/SENSOR_UNITS.md b/SENSOR_UNITS.md index 1282c11..a47e854 100644 --- a/SENSOR_UNITS.md +++ b/SENSOR_UNITS.md @@ -20,14 +20,20 @@ This document summarizes the units used for each sensor measurement. - [MS8607 PHT sensor](#MS8607-PHT-sensor) - [MPR0025PA MicroPressure sensor](#MPR0025PA-MicroPressure-sensor) - [MS5637 barometric pressure sensor](#MS5637-barometric-pressure-sensor) +- [MS5837 depth and pressure sensor](#MS5837-depth-pressure-sensor) - [AHT20 humidity and temperature sensor](#AHT20-humidity-and-temperature-sensor) - [SHTC3 humidity and temperature sensor](#SHTC3-humidity-and-temperature-sensor) +### Differential Pressure: + +- [SDP3X differential pressure sensor](#SDP3X-differential-pressure-sensor) + ### Air Quality and Environmental Sensors: - [CCS811 air quality sensor](#CCS811-air-quality-sensor) - [VEML6075 UV light sensor](#VEML6075-UV-light-sensor) - [SGP30 air quality and Volatile Organic Compound (VOC) sensor](#SGP30-air-quality-and-VOC-sensor) +- [SGP40 air quality (VOC index) sensor](#SGP40-air-quality-sensor) - [SCD30 CO2 humidity and temperature sensor](#SCD30-CO2-humidity-and-temperature-sensor) - [SN-GCJA5 Particle Sensor](#SN-GCJA5-Particle-Sensor) @@ -146,7 +152,25 @@ Carrier Solution: | []() | | | |---|---|---| | Pressure | pressure_hPa | hectoPascals | -| Temperature | pressure_degC | Degrees Centigrade | +| Temperature | temperature_degC | Degrees Centigrade | + +--- +## MS5837 depth pressure sensor + +| []() | | | +|---|---|---| +| Pressure | mbar | millibar | +| Temperature | degC | Degrees Centigrade | +| Depth | depth_m | Metres | +| Altitude | alt_m | Metres | + +--- +## SDP3X differential pressure sensor + +| []() | | | +|---|---|---| +| Pressure | Pa | Pascals | +| Temperature | degC | Degrees Centigrade | --- ## AHT20 humidity and temperature sensor @@ -193,6 +217,13 @@ VOC = Volatile Organic Compounds | H2 | H2 | none | | Ethanol | ethanol | none | +--- +## SGP40 air quality sensor + +| []() | | | +|---|---|---| +| VOC Index | VOCindex | none | + --- ## SCD30 CO2 humidity and temperature sensor