/*
 * config.c
 *
 *  Created on: Apr 23, 2021
 *      Author: thomm
 */

// Config - data field selection, modes of operation, driver config, set/get and print functions (moved from system.c)



#include "System.h"
#include "config.h"
#include "user_IO.h"
#include "ADS1248_iso.h"
#include "ADS1248_noniso.h"
#include "board_util.h"
#include "MicroCAT.h"
#include "optode.h"
#include "Sleep.h"
#include "SDCard.h"
#include "uartstdio.h"  // User local version with larger RX buffer

extern int microSD_flg;
extern int dbg_flag;


/********************************************************************************************
 *  Configuration Menu.
 ********************************************************************************************/
void configuration_menu(void)
{
    char input, buff[100];
    int response;
    time_t usersTime, timer;
    unsigned long temp;
    float ftemp;


    while(1)
    {
        //print out config menu
        uprintf("\n\n\nConfiguration Menu -- %s", VERSION);
        uprintf("\n1 -- Set Clock");
        uprintf("\n2 -- Change File Name");
        uprintf("\n3 -- Set Deployment Parameters");
        uprintf("\n4 -- Enter pH Sensor Calibration Coefficients");
        uprintf("\n5 -- Calculate pH Sensor Calibration Coefficients");
        uprintf("\n6 -- Change Baud Rate");
        uprintf("\n7 -- Config Data Fields");
        uprintf("\n8 -- Metadata Settings");        // was a hidden menu requiring password
        uprintf("\n9 -- Exit to Main Menu");
        uprintf("\nEnter Selection [9]: ");

        // Get user's selection with a 5 min timeout
        UARTFlushRx();
        timer = 300 + ROM_HibernateRTCGet();

        while(1)
        {
            if( UARTRxBytesAvail() )
            {
                input = get_key();
                break;
            }

            if( timer <= ROM_HibernateRTCGet() ) sleep(IDLE, 0);
        }

        switch(input)
        {
            case 'd':
                uprintf("\ndbg_flag = 0   OFF\n");
                dbg_flag = 0;
                break;
            case 'D':
                uprintf("\ndbg_flag = 1   ON\n");
                dbg_flag = 1;
                break;
            case '1':  // Set Clock
                response = yesOrNoMenuChoice("\n\nIs time GMT? (Y/N) [N]? ", NO);
                if(response == YES) sys_data.GMT = true;
                else sys_data.GMT = false;

                usersTime = getDateAndTime();

                if(usersTime)
                {
                    ROM_HibernateRTCSet(usersTime); // Set time if user entered valid time
                    uprintf("\nTime now: ");
                    printCurrentTime();
                    if(sys_data.GMT) uprintf(" GMT");
                    else uprintf(" Local");
                    uprintf("\n\nNote: Daylight Savings not observed. Use GMT when this will be an issue.\n");
                }
                break;

            case '2':  //Set / Change file name
                uprintf("\nEnter data file name (no spaces, 8 characters before .txt or .xls) [%s]: ", sys_data.fileName);
                if( getUserInput(buff, 100) )
                {
                    strcpy(sys_data.fileName, buff);
                    uprintf("\nFile name now: %s\n", sys_data.fileName);
                }

                uprintf("\n\nEnter user initials [%s]: ", sys_data.user);

                if( getUserInput(buff, 10) )
                {
                    strcpy(sys_data.user, buff);
                    uprintf("\nUser initials now: %s\n", sys_data.user);
                }
                break;

            case '3':  //Set timing (query user for values, save them in EEPROM)

                // Sample period
                //response = yesOrNoMenuChoice("\n\nSample aligned to hour? (Y/N) [Y]? ", YES);
                if(sys_data.sample_aligned == YES)  // THOM new 23Apr2019
                {
                    response = yesOrNoMenuChoice("\n\nSample aligned to hour? (Y/N) [Y]? ", YES);
                }
                else
                {
                    response = yesOrNoMenuChoice("\n\nSample aligned to hour? (Y/N) [N]? ", NO);
                }

                if(response == YES) sys_data.sample_aligned = true;
                else sys_data.sample_aligned = false;

                while(1)
                {
                    uprintf("\nEnter sample period [%u] sec: ", sys_data.sampling_period);
                    if(getUserInput(buff, 20))
                    {
                        if(sscanf(buff, "%u", &temp) == 1)
                        {

                            // sample_period = 0 means POLLED MODE
                            // use COMMAND mode to keep from going into DEPLOY   THOMHERE

                            if(temp == 0)
                            {
                                uprintf("\nSample period is zero - polled mode\n");
                            }
                            //else
                            //{

                                if(sys_data.sample_aligned)     // Sample aligned to hour?
                                {
                                    //if(3600 % temp)
                                    if((3600 % temp) && (temp > 0))     // BUG Fix 6 May 2019, per request to allow sample aligned to hour in polled mode (sample period = 0) - Not sure the sense of it though since in polled mode, the poller is determining the time
                                    {
                                        uprintf("\nSample period must evenly divide hour (e.g. 5, 10, 15, 20, 30 minutes)");
                                        continue;
                                    }
                                }

                                if(temp <= 3600)        // Check if less than hour
                                {
                                    sys_data.sampling_period = temp;
                                    uprintf("Sample period now %u sec.\n\n", sys_data.sampling_period);
                                    break;
                                }
                                else
                                    {
                                    uprintf("\nEnter time less than or equal to 3600 sec");
                                    }

                                continue;
                            }
                            else break;
                        //} // if (sscanf...)
                    }
                    else break;
                }

                // Sample average
                if(sys_data.fast_mode >= 1)
                {
                    uprintf("\npH sample average is 10 at 20 sps (fast sample)\n");
                }
                else
                {
                    while(1)
                    {
                        uprintf("\nEnter pH sample average [%d] samples: ", sys_data.sample_average);
                        if(getUserInput(buff, 20))
                        {
                            if(sscanf(buff, "%d", &temp) == 1)
                            {
                                if(temp <= 100)
                                {
                                    sys_data.sample_average = temp;
                                    uprintf("\npH sample average now %d.\n\n", sys_data.sample_average);
                                    break;
                                }
                                else uprintf("\nEnter value less than 100");
                                continue;
                            }
                            else break;
                        }
                        else break;
                    }
                }

                // Pump on time
                while(1)
                {
                    uprintf("\nEnter pump on time [%u] sec: ", sys_data.pumpon_time);
                    if(getUserInput(buff, 20))
                    {
                        if(sscanf(buff, "%u", &temp) == 1)
                        {
                            if(temp <= 3600)
                            {
                                sys_data.pumpon_time = temp;
                                uprintf("Pump on time now %u sec.\n\n", sys_data.pumpon_time);
                                break;
                            }
                            else uprintf("\nEnter time less than 3600 sec");
                            continue;
                        }
                        else break;
                    }
                    else break;
                }

                // Low battery voltage
                while(1)
                    {
                        sprintf(buff, "\nEnter low battery_voltage (10.5 V for SeapHOx, 5.5 V for MFET) [%.1f V]: ", sys_data.low_batt_volt);
                        uprintf("%s", buff);
                        if(getUserInput(buff, 20))
                        {
                            if(sscanf(buff, "%f", &ftemp) == 1)
                            {
                                if(ftemp >= 0 && ftemp <= 30)
                                {
                                    sys_data.low_batt_volt = ftemp;
                                    sprintf(buff, "\nLow battery_voltage now [%.1f V]\n\n", sys_data.low_batt_volt);
                                    uprintf("%s", buff);
                                break;
                                }
                                else uprintf("\nEnter voltage less than 30 V");
                                continue;
                            }
                            else break;
                        }
                            else break;
                    }


                // Output mode
                uprintf("\nOutput mode menu");
                uprintf("\n1 -- Normal  (Data only)");
                uprintf("\n2 -- Verbose (Data with prompts)");
                uprintf("\nEnter Selection [%d]: ", (int)sys_data.output);

                input = get_key();

                if(input)
                {
                    switch(input)
                    {
                        case '1': sys_data.output = NORMAL;
                        uprintf("\n\nOutput mode now: NORMAL");
                            break;

                        case '2': sys_data.output = VERBOSE;
                        uprintf("\n\nOutput mode now: VERBOSE");
                            break;
                    }

                }
                break;

            float ftemp;
            case '4': //Enter pH Sensor Calibration Coefficients
                //Eo_int_25
                enter_pH_sensor_cal_coeff();

#ifdef OLDCODE
                while(1)
                {
                    // a good default is -0.4
                    //sprintf(buff, "\nEnter E0_int @25 C (ex. -0.4) [%f]: ", sys_data.Eo_int_25C);
                    sprintf(buff, "\nEnter k0int (ex. -0.4) [%f]: ", sys_data.k0int);

                    uprintf("%s", buff);
                    if(getUserInput(buff, 20))
                    {
                        if(sscanf(buff, "%f", &ftemp) == 1)
                        {
                            if(ftemp >= (-2) && ftemp <= 2)
                            {
                                sys_data.k0int = ftemp;
                                break;
                            }
                            else uprintf("Enter number between -2 and 2 (ex. -0.4)\n\n");
                            continue;
                        }
                    else break;
                    }
                    else break;
                }


                //Eo_ext_25
                while(1)
                {
                        // a good default is -1.3
                    //sprintf(buff, "\nEnter E0_ext @25 C (ex. -1.3) [%f]: ", sys_data.Eo_ext_25C);
                    sprintf(buff, "\nEnter k0ext @25 C (ex. -1.3) [%f]: ", sys_data.k0ext);

                    uprintf("%s", buff);
                    if(getUserInput(buff, 20))
                    {
                        if(sscanf(buff, "%f", &ftemp) == 1)
                        {
                            if(ftemp >= (-2) && ftemp <= 2)
                            {
                                sys_data.k0ext = ftemp;
                                break;
                            }
                            else uprintf("Enter number between -2 and 2 (ex. -1.3)\n\n");
                            continue;
                        }
                        else break;
                        }
                    else break;
                }


                // new THOM 29 Apr 2019, remove TCOffset per Yui, TCOffset feature restored 3 Feb 2021
                if(sys_data.TCOffset > 400.0 || sys_data.TCOffset < -400.0)  // if offset is whacked, zero it.
                    sys_data.TCOffset = 0.0;
                // TCOffset added back 3 Feb 2021
                //TCOffset, standard = 0
                while(1)
                {
                    // default of zero is ok
                sprintf(buff, "\nEnter TCOffset [%f]: ", sys_data.TCOffset);
                uprintf("%s", buff);
                if(getUserInput(buff, 20))
                {
                    if(sscanf(buff, "%f", &ftemp) == 1)
                    {
                        if(ftemp >= (-2) && ftemp <= 2)
                        {
                            sys_data.TCOffset = ftemp;
                            break;
                        }
                        else uprintf("Enter 0.0\n\n");
                        continue;
                    }
                    else break;

                    }
                    else break;
                }



                // new THOM add entry of default salinity
                if(sys_data.default_sal > 100.0 || sys_data.default_sal < -100.0)  // if offset is whacked, zero it.
                    sys_data.TCOffset = 35.0;

                while(1)
                {
                    // default of 35.0
                sprintf(buff, "\nEnter Salinity for Ext Ref pH calc (typical is 35) [%f]: ", sys_data.default_sal);
                uprintf("%s", buff);
                if(getUserInput(buff, 20))
                {
                    if(sscanf(buff, "%f", &ftemp) == 1)
                    {
                        if(ftemp >= (0.0) && ftemp <= 100.0)
                        {
                            sys_data.default_sal = ftemp;
                            break;
                        }
                        else uprintf("Enter 35.0\n\n");
                        continue;
                    }
                    else break;

                    }
                    else break;
                }


                uprintf("\n*****Calibration Coefficients Saved*****\n\n");
#endif
                break;

            case '5': //Calculate pH Sensor Calibration Coeffcients
                ph_calib();
                break;

            case '6':  // Change baud rate
                change_baud_rate();
                break;

            case '7':  // Config data fields (select which fields are logged and displayed)
                config_data_fields();
                break;

            case '8': // Was a Hidden menu option, now metadata menu 2 Apr 2021
                uprintf("\nMetadata Settings:\n");




                // TODO  combine this into one routine (see code duplicated below)



#ifdef REMOVEPASSWORD       // per Yui 2 Apr 2021


                uprintf("\n\nFactory settings. Enter password: ");
                // Compare user input with password
                if( getUserInput(buff, 14) )
                {
                    uprintf("Pass: %s\n\n", buff);
                    buff[12] = 0x00;
                    if( strcmp("takeshitalab", buff)  == 0  ) // if strings are equal, strcmp returns 0
                        //      012345678901
                        matchFlg = 1;  //break;
                    buff[8] = 0x00;
                    if( strcmp("martzlab", buff) == 0 )
                        matchFlg = 1;  //break;

                }
                else
                    break;

                // if bad password, no access
                if(matchFlg == 0)
                    break;
#endif

                set_metadata();


#ifdef OLDCODE_METADATA
                // Todo print metadata settings
                uprintf("Sensor name now: %s\n\n", sys_data.sensor_name);
                uprintf("Durafet serial number now: %s\n\n", sys_data.durafet_SN);
                uprintf("CAP adapter serial number now: %s\n\n", sys_data.capadap_SN);
                uprintf("ISE serial number now: %s\n\n", sys_data.ISE_SN);
                uprintf("Microcat serial number now: %s\n\n", sys_data.microcat_SN);
                uprintf("Pump serial number now: %s\n\n", sys_data.pump_SN);
                uprintf("\npH Vint gain now %d\n\n", sys_data.Vint_gain);
                uprintf("\npH Vint data rate now %d sps\n\n", sys_data.Vint_sps);


                // Sensor name
                uprintf("\n\nEnter sensor name [%s]: ", sys_data.sensor_name);
                if( getUserInput(buff, 30) )
                {
                    strcpy(sys_data.sensor_name, buff);
                    uprintf("Sensor name now: %s\n\n", sys_data.sensor_name);
                }

                // Board serial #
                // MCAP serial #
#if BOARD_MFET >= 1
                uprintf("\nEnter MFET serial number [%s]: ", sys_data.board_SN);
#endif
#if BOARD_MPHOX >= 1
                uprintf("\nEnter MpHOx serial number [%s]: ", sys_data.board_SN);
#endif
#if BOARD_NANOFET >= 1
                uprintf("\nEnter nanoFET serial number [%s]: ", sys_data.board_SN);
#endif

                if( getUserInput(buff, 30) )
                {
                    strcpy(sys_data.board_SN, buff);
#if BOARD_MFET >= 1
                uprintf("\nEnter MFET serial number [%s]: ", sys_data.board_SN);
#endif
#if BOARD_MPHOX >= 1
                uprintf("\nEnter MpHOx serial number [%s]: ", sys_data.board_SN);
#endif
#if BOARD_NANOFET >= 1
                uprintf("\nEnter nanoFET serial number [%s]: ", sys_data.board_SN);
#endif
                }

#if BOARD_MFET >= 1 || BOARD_MPHOX >= 1
                // MCAP serial #
                uprintf("\nEnter MCAP serial number [%s]: ", sys_data.mcap_SN);
                if( getUserInput(buff, 30) )
                {
                    strcpy(sys_data.mcap_SN, buff);
                    uprintf("MCAP serial number now: %s\n\n", sys_data.mcap_SN);
                }
#endif
#if BOARD_NANOFET >= 1
#endif

                // DuraFET serial #
                uprintf("\nEnter Durafet serial number [%s]: ", sys_data.durafet_SN);
                if( getUserInput(buff, 30) )
                {
                    strcpy(sys_data.durafet_SN, buff);
                    uprintf("Durafet serial number now: %s\n\n", sys_data.durafet_SN);
                }

                // Cap adapter serial #
                uprintf("\nEnter CAP adapter serial number [%s]: ", sys_data.capadap_SN);
                if( getUserInput(buff, 30) )
                {
                    strcpy(sys_data.capadap_SN, buff);
                    uprintf("CAP adapter serial number now: %s\n\n", sys_data.capadap_SN);
                }

                // ISE serial #
                uprintf("\nEnter ISE serial number [%s]: ", sys_data.ISE_SN);
                if( getUserInput(buff, 30) )
                {
                    strcpy(sys_data.ISE_SN, buff);
                    uprintf("ISE serial number now: %s\n\n", sys_data.ISE_SN);
                }

                // Microcat serial #
                uprintf("\nEnter Microcat serial number [%s]: ", sys_data.microcat_SN);
                if( getUserInput(buff, 30) )
                {
                    strcpy(sys_data.microcat_SN, buff);
                    uprintf("Microcat serial number now: %s\n\n", sys_data.microcat_SN);
                }

                // Pump serial #
                uprintf("\nEnter pump serial number [%s]: ", sys_data.pump_SN);
                if( getUserInput(buff, 30) )
                {
                    strcpy(sys_data.pump_SN, buff);
                    uprintf("Pump serial number now: %s\n\n", sys_data.pump_SN);
                }

                uprintf("\n\nEnter board Fabrication notes [%s]: ", sys_data.board_fab_note);
                if( getUserInput(buff, MAX_board_fab_note-1) )       // board serial number
                {
                    strcpy(sys_data.board_fab_note, buff);
                    uprintf("\nBoard Fab notes: %s\n", sys_data.board_fab_note);
                }

#if BOARD_MFET >= 1 || BOARD_MPHOX >= 1
                uprintf("\n\nEnter MCAP Serial # [%s]: ", sys_data.mcap_SN);
                if( getUserInput(buff, MAX_MCAP_SN-1) )       // board serial number
                {
                    strcpy(sys_data.mcap_SN, buff);
                    uprintf("\nBoard Fab notes: %s\n", sys_data.mcap_SN);
                }
#endif

uprintf("\n\nEnter Durafet Serial # [%s]: ", sys_data.durafet_SN);
if( getUserInput(buff, MAX_DURAFET_SN-1) )       // board serial number
{
    strcpy(sys_data.durafet_SN, buff);
    uprintf("\n: %s\n", sys_data.durafet_SN);
}

uprintf("\n\nEnter CapAdapter Serial # [%s]: ", sys_data.capadap_SN);
if( getUserInput(buff, MAX_CAPADAP_SN-1) )       // board serial number
{
    strcpy(sys_data.capadap_SN, buff);
    uprintf("\n: %s\n", sys_data.capadap_SN);
}

uprintf("\n\nEnter ISE Serial # [%s]: ", sys_data.ISE_SN);
if( getUserInput(buff, MAX_ISE_SN-1) )       // board serial number
{
    strcpy(sys_data.ISE_SN, buff);
    uprintf("\n: %s\n", sys_data.ISE_SN);
}

uprintf("\n\nEnter MicroCat Serial # [%s]: ", sys_data.microcat_SN);
if( getUserInput(buff, MAX_MICROCAT_SN-1) )       // board serial number
{
    strcpy(sys_data.microcat_SN, buff);
    uprintf("\n: %s\n", sys_data.microcat_SN);
}
#if BOARD_MPHOX >= 1
    uprintf("\n\nEnter Optode Serial # [%s]: ", sys_data.optode_SN);
    if( getUserInput(buff, MAX_OPTODE_SN-1) )       //
    {
        strcpy(sys_data.optode_SN, buff);
        uprintf("\n: %s\n", sys_data.optode_SN);
    }

    uprintf("\n\nEnter Conductivity Serial # [%s]: ", sys_data.condo_SN);
    if( getUserInput(buff, MAX_CONDO_SN-1) )       //
    {
        strcpy(sys_data.condo_SN, buff);
        uprintf("\n: %s\n", sys_data.condo_SN);
    }
#endif



#endif


#ifdef REMOVEPRESSURESENSORMAX      // Per Yui 2 Apr 2021
                // Pressure sensor full scale
                while(1)
                {
                    uprintf("\nEnter pressure sensor full-scale [%d] psi: ", sys_data.press_full_scale);
                    if(getUserInput(buff, 20))
                    {
                        if(sscanf(buff, "%d", &temp) == 1)
                        {
                            if(temp == 100 || temp == 300)
                            {
                                sys_data.press_full_scale = temp;
                                uprintf("\nPressure sensor full-scale now %d psi\n\n", sys_data.press_full_scale);
                                break;
                            }
                            else uprintf("\nEnter 100 or 300");
                            continue;
                        }
                        else break;
                    }
                    else break;
                }
#endif

                // pH Vint gain setting
                while(1)
                {
                    uprintf("\nEnter pH Vint gain setting [%d]: ", sys_data.Vint_gain);
                    if(getUserInput(buff, 20))
                    {
                        if(sscanf(buff, "%d", &temp) == 1)
                        {
                            if(temp == 1 || temp == 2 || temp == 4 || temp == 8 || temp == 16 || temp == 32)
                            {
                                sys_data.Vint_gain = temp;
                                uprintf("\npH Vint gain now %d\n\n", sys_data.Vint_gain);
                                break;
                            }
                            else uprintf("\nEnter 1, 2, 4, 8, 16, or 32");
                            continue;
                        }
                        else break;
                    }
                    else break;
                }

                // pH Vint sample rate setting
                while(1)
                {
                    uprintf("\nEnter pH Vint sample rate setting [%d]: ", sys_data.Vint_sps);
                    if(getUserInput(buff, 20))
                    {
                        if(sscanf(buff, "%d", &temp) == 1)
                        {
                            if(temp == 5 || temp == 10 || temp == 20 || temp == 40 || temp == 80 || temp == 160
                                    || temp == 320 || temp == 640 || temp == 1000 || temp == 2000)
                            {
                                sys_data.Vint_sps = temp;
                                uprintf("\npH Vint data rate now %d sps\n\n", sys_data.Vint_sps);
                                break;
                            }
                            else uprintf("\nEnter 5, 10, 20, 40, 80, 160, 320, 640, 1000, or 2000");
                            continue;
                        }
                        else break;
                    }
                    else break;
                }

            default: //Exit
                // Write the sys_data struct into EEPROM.  Last argument ensures # of bytes is multiple of 4
                if(storeSysDataVariables())                     //if(EEPROMProgram((uint32_t*) &sys_data, 0x400, (sizeof(sys_data) + 3) & ~3))
                {
                    uprintf("\n\nError storing system data.\n");
                }
                else uprintf("\n\nSystem data stored.  -- Press enter to bring up main menu\n");
                return;
        }
    }
}


void enter_pH_sensor_cal_coeff(void)
{
    char input, buff[100];
    int response;
    time_t usersTime, timer;
    unsigned long temp;
    float ftemp;

    while(1)
    {
        // a good default is -0.4
        //sprintf(buff, "\nEnter E0_int @25 C (ex. -0.4) [%f]: ", sys_data.Eo_int_25C);
        sprintf(buff, "\nEnter k0int (ex. -0.4) [%f]: ", sys_data.k0int);

        uprintf("%s", buff);
        if(getUserInput(buff, 20))
        {
            if(sscanf(buff, "%f", &ftemp) == 1)
            {
                if(ftemp >= (-2) && ftemp <= 2)
                {
                    sys_data.k0int = ftemp;
                    break;
                }
                else uprintf("Enter number between -2 and 2 (ex. -0.4)\n\n");
                continue;
            }
        else break;
        }
        else break;
    }


    //Eo_ext_25
    while(1)
    {
            // a good default is -1.3
        //sprintf(buff, "\nEnter E0_ext @25 C (ex. -1.3) [%f]: ", sys_data.Eo_ext_25C);
        sprintf(buff, "\nEnter k0ext (ex. -1.3) [%f]: ", sys_data.k0ext);

        uprintf("%s", buff);
        if(getUserInput(buff, 20))
        {
            if(sscanf(buff, "%f", &ftemp) == 1)
            {
                if(ftemp >= (-2) && ftemp <= 2)
                {
                    sys_data.k0ext = ftemp;
                    break;
                }
                else uprintf("Enter number between -2 and 2 (ex. -1.3)\n\n");
                continue;
            }
            else break;
            }
        else break;
    }

    while(1)
    {
        sprintf(buff, "\nEnter k2int (ex. -0.001) [%f]: ", sys_data.k2int);

        uprintf("%s", buff);
        if(getUserInput(buff, 20))
        {
            if(sscanf(buff, "%f", &ftemp) == 1)
            {
                if(ftemp >= (-2) && ftemp <= 2)
                {
                    sys_data.k2int = ftemp;
                    break;
                }
                else uprintf("Enter number between -2 and 2 (ex. -0.001)\n\n");
                continue;
            }
            else break;
            }
        else break;
    }

    while(1)
    {
        sprintf(buff, "\nEnter k2ext (ex. -0.001) [%f]: ", sys_data.k2ext);

        uprintf("%s", buff);
        if(getUserInput(buff, 20))
        {
            if(sscanf(buff, "%f", &ftemp) == 1)
            {
                if(ftemp >= (-2) && ftemp <= 2)
                {
                    sys_data.k2ext = ftemp;
                    break;
                }
                else uprintf("Enter number between -2 and 2 (ex. -0.001)\n\n");
                continue;
            }
            else break;
            }
        else break;
    }


    // new THOM 29 Apr 2019, remove TCOffset per Yui, TCOffset feature restored 3 Feb 2021
    if(sys_data.TCOffset > 400.0 || sys_data.TCOffset < -400.0)  // if offset is whacked, zero it.
        sys_data.TCOffset = 0.0;
    // TCOffset added back 3 Feb 2021
    //TCOffset, standard = 0
    while(1)
    {
        // default of zero is ok
    sprintf(buff, "\nEnter TCOffset [%f]: ", sys_data.TCOffset);
    uprintf("%s", buff);
    if(getUserInput(buff, 20))
    {
        if(sscanf(buff, "%f", &ftemp) == 1)
        {
            if(ftemp >= -400.0 && ftemp <= 400.00)
            {
                sys_data.TCOffset = ftemp;
                break;
            }
            else uprintf("Enter a resonable TCOffset such as 0.0\n\n");
            continue;
        }
        else break;

        }
        else break;
    }



    // new THOM add entry of default salinity
    if(sys_data.default_sal > 100.0 || sys_data.default_sal < 0.0)  // if salinity is whacked, zero it.
    {
        uprintf("Salinity out of range, recommend running the test menu, qa board menu to initialize vars in eeprom\n");
        sys_data.TCOffset = 35.0;
    }

    while(1)
    {
        // default of 35.0
    sprintf(buff, "\nEnter Salinity for Ext Ref pH calc (typical is 35) [%f]: ", sys_data.default_sal);
    uprintf("%s", buff);
    if(getUserInput(buff, 20))
    {
        if(sscanf(buff, "%f", &ftemp) == 1)
        {
            if(ftemp >= (0.0) && ftemp <= 100.0)
            {
                sys_data.default_sal = ftemp;
                break;
            }
            else uprintf("Enter 35.0\n\n");
            continue;
        }
        else break;

        }
        else break;
    }

    uprintf("     c0 = 340.9819863\n");
    uprintf("     c1 = -9.10257E-05\n");
    uprintf("     c2 = -95.08806667\n");
    uprintf("     c3 = 0.965370274\n");

    while(1)
    {
        sprintf(buff, "\nEnter Steinhart-Hart c0 (ex. 340.9819863) [%f]: ", sys_data.shTherm_c0);

        uprintf("%s", buff);
        if(getUserInput(buff, 20))
        {
            if(sscanf(buff, "%f", &ftemp) == 1)
            {
                if(ftemp >= (0.0) && ftemp <= 500.0)
                {
                    sys_data.shTherm_c0 = ftemp;
                    break;
                }
                else uprintf("Enter number between 0 and 500 (ex. 340.9819863)\n\n");
                continue;
            }
            else break;
            }
        else break;
    }

    while(1)                 // -0.0000910257
    {
        sprintf(buff, "\nEnter Steinhart-Hart c1 (ex. -0.0000910257, -9.10257E-05) [%f]: ", sys_data.shTherm_c1);

        uprintf("%s", buff);
        if(getUserInput(buff, 20))
        {
            if(sscanf(buff, "%f", &ftemp) == 1)
            {
                if(ftemp >= (-0.1) && ftemp <= 0.1)
                {
                    sys_data.shTherm_c1 = ftemp;
                    break;
                }
                else uprintf("Enter number between 0.1 and -0.1 (ex. 0.0000910257)\n\n");
                continue;
            }
            else break;
            }
        else break;
    }

    while(1)                 // -0.0000910257
    {
        sprintf(buff, "\nEnter Steinhart-Hart c2 (ex. -95.08806667) [%f]: ", sys_data.shTherm_c2);

        uprintf("%s", buff);
        if(getUserInput(buff, 20))
        {
            if(sscanf(buff, "%f", &ftemp) == 1)
            {
                if(ftemp >= (-200.0) && ftemp <= 200.0)
                {
                    sys_data.shTherm_c2 = ftemp;
                    break;
                }
                else uprintf("Enter number between -200.0 and 200.0 (ex. -95.08806667)\n\n");
                continue;
            }
            else break;
            }
        else break;
    }


    while(1)                 // -0.0000910257
    {
        sprintf(buff, "\nEnter Steinhart-Hart c3 (ex. 0.965370274) [%f]: ", sys_data.shTherm_c3);

        uprintf("%s", buff);
        if(getUserInput(buff, 20))
        {
            if(sscanf(buff, "%f", &ftemp) == 1)
            {
                if(ftemp >= (-2.0) && ftemp <= 2.0)
                {
                    sys_data.shTherm_c3 = ftemp;
                    break;
                }
                else uprintf("Enter number between -2.0 and 2.0 (ex. 0.965370274)\n\n");
                continue;
            }
            else break;
            }
        else break;
    }

    //uprintf("\n*****Calibration Coefficients Saved*****\n\n");
}

void change_baud_rate(void)
{
    char input;
    time_t timer;

    //print out config menu
    uprintf("\n\n\nChange Baud Rate - select baud menu item, change terminal baud rate, then hit 'V' to verify, then sleep and wakeup");
    //uprintf("\nV -- Verify");
    uprintf("\n1 -- 115200");
    uprintf("\n2 -- 9600");
    uprintf("\n9 -- Exit to Main Menu");
    uprintf("\nEnter Selection [9]: ");

    // Get user's selection with a 5 min timeout
    UARTFlushRx();
    timer = 300 + ROM_HibernateRTCGet();

    while(1)
    {
        if( UARTRxBytesAvail() )
        {
            input = get_key();
            break;
        }

        if( timer <= ROM_HibernateRTCGet() ) sleep(IDLE, 0);
    }

    switch(input)
    {
        case 'V':
        case 'v':
            uprintf("\nBaud rate verify\n");
            break;
        case '1':
            // 115200
            sys_data.baud_rate = 115200L;
            UARTStdioConfig(0, 115200, 16000000);       // 115200 bits per second
            break;
        case '2':
            sys_data.baud_rate = 9600L;
            UARTStdioConfig(0, 9600, 16000000);       // 9600 bits per second
            break;
        default:
            // Write the sys_data struct into EEPROM.  Last argument ensures # of bytes is multiple of 4
            if(storeSysDataVariables())                 //if(EEPROMProgram((uint32_t*) &sys_data, 0x400, (sizeof(sys_data) + 3) & ~3))
            {
                uprintf("\n\nError storing system data.\n");
            }
            else
                uprintf("\n\nSystem data stored.  -- Press enter to bring up main menu\n");
            break;

    }

}

/********************************************************************************************
 *  Config Data Fields
 ********************************************************************************************/
void config_data_fields(void)
{
    char input;
    time_t timer;
    //unsigned char cfg;
    //unsigned char index;

    while(1)
    {
        //print out config menu
        uprintf("\n\n\nChange Data Field - lower case turns data field off (=0), upper case turns field on (=1)\n\n\n");
//#if BOARD_MFET >= 1 || BOARD_MPHOX == 1 || BOARD_NANOFET == 1

        uprintf("A -- Sample Num            = %u\n", sys_data.data_cfg[CFG_SAMPLE_NUM]);    //+ Sample_Number\t
        uprintf("B -- MM/DD/YYYY HH:MM:SS   = %u\n", sys_data.data_cfg[CFG_TIMEDATE]);                     //+ MM/DD/YYYY HH:MM:SS\t
        uprintf("C -- Battery Volt          = %u\n", sys_data.data_cfg[CFG_ENV_BAT_VOLT]);             //+ Battery_Voltage\t
        uprintf("D -- Board Temperature     = %u\n", sys_data.data_cfg[CFG_ENV_BRD_TEMP]);                   //+ Board_Temperature\t
        uprintf("E -- Board Humidity        = %u\n", sys_data.data_cfg[CFG_ENV_HUMIDITY]);                  //+ Humidity_sensor\t
        uprintf("F -- Bias Battery          = %u\n", sys_data.data_cfg[CFG_BIAS_BAT_VOLT]);                  //+ Internal_Pressure\t was uprintf("\nF -- Pressure = %u\t\t\t"
        uprintf("G -- Vthermistor           = %u\n", sys_data.data_cfg[CFG_V_THERMISTOR]);                     //+ Vthermistor\t
        uprintf("H -- Vtermistor Std        = %u\n", sys_data.data_cfg[CFG_V_THERMISTOR_STD]);                 //+ Vthermistor_std\t
        uprintf("I -- Vrsi Biased (7pH=0v)  = %u\n", sys_data.data_cfg[CFG_V_INT_OFFSET]);                //- Vint_offset\t
        uprintf("J -- Vrsi Biased Std       = %u\n", sys_data.data_cfg[CFG_V_INT_OFFSET_STD]);            //- Vint_offset_std\t
        uprintf("K -- Vrse Biased (7pH=0v)  = %u\n", sys_data.data_cfg[CFG_V_EXT_OFFSET]);                //- Vext_offset\t
        uprintf("L -- Vrse Biased Std       = %u\n", sys_data.data_cfg[CFG_V_EXT_OFFSET_STD]);            //- Vext_offset_std\t
        uprintf("M -- Vrsi (Int Ref pH volt) = %u\n", sys_data.data_cfg[CFG_V_INT]);                       //+ Vint\t
        uprintf("N -- Vrsi Std              = %u\n", sys_data.data_cfg[CFG_V_INT_STD]);                   //+ Vint_std\t
        uprintf("O -- Vrse (Ext Ref pH volt) = %u\n", sys_data.data_cfg[CFG_V_EXT]);                   //- Vext\t
        uprintf("P -- Vrse Std              = %u\n", sys_data.data_cfg[CFG_V_EXT_STD]);                   //- Vext_std\t
        uprintf("Q -- Counter Electrode Vk  = %u\n", sys_data.data_cfg[CFG_V_COUNTER_ELECT]);         // Vcounter_electrode\t
        uprintf("R -- Counter Electrode Vk Std = %u\n", sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD]);     // Vcounter_electrode_std\t
        uprintf("S -- Counter Electrode Current = %u\n", sys_data.data_cfg[CFG_I_COUNTER]);            // Counter_current\t
        uprintf("T -- Substrate Current     = %u\n", sys_data.data_cfg[CFG_I_SUBSTRATE]);         // Substrate_current\t
        uprintf("U -- Temperature Calc      = %u\n", sys_data.data_cfg[CFG_CALC_TEMP]); //uprintf("%8.6f\t", calculated_temperature_Vthermistor);          // calculated_temperature_Vthermistor\t
        uprintf("V -- pH Vrsi Calc          = %u\n", sys_data.data_cfg[CFG_EST_PH_INT]);                      // estimated_pH_int\r\n
        uprintf("W -- pH Vrse Calc          = %u\n", sys_data.data_cfg[CFG_EST_PH_EXT]);
        uprintf("X -- Optode                = %u\n", sys_data.data_cfg[CFG_OPTODE]);
        uprintf("Y -- Conductivity          = %u\n", sys_data.data_cfg[CFG_CONDO]);

#ifdef OLDCODE
        uprintf("\nA -- Sample Num = %u\t\t", sys_data.data_cfg[CFG_SAMPLE_NUM]);    //+ Sample_Number\t
        uprintf("\nB -- MM/DD/YYYY HH:MM:SS = %u\t", sys_data.data_cfg[CFG_TIMEDATE]);                     //+ MM/DD/YYYY HH:MM:SS\t
        uprintf("\nC -- Battery Volt = %u\t\t", sys_data.data_cfg[CFG_ENV_BAT_VOLT]);             //+ Battery_Voltage\t
        uprintf("\nD -- Board Temp = %u\t\t", sys_data.data_cfg[CFG_ENV_BRD_TEMP]);                   //+ Board_Temperature\t
        uprintf("\nE -- Humidity = %u\t\t\t", sys_data.data_cfg[CFG_ENV_HUMIDITY]);                  //+ Humidity_sensor\t
        uprintf("\nF -- Bias Battery = %u\t\t\t", sys_data.data_cfg[CFG_BIAS_BAT_VOLT]);                  //+ Internal_Pressure\t was uprintf("\nF -- Pressure = %u\t\t\t"
        uprintf("\nG -- Vthermistor = %u\t\t\t", sys_data.data_cfg[CFG_V_THERMISTOR]);                     //+ Vthermistor\t
        uprintf("\nH -- Vtermistor Std = %u\t\t", sys_data.data_cfg[CFG_V_THERMISTOR_STD]);                 //+ Vthermistor_std\t
        uprintf("\nI -- Vint Offset = %u\t\t\t", sys_data.data_cfg[CFG_V_INT_OFFSET]);                //- Vint_offset\t
        uprintf("\nJ -- Vint Offset Std = %u\t\t", sys_data.data_cfg[CFG_V_INT_OFFSET_STD]);            //- Vint_offset_std\t
        uprintf("\nK -- Vext Offset = %u\t\t", sys_data.data_cfg[CFG_V_EXT_OFFSET]);                //- Vext_offset\t
        uprintf("\nL -- Vext Offset Std = %u\t\t", sys_data.data_cfg[CFG_V_EXT_OFFSET_STD]);            //- Vext_offset_std\t
        uprintf("\nM -- Vint = %u\t\t\t", sys_data.data_cfg[CFG_V_INT]);                       //+ Vint\t
        uprintf("\nN -- Vint Std = %u\t\t\t", sys_data.data_cfg[CFG_V_INT_STD]);                   //+ Vint_std\t
        uprintf("\nO -- Vext Ref = %u\t\t\t", sys_data.data_cfg[CFG_V_EXT]);                   //- Vext\t
        uprintf("\nP -- Vext Ref Std = %u\t\t\t", sys_data.data_cfg[CFG_V_EXT_STD]);                   //- Vext_std\t
        uprintf("\nQ -- Vcounter Electrode Vk = %u\t\t", sys_data.data_cfg[CFG_V_COUNTER_ELECT]);         // Vcounter_electrode\t
        uprintf("\nR -- Vcounter Electrode Vk Std = %u\t\t", sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD]);     // Vcounter_electrode_std\t
        uprintf("\nS -- Counter Electrode Current = %u\t", sys_data.data_cfg[CFG_I_COUNTER]);            // Counter_current\t
        uprintf("\nT -- Substrate Current = %u\t\t\t", sys_data.data_cfg[CFG_I_SUBSTRATE]);         // Substrate_current\t
        uprintf("\nU -- Calc Temperature = %u\t\t\t", sys_data.data_cfg[CFG_CALC_TEMP]); //uprintf("%8.6f\t", calculated_temperature_Vthermistor);          // calculated_temperature_Vthermistor\t
        //uprintf("\nV -- Estimated pH = %u\t\t\t", sys_data.data_cfg[CFG_EST_PH_INT]);                      // estimated_pH_int\r\n
        uprintf("\nV -- Estimated pH Int = %u\t\t\t", sys_data.data_cfg[CFG_EST_PH_INT]);                      // estimated_pH_int\r\n
        uprintf("\nW -- Estimated pH Ext = %u\t\t\t", sys_data.data_cfg[CFG_EST_PH_EXT]);
        uprintf("\nX -- Optode = %u\t\t\t", sys_data.data_cfg[CFG_OPTODE]);
        uprintf("\nY -- Conductivity = %u\t\t\t", sys_data.data_cfg[CFG_CONDO]);
#endif
        //uprintf("\nZ -- Fast Mode = %u\t\t\t", sys_data.fast_mode);
        uprintf("\n0 -- Zero (Clear) all config fields");
        uprintf("\n1 -- Set all config fields");
        ROM_SysCtlDelay(MILLISECOND * 200);   // 128 byte fifo, use case 5 causes max q so give some time for xmit
        uprintf("\n2 -- Use Case: GLIDER,          (A,B,C,O,P,Q,R,S,T)");
        uprintf("\n3 -- Use Case: mFET Default,    (A,B,C,D,E,G,H,I,J,M,N,Q,R,S,T,U)"); //  FIELDS ACTIVE for MiniFET: A= Samp #, B= Time, C= Batt Volt, D= Board Temp, E= Humidity, G= Vtherm, H= Vtherm_STD, I= Vint_off, J= Vint_off_STD, M= Vint, N= Vint_STD, Q= Vk (counter electrode Voltage), R= Vk_STD, S= Counter electrode current, T= Substrate current, Z= Fast mode ON
        uprintf("\n4 -- Use Case: MpHOx Default,   (C,D,E,F,G,H,I,J,Q,R,S,T,U,V,X,Y)");   //C Battery Volt, G Vtherm (Thermistor voltage), H Vtherm_std, I Vint (internal reference pH voltage), J Vint_std, Q Vk (counter electrode voltage), R Vk_std, S Counter electrode current (diagnostic), T Substrate current (diagnostic), F Bias battery voltages (I don't know what this is called in the new program)
        uprintf("\n5 -- Use Case: nanoFET Default, (A,B,C,D,E,F,G,H,O,P,Q,R,S,T)");

//#endif




        uprintf("\n9 -- Exit to Main Menu");
        uprintf("\nEnter Selection [9]: ");

        // Get user's selection with a 5 min timeout
        UARTFlushRx();
        timer = 300 + ROM_HibernateRTCGet();

        while(1)
        {
            if( UARTRxBytesAvail() )
            {
                input = get_key();
                break;
            }

            if( timer <= ROM_HibernateRTCGet() ) sleep(IDLE, 0);
        }

        switch(input)
        {
            case 'A':
                sys_data.data_cfg[CFG_SAMPLE_NUM] = 1;   //
                break;
            case 'a':
                sys_data.data_cfg[CFG_SAMPLE_NUM] = 0;
                break;
            case 'B':
                sys_data.data_cfg[CFG_TIMEDATE] = 1;
                break;
            case 'b':
                sys_data.data_cfg[CFG_TIMEDATE] = 0;
                break;
            case 'C':
                sys_data.data_cfg[CFG_ENV_BAT_VOLT] = 1;   //        2   //+ Battery_Volt
                break;
            case 'c':
                sys_data.data_cfg[CFG_ENV_BAT_VOLT] = 0;
                break;
            case 'D':
                sys_data.data_cfg[CFG_ENV_BRD_TEMP] = 1;   //        3   //+ Board_Temperature\t
                break;
            case 'd':
                sys_data.data_cfg[CFG_ENV_BRD_TEMP] = 0;
                break;
            case 'E':
                sys_data.data_cfg[CFG_ENV_HUMIDITY] = 1;   //        4   // + Humidity_sensor
                break;
            case 'e':
                sys_data.data_cfg[CFG_ENV_HUMIDITY] = 0;
                break;
            case 'F':
                sys_data.data_cfg[CFG_BIAS_BAT_VOLT] = 1;   //        5   //+ Internal_pressure, Now bias bat volt
                break;
            case 'f':
                sys_data.data_cfg[CFG_BIAS_BAT_VOLT] = 0;
                break;
            case 'G':
                sys_data.data_cfg[CFG_V_THERMISTOR] = 1;   //        6       //+ Vthermistor\t
                break;
            case 'g':
                sys_data.data_cfg[CFG_V_THERMISTOR] = 0;
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 0;
                break;
            case 'H':
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 1;   //    7   //+ Vthermistor_std\t
                sys_data.data_cfg[CFG_V_THERMISTOR] = 1;
                break;
            case 'h':
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 0;
                break;
            case 'I':
                sys_data.data_cfg[CFG_V_INT_OFFSET] = 1;   //        8   //+ Vint_offset\t
                break;
            case 'i':
                sys_data.data_cfg[CFG_V_INT_OFFSET] = 0;
                sys_data.data_cfg[CFG_V_INT_OFFSET_STD] = 0;
                break;
            case 'J':
                sys_data.data_cfg[CFG_V_INT_OFFSET_STD] = 1;   //    9   //+ Vint_offset_std\t
                sys_data.data_cfg[CFG_V_INT_OFFSET] = 1;
                break;
            case 'j':
                sys_data.data_cfg[CFG_V_INT_OFFSET_STD] = 0;
                break;
            case 'K':
                sys_data.data_cfg[CFG_V_EXT_OFFSET] = 1;   //        10   //+ Vext_offset\t
                break;
            case 'k':
                sys_data.data_cfg[CFG_V_EXT_OFFSET] = 0;
                sys_data.data_cfg[CFG_V_EXT_OFFSET_STD] = 0;
                break;
            case 'L':
                sys_data.data_cfg[CFG_V_EXT_OFFSET_STD] = 1;   //    11   //+ Vext_offset_std\t
                sys_data.data_cfg[CFG_V_EXT_OFFSET] = 1;
                break;
            case 'l':
                sys_data.data_cfg[CFG_V_EXT_OFFSET_STD] = 0;
                break;
            case 'M':
                sys_data.data_cfg[CFG_V_INT] = 1;   //               12   //+ Vint\t
                break;
            case 'm':
                sys_data.data_cfg[CFG_V_INT] = 0;
                sys_data.data_cfg[CFG_V_INT_STD] = 0;
                break;
            case 'N':
                sys_data.data_cfg[CFG_V_INT_STD] = 1;   //           13   //+ Vint_std\t
                sys_data.data_cfg[CFG_V_INT] = 1;

                break;
            case 'n':
                sys_data.data_cfg[CFG_V_INT_STD] = 0;
                break;
            case 'O':
                sys_data.data_cfg[CFG_V_EXT] = 1;   //               14   //+ Vext
                break;
            case 'o':
                sys_data.data_cfg[CFG_V_EXT] = 0;
                sys_data.data_cfg[CFG_V_EXT_STD] = 0;
                break;
            case 'P':
                sys_data.data_cfg[CFG_V_EXT_STD] = 1;   //           15   // + Vext_std
                sys_data.data_cfg[CFG_V_EXT] = 1;
                break;
            case 'p':
                sys_data.data_cfg[CFG_V_EXT_STD] = 0;
                break;
            case 'Q':
                sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 1;   //     16   //+ Vcounter_electrode
                break;
            case 'q':
                sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 0;
                sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 0;
                break;
            case 'R':
                sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 1;   //   //+ Vcounter_electrode_std
                sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 1;
                break;
            case 'r':
                sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 0;
                break;
            case 'S':
                sys_data.data_cfg[CFG_I_COUNTER] = 1;   //           18   // + Counter_current
                break;
            case 's':
                sys_data.data_cfg[CFG_I_COUNTER] = 0;
                break;
            case 'T':
                sys_data.data_cfg[CFG_I_SUBSTRATE] = 1;   //         19   //+ Substrate_current
                break;
            case 't':
                sys_data.data_cfg[CFG_I_SUBSTRATE] = 0;
                break;
            case 'U':
                sys_data.data_cfg[CFG_CALC_TEMP] = 1;   //           20   //+ calculated_temperature_Vthermistor\t
                break;
            case 'u':
                sys_data.data_cfg[CFG_CALC_TEMP] = 0;
                break;
            case 'V':
                sys_data.data_cfg[CFG_EST_PH_INT] = 1;   //          21   //+ estimated_pH_int\r\n
                break;
            case 'v':
                sys_data.data_cfg[CFG_EST_PH_INT] = 0;
                break;
            case 'W':
                sys_data.data_cfg[CFG_EST_PH_EXT] = 1;   //          22   //+ estimated_pH_ext\r\n (new 6May2019 TM)
                break;
            case 'w':
                sys_data.data_cfg[CFG_EST_PH_EXT] = 0;
                break;
            case 'X':
                sys_data.data_cfg[CFG_OPTODE] = 1;
                break;
            case 'x':
                sys_data.data_cfg[CFG_OPTODE] = 0;
                break;
#ifdef NOCODE
            case 'Z':
                sys_data.fast_mode = 1;
                break;
            case 'z':
                sys_data.fast_mode = 0;
                break;
#endif
                // new 25 Mar 2021
            case 'Y':
                sys_data.data_cfg[CFG_CONDO] = 1;
                break;
            case 'y':
                sys_data.data_cfg[CFG_CONDO] = 0;
                break;

            case '2':
                // -- Glider Data Config Set
                // A Sample Num
                // B MM/DD/YYYY HH:MM:SS
                // C Battery Volt
                // O Vext Ref
                // P Vext Ref Std
                // Q Vcounter Electrode
                // R Vcounter Electrode Std
                // S Counter Electrode Current
                // T Substrate Current
                // Z FAST

                sys_data.data_cfg[CFG_SAMPLE_NUM] = 1;          // A
                sys_data.data_cfg[CFG_TIMEDATE] = 1;            // B
                sys_data.data_cfg[CFG_ENV_BAT_VOLT] = 1;        // C
                sys_data.data_cfg[CFG_ENV_BRD_TEMP] = 0;        // d
                sys_data.data_cfg[CFG_ENV_HUMIDITY] = 0;        //e
                sys_data.data_cfg[CFG_BIAS_BAT_VOLT] = 0;        //f
                sys_data.data_cfg[CFG_V_THERMISTOR] = 0;        //g
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 0;    //h
                sys_data.data_cfg[CFG_V_INT_OFFSET] = 0;        //i
                sys_data.data_cfg[CFG_V_INT_OFFSET_STD] = 0;    // j
                sys_data.data_cfg[CFG_V_EXT_OFFSET] = 0;        // k
                sys_data.data_cfg[CFG_V_EXT_OFFSET_STD] = 0;    //l
                sys_data.data_cfg[CFG_V_INT] = 0;               // m
                sys_data.data_cfg[CFG_V_INT_STD] = 0;           // n
                sys_data.data_cfg[CFG_V_EXT] = 1;               // O              14   //+ Vext
                sys_data.data_cfg[CFG_V_EXT_STD] = 1;           //   P        15   // + Vext_std
                sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 1;     //  Q   16   //+ Vcounter_electrode
                sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 1; // R  //+ Vcounter_electrode_std
                sys_data.data_cfg[CFG_I_COUNTER] = 1;           //  S         18   // + Counter_current
                sys_data.data_cfg[CFG_I_SUBSTRATE] = 1;         // T        19   //+ Substrate_current
                sys_data.data_cfg[CFG_CALC_TEMP] = 0;           // u
                sys_data.data_cfg[CFG_EST_PH_INT] = 0;          // v
                sys_data.data_cfg[CFG_EST_PH_EXT] = 0;          // w
                sys_data.data_cfg[CFG_OPTODE] = 0;              // x
                sys_data.data_cfg[CFG_CONDO] = 0;        // y
                //sys_data.fast_mode = 1;                         // Z

                break;

            case '0':
                sys_data.data_cfg[CFG_SAMPLE_NUM] = 0;          // A
                sys_data.data_cfg[CFG_TIMEDATE] = 0;            // B
                sys_data.data_cfg[CFG_ENV_BAT_VOLT] = 0;        // C
                sys_data.data_cfg[CFG_ENV_BRD_TEMP] = 0;        // d
                sys_data.data_cfg[CFG_ENV_HUMIDITY] = 0;        //e
                sys_data.data_cfg[CFG_BIAS_BAT_VOLT] = 0;        //f
                sys_data.data_cfg[CFG_V_THERMISTOR] = 0;        //g
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 0;    //h
                sys_data.data_cfg[CFG_V_INT_OFFSET] = 0;        //i
                sys_data.data_cfg[CFG_V_INT_OFFSET_STD] = 0;    // j
                sys_data.data_cfg[CFG_V_EXT_OFFSET] = 0;        // k
                sys_data.data_cfg[CFG_V_EXT_OFFSET_STD] = 0;    //l
                sys_data.data_cfg[CFG_V_INT] = 0;               // m
                sys_data.data_cfg[CFG_V_INT_STD] = 0;           // n
                sys_data.data_cfg[CFG_V_EXT] = 0;               // O              14   //+ Vext
                sys_data.data_cfg[CFG_V_EXT_STD] = 0;           //   P        15   // + Vext_std
                sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 0;     //  Q   16   //+ Vcounter_electrode
                sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 0; // R  //+ Vcounter_electrode_std
                sys_data.data_cfg[CFG_I_COUNTER] = 0;           //  S         18   // + Counter_current
                sys_data.data_cfg[CFG_I_SUBSTRATE] = 0;         // T        19   //+ Substrate_current
                sys_data.data_cfg[CFG_CALC_TEMP] = 0;           // u
                sys_data.data_cfg[CFG_EST_PH_INT] = 0;          // v
                sys_data.data_cfg[CFG_EST_PH_EXT] = 0;          // w
                sys_data.data_cfg[CFG_OPTODE] = 0;              // x
                //sys_data.fast_mode = 1;                         // z
                sys_data.data_cfg[CFG_CONDO] = 0;        // y
                break;

            case '1':
                sys_data.data_cfg[CFG_SAMPLE_NUM] = 1;          // A
                sys_data.data_cfg[CFG_TIMEDATE] = 1;            // B
                sys_data.data_cfg[CFG_ENV_BAT_VOLT] = 1;        // C
                sys_data.data_cfg[CFG_ENV_BRD_TEMP] = 1;        // D
                sys_data.data_cfg[CFG_ENV_HUMIDITY] = 1;        //E
                sys_data.data_cfg[CFG_BIAS_BAT_VOLT] = 1;        //F
                sys_data.data_cfg[CFG_V_THERMISTOR] = 1;        //G
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 1;    //H
                sys_data.data_cfg[CFG_V_INT_OFFSET] = 1;        //I
                sys_data.data_cfg[CFG_V_INT_OFFSET_STD] = 1;    // J
                sys_data.data_cfg[CFG_V_EXT_OFFSET] = 1;        // K
                sys_data.data_cfg[CFG_V_EXT_OFFSET_STD] = 1;    //L
                sys_data.data_cfg[CFG_V_INT] = 1;               // M
                sys_data.data_cfg[CFG_V_INT_STD] = 1;           // N
                sys_data.data_cfg[CFG_V_EXT] = 1;               // O              14   //+ Vext
                sys_data.data_cfg[CFG_V_EXT_STD] = 1;           //   P        15   // + Vext_std
                sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 1;     //  Q   16   //+ Vcounter_electrode
                sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 1; // R  //+ Vcounter_electrode_std
                sys_data.data_cfg[CFG_I_COUNTER] = 1;           //  S         18   // + Counter_current
                sys_data.data_cfg[CFG_I_SUBSTRATE] = 1;         // T        19   //+ Substrate_current
                sys_data.data_cfg[CFG_CALC_TEMP] = 1;           // U
                sys_data.data_cfg[CFG_EST_PH_INT] = 1;          // V
                sys_data.data_cfg[CFG_EST_PH_EXT] = 1;          // W
                sys_data.data_cfg[CFG_OPTODE] = 1;              // X
                //sys_data.fast_mode = 1;                         // Z
                sys_data.data_cfg[CFG_CONDO] = 1;        // Y

                break;

            case '3':           // Updated to add Calc Temp 23 Mar 2021   MFET Default
                    //Default for MFET
                //A,B,C,D,E,G,H,I,J,M,N,Q,R,S,T,Z  per Joseph for MiniFET use case
                sys_data.data_cfg[CFG_SAMPLE_NUM] = 1;          // A
                sys_data.data_cfg[CFG_TIMEDATE] = 1;            // B
                sys_data.data_cfg[CFG_ENV_BAT_VOLT] = 1;        // C
                sys_data.data_cfg[CFG_ENV_BRD_TEMP] = 1;        // D
                sys_data.data_cfg[CFG_ENV_HUMIDITY] = 1;        // E
                sys_data.data_cfg[CFG_BIAS_BAT_VOLT] = 0;        //f
                sys_data.data_cfg[CFG_V_THERMISTOR] = 1;        // G
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 1;    // H
                sys_data.data_cfg[CFG_V_INT_OFFSET] = 1;        // I
                sys_data.data_cfg[CFG_V_INT_OFFSET_STD] = 1;    // J
                sys_data.data_cfg[CFG_V_EXT_OFFSET] = 0;        // k
                sys_data.data_cfg[CFG_V_EXT_OFFSET_STD] = 0;    // l
                sys_data.data_cfg[CFG_V_INT] = 1;               // M
                sys_data.data_cfg[CFG_V_INT_STD] = 1;           // N
                sys_data.data_cfg[CFG_V_EXT] = 0;               // o              14   //+ Vext
                sys_data.data_cfg[CFG_V_EXT_STD] = 0;           // p        15   // + Vext_std
                sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 1;     // Q   16   //+ Vcounter_electrode
                sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 1; // R  //+ Vcounter_electrode_std
                sys_data.data_cfg[CFG_I_COUNTER] = 1;           // S         18   // + Counter_current
                sys_data.data_cfg[CFG_I_SUBSTRATE] = 1;         // T        19   //+ Substrate_current
                sys_data.data_cfg[CFG_CALC_TEMP] = 1;           // u
                sys_data.data_cfg[CFG_EST_PH_INT] = 0;          // v
                sys_data.data_cfg[CFG_EST_PH_EXT] = 0;          // w
                sys_data.data_cfg[CFG_OPTODE] = 0;              // x
                sys_data.data_cfg[CFG_CONDO] = 0;       // y
                //sys_data.fast_mode = 1;                         // Z
                break;

            case '4':
                //uprintf("\nfast_mode = 2    4*100msec = 400msec  trials=4, gain=1, sps=10\n");
                //sys_data.fast_mode = 2;
                //Use Case: nsFOCE, fields (C,D,E,F,G,H,I,J,Q,R,S,T,X,Z)
                sys_data.data_cfg[CFG_SAMPLE_NUM] = 0;          // a
                sys_data.data_cfg[CFG_TIMEDATE] = 0;            // b
                sys_data.data_cfg[CFG_ENV_BAT_VOLT] = 1;        // C
                sys_data.data_cfg[CFG_ENV_BRD_TEMP] = 1;        // D
                sys_data.data_cfg[CFG_ENV_HUMIDITY] = 1;        //E
                sys_data.data_cfg[CFG_BIAS_BAT_VOLT] = 1;        //F
                sys_data.data_cfg[CFG_V_THERMISTOR] = 1;        //G
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 1;    //H
                sys_data.data_cfg[CFG_V_INT_OFFSET] = 1;        //I
                sys_data.data_cfg[CFG_V_INT_OFFSET_STD] = 1;    //J
                sys_data.data_cfg[CFG_V_EXT_OFFSET] = 0;        //k
                sys_data.data_cfg[CFG_V_EXT_OFFSET_STD] = 0;    //l
                sys_data.data_cfg[CFG_V_INT] = 0;               //m
                sys_data.data_cfg[CFG_V_INT_STD] = 0;           //n
                sys_data.data_cfg[CFG_V_EXT] = 0;               //o              14   //+ Vext
                sys_data.data_cfg[CFG_V_EXT_STD] = 0;           //p        15   // + Vext_std
                sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 1;     //Q   16   //+ Vcounter_electrode
                sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 1; //R  //+ Vcounter_electrode_std
                sys_data.data_cfg[CFG_I_COUNTER] = 1;           //S         18   // + Counter_current
                sys_data.data_cfg[CFG_I_SUBSTRATE] = 1;         //T        19   //+ Substrate_current
                sys_data.data_cfg[CFG_CALC_TEMP] = 1;           //U
                sys_data.data_cfg[CFG_EST_PH_INT] = 1;          //V
                sys_data.data_cfg[CFG_EST_PH_EXT] = 0;          //w
                sys_data.data_cfg[CFG_OPTODE] = 1;              //X
                sys_data.data_cfg[CFG_CONDO] = 1;        //Y
                //sys_data.fast_mode = 1;                         // Z

                break;

            case '5':
                //Use Case: nanoFET default, fields (A,B,C,D,E,F,G,H,O,P,Q,R,S,T)
                sys_data.data_cfg[CFG_SAMPLE_NUM] = 1;          // A
                sys_data.data_cfg[CFG_TIMEDATE] = 1;            // B
                sys_data.data_cfg[CFG_ENV_BAT_VOLT] = 1;        // C
                sys_data.data_cfg[CFG_ENV_BRD_TEMP] = 1;        // D
                sys_data.data_cfg[CFG_ENV_HUMIDITY] = 1;        // E
                sys_data.data_cfg[CFG_BIAS_BAT_VOLT] = 1;       //F
                sys_data.data_cfg[CFG_V_THERMISTOR] = 1;        //G
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 1;    //H
                sys_data.data_cfg[CFG_V_INT_OFFSET] = 0;        //i  Not valid on nanoFET v1
                sys_data.data_cfg[CFG_V_INT_OFFSET_STD] = 0;    //j  Not valid on nanoFET
                sys_data.data_cfg[CFG_V_EXT_OFFSET] = 0;        //k  Not valid on nanoFET
                sys_data.data_cfg[CFG_V_EXT_OFFSET_STD] = 0;    //l  Not valid on nanoFET
                sys_data.data_cfg[CFG_V_INT] = 0;               //m  Not valid on nanoFET
                sys_data.data_cfg[CFG_V_INT_STD] = 0;           //n  Not valid on naoFET
                sys_data.data_cfg[CFG_V_EXT] = 1;               //O  14   //+ Vext
                sys_data.data_cfg[CFG_V_EXT_STD] = 1;           //P  15   // + Vext_std
                sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 1;     //Q  16   //+ Vcounter_electrode
                sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 1; //R  //+ Vcounter_electrode_std
                sys_data.data_cfg[CFG_I_COUNTER] = 1;           //S  18   // + Counter_current
                sys_data.data_cfg[CFG_I_SUBSTRATE] = 1;         //T  19   //+ Substrate_current
                sys_data.data_cfg[CFG_CALC_TEMP] = 1;           //U
                sys_data.data_cfg[CFG_EST_PH_INT] = 0;          //v
                sys_data.data_cfg[CFG_EST_PH_EXT] = 0;          //w
                sys_data.data_cfg[CFG_OPTODE] = 0;              //x
                sys_data.data_cfg[CFG_CONDO] = 0;        //y
                //sys_data.fast_mode = 1;                         // Z


            case '9':
            default:
                sys_data.fast_mode = 1;  // removed from config 21 Apr 2021
                // Write the sys_data struct into EEPROM.  Last argument ensures # of bytes is multiple of 4
                if(storeSysDataVariables())                         //if(EEPROMProgram((uint32_t*) &sys_data, 0x400, (sizeof(sys_data) + 3) & ~3))
                {
                    uprintf("\n\nError storing system data.\n");
                }
                else
                    uprintf("\n\nSystem data stored. (910) -- Press enter to bring up main menu\n");
                return;

        }  // end of switch statement


//#if BOARD_NANOFET == 1
#ifdef BLOCKINVALIDNANOFETSETTINGS
        sys_data.data_cfg[CFG_V_INT] = 0;   //        8   // not valid on nanoFET
        sys_data.data_cfg[CFG_V_INT_STD] = 0;

        sys_data.data_cfg[CFG_V_INT_OFFSET] = 0;   //        8   // not valid on nanoFET
        sys_data.data_cfg[CFG_V_INT_OFFSET_STD] = 0;

        sys_data.data_cfg[CFG_V_EXT_OFFSET] = 0;
        sys_data.data_cfg[CFG_V_EXT_OFFSET_STD] = 0;
#endif

    }
}















void print_all_metadata(void)
{
#if BOARD_MFET >= 1
    uprintf("MFET Serial #: %s\n", sys_data.board_SN);
#endif
#if BOARD_MPHOX >= 1
    uprintf("MpHOx Serial #: %s\n", sys_data.board_SN);
#endif
#if BOARD_NANOFET >= 1
    uprintf("nanoFET Serial #: %s\n", sys_data.board_SN);
#endif

#if BOARD_MFET >= 1 || BOARD_MPHOX >= 1
    uprintf("MCAP Serial #: %s\n", sys_data.mcap_SN);
#endif

    uprintf("Board Fabrication notes: %s\n", sys_data.board_fab_note);

    uprintf("Durafet Serial #: %s\n", sys_data.durafet_SN);
//    uprintf("CAP adapter Serial #: %s\n", sys_data.capadap_SN);
//    uprintf("ISE Serial #: %s\n", sys_data.ISE_SN);
    uprintf("Package name: %s\n", sys_data.package_name);

    //uprintf("Conductivity Serial #: %s\n", sys_data.condo_SN);

#if BOARD_MPHOX >= 1
    uprintf("Optode Serial #: %s\n", sys_data.optode_SN);
    uprintf("Conductivity Serial #: %s\n", sys_data.condo_SN);
#endif

    uprintf("Pump Serial #: %s\n", sys_data.pump_SN);

    //THOM todo, what about the rest of the metadata?


    //uprintf("\npH Vint gain now %d\n\n", sys_data.Vint_gain);
    //uprintf("\npH Vint data rate now %d sps\n\n", sys_data.Vint_sps);

    uprintf("\n\n");


}

void set_metadata(void)
{
    char buff[128];

    // print metadata settings
    print_all_metadata();

    // it might make sense to group all metadata under one menu item
    // Fabrication info
    // Peripheral instruments
    // Calibration
    // Data Fields

    //char board_SN[MAX_BOARD_SN];   MAX_BOARD_SN 30
#if BOARD_MFET >= 1
    uprintf("\nEnter MFET Serial # [%s]: ", sys_data.board_SN);
#endif
#if BOARD_MPHOX >= 1
    uprintf("\nEnter MPHOX Serial # [%s]: ", sys_data.board_SN);
#endif
#if BOARD_NANOFET >= 1
    uprintf("\nEnter nanoFET Serial # [%s]: ", sys_data.board_SN);
#endif
    if( getUserInput(buff, MAX_BOARD_SN-1) )       // board serial number
    {
        strcpy(sys_data.board_SN, buff);
        uprintf("\nBoard Serial #: %s\n", sys_data.board_SN);
    }


    // char mcap_SN[MAX_MCAP_SN];  MAX_MCAP_SN  30
#if BOARD_MFET >= 1 || BOARD_MPHOX >= 1
    uprintf("\nEnter MCAP Serial # [%s]: ", sys_data.mcap_SN);
    if( getUserInput(buff, MAX_MCAP_SN-1) )       // board serial number
    {
        strcpy(sys_data.mcap_SN, buff);
        uprintf("\nMCAP Serial #: %s\n", sys_data.mcap_SN);
    }
#endif


    // char board_fab_note[MAX_board_fab_note];   MAX_board_fab_note 80
    uprintf("\nEnter board Fabrication notes [%s]: ", sys_data.board_fab_note);
    if( getUserInput(buff, MAX_BOARD_FABNOTE-1) )       // board fabricaton notes
    {
        strcpy(sys_data.board_fab_note, buff);
        uprintf("\nBoard Fab notes: %s\n", sys_data.board_fab_note);
    }


    //char durafet_SN[MAX_DURAFET_SN];  30
    uprintf("\nEnter Durafet Serial # [%s]: ", sys_data.durafet_SN);
    if( getUserInput(buff, MAX_DURAFET_SN-1) )       // board serial number
    {
        strcpy(sys_data.durafet_SN, buff);
        uprintf("\nDurafet Serial #: %s\n", sys_data.durafet_SN);
    }

    //char capadap_SN[MAX_CAPADAP_SN];
//    uprintf("\nEnter CapAdapter Serial # [%s]: ", sys_data.capadap_SN);
//    if( getUserInput(buff, MAX_CAPADAP_SN-1) )       // board serial number
//    {
//        strcpy(sys_data.capadap_SN, buff);
//        uprintf("\nCapAdapter Serial #: %s\n", sys_data.capadap_SN);
//    }

    //char ISE_SN[MAX_ISE_SN];
//    uprintf("\nEnter ISE Serial # [%s]: ", sys_data.ISE_SN);
//    if( getUserInput(buff, MAX_ISE_SN-1) )       // board serial number
//    {
//        strcpy(sys_data.ISE_SN, buff);
//        uprintf("\nISE Serial #: %s\n", sys_data.ISE_SN);
//    }

    // char sensor_name[MAX_SENSOR_NAME];  30   used for temperature sensor (Needed?)
    uprintf("\nEnter Package name [%s]: ", sys_data.package_name);
    if( getUserInput(buff, MAX_PACKAGE_NAME-1) )
    {
        strcpy(sys_data.package_name, buff);
        uprintf("\nPackage name: %s\n\n", sys_data.package_name);
    }

    //char microcat_SN[MAX_MICROCAT_SN];
//    uprintf("\nEnter MicroCat Serial # [%s]: ", sys_data.microcat_SN);
//    if( getUserInput(buff, MAX_MICROCAT_SN-1) )       // board serial number
//    {
//        strcpy(sys_data.microcat_SN, buff);
//        uprintf("\nMicroCat Serial #: %s\n", sys_data.microcat_SN);
//    }

#if BOARD_MPHOX >= 1
    //char optode_SN[MAX_OPTODE_SN];
    uprintf("\nEnter Optode Serial # [%s]: ", sys_data.optode_SN);
    if( getUserInput(buff, MAX_OPTODE_SN-1) )       //
    {
        strcpy(sys_data.optode_SN, buff);
        uprintf("\nOptode Serial #: %s\n", sys_data.optode_SN);
    }

    //char condo_SN[MAX_CONDO_SN];
    uprintf("\nEnter Conductivity Serial # [%s]: ", sys_data.condo_SN);
    if( getUserInput(buff, MAX_CONDO_SN-1) )       //
    {
        strcpy(sys_data.condo_SN, buff);
        uprintf("\nConductivity Serial #: %s\n", sys_data.condo_SN);
    }
#endif

    //char pump_SN[MAX_PUMP_SN];
    uprintf("\nEnter Pump Serial #  [%s]: ", sys_data.pump_SN);
    if( getUserInput(buff, MAX_PUMP_SN-1) )       //
    {
        strcpy(sys_data.pump_SN, buff);
        uprintf("\nPump Serial #: %s\n", sys_data.pump_SN);
    }



}



// write deployment header to SD card, NOTE: the format should match print_deployment_header except for tabs in the print to format for human readable vs machine readable ascii
int write_metadata_header(const time_t currentTime)   // was deployment header
{
    struct tm *time_struct;
    char buff[TIMESTAMPLENGTH];
    FIL fileObject;     // File object
    FRESULT fresult;
    UINT bw;

    if(microSD_flg == 0)  // THOM TODO - do this possibly another way?
        return 0;       // if microSD is disabled TGM 20 Jan 2021, then return as if filesystem is ok

    // Open a file
    fresult = f_open(&fileObject, sys_data.fileName, FA_READ |FA_WRITE |FA_OPEN_ALWAYS);
    if(fresult != FR_OK)
    {
        uprintf("f_open error: %s\n", StringFromFresult(fresult));
        return 1;
    }

    // Seek to the end, to append our file
    fresult = f_lseek(&fileObject, fileObject.fsize);
    if(fresult != FR_OK)
    {
        uprintf("f_lseek error: %s\n", StringFromFresult(fresult));
        return 1;
    }

    sd_fprintf(&fileObject, "//++************** Deployment Settings ***************\n");
    // Store current time
    time_struct = localtime(&currentTime);
    //THOM 25 Mar 2021
    //strftime(buff, sizeof(buff),"\"Current time\"\t\t\t%Y/%m/%d %H:%M:%S", time_struct);
    strftime(buff, sizeof(buff),"// \"Current time\"\t%Y/%m/%d %H:%M:%S\n", time_struct);

    fresult = f_write(&fileObject, buff, strlen(buff), &bw);   // THOM TODO: what is bw???
    if(fresult != FR_OK)
    {
        uprintf("Current time f_write error: %s\n", StringFromFresult(fresult));
        return 1;
    }


    // Store timezone
    if(sys_data.GMT)
    {
        //THOM 25 Mar 2021
        //sd_fprintf(&fileObject, "\n\"Time zone\"\t\t\tGMT");
        //if(txFlg)  uprintf("\n\"Time zone\"\t\t\tGMT");         // THOM new 2 Jul 2019
        sd_fprintf(&fileObject, "// \"Time zone\"\tGMT\n");
    }
    else
    {
        sd_fprintf(&fileObject, "// \"Time zone\"\tLocal\n");
    }

#if BOARD_MPHOX == 1 // new 10 Jun 2020
    sd_fprintf(&fileObject, "// \"MpHOx version\"\t%s\n", VERSION);
#endif
    // THOM new 23Apr2019
#if BOARD_MFET >= 1
    sd_fprintf(&fileObject, "// \"MFET version\"\t%s\n", VERSION);
    //sd_fprintf(&fileObject, "\n\"MFET version\"\t\t\t%s", VERSION);     if(txFlg)  uprintf("\n\"MFET version\"\t\t\t%s", VERSION);         // THOM new 2 Jul 2019
#endif



    // Store the tab delimited deployment header. (Excel treats quoted string as text)
    sd_fprintf(&fileObject, "// File name\t%s\n", sys_data.fileName);                  //if(txFlg) uprintf("\n\"File name\"\t\t\t%s", sys_data.fileName);
    sd_fprintf(&fileObject, "// User initials\t%s\n", sys_data.user);                  //if(txFlg) uprintf("\n\"User initials\"\t\t\t%s", sys_data.user);
    sd_fprintf(&fileObject, "// Sampling period (s)\t%u\n", sys_data.sampling_period); //if(txFlg) uprintf("\n\"Sampling period (s)\"\t\t%u", sys_data.sampling_period);
    sd_fprintf(&fileObject, "// pH Sample average\t%u\n", sys_data.sample_average);    //if(txFlg) uprintf("\n\"pH Sample average\"\t\t%u", sys_data.sample_average);
    sd_fprintf(&fileObject, "// Pump on time (s)\t%u\n", sys_data.pumpon_time);        //if(txFlg) uprintf("\n\"Pump on time (s)\"\t\t%u", sys_data.pumpon_time);
    sd_fprintf(&fileObject, "// Low battery voltage (V)\t%f\n", sys_data.low_batt_volt);  // if(txFlg) uprintf("\n\"Low battery voltage (V)\"\t%f", sys_data.low_batt_volt);
    sd_fprintf(&fileObject, "// TCOffset\t%f\n", sys_data.TCOffset);                      // if(txFlg) uprintf("\n\"TCOffset\"\t\t\t%f", sys_data.TCOffset);
    sd_fprintf(&fileObject, "// k0int\t%f\n", sys_data.k0int);               //if(txFlg) uprintf("\n\"k0int @25C\"\t\t\t%f", sys_data.k0int);
    sd_fprintf(&fileObject, "// k0ext\t%f\n", sys_data.k0ext);               //if(txFlg) uprintf("\n\"k0ext @25C\"\t\t\t%f", sys_data.k0ext);
    sd_fprintf(&fileObject, "// Default salinity (ppt)\t%f\n", sys_data.default_sal);  //if(txFlg) uprintf("\n\"Default salinity (ppt)\"\t%f", sys_data.default_sal);
    sd_fprintf(&fileObject, "// Package name\t%s\n", sys_data.package_name);             //if(txFlg) uprintf("\n\"Sensor name\"\t\t\t%s", sys_data.sensor_name);
    sd_fprintf(&fileObject, "// DuraFET SN\t%s\n", sys_data.durafet_SN);               //if(txFlg) uprintf("\n\"DuraFET SN\"\t\t\t%s", sys_data.durafet_SN);
    //sd_fprintf(&fileObject, "// CAP adapter SN\t%s\n", sys_data.capadap_SN);           //if(txFlg) uprintf("\n\"CAP adapter SN\"\t\t%s", sys_data.capadap_SN);
    //sd_fprintf(&fileObject, "// ISE SN\t%s\n", sys_data.ISE_SN);                       //if(txFlg) uprintf("\n\"ISE SN\"\t\t\t%s", sys_data.ISE_SN);
    //sd_fprintf(&fileObject, "// MicroCAT SN\t%s\n", sys_data.microcat_SN);             //if(txFlg) uprintf("\n\"MicroCAT SN\"\t\t\t%s", sys_data.microcat_SN);
    sd_fprintf(&fileObject, "// Pump SN\t%s\n", sys_data.pump_SN);                     //if(txFlg) uprintf("\n\"Pump SN\"\t\t\t%s", sys_data.pump_SN);
    // pressure removed per Yui 31 Mar 2021
    //sd_fprintf(&fileObject, "\n\"Pressure sensor max (psi)\"\t%d", sys_data.press_full_scale);   if(txFlg) uprintf("\n\"Pressure sensor max (psi)\"\t%d", sys_data.press_full_scale);
    sd_fprintf(&fileObject, "// Vint gain\t%d\n", sys_data.Vint_gain);                 //if(txFlg) uprintf("\n\"Vint gain\"\t\t\t%d", sys_data.Vint_gain);
    sd_fprintf(&fileObject, "// Vint sample rate (sps)\t%d\n", sys_data.Vint_sps);     //if(txFlg) uprintf("\n\"Vint sample rate (sps)\"\t%d", sys_data.Vint_sps);

    if(sys_data.test_mode)
    {
        sd_fprintf(&fileObject, "// Test mode (pump off)\n");    //if(txFlg) uprintf("\n\"Test mode (pump off)\"");
    }
    else
    {
        sd_fprintf(&fileObject, "// Deploy mode (pump on)\n");   //if(txFlg) uprintf("\n\"Deploy mode (pump on)\"");
    }

#ifdef NOCODE
    // Store the tab delimited deployment header. (Excel treats quoted string as text)
    sd_fprintf(&fileObject, "// \"File name\"\t%s\n", sys_data.fileName);                  //if(txFlg) uprintf("\n\"File name\"\t\t\t%s", sys_data.fileName);
    sd_fprintf(&fileObject, "// \"User initials\"\t%s\n", sys_data.user);                  //if(txFlg) uprintf("\n\"User initials\"\t\t\t%s", sys_data.user);
    sd_fprintf(&fileObject, "// \"Sampling period (s)\"\t%u\n", sys_data.sampling_period); //if(txFlg) uprintf("\n\"Sampling period (s)\"\t\t%u", sys_data.sampling_period);
    sd_fprintf(&fileObject, "// \"pH Sample average\"\t%u\n", sys_data.sample_average);    //if(txFlg) uprintf("\n\"pH Sample average\"\t\t%u", sys_data.sample_average);
    sd_fprintf(&fileObject, "// \"Pump on time (s)\"\t%u\n", sys_data.pumpon_time);        //if(txFlg) uprintf("\n\"Pump on time (s)\"\t\t%u", sys_data.pumpon_time);
    sd_fprintf(&fileObject, "// \"Low battery voltage (V)\"\t%f\n", sys_data.low_batt_volt);  // if(txFlg) uprintf("\n\"Low battery voltage (V)\"\t%f", sys_data.low_batt_volt);
    sd_fprintf(&fileObject, "// \"TCOffset\"\t%f\n", sys_data.TCOffset);                      // if(txFlg) uprintf("\n\"TCOffset\"\t\t\t%f", sys_data.TCOffset);
    sd_fprintf(&fileObject, "// \"k0int @25C\"\t%f\n", sys_data.k0int);               //if(txFlg) uprintf("\n\"k0int @25C\"\t\t\t%f", sys_data.k0int);
    sd_fprintf(&fileObject, "// \"k0ext @25C\"\t%f\n", sys_data.k0ext);               //if(txFlg) uprintf("\n\"k0ext @25C\"\t\t\t%f", sys_data.k0ext);
    sd_fprintf(&fileObject, "// \"Default salinity (ppt)\"\t%f\n", sys_data.default_sal);  //if(txFlg) uprintf("\n\"Default salinity (ppt)\"\t%f", sys_data.default_sal);
    sd_fprintf(&fileObject, "// \"Sensor name\"\t%s\n", sys_data.sensor_name);             //if(txFlg) uprintf("\n\"Sensor name\"\t\t\t%s", sys_data.sensor_name);
    sd_fprintf(&fileObject, "// \"DuraFET SN\"\t%s\n", sys_data.durafet_SN);               //if(txFlg) uprintf("\n\"DuraFET SN\"\t\t\t%s", sys_data.durafet_SN);
    sd_fprintf(&fileObject, "// \"CAP adapter SN\"\t%s\n", sys_data.capadap_SN);           //if(txFlg) uprintf("\n\"CAP adapter SN\"\t\t%s", sys_data.capadap_SN);
    sd_fprintf(&fileObject, "// \"ISE SN\"\t%s\n", sys_data.ISE_SN);                       //if(txFlg) uprintf("\n\"ISE SN\"\t\t\t%s", sys_data.ISE_SN);
    sd_fprintf(&fileObject, "// \"MicroCAT SN\"\t%s\n", sys_data.microcat_SN);             //if(txFlg) uprintf("\n\"MicroCAT SN\"\t\t\t%s", sys_data.microcat_SN);
    sd_fprintf(&fileObject, "// \"Pump SN\"\t%s\n", sys_data.pump_SN);                     //if(txFlg) uprintf("\n\"Pump SN\"\t\t\t%s", sys_data.pump_SN);
    // pressure removed per Yui 31 Mar 2021
    //sd_fprintf(&fileObject, "\n\"Pressure sensor max (psi)\"\t%d", sys_data.press_full_scale);   if(txFlg) uprintf("\n\"Pressure sensor max (psi)\"\t%d", sys_data.press_full_scale);
    sd_fprintf(&fileObject, "// \"Vint gain\"\t%d\n", sys_data.Vint_gain);                 //if(txFlg) uprintf("\n\"Vint gain\"\t\t\t%d", sys_data.Vint_gain);
    sd_fprintf(&fileObject, "// \"Vint sample rate (sps)\"\t%d\n", sys_data.Vint_sps);     //if(txFlg) uprintf("\n\"Vint sample rate (sps)\"\t%d", sys_data.Vint_sps);

    if(sys_data.test_mode)
    {
        sd_fprintf(&fileObject, "// \"Test mode (pump off)\"\n");    //if(txFlg) uprintf("\n\"Test mode (pump off)\"");
    }
    else
    {
        sd_fprintf(&fileObject, "// \"Deploy mode (pump on)\"\n");   //if(txFlg) uprintf("\n\"Deploy mode (pump on)\"");
    }
#endif

    sd_fprintf(&fileObject, "//--**************************************************\n");
    // THOM DEBUG
    // Removed debug 25 Mar 2021
    //sd_fprintf(&fileObject, "\n\"Fast mode\"\t\t\t%u", sys_data.fast_mode);     if(txFlg) uprintf("\n\"Fast mode\"\t\t\t%u", sys_data.fast_mode);

    // THOM TODO, break this out into two pieces
    //write_data_header(fileObject);

    sd_fprintf(&fileObject, "\n\n");

    // Store the tab delimited column headers
    if(sys_data.data_cfg[CFG_SAMPLE_NUM] > 0)       { sd_fprintf(&fileObject, "SampNum\t");         }  //0
    if(sys_data.data_cfg[CFG_TIMEDATE] > 0)         { sd_fprintf(&fileObject, "SampTime\t");        }  //1
    if(sys_data.data_cfg[CFG_ENV_BAT_VOLT] > 0)     { sd_fprintf(&fileObject, "Vbatt_main\t");      }  //2
    if(sys_data.data_cfg[CFG_ENV_BRD_TEMP] > 0)     { sd_fprintf(&fileObject, "TC_cont\t");         }  //3
    if(sys_data.data_cfg[CFG_ENV_HUMIDITY] > 0)     { sd_fprintf(&fileObject, "Humidity\t");        }  //4
    if(sys_data.data_cfg[CFG_BIAS_BAT_VOLT] > 0)    { sd_fprintf(&fileObject, "Bias Batt\t");       }  //5
    if(sys_data.data_cfg[CFG_V_THERMISTOR] > 0)     { sd_fprintf(&fileObject, "Vtherm\t");          }  //6
    if(sys_data.data_cfg[CFG_V_THERMISTOR_STD] > 0) { sd_fprintf(&fileObject, "Vtherm std\t");      }  //7
    if(sys_data.data_cfg[CFG_V_INT_OFFSET] > 0)     { sd_fprintf(&fileObject, "VrsiBiased\t");      }  //8
    if(sys_data.data_cfg[CFG_V_INT_OFFSET_STD] > 0) { sd_fprintf(&fileObject, "VrsiBiased_std\t");  }  //9
    if(sys_data.data_cfg[CFG_V_EXT_OFFSET] > 0)     { sd_fprintf(&fileObject, "VrseBiased\t");      }  //10
    if(sys_data.data_cfg[CFG_V_EXT_OFFSET_STD] > 0) { sd_fprintf(&fileObject, "VrseBiased_std\t");  }  //11

    if(sys_data.data_cfg[CFG_V_INT] > 0)            { sd_fprintf(&fileObject, "Vrsi\t");            }  //12
    if(sys_data.data_cfg[CFG_V_INT_STD] > 0)        { sd_fprintf(&fileObject, "Vrsi_std\t");        }  //13
    if(sys_data.data_cfg[CFG_V_EXT] > 0)            { sd_fprintf(&fileObject, "Vrse\t");            }  //14
    if(sys_data.data_cfg[CFG_V_EXT_STD] > 0)        { sd_fprintf(&fileObject, "Vrse_std\t");        }  //15
    if(sys_data.data_cfg[CFG_V_COUNTER_ELECT] > 0)  { sd_fprintf(&fileObject, "Vk\t");              }  //16
    if(sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] > 0)  { sd_fprintf(&fileObject, "Vk_std\t");      }  //17
    if(sys_data.data_cfg[CFG_I_COUNTER] > 0)        { sd_fprintf(&fileObject, "Ik\t");              }  //18
    if(sys_data.data_cfg[CFG_I_SUBSTRATE] > 0)      { sd_fprintf(&fileObject, "Ib\t");              }  //19
    if(sys_data.data_cfg[CFG_CALC_TEMP] > 0)        { sd_fprintf(&fileObject, "TC_Dfet\t");         }  //20
    if(sys_data.data_cfg[CFG_EST_PH_INT] > 0)       { sd_fprintf(&fileObject, "pHint_est\t");       }  //21
    if(sys_data.data_cfg[CFG_OPTODE] > 0)           { sd_fprintf(&fileObject, "\tOpt_PN\tOpt_SN\tMoxy\tO2satper\tTC_opt\tDphase\tBphase\tRphase\tBamp\tBpot\tRamp\tOpt_rawtemp"); } //22 -
    //THOM TODO: add config for MicroCat vs Aanderaa Conductivity
    if(sys_data.data_cfg[CFG_CONDO] > 0)     { sd_fprintf(&fileObject, "\tCond_PN\tCond_SN\tCond\tTemp\t"); }

#ifdef OLDCODE

    // Store the tab delimited column headers
    if(sys_data.data_cfg[CFG_SAMPLE_NUM] > 0)       { sd_fprintf(&fileObject, "\"SampNum\"\t");         }  //0
    if(sys_data.data_cfg[CFG_TIMEDATE] > 0)         { sd_fprintf(&fileObject, "\"SampTime\"\t");        }  //1
    if(sys_data.data_cfg[CFG_ENV_BAT_VOLT] > 0)     { sd_fprintf(&fileObject, "\"Vbatt_main\"\t");      }  //2
    if(sys_data.data_cfg[CFG_ENV_BRD_TEMP] > 0)     { sd_fprintf(&fileObject, "\"TC_cont\"\t");         }  //3
    if(sys_data.data_cfg[CFG_ENV_HUMIDITY] > 0)     { sd_fprintf(&fileObject, "\"Humidity\"\t");        }  //4
    if(sys_data.data_cfg[CFG_BIAS_BAT_VOLT] > 0)    { sd_fprintf(&fileObject, "\"Bias Batt\"\t");       }  //5
    if(sys_data.data_cfg[CFG_V_THERMISTOR] > 0)     { sd_fprintf(&fileObject, "\"Vtherm\"\t");          }  //6
    if(sys_data.data_cfg[CFG_V_THERMISTOR_STD] > 0) { sd_fprintf(&fileObject, "\"Vtherm std\"\t");      }  //7
    if(sys_data.data_cfg[CFG_V_INT_OFFSET] > 0)     { sd_fprintf(&fileObject, "\"VrsiBiased\"\t");      }  //8
    if(sys_data.data_cfg[CFG_V_INT_OFFSET_STD] > 0) { sd_fprintf(&fileObject, "\"VrsiBiased_std\"\t");  }  //9
    if(sys_data.data_cfg[CFG_V_EXT_OFFSET] > 0)     { sd_fprintf(&fileObject, "\"VrseBiased\"\t");      }  //10
    if(sys_data.data_cfg[CFG_V_EXT_OFFSET_STD] > 0) { sd_fprintf(&fileObject, "\"VrseBiased_std\"\t");  }  //11

    if(sys_data.data_cfg[CFG_V_INT] > 0)            { sd_fprintf(&fileObject, "\"Vrsi\"\t");            }  //12
    if(sys_data.data_cfg[CFG_V_INT_STD] > 0)        { sd_fprintf(&fileObject, "\"Vrsi_std\"\t");        }  //13
    if(sys_data.data_cfg[CFG_V_EXT] > 0)            { sd_fprintf(&fileObject, "\"Vrse\"\t");            }  //14
    if(sys_data.data_cfg[CFG_V_EXT_STD] > 0)        { sd_fprintf(&fileObject, "\"Vrse_std\"\t");        }  //15
    if(sys_data.data_cfg[CFG_V_COUNTER_ELECT] > 0)  { sd_fprintf(&fileObject, "\"Vk\"\t");              }  //16
    if(sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] > 0)  { sd_fprintf(&fileObject, "\"Vk_std\"\t");      }  //17
    if(sys_data.data_cfg[CFG_I_COUNTER] > 0)        { sd_fprintf(&fileObject, "\"Ik\"\t");              }  //18
    if(sys_data.data_cfg[CFG_I_SUBSTRATE] > 0)      { sd_fprintf(&fileObject, "\"Ib\"\t");              }  //19
    if(sys_data.data_cfg[CFG_CALC_TEMP] > 0)        { sd_fprintf(&fileObject, "\"TC_Dfet\"\t");         }  //20
    if(sys_data.data_cfg[CFG_EST_PH_INT] > 0)       { sd_fprintf(&fileObject, "\"pHint_est\"\t");       }  //21
    if(sys_data.data_cfg[CFG_OPTODE] > 0)           { sd_fprintf(&fileObject, "\tOpt_PN\tOpt_SN\tMoxy\tO2satper\tTC_opt\tDphase\tBphase\tRphase\tBamp\tBpot\tRamp\tOpt_rawtemp"); } //22 -
    if(sys_data.data_cfg[CFG_CONDUCTIVITY] > 0)     { sd_fprintf(&fileObject, "\tCond_PN\tCond_SN\tCond\tTemp\t"); }

#endif

    sd_fprintf(&fileObject, "\n");

    sys_data.next_gdata_fptr = fileObject.fptr;     // Store the file pointer for the first sample (for gdata)

    // Close the file
    fresult = f_close( &fileObject);
    if(fresult != FR_OK)
    {
        uprintf("f_close error: %s\n", StringFromFresult(fresult));
        return 1;
    }

    return 0;
}



void print_data_header(void)
{
//#SampNum        MM/DD/YYYY HH:MM:SS     Bat V   Vtherm  VthrStd VextRef VextRStd        VcntElec        VceStd  Ik      Ib
//#SampNum        MM/DD/YYYY HH:MM:SS     Bat V    Vtherm         VthermStd       VextRef VextRStd        VcntElec        VceStd  Ik      Ib
//#0000030        05/29/2019 16:41:59     12.03   -0.047092       0.000766        -0.040439       0.000090        -2.048000       0.000000        0.001311        0.000385

    //poopout_data_header(1, 0);

    uprintf("\n\n");

    if(sys_data.data_cfg[CFG_SAMPLE_NUM] > 0)       { uprintf("SampNum\t");                 } //0
    if(sys_data.data_cfg[CFG_TIMEDATE] > 0)         { uprintf("MM/DD/YYYY HH:MM:SS\t");     } //1
    if(sys_data.data_cfg[CFG_ENV_BAT_VOLT] > 0)     { uprintf("Vbatt_main\t");              } //2
    if(sys_data.data_cfg[CFG_ENV_BRD_TEMP] > 0)     { uprintf("TC_cont\t");                 } //3
    if(sys_data.data_cfg[CFG_ENV_HUMIDITY] > 0)     { uprintf("Humidity\t");                } //4
    if(sys_data.data_cfg[CFG_BIAS_BAT_VOLT] > 0)    { uprintf("Vbatt_bias\t");              } //5  Bias Battery Volts
    if(sys_data.data_cfg[CFG_V_THERMISTOR] > 0)     { uprintf("Vtherm\t");                  } //6
    if(sys_data.data_cfg[CFG_V_THERMISTOR_STD] > 0) { uprintf("Vtherm_std\t");              } //7
    if(sys_data.data_cfg[CFG_V_INT_OFFSET] > 0)     { uprintf("VrsiBiased\t");              } //8
    if(sys_data.data_cfg[CFG_V_INT_OFFSET_STD] > 0) { uprintf("VrsiBiased_std\t");          } //9
    if(sys_data.data_cfg[CFG_V_EXT_OFFSET] > 0)     { uprintf("VrseBiased\t");              } //10
    if(sys_data.data_cfg[CFG_V_EXT_OFFSET_STD] > 0) { uprintf("VrseBiased_std\t");          } //11

    if(sys_data.data_cfg[CFG_V_INT] > 0)            { uprintf("Vrsi\t");                    } //12
    if(sys_data.data_cfg[CFG_V_INT_STD] > 0)        { uprintf("Vrsi_std\t");                } //13
    if(sys_data.data_cfg[CFG_V_EXT] > 0)            { uprintf("Vrse\t");                    } //14
    if(sys_data.data_cfg[CFG_V_EXT_STD] > 0)        { uprintf("Vrse_std\t");                } //15
    if(sys_data.data_cfg[CFG_V_COUNTER_ELECT] > 0)  { uprintf("Vk\t");                      } //16
    if(sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] > 0) { uprintf("Vk_std\t");               } //17
    if(sys_data.data_cfg[CFG_I_COUNTER] > 0)        { uprintf("Ik\t");                      } //18
    if(sys_data.data_cfg[CFG_I_SUBSTRATE] > 0)      { uprintf("Ib\t");                      } //19
    if(sys_data.data_cfg[CFG_CALC_TEMP] > 0)        { uprintf("TC_Dfet\t");                 } //20
    if(sys_data.data_cfg[CFG_EST_PH_INT] > 0)       { uprintf("pHint_est\t");               } //21
    if(sys_data.data_cfg[CFG_OPTODE] > 0)           { uprintf("\tOpt_PN\tOpt_SN\tMoxy\tO2satper\tTC_opt\tDphase\tBphase\tRphase\tBamp\tBpot\tRamp\tOpt_rawtemp"); } //22 -
    if(sys_data.data_cfg[CFG_CONDO] > 0)            { uprintf("\tCond_PN\tCond_SN\tCond\tTemp\t"); }
    uprintf("\n");      // was uprintf("\r\n);  changed to match write
    ROM_SysCtlDelay(MILLISECOND*50);        // time to send string
}

void get_header(void)
{
    print_data_header();

}


int get_deployment_note(void)
{
    int byteCnt = 0;
    unsigned char noteBuf[84];

    //THOM todo, add timeout

    noteBuf[0] = 0x00;
    uprintf("\nEnter Deployment Note: ");
    if( getUserInput(noteBuf, 80) )
    {
        uprintf("\n%s\n", noteBuf);

    }

    return(byteCnt);
}

/*
 * print_metadata_header(currentTime)
 */


void print_metadata_header(const time_t currentTime)
//void print_metadata_header(void)
{
    struct tm *time_struct;
    char buff[TIMESTAMPLENGTH+6];

    // Print Deployment Header
    uprintf("\n\n\n");      // was uprintf("\n\n\n\n\n
    uprintf("//++*************** Deployment Settings **************\n");
    // Sensor name
    // Durafet ID

    //      "// MpHOx version:          \t%s\n
    uprintf("// Sampling period:        \t%d seconds\n", sys_data.sampling_period);

    uprintf("// Samples hour align:     \t");
    if(sys_data.sample_aligned) uprintf("Yes\n");
    else uprintf("No\n");

    // THOM: update the header with correct info (fast sampling, etc)

    uprintf("// pH sample average:      \t%d samples\n", sys_data.sample_average);
    uprintf("// Pump on time:           \t%d seconds\n", sys_data.pumpon_time);
    uprintf("// Low battery voltage:    \t%.1f V\n", sys_data.low_batt_volt);

    if(sys_data.output == 1)      uprintf("// Output mode:            \tNormal\n");
    else if(sys_data.output == 2) uprintf("// Output mode:            \tVerbose\n");
#ifdef DUPCODE
    uprintf("// k0int       =           \t%1.6f V\n", sys_data.k0int);
    uprintf("// k0ext       =           \t%1.6f V\n", sys_data.k0ext);
    uprintf("// k2int       =           \t%1.6f V\n", sys_data.k2int);
    uprintf("// k2ext       =           \t%1.6f V\n", sys_data.k2ext);
          //"// MpHOx version:          \t%s\n"
    uprintf("// File name:              \t%s\n", sys_data.fileName);
#endif
    //uprintf("// Current time: ");       // THOM TODO: time is needing to be passed in
    //printCurrentTime();

    time_struct = localtime(&currentTime);
    //THOM 20 Apr 2021
    strftime(buff, sizeof(buff),"// Current time:           \t%Y/%m/%d %H:%M:%S", time_struct);
    uprintf("%s\n", buff);

    // Store timezone
    if(sys_data.GMT)   { uprintf("// Time zone:              \tGMT\n");     }
    else               { uprintf("// Time zone:              \tLocal\n");   }

#if BOARD_MPHOX == 1
    uprintf("// MpHOx version:          \t%s\n", VERSION);
    #endif
    // THOM new 23Apr2019
#if BOARD_MFET >= 1
    uprintf("//MFET version:            \t%s"\n, VERSION);         // THOM new 2 Jul 2019
#endif

    wait_consoleTx();       // defd in uartstdio.c  TODO add timeout

    // print the tab delimited deployment header. (Excel treats quoted string as text)
    uprintf("// File name:              \t%s\n", sys_data.fileName);
    uprintf("// User initials:          \t%s\n", sys_data.user);
    uprintf("// Sampling period (s):    \t%u\n", sys_data.sampling_period);
    uprintf("// pH Sample average:      \t%u\n", sys_data.sample_average);
    uprintf("// Pump on time (s):       \t%u\n", sys_data.pumpon_time);
    uprintf("// Low battery (V):        \t%f\n", sys_data.low_batt_volt);
    uprintf("// TCOffset:               \t%f\n", sys_data.TCOffset);
    uprintf("// k0int:                  \t%f\n", sys_data.k0int);
    uprintf("// k0ext:                  \t%f\n", sys_data.k0ext);
    uprintf("// k2int:                  \t%f\n", sys_data.k2int);
    uprintf("// k2ext:                  \t%f\n", sys_data.k2ext);

    ROM_SysCtlDelay(MILLISECOND*100);        // time to send string  THOM TODO, figure out why the stdio buffer is not big enough (now 2048 20 Apr 2021)

    uprintf("// Default salinity (ppt): \t%f\n", sys_data.default_sal);
    uprintf("// Package name:           \t%s\n", sys_data.package_name);
    uprintf("// DuraFET SN:             \t%s\n", sys_data.durafet_SN);
    //uprintf("// CAP adapter SN:         \t%s\n", sys_data.capadap_SN);
    //uprintf("// ISE SN:                 \t%s\n", sys_data.ISE_SN);
    //uprintf("// MicroCAT SN:            \t%s\n", sys_data.microcat_SN);
    uprintf("// Pump SN:                \t%s\n", sys_data.pump_SN);  //    uprintf("// Pump SN\t\t\t%s\n", sys_data.pump_SN);
    uprintf("// Vint gain:              \t%d\n", sys_data.Vint_gain);
    uprintf("// Vint sample rate (sps): \t%d\n", sys_data.Vint_sps);

    if(sys_data.test_mode)
    {
        uprintf("// Test mode:              \t(pump off)\n");
    }
    else
    {
        uprintf("// Deploy mode:            \t(pump on)\n");
    }

    ROM_SysCtlDelay(MILLISECOND*100);        // time to send string

    uprintf("//--***************************************************\n");

    uprintf("\n");

}












#ifdef OLDCODE
// print deployment header to serial terminal
void print_deployment_header(const time_t currentTime)
{
    struct tm *time_struct;
    char buff[TIMESTAMPLENGTH];

    // Store current time
    time_struct = localtime(&currentTime);
    //THOM 25 Mar 2021
    strftime(buff, sizeof(buff),"\"Current time\"\t%Y/%m/%d %H:%M:%S", time_struct);
    uprintf("%s", buff);

    // Store timezone
    if(sys_data.GMT)
    {
        uprintf("\n\"Time zone\"\tGMT");
    }
    else
    {
        uprintf("\n\"Time zone\"\tLocal");
    }

#if BOARD_MPHOX == 1
    uprintf("\n\"MpHOx version\"\t\t\t%s", VERSION);
    #endif
    // THOM new 23Apr2019
#if BOARD_MFET >= 1
    uprintf("\n\"MFET version\"\t\t\t%s", VERSION);         // THOM new 2 Jul 2019
#endif


    // print the tab delimited deployment header. (Excel treats quoted string as text)
    uprintf("\n\"File name\"\t\t\t%s", sys_data.fileName);
    uprintf("\n\"User initials\"\t\t\t%s", sys_data.user);
    uprintf("\n\"Sampling period (s)\"\t\t%u", sys_data.sampling_period);
    uprintf("\n\"pH Sample average\"\t\t%u", sys_data.sample_average);
    uprintf("\n\"Pump on time (s)\"\t\t%u", sys_data.pumpon_time);
    uprintf("\n\"Low battery voltage (V)\"\t%f", sys_data.low_batt_volt);
    uprintf("\n\"TCOffset\"\t\t\t%f", sys_data.TCOffset);
    uprintf("\n\"k0int @25C\"\t\t\t%f", sys_data.k0int);
    uprintf("\n\"k0ext @25C\"\t\t\t%f", sys_data.k0ext);

    ROM_SysCtlDelay(MILLISECOND*100);        // time to send string

    uprintf("\n\"Default salinity (ppt)\"\t%f", sys_data.default_sal);
    uprintf("\n\"Sensor name\"\t\t\t%s", sys_data.sensor_name);
    uprintf("\n\"DuraFET SN\"\t\t\t%s", sys_data.durafet_SN);
    uprintf("\n\"CAP adapter SN\"\t\t%s", sys_data.capadap_SN);
    uprintf("\n\"ISE SN\"\t\t\t%s", sys_data.ISE_SN);
    uprintf("\n\"MicroCAT SN\"\t\t\t%s", sys_data.microcat_SN);
    uprintf("\n\"Pump SN\"\t\t\t%s", sys_data.pump_SN);
    uprintf("\n\"Vint gain\"\t\t\t%d", sys_data.Vint_gain);
    uprintf("\n\"Vint sample rate (sps)\"\t%d", sys_data.Vint_sps);

    if(sys_data.test_mode)
    {
        uprintf("\n\"Test mode (pump off)\"");
    }
    else
    {
        uprintf("\n\"Deploy mode (pump on)\"");
    }

    uprintf("\n\n");

    ROM_SysCtlDelay(MILLISECOND*100);        // time to send string

    // THOM TODO should print the data headers
    print_data_header();

//    return 0;
}
#endif

#ifdef EXAMPLEOUTPUT
//++*************** Deployment Settings **************
// Sampling period:     10 seconds
//Samples hour aligned  No
// pH sample average:   10 samples
// Pump on time:        0 seconds
// Low battery voltage:         8.0 V
// Output mode:         Normal
// k0int @25 C =        -0.400000 V
// k0ext @25 C =        -1.300000 V
// File name:   noname.txt
// Current time: 04/08/21 05:00:30
//--***************************************************
"Current time"  2021/04/08 05:00:30
"Time zone"     Local
"MFET version"                  v3.4.0Pre (3.x.x) MFET v2
"File name"                     noname.txt
"User initials"                 abc
"Sampling period (s)"           10
"pH Sample average"             10
"Pump on time (s)"              0
"Low battery voltage (V)"       8.000000
"TCOffset"                      0.000000
"k0int @25C"                    -0.400000
"k0ext @25C"                    -1.300000
"Default salinity (ppt)"        35.000000
"Sensor name"                   abc
"DuraFET SN"                    abc
"CAP adapter SN"                abc
"ISE SN"                        abc
"MicroCAT SN"                   abc
"Pump SN"                       abc
"Vint gain"                     1
"Vint sample rate (sps)"        10
"Deploy mode (pump on)"
#endif

/*
 * Store the deployment parameters to the beginning of a new deployment.
 * Returns non-zero if there is a file error. Usually because user forgot to
 * install a SD card.
 * Modified RCG 5/14
 */
// DEPRECATED
#ifdef OLDCODE
int writeDeploymentInformationHeader(const time_t currentTime)
{
    struct tm *time_struct;
    char buff[TIMESTAMPLENGTH];
    FIL fileObject;     // File object
    FRESULT fresult;
    UINT bw;

    //if(txFlg > 0)
    //    print_deployment_header(currentTime, firstSample);

    if(microSD_flg == 0)
        return 1;       // microSD is disabled TGM 20 Jan 2021

    write_deployment_header(currentTime); // write to uSD card

#ifdef OLDCODESEPARATEWRITEFROMPRINT
    // Open a file
    fresult = f_open(&fileObject, sys_data.fileName, FA_READ |FA_WRITE |FA_OPEN_ALWAYS);
    if(fresult != FR_OK)
    {
        uprintf("Filesystem f_open error: %s\n", StringFromFresult(fresult));
        uprintf("Check microSD card: either missing, not seated in connector, or bad\n");
        return 1;
    }

    // Seek to the end, to append our file
    fresult = f_lseek(&fileObject, fileObject.fsize);
    if(fresult != FR_OK)
    {
        uprintf("f_lseek error: %s\n", StringFromFresult(fresult));
        return 1;
    }

    // Store current time
    time_struct = localtime(&currentTime);
    //THOM 25 Mar 2021
    //strftime(buff, sizeof(buff),"\"Current time\"\t\t\t%Y/%m/%d %H:%M:%S", time_struct);
    strftime(buff, sizeof(buff),"\"Current time\"\t%Y/%m/%d %H:%M:%S", time_struct);

    fresult = f_write(&fileObject, buff, strlen(buff), &bw);
    if(txFlg)  uprintf("%s", buff);       // THOM new 2 Jul 2019
    if(fresult != FR_OK)
    {
        uprintf("Current time f_write error: %s\n", StringFromFresult(fresult));
        return 1;
    }


    // Store timezone
    if(sys_data.GMT)
    {
        //THOM 25 Mar 2021
        //sd_fprintf(&fileObject, "\n\"Time zone\"\t\t\tGMT");
        //if(txFlg)  uprintf("\n\"Time zone\"\t\t\tGMT");         // THOM new 2 Jul 2019
        sd_fprintf(&fileObject, "\n\"Time zone\"\tGMT");            if(txFlg)  uprintf("\n\"Time zone\"\tGMT");         // THOM new 2 Jul 2019
    }
    else
    {
        //THOM 25 Mar 2021
        sd_fprintf(&fileObject, "\n\"Time zone\"\tLocal");          if(txFlg)  uprintf("\n\"Time zone\"\tLocal");
        //sd_fprintf(&fileObject, "\n\"Time zone\"\t\t\tLocal");
        //if(txFlg)  uprintf("\n\"Time zone\"\t\t\tLocal");
    }

#if BOARD_MPHOX == 1 // new 10 Jun 2020
    sd_fprintf(&fileObject, "\n\"MpHOx version\"\t%s", VERSION);     if(txFlg)  uprintf("\n\"MpHOx version\"\t\t\t%s", VERSION);
    //sd_fprintf(&fileObject, "\n\"MpHOx version\"\t\t\t%s", VERSION);     if(txFlg)  uprintf("\n\"MpHOx version\"\t\t\t%s", VERSION);
    #endif
    // THOM new 23Apr2019
#if BOARD_MFET >= 1
    sd_fprintf(&fileObject, "\n\"MFET version\"\t%s", VERSION);     if(txFlg)  uprintf("\n\"MFET version\"\t\t\t%s", VERSION);         // THOM new 2 Jul 2019
    //sd_fprintf(&fileObject, "\n\"MFET version\"\t\t\t%s", VERSION);     if(txFlg)  uprintf("\n\"MFET version\"\t\t\t%s", VERSION);         // THOM new 2 Jul 2019
#endif



    // Store the tab delimited deployment header. (Excel treats quoted string as text)
    sd_fprintf(&fileObject, "\n\"File name\"\t%s", sys_data.fileName);                  if(txFlg) uprintf("\n\"File name\"\t\t\t%s", sys_data.fileName);
    sd_fprintf(&fileObject, "\n\"User initials\"\t%s", sys_data.user);                  if(txFlg) uprintf("\n\"User initials\"\t\t\t%s", sys_data.user);
    sd_fprintf(&fileObject, "\n\"Sampling period (s)\"\t%u", sys_data.sampling_period); if(txFlg) uprintf("\n\"Sampling period (s)\"\t\t%u", sys_data.sampling_period);
    sd_fprintf(&fileObject, "\n\"pH Sample average\"\t%u", sys_data.sample_average);    if(txFlg) uprintf("\n\"pH Sample average\"\t\t%u", sys_data.sample_average);
    sd_fprintf(&fileObject, "\n\"Pump on time (s)\"\t%u", sys_data.pumpon_time);        if(txFlg) uprintf("\n\"Pump on time (s)\"\t\t%u", sys_data.pumpon_time);
    sd_fprintf(&fileObject, "\n\"Low battery voltage (V)\"\t%f", sys_data.low_batt_volt);   if(txFlg) uprintf("\n\"Low battery voltage (V)\"\t%f", sys_data.low_batt_volt);
    sd_fprintf(&fileObject, "\n\"TCOffset\"\t%f", sys_data.TCOffset);                       if(txFlg) uprintf("\n\"TCOffset\"\t\t\t%f", sys_data.TCOffset);
    sd_fprintf(&fileObject, "\n\"k0int @25C\"\t%f", sys_data.k0int);               if(txFlg) uprintf("\n\"k0int @25C\"\t\t\t%f", sys_data.k0int);
    sd_fprintf(&fileObject, "\n\"k0ext @25C\"\t%f", sys_data.k0ext);               if(txFlg) uprintf("\n\"k0ext @25C\"\t\t\t%f", sys_data.k0ext);
    sd_fprintf(&fileObject, "\n\"Default salinity (ppt)\"\t%f", sys_data.default_sal);  if(txFlg) uprintf("\n\"Default salinity (ppt)\"\t%f", sys_data.default_sal);
    sd_fprintf(&fileObject, "\n\"Sensor name\"\t%s", sys_data.sensor_name);             if(txFlg) uprintf("\n\"Sensor name\"\t\t\t%s", sys_data.sensor_name);
    sd_fprintf(&fileObject, "\n\"DuraFET SN\"\t%s", sys_data.durafet_SN);               if(txFlg) uprintf("\n\"DuraFET SN\"\t\t\t%s", sys_data.durafet_SN);
    sd_fprintf(&fileObject, "\n\"CAP adapter SN\"\t%s", sys_data.capadap_SN);           if(txFlg) uprintf("\n\"CAP adapter SN\"\t\t%s", sys_data.capadap_SN);
    sd_fprintf(&fileObject, "\n\"ISE SN\"\t%s", sys_data.ISE_SN);                       if(txFlg) uprintf("\n\"ISE SN\"\t\t\t%s", sys_data.ISE_SN);
    sd_fprintf(&fileObject, "\n\"MicroCAT SN\"\t%s", sys_data.microcat_SN);             if(txFlg) uprintf("\n\"MicroCAT SN\"\t\t\t%s", sys_data.microcat_SN);
    sd_fprintf(&fileObject, "\n\"Pump SN\"\t%s", sys_data.pump_SN);                     if(txFlg) uprintf("\n\"Pump SN\"\t\t\t%s", sys_data.pump_SN);
    // pressure removed per Yui 31 Mar 2021
    //sd_fprintf(&fileObject, "\n\"Pressure sensor max (psi)\"\t%d", sys_data.press_full_scale);   if(txFlg) uprintf("\n\"Pressure sensor max (psi)\"\t%d", sys_data.press_full_scale);
    sd_fprintf(&fileObject, "\n\"Vint gain\"\t%d", sys_data.Vint_gain);                 if(txFlg) uprintf("\n\"Vint gain\"\t\t\t%d", sys_data.Vint_gain);
    sd_fprintf(&fileObject, "\n\"Vint sample rate (sps)\"\t%d", sys_data.Vint_sps);     if(txFlg) uprintf("\n\"Vint sample rate (sps)\"\t%d", sys_data.Vint_sps);

    if(sys_data.test_mode)
    {
        sd_fprintf(&fileObject, "\n\"Test mode (pump off)\"");    if(txFlg) uprintf("\n\"Test mode (pump off)\"");
    }
    else
    {
        sd_fprintf(&fileObject, "\n\"Deploy mode (pump on)\"");   if(txFlg) uprintf("\n\"Deploy mode (pump on)\"");
    }

    // THOM DEBUG
    // Removed debug 25 Mar 2021
    //sd_fprintf(&fileObject, "\n\"Fast mode\"\t\t\t%u", sys_data.fast_mode);     if(txFlg) uprintf("\n\"Fast mode\"\t\t\t%u", sys_data.fast_mode);


    // Store the tab delimited column headers
    if(sys_data.data_cfg[CFG_SAMPLE_NUM] > 0)       { sd_fprintf(&fileObject, "\n\n\"SampNum\"\t");    }  //0
    if(sys_data.data_cfg[CFG_TIMEDATE] > 0)         { sd_fprintf(&fileObject, "\"SampTime\"\t");     }  //1
    if(sys_data.data_cfg[CFG_ENV_BAT_VOLT] > 0)     { sd_fprintf(&fileObject, "\"Vbatt_main\"\t");       }  //2
    if(sys_data.data_cfg[CFG_ENV_BRD_TEMP] > 0)     { sd_fprintf(&fileObject, "\"TC_cont\"\t");        }  //3
    if(sys_data.data_cfg[CFG_ENV_HUMIDITY] > 0)     { sd_fprintf(&fileObject, "\"Humidity\"\t");    }  //4
    if(sys_data.data_cfg[CFG_BIAS_BAT_VOLT] > 0)    { sd_fprintf(&fileObject, "\"Bias Batt\"\t");    }  //5
    if(sys_data.data_cfg[CFG_V_THERMISTOR] > 0)     { sd_fprintf(&fileObject, "\"Vtherm\"\t");          }  //6
    if(sys_data.data_cfg[CFG_V_THERMISTOR_STD] > 0) { sd_fprintf(&fileObject, "\"Vtherm std\"\t");      }  //7
    if(sys_data.data_cfg[CFG_V_INT_OFFSET] > 0)     { sd_fprintf(&fileObject, "\"VrsiBiased\"\t");     }  //8
    if(sys_data.data_cfg[CFG_V_INT_OFFSET_STD] > 0) { sd_fprintf(&fileObject, "\"VrsiBiased Std\"\t"); }  //9
    if(sys_data.data_cfg[CFG_V_EXT_OFFSET] > 0)     { sd_fprintf(&fileObject, "\"VrseBiased\"\t");     }  //10
    if(sys_data.data_cfg[CFG_V_EXT_OFFSET_STD] > 0) { sd_fprintf(&fileObject, "\"VrseBiased_std\"\t"); }  //11

    if(sys_data.data_cfg[CFG_V_INT] > 0)            { sd_fprintf(&fileObject, "\"Vint\"\t");            }  //12
    if(sys_data.data_cfg[CFG_V_INT_STD] > 0)        { sd_fprintf(&fileObject, "\"Vint Std\"\t");        }  //13
    if(sys_data.data_cfg[CFG_V_EXT] > 0)            { sd_fprintf(&fileObject, "\"Vext\"\t");            }  //14
    if(sys_data.data_cfg[CFG_V_EXT_STD] > 0)        { sd_fprintf(&fileObject, "\"Vext Std\"\t");        }  //15
    if(sys_data.data_cfg[CFG_V_COUNTER_ELECT] > 0)  { sd_fprintf(&fileObject, "\"Vcntr E\"\t");         }  //16
    if(sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] > 0)  { sd_fprintf(&fileObject, "\"Vcntr E Std\"\t"); }  //17
    if(sys_data.data_cfg[CFG_I_COUNTER] > 0)        { sd_fprintf(&fileObject, "\"Icntr Elec\"\t");      }  //18
    if(sys_data.data_cfg[CFG_I_SUBSTRATE] > 0)      { sd_fprintf(&fileObject, "\"Substrate Leak\"\t");  }  //19
    if(sys_data.data_cfg[CFG_CALC_TEMP] > 0)        { sd_fprintf(&fileObject, "\"pH Temp\"\t");         }  //20
    if(sys_data.data_cfg[CFG_EST_PH_INT] > 0)       { sd_fprintf(&fileObject, "\"pH Int\"\t");          }  //21
    sd_fprintf(&fileObject, "\n");

    sys_data.next_gdata_fptr = fileObject.fptr;     // Store the file pointer for the first sample (for gdata)

    // Close the file
    fresult = f_close( &fileObject);
    if(fresult != FR_OK)
    {
        uprintf("f_close error: %s\n", StringFromFresult(fresult));
        return 1;
    }
#endif
    return 0;
}
#endif






#ifdef DOESNOTFULLYPRINTTHEBIGGESTSTRING
void poopout_data_header(int prnFlg, int usdFlg)
{
    unsigned int indx;
    //unsigned char prnBuf[512];

    indx = 0;



    if(sys_data.data_cfg[CFG_SAMPLE_NUM] > 0)       { indx += sprintf(&prnBuf[indx], "SampNum\t");               } //0
    if(sys_data.data_cfg[CFG_TIMEDATE] > 0)         { indx += sprintf(&prnBuf[indx], "MM/DD/YYYY HH:MM:SS\t");   } //1
    if(sys_data.data_cfg[CFG_ENV_BAT_VOLT] > 0)     { indx += sprintf(&prnBuf[indx], "Vbatt_main\t");            } //2
    if(sys_data.data_cfg[CFG_ENV_BRD_TEMP] > 0)     { indx += sprintf(&prnBuf[indx], "TC_cont\t");               } //3
    if(sys_data.data_cfg[CFG_ENV_HUMIDITY] > 0)     { indx += sprintf(&prnBuf[indx], "Humidity\t");              } //4
    if(sys_data.data_cfg[CFG_BIAS_BAT_VOLT] > 0)    { indx += sprintf(&prnBuf[indx], "Vbatt_bias\t");            } //5
    if(sys_data.data_cfg[CFG_V_THERMISTOR] > 0)     { indx += sprintf(&prnBuf[indx], "Vtherm\t");                } //6
    if(sys_data.data_cfg[CFG_V_THERMISTOR_STD] > 0) { indx += sprintf(&prnBuf[indx], "Vtherm_std\t");            } //7
    if(sys_data.data_cfg[CFG_V_INT_OFFSET] > 0)     { indx += sprintf(&prnBuf[indx], "VrsiBiased\t");            } //8
    if(sys_data.data_cfg[CFG_V_INT_OFFSET_STD] > 0) { indx += sprintf(&prnBuf[indx], "VrsiBiased_std\t");        } //9
    if(sys_data.data_cfg[CFG_V_EXT_OFFSET] > 0)     { indx += sprintf(&prnBuf[indx], "VrseBiased\t");            } //10
    if(sys_data.data_cfg[CFG_V_EXT_OFFSET_STD] > 0) { indx += sprintf(&prnBuf[indx], "%VrseBiased_std\t");       } //11

    if(sys_data.data_cfg[CFG_V_INT] > 0)            { indx += sprintf(&prnBuf[indx], "Vrsi\t");                  } //12
    if(sys_data.data_cfg[CFG_V_INT_STD] > 0)        { indx += sprintf(&prnBuf[indx], "Vrsi_std\t");              } //13
    if(sys_data.data_cfg[CFG_V_EXT] > 0)            { indx += sprintf(&prnBuf[indx], "Vrse\t");                  } //14
    if(sys_data.data_cfg[CFG_V_EXT_STD] > 0)        { indx += sprintf(&prnBuf[indx], "Vrse_std\t");              } //15
    if(sys_data.data_cfg[CFG_V_COUNTER_ELECT] > 0)  { indx += sprintf(&prnBuf[indx], "Vk\t");                    } //16
    if(sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] > 0)  { indx += sprintf(&prnBuf[indx], "Vk_std\t");            } //17
    if(sys_data.data_cfg[CFG_I_COUNTER] > 0)        { indx += sprintf(&prnBuf[indx], "Ik\t");                    } //18
    if(sys_data.data_cfg[CFG_I_SUBSTRATE] > 0)      { indx += sprintf(&prnBuf[indx], "Ib\t");                    } //19
    if(sys_data.data_cfg[CFG_CALC_TEMP] > 0)        { indx += sprintf(&prnBuf[indx], "TC_Dfet\t");               } //20
    if(sys_data.data_cfg[CFG_EST_PH_INT] > 0)       { indx += sprintf(&prnBuf[indx], "pHint_est\t");             } //21
    if(sys_data.data_cfg[CFG_OPTODE] > 0)           { indx += sprintf(&prnBuf[indx], "Opt_PN\tOpt_SN\tMoxy\tO2satper\tTC_opt\tDphase\tBphase\tRphase\tBamp\tBpot\tRamp\tOpt_rawtemp\t");                  } //22
    if(sys_data.data_cfg[CFG_CONDUCTIVITY] > 0)     { indx += sprintf(&prnBuf[indx], "\tCond_PN\tCond_SN\tCond\tTemp\t"); }
    indx += sprintf(&prnBuf[indx], "cnt=%u\r\n", indx);

#ifdef NOCODE
    for(indx=0; indx<SIZEOF_PRNBUF; indx++)
    {
        if(prnBuf[indx] == 0)
            prnBuf[indx] = 'x';      // DEBUG - make this a space
        if(prnBuf[indx] == 0x0a || sampBuf[indx] == 0x0d)
            break;
    }
#endif

    if(prnFlg == 1)
        uprintf("%s", prnBuf);      // debug

    ROM_SysCtlDelay(MILLISECOND*50);        // time to send string


}
#endif
#ifdef POOPPOOP
void print_data_header(void)
{
//#SampNum        MM/DD/YYYY HH:MM:SS     Bat V   Vtherm  VthrStd VextRef VextRStd        VcntElec        VceStd  Ik      Ib
//#SampNum        MM/DD/YYYY HH:MM:SS     Bat V    Vtherm         VthermStd       VextRef VextRStd        VcntElec        VceStd  Ik      Ib
//#0000030        05/29/2019 16:41:59     12.03   -0.047092       0.000766        -0.040439       0.000090        -2.048000       0.000000        0.001311        0.000385

    //poopout_data_header(1, 0);

    uprintf("\n\n");

    if(sys_data.data_cfg[CFG_SAMPLE_NUM] > 0)       { uprintf("SampNum\t");                 } //0
    if(sys_data.data_cfg[CFG_TIMEDATE] > 0)         { uprintf("MM/DD/YYYY HH:MM:SS\t");     } //1
    if(sys_data.data_cfg[CFG_ENV_BAT_VOLT] > 0)     { uprintf("Vbatt_main\t");              } //2
    if(sys_data.data_cfg[CFG_ENV_BRD_TEMP] > 0)     { uprintf("TC_cont\t");                 } //3
    if(sys_data.data_cfg[CFG_ENV_HUMIDITY] > 0)     { uprintf("Humidity\t");                } //4
    if(sys_data.data_cfg[CFG_BIAS_BAT_VOLT] > 0)    { uprintf("Vbatt_bias\t");              } //5  Bias Battery Volts
    if(sys_data.data_cfg[CFG_V_THERMISTOR] > 0)     { uprintf("Vtherm\t");                  } //6
    if(sys_data.data_cfg[CFG_V_THERMISTOR_STD] > 0) { uprintf("Vtherm_std\t");              } //7
    if(sys_data.data_cfg[CFG_V_INT_OFFSET] > 0)     { uprintf("VrsiBiased\t");              } //8
    if(sys_data.data_cfg[CFG_V_INT_OFFSET_STD] > 0) { uprintf("VrsiBiased_std\t");          } //9
    if(sys_data.data_cfg[CFG_V_EXT_OFFSET] > 0)     { uprintf("VrseBiased\t");              } //10
    if(sys_data.data_cfg[CFG_V_EXT_OFFSET_STD] > 0) { uprintf("VrseBiased_std\t");          } //11

    if(sys_data.data_cfg[CFG_V_INT] > 0)            { uprintf("Vrsi\t");                    } //12
    if(sys_data.data_cfg[CFG_V_INT_STD] > 0)        { uprintf("Vrsi_std\t");                } //13
    if(sys_data.data_cfg[CFG_V_EXT] > 0)            { uprintf("Vrse\t");                    } //14
    if(sys_data.data_cfg[CFG_V_EXT_STD] > 0)        { uprintf("Vrse_std\t");                } //15
    if(sys_data.data_cfg[CFG_V_COUNTER_ELECT] > 0)  { uprintf("Vk\t");                      } //16
    if(sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] > 0) { uprintf("Vk_std\t");               } //17
    if(sys_data.data_cfg[CFG_I_COUNTER] > 0)        { uprintf("Ik\t");                      } //18
    if(sys_data.data_cfg[CFG_I_SUBSTRATE] > 0)      { uprintf("Ib\t");                      } //19
    if(sys_data.data_cfg[CFG_CALC_TEMP] > 0)        { uprintf("CalcTC\t");                  } //20
    if(sys_data.data_cfg[CFG_EST_PH_INT] > 0)       { uprintf("Est pH\t");                  } //21
    if(sys_data.data_cfg[CFG_OPTODE] > 0)           { uprintf("\tOpt_PN\tOpt_SN\tMoxy\tO2satper\tTC_opt\tDphase\tBphase\tRphase\tBamp\tBpot\tRamp\tOpt_rawtemp"); } //22 -
    if(sys_data.data_cfg[CFG_CONDUCTIVITY] > 0)     { uprintf("\tCond_PN\tCond_SN\tCond\tTemp\t"); }
    uprintf("\r\n");
    ROM_SysCtlDelay(MILLISECOND*50);        // time to send string
}

void get_header(void)
{
    print_data_header();

}
#endif
