/*
 * 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 "ctd_base.h"
#include "optode.h"

#include "sleep.h"
#include "sample.h"
#include "microsd.h"
#include "uartstdio.h"  // User local version with larger RX buffer

extern int microSD_flg;
extern int dbg_flag;
extern struct systemSamplingData sys_samp;
extern struct ctdDriver ctd;

extern unsigned char prnBuf[SIZEOF_PRNBUF+4];      // size is defd in system.h


void config_adc24_sampling_parms(void)
{
#ifdef NOCODE
    uint32_t Vrsi_sps;              //Vrsi_sps  //418 pH Vint data rate setting (sps)
    uint32_t Vrsi_trials;           //Vrsi_trials
    uint32_t Vrse_sps;
    uint32_t Vrse_trials;
    uint32_t Vtherm_sps;
    uint32_t Vtherm_trials;
    uint32_t Ik_sps;
    uint32_t Ik_trials;
    uint32_t Vk_sps;
    uint32_t Vk_trials;
    uint32_t Ib_sps;
    uint32_t Ib_trials;
    uint32_t Vb_sps;
    uint32_t Vb_trials;
    uint32_t Vbias_sps;
    uint32_t Vbias_trials;

    // pH Vint sample rate setting
    while(1)
    {
        uprintf("\r\nEnter pH Vint sample rate setting [%d]: ", sys_data.Vrsi_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.Vrsi_sps = temp;
                    uprintf("\r\npH Vint data rate now %d sps\r\n\r\n", sys_data.Vrsi_sps);
                    break;
                }
                else uprintf("\r\nEnter 5, 10, 20, 40, 80, 160, 320, 640, 1000, or 2000");
                continue;
            }
            else break;
        }
        else break;
    }

    break;


    // pH Vint gain setting
    while(1)
    {
        uprintf("\r\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("\r\npH Vint gain now %d\r\n\r\n", sys_data.Vint_gain);
                    break;
                }
                else uprintf("\r\nEnter 1, 2, 4, 8, 16, or 32");
                continue;
            }
            else break;
        }
        else break;
    }


#endif



    while(1)
    {
        uprintf("\r\nThird batch of 20 sys_data fields:\r\n\r\n");

        uprintf("Vrsi_sps [%u]: ", sys_data.Vrsi_sps);
        edit_uint(&sys_data.Vrsi_sps, 0, 80);

        uprintf("Vrsi_trials [%u]: ", sys_data.Vrsi_trials);
        edit_uint(&sys_data.Vrsi_trials, 0, 80);

        uprintf("Vrse_sps [%u]: ", sys_data.Vrse_sps);
        edit_uint(&sys_data.Vrse_sps, 0, 80);

        uprintf("Vrse_trials [%u]: ", sys_data.Vrse_trials);
        edit_uint(&sys_data.Vrse_trials, 0, 80);

        uprintf("Vtherm_sps [%u]: ", sys_data.Vtherm_sps);
        edit_uint(&sys_data.Vtherm_sps, 0, 80);

        uprintf("Vtherm_trials [%u]: ", sys_data.Vtherm_trials);
        edit_uint(&sys_data.Vtherm_trials, 0, 80);

        uprintf("Vtherm_trials [%u]: ", sys_data.Vtherm_trials);
        edit_uint(&sys_data.Vtherm_trials, 0, 80);

        uprintf("Ik_sps [%u]: ", sys_data.Ik_sps);
        edit_uint(&sys_data.Ik_sps, 0, 80);

        uprintf("Ik_trials [%u]: ", sys_data.Ik_trials);
        edit_uint(&sys_data.Ik_trials, 0, 80);

        uprintf("Vk_sps [%u]: ", sys_data.Vk_sps);
        edit_uint(&sys_data.Vk_sps, 0, 80);

        uprintf("Vk_trials [%u]: ", sys_data.Vk_trials);
        edit_uint(&sys_data.Vk_trials, 0, 80);

        uprintf("Ib_sps [%u]: ", sys_data.Ib_sps);
        edit_uint(&sys_data.Ib_sps, 0, 80);

        uprintf("Ib_trials [%u]: ", sys_data.Ib_trials);
        edit_uint(&sys_data.Ib_trials, 0, 80);

        uprintf("Vb_sps [%u]: ", sys_data.Vb_sps);
        edit_uint(&sys_data.Vb_sps, 0, 80);

        uprintf("Vb_trials [%u]: ", sys_data.Vb_trials);
        edit_uint(&sys_data.Vb_trials, 0, 80);

        uprintf("Vbias_sps [%u]: ", sys_data.Vbias_sps);
        edit_uint(&sys_data.Vbias_sps, 0, 80);

        uprintf("Vbias_trials [%u]: ", sys_data.Vbias_trials);
        edit_uint(&sys_data.Vbias_trials, 0, 80);

        uprintf("offset_Ik [%u]: ", sys_data.offset_Ik);
        edit_uint(&sys_data.offset_Ik, 0, 80);

        uprintf("offset_Ib [%u]: ", sys_data.offset_Ib);
        edit_uint(&sys_data.offset_Ib, 0, 80);

        break;

    }

}


/********************************************************************************************
 *  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("\r\n\r\n\r\nConfiguration Menu -- %s", VERSION);
        uprintf("\r\n\r\n\r\nConfiguration Menu:\r\n");
        uprintf("1 -- Set Clock\r\n");
        uprintf("2 -- Change File Name\r\n");
        uprintf("3 -- Set Deployment Parameters\r\n");
        uprintf("4 -- Enter pH Sensor Calibration Coefficients\r\n");
        uprintf("5 -- Calculate pH Sensor Calibration Coefficients\r\n");
        uprintf("6 -- Change Baud Rate\r\n");
        uprintf("7 -- Config Data Fields\r\n");
        uprintf("8 -- Metadata Settings\r\n");        // was a hidden menu requiring password
        uprintf("\r\n");
        uprintf("D -- Data Header, Sample Data, Sample Timing\r\n");
        uprintf("E -- Edit/Copy EEPROM sys_data structure\r\n");          // Copy and edit sys_data EEPROM structure after firmware upgrade\r\n");
        uprintf("S -- Print EEPROM Sys_data structure\r\n");              // turn this on by 'Q' in Help menu (main.c)
        uprintf("A -- App Config Fields\r\n");
        uprintf("Z -- ADC 24bit Sampling Parameters\r\n");
#if BOARD_MPHOX >= 1
        uprintf("P -- Pump Sequencer Setup\r\n");
#endif

        uprintf("9 -- Exit to Main Menu\r\n");
        uprintf("\r\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 'z':
            case 'Z':
                config_adc24_sampling_parms();
                break;

#if BOARD_MPHOX >= 1
            case 'P':
            case 'p':
                // Pump Sequencer Setup
                pump_sequencer_setup();
                break;
#endif

            case 'A':
            case 'a':
                edit_appcfg_fields();
                break;

            case 'S':
            case 's':
                print_sys_data_structure();
                break;

            case 'c':
            case 'C':
                exercise_iso();
                break;

            case 'd':
                test_get_sample_timing();
                break;
            case 'D':
                test_get_sample_loop();
                break;

#ifdef MAKESAMEASTESTDd
            case 'd':
            case 'D':
            //case ' ':
                //print_config_data_fields();
                uprintf("\r\n Data Fields:\r\n\r\n");
                print_write_config_data_fields(1,0,1);  // print with pad of // 
                uprintf("\r\n\r\n");
                print_data_header();     // defd in config.c
                sys_data.app_cfg[APPCFG_SAMPLING_DIAG] = 1;
                sys_samp.pump_seq_state = 0;   // initialize pump sequence variable to disable pumps
                get_sample(1,0);
                sys_data.app_cfg[APPCFG_SAMPLING_DIAG] = 0;
                break;
#endif
            case 'e':
            case 'E':
                copy_edit_sys_data_structure();
                break;
#ifdef OLDCODE
            case 'm':
            case 'M':
                //microsd_logging();
                if(sys_data.app_cfg[APPCFG_MICROSD_ENABLE] == 1)
                {
                    response = yesOrNoMenuChoice("\r\n\r\nDisable MicroSD logging? (Y/N) [N]? ", NO);
                    if(response == YES)
                    {
                        sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 0;
                        storeSysDataVariables();
                    }
                }
                else
                {
                    response = yesOrNoMenuChoice("\r\n\r\nEnable MicroSD logging? (Y/N) [N]? ", NO);
                    if(response == YES)
                    {
                        sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 1;
                        storeSysDataVariables();
                    }
                }

                if(sys_data.app_cfg[APPCFG_MICROSD_ENABLE] == 1)
                    uprintf("MicroSD logging is Enabled\r\n\r\n");
                else
                    uprintf("MicroSD card DISabled, no Logging\r\n\r\n");
                break;
#endif
            case '1':  // Set Clock
                response = yesOrNoMenuChoice("\r\n\r\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("\r\nTime now: ");
                    printCurrentTime();
                    if(sys_data.GMT) uprintf(" GMT");
                    else uprintf(" Local");
                    uprintf("\r\n\r\nNote: Daylight Savings not observed. Use GMT when this will be an issue.\r\n");
                }
                break;

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

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

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

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

                // Sample period
                if(sys_data.sample_aligned == true)  // THOM new 23Apr2019
                {
                    response = yesOrNoMenuChoice("\r\n\r\nSample aligned to hour? (Y/N) [Y]? ", YES);
                }
                else
                {
                    response = yesOrNoMenuChoice("\r\n\r\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("\r\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("\r\nSample period is zero - polled mode\r\n");
                            }


                            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("\r\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.\r\n\r\n", sys_data.sampling_period);
                                break;
                            }
                            else
                            {
                            uprintf("\r\nEnter time less than or equal to 3600 sec");
                            }

                            continue;
                        } // scanf
                        else break;

                    }
                    else break;
                }
#if BOARD_MPHOX >= 1
                pump_sequencer_setup();
#endif
                // Low battery voltage
                while(1)
                    {
#if BOARD_MFET >= 1
                        sprintf(buff, "\r\nEnter low battery_voltage (ex. 5.5 V) [%.1f V]: ", sys_data.low_batt_volt);
#endif
#if BOARD_MPHOX >= 1
                        sprintf(buff, "\r\nEnter low battery_voltage (ex. 10.5 V with Pump) [%.1f V]: ", sys_data.low_batt_volt);
#endif
#if BOARD_NANOFET >= 1
                        sprintf(buff, "\r\nEnter low battery_voltage (ex. 5.5 V) [%.1f V]: ", sys_data.low_batt_volt);
#endif

                        uprintf("%s", buff);
                        if(getUserInput(buff, strlen(buff) ))
                        {
                            if(sscanf(buff, "%f", &ftemp) == 1)
                            {
                                if(ftemp >= 0 && ftemp <= 30)
                                {
                                    sys_data.low_batt_volt = ftemp;
                                    sprintf(buff, "\r\nLow battery_voltage now [%.1f V]\r\n\r\n", sys_data.low_batt_volt);
                                    uprintf("%s", buff);
                                break;
                                }
                                else uprintf("\r\nEnter voltage less than 30 V");
                                continue;
                            }
                            else break;
                        }
                            else break;
                    }


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

                input = get_key();

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

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

                }

                // Error check the setup

                uint32_t sampTimeEst;
                sampTimeEst = sys_data.pump1_ontime * 1000;


                if((sys_data.data_cfg[CFG_OPTODE] > 0) ||  (sys_data.data_cfg[CFG_CTD] > 0))
                    sampTimeEst += 2500;        // TBD

                if(sys_data.data_cfg[CFG_BIAS_BAT_NEG] > 0)
                    sampTimeEst += ((VBIAS_TRIALS * 1000) / VBIAS_SPS);
                if(sys_data.data_cfg[CFG_BIAS_BAT_POS] > 0)
                    sampTimeEst += ((VBIAS_TRIALS * 1000) / VBIAS_SPS);
                if(sys_data.data_cfg[CFG_I_SUBSTRATE] > 0)
                    sampTimeEst += ((IB_TRIALS * 1000) / IB_SPS);
                if(sys_data.data_cfg[CFG_I_COUNTER] > 0)
                    sampTimeEst += ((IK_TRIALS * 1000) / IK_SPS);
                if(sys_data.data_cfg[CFG_V_COUNTER_ELECT] > 0)
                    sampTimeEst += ((VK_TRIALS * 1000) / VK_SPS);
                if(sys_data.data_cfg[CFG_V_THERMISTOR] > 0)
                    sampTimeEst += ((VTHERM_TRIALS * 1000) / VTHERM_SPS);
                if(sys_data.data_cfg[CFG_VRSI_BIASED] > 0)
                    sampTimeEst += ((VRSI_TRIALS * 1000) / VRSI_SPS);
                if(sys_data.data_cfg[CFG_VRSI] > 0)
                    sampTimeEst += ((VRSI_TRIALS * 1000) / VRSI_SPS);
                if(sys_data.data_cfg[CFG_VRSE_BIASED] > 0)
                    sampTimeEst += ((VRSE_TRIALS * 1000) / VRSE_SPS);
                if(sys_data.data_cfg[CFG_VRSE] > 0)
                    sampTimeEst += ((VRSE_TRIALS * 1000) / VRSE_SPS);

                sampTimeEst += 150;


                if(sampTimeEst > (250 + sys_data.sampling_period*1000)) // 250msec is margin (somewhat arbitrarily set)
                {
                    if(sys_data.sampling_period > 0)
                        uprintf("\r\nError: Estimated sample time = %.2f sec, is greater than sample period = %u sec.  Increase sample period\r\n", (float)sampTimeEst/1000.0, sys_data.sampling_period);
                    else
                        uprintf("\r\nEstimated sample time = %.2f sec in polled mode (sample period is 0)\r\n", (float)sampTimeEst/1000.0, sys_data.sampling_period);  // buf fix 22 Jul 2021
                }
                else
                {
                    uprintf("\r\nEstimated sample time = %.2f sec, sample period = %u sec\r\n", (float)sampTimeEst/1000.0, sys_data.sampling_period);

                }

                break;

            //float ftemp;
            case '4': //Enter pH Sensor Calibration Coefficients
                //Eo_int_25
                enter_pH_sensor_cal_coeff();
                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("\r\nMetadata Settings:\r\n");

                enter_metadata();  // user entry of metadata settings

                break;



#ifdef FUTURECODE_ENTERTRIALSSPS
            case 'Q':

                // pH Vint sample rate setting
                while(1)
                {
                    uprintf("\r\nEnter pH Vint sample rate setting [%d]: ", sys_data.Vrsi_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.Vrsi_sps = temp;
                                uprintf("\r\npH Vint data rate now %d sps\r\n\r\n", sys_data.Vrsi_sps);
                                break;
                            }
                            else uprintf("\r\nEnter 5, 10, 20, 40, 80, 160, 320, 640, 1000, or 2000");
                            continue;
                        }
                        else break;
                    }
                    else break;
                }

                break;


                // pH Vint gain setting
                while(1)
                {
                    uprintf("\r\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("\r\npH Vint gain now %d\r\n\r\n", sys_data.Vint_gain);
                                break;
                            }
                            else uprintf("\r\nEnter 1, 2, 4, 8, 16, or 32");
                            continue;
                        }
                        else break;
                    }
                    else break;
                }

#endif
            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("\r\n\r\nError storing system data.\r\n");
                }
                else uprintf("\r\n\r\nSystem data stored.  -- Press enter to bring up main menu\r\n");
                return;
        }
    }
}


void pump_sequencer_setup(void)
{

    char input, buff[100];
    int response;
    uint32_t temp;

    // Pump Sequence Type
    while(1)
    {
        if(sys_data.pump_seq_type == TYPE_PUMP_NOTDEFD)     // For now, dont allow 'not defined', default is single pump
            sys_data.pump_seq_type = TYPE_PUMP_SINGLE;

        //uprintf("\r\nEnter Pump Sequence Type (1=Single, 2=Two Pump Alt BEAMSv1, 3=Self Cal, 4=Two Pump BEAMSv2 [%d]: ", sys_data.pump_seq_type);
        uprintf("\r\nEnter Pump Sequence Type (1=Single, 2=Two Pump Alt BEAMSv1 [%d]: ", sys_data.pump_seq_type);
        if(getUserInput(buff, 2))
        {
            if(sscanf(buff, "%d", &temp) == 1)
            {
                // from system.h
                //#define TYPE_PUMP_SINGLE        0
                //#define TYPE_2PUMP_BEAMSV1      1
                //#define TYPE_2PUMP_BEAMSV2      2
                //if(temp == 1 || temp == 2 || temp == 3)
                if(temp == 1 || temp == 2)
                {
                    sys_data.pump_seq_type = temp;
                    uprintf("\r\nPump Sequence Type = %d\r\n\r\n", sys_data.pump_seq_type);
                    break;
                }
                else uprintf("\r\nEnter 1 or 2");
                continue;
            }
            else break;
        }
        else break;
    }

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

    uprintf("\r\nEnter Experiment Duty Cycle feature is not yet implemented...\r\n");
#ifdef FUTURECODE
    // Duty Cycle On
    while(1)
    {

        uprintf("\r\nEnter Experiment Duty Cycle ON Time in hours (0 for Disable) [%d]: ", sys_data.sampleCnt_duty_on/3600);
        if(getUserInput(buff, 4))
        {
            if(sscanf(buff, "%d", &temp) == 1)
            {
                if(temp <= 1000)
                {
                    sys_data.sampleCnt_duty_on = 3600 * temp;       // on time in seconds
                    uprintf("\r\nExperiment Duty Cycle On Time = %d\r\n\r\n", sys_data.sampleCnt_duty_on/3600);
                    break;
                }
                else uprintf("\r\nEnter a number less than 1000 hours");
                continue;
            }
            else break;
        }
        else break;
    }

    // Duty Cycle Off
    if(sys_data.sampleCnt_duty_on > 0)
    {
        while(1)
        {
            uprintf("\r\nEnter Experiment Duty Cycle OFF Time in hours [%d]: ", sys_data.sampleCnt_duty_off/3600);
            if(getUserInput(buff, 4))
            {
                if(sscanf(buff, "%d", &temp) == 1)
                {
                    if((temp <= 1000) || (temp == 0))
                    {
                        sys_data.sampleCnt_duty_off = 3600 * temp;       // on time in seconds
                        uprintf("\r\nExperiment Duty Cycle On Time = %d\r\n\r\n", sys_data.sampleCnt_duty_off/3600);
                        break;
                    }
                    else uprintf("\r\nEnter a number greater than 0, less than 1000 hours");
                    continue;
                }
                else break;
            }
            else break;
        }
    }
#endif


    if(sys_data.pump_seq_type == TYPE_2PUMP_BEAMSV1)
    {
        // Pump 1 ontime (seconds)
        while(1)
        {
            uprintf("\r\nEnter Pump1 run time [%d] sec: ", sys_data.pump1_ontime);
            if(getUserInput(buff, 8))
            {
                if(sscanf(buff, "%d", &temp) == 1)
                {
                    if(temp <= 5*3600)
                    {
                        sys_data.pump1_ontime = temp;       // on time in seconds
                        uprintf("Pump1 run time = %d sec\r\n\r\n", sys_data.pump1_ontime);
                        break;
                    }
                    else uprintf("\r\nEnter a number less than or equal to %d seconds", 5*3600);
                    continue;
                }
                else break;
            }
            else break;
        }

        // Pump 2 ontime (seconds)
        while(1)
        {
            uprintf("\r\nEnter Pump2 run time [%d] sec: ", sys_data.pump2_ontime);
            if(getUserInput(buff, 8))
            {
                if(sscanf(buff, "%d", &temp) == 1)
                {
                    if(temp <= 5*3600)
                    {
                        sys_data.pump2_ontime = temp;       // on time in seconds
                        uprintf("\r\nPump2 run time = %d sec\r\n\r\n", sys_data.pump2_ontime);
                        break;
                    }
                    else uprintf("\r\nEnter a number less than or equal to %d seconds", 5*3600);
                    continue;
                }
                else break;
            }
            else break;
        }


        // Pump 1 cycles
        while(1)
        {
            uprintf("\r\nEnter number of sampling cycles for Pump1 [%d]: ", sys_data.pump1_cycles);
            if(getUserInput(buff, 4))
            {
                if(sscanf(buff, "%d", &temp) == 1)
                {
                    if(temp <= 1000)
                    {
                        sys_data.pump1_cycles = temp;       // on time in seconds
                        uprintf("\r\nSampling cycles Pump1 = %d\r\n\r\n", sys_data.pump1_cycles);
                        break;
                    }
                    else uprintf("\r\nEnter a number less than 1000 cycles");
                    continue;
                }
                else break;
            }
            else break;
        }




        // Pump 2 cycles
        while(1)
        {
            uprintf("\r\nEnter number of sampling cycles for Pump2 [%d]: ", sys_data.pump2_cycles);
            if(getUserInput(buff, 4))
            {
                if(sscanf(buff, "%d", &temp) == 1)
                {
                    if(temp <= 1000)
                    {
                        sys_data.pump2_cycles = temp;       // on time in seconds
                        uprintf("\r\nSampling cycles Pump2 = %d\r\n\r\n", sys_data.pump2_cycles);
                        break;
                    }
                    else uprintf("\r\nEnter a number less than 1000 cycles");
                    continue;
                }
                else break;
            }
            else break;
        }

    }
    //}


}


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

    while(1)
    {
        // a good default is -0.4
        //sprintf(buff, "\r\nEnter E0_int @25 C (ex. -0.4) [%f]: ", sys_data.Eo_int_25C);
        sprintf(buff, "\r\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)\r\n\r\n");
                continue;
            }
        else break;
        }
        else break;
    }


    //Eo_ext_25
    while(1)
    {
            // a good default is -1.3
        //sprintf(buff, "\r\nEnter E0_ext @25 C (ex. -1.3) [%f]: ", sys_data.Eo_ext_25C);
        sprintf(buff, "\r\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)\r\n\r\n");
                continue;
            }
            else break;
            }
        else break;
    }

    while(1)
    {
        sprintf(buff, "\r\nEnter k2int (ex. -0.001455) [%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)\r\n\r\n");
                continue;
            }
            else break;
            }
        else break;
    }

    while(1)
    {
        sprintf(buff, "\r\nEnter k2ext (ex. -0.001081) [%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)\r\n\r\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, "\r\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 reasonable TCOffset such as 0.0\r\n\r\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\r\n");
        sys_data.TCOffset = 35.0;
    }

    while(1)
    {
        // default of 35.0
    sprintf(buff, "\r\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\r\n\r\n");
            continue;
        }
        else break;

        }
        else break;
    }
    if(sys_data.app_cfg[APPCFG_TEMPC_SH_ALG] == 0)
    {
        uprintf("\r\n4 Var S-H coefficients for Thermistor to Temperature Celsius:\r\n");
        uprintf("     c0 = %.11lf\r\n", sys_data.quadTherm_c0);
        uprintf("     c1 = %.11lf\r\n", sys_data.quadTherm_c1);
        uprintf("     c2 = %.11lf\r\n", sys_data.quadTherm_c2);
        uprintf("     c3 = %f.11l\r\n", sys_data.quadTherm_c3);
        uprintf("\r\n");
    }
    if(sys_data.app_cfg[APPCFG_TEMPC_SH_ALG] == 1)
    {
        uprintf("\r\n3 Var S-H coefficients for Thermistor to Temperature Celsius:\r\n");
        uprintf("      A = %.11lff\r\n", sys_data.shTherm_A);
        uprintf("      B = %.11lf\r\n", sys_data.shTherm_B);
        uprintf("      C = %.11lf\r\n", sys_data.shTherm_C);
        uprintf("\r\n");
    }


        if(sys_data.app_cfg[APPCFG_TEMPC_SH_ALG] == 0)
        {

        while(1)
        {
            //sprintf(buff, "\r\nEnter Steinhart-Hart c0 (ex. 340.9819863) [%f]: ", sys_data.quadTherm_c0);
            sprintf(buff, "\r\nEnter 4 Var S-H c0 (ex. 340.9819863) [%.11lf]: ", sys_data.quadTherm_c0);

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

        while(1)                 // -0.0000910257
        {
            sprintf(buff, "\r\nEnter 4 Var S-H c1 (ex. -0.0000910257, -9.10257E-05) [%.11lf]: ", sys_data.quadTherm_c1);

            uprintf("%s", buff);
            if(getUserInput(buff, 20))
            {
                if(sscanf(buff, "%lf", &dtemp) == 1)
                {
                    if(dtemp >= (-0.1) && dtemp <= 0.1)
                    {
                        sys_data.quadTherm_c1 = dtemp;
                        uprintf("c1 = %.11lf", sys_data.quadTherm_c1);
                        break;
                    }
                    else uprintf("Enter number between 0.1 and -0.1 (ex. 0.0000910257)\r\n\r\n");
                    continue;
                }
                else break;
                }
            else break;
        }

        while(1)                 // -0.0000910257
        {
            sprintf(buff, "\r\nEnter 4 Var S-H  c2 (ex. -95.08806667) [%.11lf]: ", sys_data.quadTherm_c2);

            uprintf("%s", buff);
            if(getUserInput(buff, 20))
            {
                if(sscanf(buff, "%lf", &dtemp) == 1)
                {
                    if(dtemp >= (-200.0) && dtemp <= 200.0)
                    {
                        sys_data.quadTherm_c2 = dtemp;
                        uprintf("c2 = %.11lf", sys_data.quadTherm_c2);
                        break;
                    }
                    else uprintf("Enter number between -200.0 and 200.0 (ex. -95.08806667)\r\n\r\n");
                    continue;
                }
                else break;
                }
            else break;
        }


        while(1)                 // -0.0000910257
        {
            sprintf(buff, "\r\nEnter 4 Var S-H  c3 (ex. 0.965370274) [%.11lf]: ", sys_data.quadTherm_c3);

            uprintf("%s", buff);
            if(getUserInput(buff, 20))
            {
                if(sscanf(buff, "%lf", &dtemp) == 1)
                {
                    if(dtemp >= (-2.0) && dtemp <= 2.0)
                    {
                        sys_data.quadTherm_c3 = dtemp;
                        uprintf("c3 = %.11lf", sys_data.quadTherm_c3);
                        break;
                    }
                    else uprintf("Enter number between -2.0 and 2.0 (ex. 0.965370274)\r\n\r\n");
                    continue;
                }
                else break;
                }
            else break;
        }
    } // if 4 var

    if(sys_data.app_cfg[APPCFG_TEMPC_SH_ALG] == 1)
    {
        while(1)
        {
            sprintf(buff, "\r\nEnter 3 Var Steinhart-Hart A  [%.11lf]: ", sys_data.shTherm_A);
            uprintf("%s", buff);
            if(getUserInput(buff, 20))
            {
                if(sscanf(buff, "%lf", &dtemp) == 1)
                {
                    if(dtemp >= (-500.00) && dtemp <= 500.0)
                    {
                        sys_data.shTherm_A = dtemp;
                        uprintf("A = %.11lf", sys_data.shTherm_A);
                        break;
                    }
                    else uprintf("Enter number between -500 and 500, not sure what to recommend \r\n\r\n");
                    continue;
                }
                else break;
                }
            else break;
        }


        while(1)
        {
            sprintf(buff, "\r\nEnter 3 Var Steinhart-Hart B  [%.11lf]: ", sys_data.shTherm_B);
            uprintf("%s", buff);
            if(getUserInput(buff, 20))
            {
                if(sscanf(buff, "%lf", &dtemp) == 1)
                {
                    if(dtemp >= (-500.00) && dtemp <= 500.0)
                    {
                        sys_data.shTherm_B = dtemp;
                        uprintf("B = %.11lf", sys_data.shTherm_B);
                        break;
                    }
                    else uprintf("Enter number between -500 and 500, not sure what to recommend \r\n\r\n");
                    continue;
                }
                else break;
                }
            else break;
        }

        while(1)
        {
            sprintf(buff, "\r\nEnter 3 Var Steinhart-Hart C  [%.11lf]: ", sys_data.shTherm_C);
            uprintf("%s", buff);
            if(getUserInput(buff, 20))
            {
                if(sscanf(buff, "%lf", &dtemp) == 1)
                {
                    if(dtemp >= (-500.00) && dtemp <= 500.0)
                    {
                        sys_data.shTherm_C = dtemp;
                        uprintf("C = %.11lf", sys_data.shTherm_C);
                        break;
                    }
                    else uprintf("Enter number between -500 and 500, not sure what to recommend \r\n\r\n");
                    continue;
                }
                else break;
                }
            else break;
        }
    } // if 3 var
    //uprintf("\r\n*****Calibration Coefficients Saved*****\r\n\r\n");
}

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

    //print out config menu
    uprintf("\r\n\r\n\r\nChange Baud Rate - select baud menu item, change terminal baud rate, then hit 'V' to verify, then main menu, sleep and wakeup");
    //uprintf("\r\nV -- Verify");
    uprintf("\r\n1 -- 115200");
    uprintf("\r\n2 -- 57600");
    uprintf("\r\n3 -- 38400");
    uprintf("\r\n4 -- 19200");
    uprintf("\r\n5 -- 9600");
    uprintf("\r\n6 -- 4800");
    uprintf("\r\n9 -- Exit to Main Menu");
    uprintf("\r\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("\r\nBaud rate verify %u\r\n", sys_data.baud_rate);
            break;
        case '1':
            // 115200
            sys_data.baud_rate = 115200L;
            uprintf("baud rate = %u\r\n", sys_data.baud_rate);
            wait_consoleTx();
            UARTStdioConfig(0, 115200, 16000000);       // 115200 bits per second
            break;
        case '2':
            sys_data.baud_rate = 57600L;
            uprintf("baud rate = %u\r\n", sys_data.baud_rate);
            wait_consoleTx();
            UARTStdioConfig(0, 57600, 16000000);       // 9600 bits per second
            break;
        case '3':
            sys_data.baud_rate = 38400L;
            uprintf("baud rate = %u\r\n", sys_data.baud_rate);
            wait_consoleTx();
            UARTStdioConfig(0, 38400, 16000000);       // 9600 bits per second
            break;
        case '4':
            sys_data.baud_rate = 19200L;
            uprintf("baud rate = %u\r\n", sys_data.baud_rate);
            wait_consoleTx();
            UARTStdioConfig(0, 19200, 16000000);       // 9600 bits per second
            break;
        case '5':
            sys_data.baud_rate = 9600L;
            uprintf("baud rate = %u\r\n", sys_data.baud_rate);
            wait_consoleTx();
            UARTStdioConfig(0, 9600, 16000000);       // 9600 bits per second
            break;
        case '6':
            sys_data.baud_rate = 4800L;
            uprintf("baud rate = %u\r\n", sys_data.baud_rate);
            wait_consoleTx();
            UARTStdioConfig(0, 4800, 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("\r\n\r\nError storing system data.\r\n");
            }
            else
                uprintf("\r\n\r\nSystem data stored.  -- Press enter to bring up main menu\r\n");
            break;

    }

}

// pass in printFlg, writeFlg = 2 to pad the string with //
void print_write_config_data_fields(uint32_t printFlg, uint32_t writeFlg, uint32_t padFlg)
{
    FIL fileObject;     // File object
    FRESULT fresult;
    UINT bw;
    int retVal;
    char padString[10];




    retVal = 0;     // assume a good return (1 is error due to SD card

    if(sys_data.app_cfg[APPCFG_MICROSD_ENABLE] == 0)        // Fix 6 Aug 2021
    {
        retVal = 0;  // pretend it's good
        writeFlg = 0;
    }

    padString[0] = 0;
    if(padFlg == 1)
    {
        strcpy(padString, "// ");
    }

    if(writeFlg == 1)
    {

        // 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\r\n", StringFromFresult(fresult));
            retVal = 1;
            writeFlg = 0;
            //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\r\n", StringFromFresult(fresult));
            retVal = 1;
            writeFlg = 0;
        }

    }

    if(printFlg==1)                 uprintf("%sA -- Sample Num               = %u\r\n", padString, sys_data.data_cfg[CFG_SAMPLE_NUM]);                 //A + Sample_Number\t
    if(writeFlg==1) sd_fprintf(&fileObject, "%sA -- Sample Num               = %u\r\n", padString, sys_data.data_cfg[CFG_SAMPLE_NUM]);                 //A + Sample_Number\t

    if( sys_data.data_cfg[CFG_TIMESTAMP] == 0 || sys_data.data_cfg[CFG_TIMESTAMP] == TYPE_US_DATETIME)
    {
        if(printFlg==1)                  uprintf("%sB -- MM/DD/YYYY HH:MM:SS      = %u\r\n", padString, sys_data.data_cfg[CFG_TIMESTAMP]);                   //B + MM/DD/YYYY HH:MM:SS\t
        if(writeFlg==1) sd_fprintf(&fileObject,  "%sB -- MM/DD/YYYY HH:MM:SS      = %u\r\n", padString, sys_data.data_cfg[CFG_TIMESTAMP]);                   //B + MM/DD/YYYY HH:MM:SS\t
    }
    if( sys_data.data_cfg[CFG_TIMESTAMP] == TYPE_EPOCH_MSEC)
    {
        if(printFlg==1)                  uprintf("%sB -- MM/DD/YYYY HH:MM:SS      = %u,  Epoch millisec\r\n\r\n", padString, sys_data.data_cfg[CFG_TIMESTAMP]);                   //B + MM/DD/YYYY HH:MM:SS\t
        if(writeFlg==1) sd_fprintf(&fileObject,  "%sB -- MM/DD/YYYY HH:MM:SS      = %u,  Epoch millisec\r\n\r\n", padString, sys_data.data_cfg[CFG_TIMESTAMP]);                   //B + MM/DD/YYYY HH:MM:SS\t
    }



    //if(printFlg==1)                  uprintf("\r\n");
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1   // Not available on nanoFET
    if(printFlg==1)                 uprintf("%sC -- Battery Volt             = %u\r\n", padString, sys_data.data_cfg[CFG_VIN_BAT_VOLT]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%sC -- Battery Volt             = %u\r\n", padString, sys_data.data_cfg[CFG_VIN_BAT_VOLT]);
#endif

    if(printFlg==1)                 uprintf("%sD -- Bias Battery Pos         = %u\r\n", padString, sys_data.data_cfg[CFG_BIAS_BAT_POS]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%sD -- Bias Battery Pos         = %u\r\n", padString, sys_data.data_cfg[CFG_BIAS_BAT_POS]);
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1   // Not available on nanoFET
    if(printFlg==1)                 uprintf("%sE -- Bias Battery Neg         = %u\r\n", padString, sys_data.data_cfg[CFG_BIAS_BAT_NEG]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%sE -- Bias Battery Neg         = %u\r\n", padString, sys_data.data_cfg[CFG_BIAS_BAT_NEG]);
#endif
    if(printFlg==1)                 uprintf("%sF -- Board Temperature        = %u\r\n", padString, sys_data.data_cfg[CFG_BRD_TEMP]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%sF -- Board Temperature        = %u\r\n", padString, sys_data.data_cfg[CFG_BRD_TEMP]);

    if(printFlg==1)                 uprintf("%sG -- Board Humidity           = %u\r\n", padString, sys_data.data_cfg[CFG_BRD_HUMIDITY]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%sG -- Board Humidity           = %u\r\n", padString, sys_data.data_cfg[CFG_BRD_HUMIDITY]);

    //if(printFlg==1) uprintf("\r\n");

    if(printFlg==1)                 uprintf("%sH -- Vthermistor              = %u\r\n", padString, sys_data.data_cfg[CFG_V_THERMISTOR]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%sH -- Vthermistor              = %u\r\n", padString, sys_data.data_cfg[CFG_V_THERMISTOR]);

    if(printFlg==1)                 uprintf("%s     Vtermistor Std           = %u\r\n", padString, sys_data.data_cfg[CFG_V_THERMISTOR_STD]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%s     Vtermistor Std           = %u\r\n", padString, sys_data.data_cfg[CFG_V_THERMISTOR_STD]);

    if(printFlg==1)                 uprintf("%sI -- Temperature Calc         = %u\r\n", padString, sys_data.data_cfg[CFG_CALC_TEMP]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%sI -- Temperature Calc         = %u\r\n", padString, sys_data.data_cfg[CFG_CALC_TEMP]);

#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1   // Not available on nanoFET
    if(printFlg==1)                 uprintf("%sJ -- Vrsi (Int Ref pH volt)   = %u\r\n", padString, sys_data.data_cfg[CFG_VRSI]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%sJ -- Vrsi (Int Ref pH volt)   = %u\r\n", padString, sys_data.data_cfg[CFG_VRSI]);

    if(printFlg==1)                 uprintf("%s     Vrsi Std                 = %u\r\n", padString, sys_data.data_cfg[CFG_VRSI_STD]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%s     Vrsi Std                 = %u\r\n", padString, sys_data.data_cfg[CFG_VRSI_STD]);

    if(printFlg==1)                 uprintf("%sK -- pH Vrsi Calc             = %u\r\n", padString, sys_data.data_cfg[CFG_CALC_PH_VRSI]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%sK -- pH Vrsi Calc             = %u\r\n", padString, sys_data.data_cfg[CFG_CALC_PH_VRSI]);
#endif

    if(printFlg==1)                 uprintf("%sL -- Vrse (Ext Ref pH volt)   = %u\r\n", padString, sys_data.data_cfg[CFG_VRSE]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%sL -- Vrse (Ext Ref pH volt)   = %u\r\n", padString, sys_data.data_cfg[CFG_VRSE]);

    if(printFlg==1)                 uprintf("%s     Vrse Std                 = %u\r\n", padString, sys_data.data_cfg[CFG_VRSE_STD]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%s     Vrse Std                 = %u\r\n", padString, sys_data.data_cfg[CFG_VRSE_STD]);

    if(printFlg==1)                 uprintf("%sM -- pH Vrse Calc             = %u\r\n", padString, sys_data.data_cfg[CFG_CALC_PH_VRSE]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%sM -- pH Vrse Calc             = %u\r\n", padString, sys_data.data_cfg[CFG_CALC_PH_VRSE]);
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1   // Not available on nanoFET
    if(printFlg==1)                 uprintf("%sN -- Vrsi Biased (7pH=0v)     = %u\r\n", padString, sys_data.data_cfg[CFG_VRSI_BIASED]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%sN -- Vrsi Biased (7pH=0v)     = %u\r\n", padString, sys_data.data_cfg[CFG_VRSI_BIASED]);

    if(printFlg==1)                 uprintf("%sO -- Vrsi Biased Std          = %u\r\n", padString, sys_data.data_cfg[CFG_VRSI_BIASED_STD]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%sO -- Vrsi Biased Std          = %u\r\n", padString, sys_data.data_cfg[CFG_VRSI_BIASED_STD]);

    if(printFlg==1)                 uprintf("%sP -- Vrse Biased (7pH=0v)     = %u\r\n", padString, sys_data.data_cfg[CFG_VRSE_BIASED]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%sP -- Vrse Biased (7pH=0v)     = %u\r\n", padString, sys_data.data_cfg[CFG_VRSE_BIASED]);

    if(printFlg==1)                 uprintf("%sQ -- Vrse Biased Std          = %u\r\n", padString, sys_data.data_cfg[CFG_VRSE_BIASED_STD]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%sQ -- Vrse Biased Std          = %u\r\n", padString, sys_data.data_cfg[CFG_VRSE_BIASED_STD]);
#endif
    //if(printFlg==1) uprintf("\r\n");

    if(printFlg==1)                 uprintf("%sR -- Counter Electrode Vk     = %u\r\n", padString, sys_data.data_cfg[CFG_V_COUNTER_ELECT]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%sR -- Counter Electrode Vk     = %u\r\n", padString, sys_data.data_cfg[CFG_V_COUNTER_ELECT]);

    if(printFlg==1)                 uprintf("%s     Counter Electrode Vk Std = %u\r\n", padString, sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%s     Counter Electrode Vk Std = %u\r\n", padString, sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD]);

    if(printFlg==1)                 uprintf("%sT -- Counter Electrode Cur Ik = %u\r\n", padString, sys_data.data_cfg[CFG_I_COUNTER]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%sT -- Counter Electrode Cur Ik = %u\r\n", padString, sys_data.data_cfg[CFG_I_COUNTER]);

    if(printFlg==1)                 uprintf("%sU -- Substrate Current        = %u\r\n", padString, sys_data.data_cfg[CFG_I_SUBSTRATE]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%sU -- Substrate Current        = %u\r\n", padString, sys_data.data_cfg[CFG_I_SUBSTRATE]);

    //if(printFlg==1) uprintf("\r\n");

#if BOARD_MPHOX >= 1 || BOARD_MFET >= 1   // BUG 28 Dec 2021 (NANOFET instead of MFET on conditional)
    if(printFlg==1)                 uprintf("%sV -- Optode                   = %u\r\n", padString, sys_data.data_cfg[CFG_OPTODE]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%sV -- Optode                   = %u\r\n", padString, sys_data.data_cfg[CFG_OPTODE]);
#endif
#if BOARD_MPHOX >= 1
    if( sys_data.data_cfg[CFG_CTD] == 0)
    {
        if(printFlg==1)                 uprintf("%sW -- Conductivity             = %u\r\n", padString, sys_data.data_cfg[CFG_CTD]);
        if(writeFlg==1) sd_fprintf(&fileObject, "%sW -- Conductivity             = %u\r\n", padString, sys_data.data_cfg[CFG_CTD]);
    }
    if( sys_data.data_cfg[CFG_CTD] == TYPE_SBE37_MICROCAT)
    {
        if(printFlg==1)                 uprintf("%sW -- Conductivity             = %u,  SBE37 MicroCat\r\n", padString, sys_data.data_cfg[CFG_CTD]);
        if(writeFlg==1) sd_fprintf(&fileObject, "%sW -- Conductivity             = %u,  SBE37 MicroCat\r\n", padString, sys_data.data_cfg[CFG_CTD]);
    }
    if( sys_data.data_cfg[CFG_CTD] == TYPE_AANDERAA_5860)
    {
        if(printFlg==1)                 uprintf("%sW -- Conductivity             = %u,  Aanderaa 5860\r\n", padString, sys_data.data_cfg[CFG_CTD]);
        if(writeFlg==1) sd_fprintf(&fileObject, "%sW -- Conductivity             = %u,  Aanderaa 5860\r\n", padString, sys_data.data_cfg[CFG_CTD]);
    }
#endif
#if BOARD_MPHOX >= 1 || BOARD_MFET >= 1   // BUG 28 Dec 2021 (NANOFET instead of MFET on conditional)
    if(printFlg==1)                 uprintf("%sX -- OCR-504                  = %u\r\n", padString, sys_data.data_cfg[CFG_OCR]);
    if(writeFlg==1) sd_fprintf(&fileObject, "%sX -- OCR-504                  = %u\r\n", padString, sys_data.data_cfg[CFG_OCR]);
#endif
    // close the file
    if(writeFlg == 1)
    {
        sys_samp.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\r\n", StringFromFresult(fresult));
            //return 1;
            retVal = 1;
            writeFlg = 0;
        }
    }

}


void print_config_data_fields(void)
{
    print_write_config_data_fields(1,0,1);    // 2 prints //, 1 has no // pad

}

void user_select_ctd(void)
{
    char input;

    uprintf("Select CTD type[%u]:  1 -- SBE37 MicroCat, 2 -- Aanderaa 5860  ");
    while(1)
    {
        if( UARTRxBytesAvail() )
        {
            input = get_key();
            if(input == '1')
            {
                sys_data.data_cfg[CFG_CTD] = TYPE_SBE37_MICROCAT;        //1;
                break;
            }
            if(input == '2')
            {
                sys_data.data_cfg[CFG_CTD] = TYPE_AANDERAA_5860;         //2;
                break;
            }
            if(input == 24)     // Ctrl-x
            {
                sys_data.data_cfg[CFG_CTD] = TYPE_CTD_NOTDEFD;           //0;
                break;
            }
            uprintf("Enter 1 or 2:  1 for SBE37 MicroCat, 2 for Aanderaa 5860, Ctrl-X <enter> to exit  ");
        }

    }
}


void user_select_timestamp(void)
{
    char input;

    uprintf("Select Timestamp type[%u]:  1 -- MM/DD/YYYY HH:MM:SS, 2 -- Epoch millisec ");
    while(1)
    {
        if( UARTRxBytesAvail() )
        {
            input = get_key();
            if(input == '1')
            {
                sys_data.data_cfg[CFG_TIMESTAMP] = TYPE_US_DATETIME;        //1;
                break;
            }
            if(input == '2')
            {
                sys_data.data_cfg[CFG_TIMESTAMP] = TYPE_EPOCH_MSEC;         //2;
                break;
            }
            if(input == 24)     // Ctrl-x
            {
                sys_data.data_cfg[CFG_TIMESTAMP] = TYPE_US_DATETIME;           // Default
                break;
            }
            uprintf("Enter 1 or 2:  1 for MM/DD/YYYY HH:MM:SS, 2 for Epoch milli-seconds 13digit, Ctrl-X <enter> to exit  ");
        }

    }
}


/********************************************************************************************
 *  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("\r\n\r\n\r\nChange Data Field - lower case turns data field off (=0), upper case turns field on (=1)\r\n\r\n\r\n");

        //print_config_data_fields();
        print_write_config_data_fields(1,0,0);  // print, not write, no pad
        wait_consoleTx();

        uprintf("\r\n0 -- Zero (Clear) all config fields");
        uprintf("\r\n1 -- Set all config fields");
        ROM_SysCtlDelay(MILLISECOND * 200);   // 128 byte fifo, use case 5 causes max q so give some time for xmit
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1   // Not available on nanoFET
        uprintf("\r\n2 -- Use Case: GLIDER,          (A,B,C,D,E,L,M,R,T,U)"); //(A,B,G,M,N,O,P,Q)");  //(A,B,C,O,P,Q,R,S,T)");  //ABIJPQRS
        uprintf("\r\n3 -- Use Case: mFET Default,    (A,B,C,D,E,F,G,H,I,J,K,R,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("\r\n4 -- Use Case: MpHOx Default,   (A,B,C,D,E,F,G,H,I,J,K,L,M,R,T,U,V,W)");   //A,C,D,E,F,G,H,I,J,Q,R,S,T,U,V
        uprintf("\r\n5 -- Use Case: MpHOx m2m,       (A,C,D,E,F,G,H,I,J,K,N,R,T,U)");   //A,C,D,E,F,G,H,I,J,Q,R,S,T,U,V   // Added 'N' for pHcalc
        uprintf("\r\n6 -- Use Case: nanoFET Default, (A,B,D,F,G,H,I,L,R,S,T,U)");
        uprintf("\r\n7 -- Use Case: MFET WireWalker, (B,G,L,R,T,U)");
#endif
#if BOARD_NANOFET >= 1
        uprintf("\r\n     Use cases are tailored for nanoFET capability");
        uprintf("\r\n2 -- Use Case: GLIDER,          (A,B,D,L,M,R,T,U)"); //(A,B,G,M,N,O,P,Q)");  //(A,B,C,O,P,Q,R,S,T)");  //ABIJPQRS
        uprintf("\r\n3 -- Use Case: mFET Default,    (A,B,D,F,G,H,I,R,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("\r\n4 -- Use Case: MpHOx Default,   (A,B,D,F,G,H,I,L,M,R,T,U)");   //A,C,D,E,F,G,H,I,J,Q,R,S,T,U,V
        uprintf("\r\n5 -- Use Case: MpHOx m2m,       (A,D,F,G,H,I,R,T,U)");   //A,C,D,E,F,G,H,I,J,Q,R,S,T,U,V   // Added 'N' for p
        uprintf("\r\n6 -- Use Case: nanoFET Default, (A,B,D,F,G,H,I,L,R,S,T,U)");  //(A,B,C,D,E,F,G,H,I,L,R,T,U)");    //(A,B,C,D,E,F,G,H,O,P,Q,R,S,T)");
#endif
        uprintf("\r\n");
        //if(sys_data.diag == 1) uprintf("\r\n8 -- get_sample() Flex Sampling = %u\t\t\t", sys_data.app_cfg[APPCFG_SAMP_FLEX]);

        //uprintf("\r\n");
        uprintf("\r\n9 -- Exit to Main Menu");
        uprintf("\r\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_TIMESTAMP] = TYPE_US_DATETIME;
                // Ask the user which TIMESTAMP?
                user_select_timestamp();
                break;
            case 'b':
                sys_data.data_cfg[CFG_TIMESTAMP] = 0;
                break;

            case 'C':
#if BOARD_NANOFET >= 1
                sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 0;
#endif

#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 1;   //        2   //+ Battery_Volt
#endif
                break;
            case 'c':
                sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 0;
                break;
            case 'D':
                sys_data.data_cfg[CFG_BIAS_BAT_POS] = 1;   //        5   //+ bias bat pos volt
                break;
            case 'd':
                sys_data.data_cfg[CFG_BIAS_BAT_POS] = 0;
                break;
            case 'E':
#if BOARD_NANOFET >= 1
                sys_data.data_cfg[CFG_BIAS_BAT_NEG] = 0;
#endif
#if BOARD_MFET >= 1 || BOARD_MPHOX >= 1
                sys_data.data_cfg[CFG_BIAS_BAT_NEG] = 1;   //        5   //new
#endif
                break;
            case 'e':
                sys_data.data_cfg[CFG_BIAS_BAT_NEG] = 0;
                break;

            case 'F':
                sys_data.data_cfg[CFG_BRD_TEMP] = 1;   //        3   //+ Board_Temperature\t
                break;
            case 'f':
                sys_data.data_cfg[CFG_BRD_TEMP] = 0;
                break;
            case 'G':
                sys_data.data_cfg[CFG_BRD_HUMIDITY] = 1;   //        4   // + Humidity_sensor
                break;
            case 'g':
                sys_data.data_cfg[CFG_BRD_HUMIDITY] = 0;
                break;


            case 'H':
                sys_data.data_cfg[CFG_V_THERMISTOR] = 1;   //        6       //+ Vthermistor\t
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 1;            // New 13 May 2021
                break;
            case 'h':
                sys_data.data_cfg[CFG_V_THERMISTOR] = 0;
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 0;
                sys_data.data_cfg[CFG_CALC_PH_VRSI] = 0;
                sys_data.data_cfg[CFG_CALC_PH_VRSE] = 0;
                break;
            case 'I':
                sys_data.data_cfg[CFG_CALC_TEMP] = 1;   //           20   //+ calculated_temperature_Vthermistor\t
                break;
            case 'i':
                sys_data.data_cfg[CFG_CALC_TEMP] = 0;
                sys_data.data_cfg[CFG_CALC_PH_VRSI] = 0;          // cant calc vrsi pH without temp   19 Jul 2021
                sys_data.data_cfg[CFG_CALC_PH_VRSE] = 0;          // cant calc vrsi pH without temp   19 Jul 2021
                break;

            case 'J':
#if BOARD_NANOFET >= 1
                sys_data.data_cfg[CFG_VRSI] = 0;
                sys_data.data_cfg[CFG_VRSI_STD] = 0;
#endif
#if BOARD_MFET >= 1 || BOARD_MPHOX >= 1
                sys_data.data_cfg[CFG_VRSI] = 1;   //               12   //+ Vint\t
                sys_data.data_cfg[CFG_VRSI_STD] = 1;
#endif
                break;
            case 'j':
                sys_data.data_cfg[CFG_VRSI] = 0;
                sys_data.data_cfg[CFG_VRSI_STD] = 0;
                break;
            case 'K':
#if BOARD_NANOFET >= 1
                sys_data.data_cfg[CFG_CALC_PH_VRSI] = 0;
#endif
#if BOARD_MFET >= 1 || BOARD_MPHOX >= 1
                sys_data.data_cfg[CFG_CALC_PH_VRSI] = 1;   //          21   //+ estimated_pH_int\r\r\n
                sys_data.data_cfg[CFG_V_THERMISTOR] = 1; // new 29 Apr 2021
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 1; // new 17 Jul 2021
                sys_data.data_cfg[CFG_CALC_TEMP] = 1;   // new 29 Apr 2021
                //sys_data.data_cfg[CFG_VRSI_BIASED] = 1; // new 29 Apr 2021
                sys_data.data_cfg[CFG_VRSI] = 1; // new 29 Dec 2021 Removed dependency on VRSI_BIASED
#endif
                break;
            case 'k':
                sys_data.data_cfg[CFG_CALC_PH_VRSI] = 0;
                break;

            case 'L':
                sys_data.data_cfg[CFG_VRSE] = 1;   //               14   //+ Vext
                sys_data.data_cfg[CFG_VRSE_STD] = 1;
                break;
            case 'l':
                sys_data.data_cfg[CFG_VRSE] = 0;
                sys_data.data_cfg[CFG_VRSE_STD] = 0;
                break;
            case 'M':
                sys_data.data_cfg[CFG_CALC_PH_VRSE] = 1;   //          22   //+ estimated_pH_ext\r\r\n (new 6May2019 TM)
                sys_data.data_cfg[CFG_V_THERMISTOR] = 1; // new 29 Apr 2021
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 1; // new 17 Jul 2021
                sys_data.data_cfg[CFG_CALC_TEMP] = 1;   // new 29 Apr 2021
                sys_data.data_cfg[CFG_VRSE] = 1; // new 17 Jan 2022  // Get rid of Biased
#if GETTINGRIDOFBIASED
                sys_data.data_cfg[CFG_VRSE_BIASED] = 1; // new 29 Apr 2021
#endif
                break;
            case 'm':
                sys_data.data_cfg[CFG_CALC_PH_VRSE] = 0;
                break;

            case 'N':
#if BOARD_NANOFET >= 1
                sys_data.data_cfg[CFG_VRSI_BIASED] = 0;   //        8   //+ Vint_offset\t  No VRSI or VRSI_B on nanofet
#endif
#if BOARD_MFET >= 1 || BOARD_MPHOX >= 1
                sys_data.data_cfg[CFG_VRSI_BIASED] = 1;   //        8   //+ Vint_offset\t
#endif
                break;
            case 'n':
                sys_data.data_cfg[CFG_VRSI_BIASED] = 0;
                sys_data.data_cfg[CFG_VRSI_BIASED_STD] = 0;
                break;
            case 'O':
#if BOARD_NANOFET >= 1
                sys_data.data_cfg[CFG_VRSI_BIASED_STD] = 0;       //8   //+ Vint_offset\t  No VRSI or VRSI_B on nanofet
#endif
#if BOARD_MFET >= 1 || BOARD_MPHOX >= 1
                sys_data.data_cfg[CFG_VRSI_BIASED_STD] = 1;   //    9   //+ Vint_offset_std\t
                sys_data.data_cfg[CFG_VRSI_BIASED] = 1;
#endif
                break;
            case 'o':
                sys_data.data_cfg[CFG_VRSI_BIASED_STD] = 0;
                break;
            case 'P':
#if BOARD_NANOFET >= 1
                sys_data.data_cfg[CFG_VRSE_BIASED] = 0;   //        10   //+ Vext_offset\t
#endif
#if BOARD_MFET >= 1 || BOARD_MPHOX >= 1
                sys_data.data_cfg[CFG_VRSE_BIASED] = 1;   //        10   //+ Vext_offset\t
#endif
                break;
            case 'p':
                sys_data.data_cfg[CFG_VRSE_BIASED] = 0;
                sys_data.data_cfg[CFG_VRSE_BIASED_STD] = 0;
                break;
            case 'Q':
#if BOARD_NANOFET >= 1
                sys_data.data_cfg[CFG_VRSE_BIASED_STD] = 0;   //    11   //+ Vext_offset_std\t
                sys_data.data_cfg[CFG_VRSE_BIASED] = 0;
#endif
#if BOARD_MFET >= 1 || BOARD_MPHOX >= 1
                sys_data.data_cfg[CFG_VRSE_BIASED_STD] = 1;   //    11   //+ Vext_offset_std\t
                sys_data.data_cfg[CFG_VRSE_BIASED] = 1;
#endif
                break;
            case 'q':
                sys_data.data_cfg[CFG_VRSE_BIASED_STD] = 0;
                break;

            case 'R':
                sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 1;   //     16   //+ Vcounter_electrode
                sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 1;
                break;
            case 'r':
                sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 0;
                sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 0;
                break;
                //S is up for grabs! 22 Jul 2021 (bug fix)
            case 'S':
                //sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 1;   //   //+ Vcounter_electrode_std
                //sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 1;
                break;
            case 's':
                //sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 0;
                break;

            case 'T':
                sys_data.data_cfg[CFG_I_COUNTER] = 1;   //           18   // + Counter_current
                break;
            case 't':
                sys_data.data_cfg[CFG_I_COUNTER] = 0;
                break;
            case 'U':
                sys_data.data_cfg[CFG_I_SUBSTRATE] = 1;   //         19   //+ Substrate_current
                break;
            case 'u':
                sys_data.data_cfg[CFG_I_SUBSTRATE] = 0;
                break;

            case 'V':
#if BOARD_NANOFET >= 1
                sys_data.data_cfg[CFG_OPTODE] = 0;
#endif
#if BOARD_MFET >= 1 || BOARD_MPHOX >= 1
                sys_data.data_cfg[CFG_OPTODE] = 1;
                sys_data.data_cfg[CFG_OCR] = 0;             // either OCR or OPTODE, can't be both (same port)
#endif
                break;
            case 'v':
                sys_data.data_cfg[CFG_OPTODE] = 0;
                break;

            case 'W':
                sys_data.data_cfg[CFG_CTD] = TYPE_CTD_NOTDEFD;
#if BOARD_MPHOX >= 1
                // Ask the user which CTD?
                user_select_ctd();
#endif
                break;
            case 'w':
//#if BOARD_MPHOX >= 1
                sys_data.data_cfg[CFG_CTD] = TYPE_CTD_NOTDEFD;      //0;
//#endif
                break;

            case 'X':
#if BOARD_MPHOX >= 1 || BOARD_MFET >= 2
                sys_data.data_cfg[CFG_OCR] = 1;
                sys_data.data_cfg[CFG_OPTODE] = 0;
#endif
                break;
            case 'x':
#if BOARD_MPHOX >= 1 || BOARD_MFET >= 2
                sys_data.data_cfg[CFG_OCR] = 0;
#endif
                break;
            case 'Y':
                break;
            case 'y':
                break;
            case 'Z':
                break;
            case 'z':
                break;

            case '0':
                // all clear
                sys_data.data_cfg[CFG_SAMPLE_NUM] = 0;          // a
                sys_data.data_cfg[CFG_TIMESTAMP] = 0;            // b

                sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 0;        // t
                sys_data.data_cfg[CFG_BIAS_BAT_POS] = 0;        // u
                sys_data.data_cfg[CFG_BIAS_BAT_NEG] = 0;        // v
                sys_data.data_cfg[CFG_BRD_TEMP] = 0;            // w
                sys_data.data_cfg[CFG_BRD_HUMIDITY] = 0;        // x

                sys_data.data_cfg[CFG_V_THERMISTOR] = 0;        // c
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 0;    // d
                sys_data.data_cfg[CFG_CALC_TEMP] = 0;           // e

                sys_data.data_cfg[CFG_VRSI] = 0;               // f
                sys_data.data_cfg[CFG_VRSI_STD] = 0;           // g
                sys_data.data_cfg[CFG_CALC_PH_VRSI] = 0;          // h

                sys_data.data_cfg[CFG_VRSE] = 0;               // i
                sys_data.data_cfg[CFG_VRSE_STD] = 0;           // j
                sys_data.data_cfg[CFG_CALC_PH_VRSE] = 0;          // k

                sys_data.data_cfg[CFG_VRSI_BIASED] = 0;        // l
                sys_data.data_cfg[CFG_VRSI_BIASED_STD] = 0;    // m
                sys_data.data_cfg[CFG_VRSE_BIASED] = 0;        // n
                sys_data.data_cfg[CFG_VRSE_BIASED_STD] = 0;    // o

                sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 0;     // p
                sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 0; // q
                sys_data.data_cfg[CFG_I_COUNTER] = 0;           // r
                sys_data.data_cfg[CFG_I_SUBSTRATE] = 0;         // s

                sys_data.data_cfg[CFG_OPTODE] = 0;              // y
                sys_data.data_cfg[CFG_CTD] = 0;                 // z
                sys_data.data_cfg[CFG_OCR] = 0;
                break;

            case '1':
                // all set
                sys_data.data_cfg[CFG_SAMPLE_NUM] = 1;          // A
                sys_data.data_cfg[CFG_TIMESTAMP] = TYPE_US_DATETIME;            // B

#if BOARD_NANOFET >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 0;
                sys_data.data_cfg[CFG_BIAS_BAT_NEG] = 0;        //

                sys_data.data_cfg[CFG_VRSI] = 0;                //
                sys_data.data_cfg[CFG_VRSI_STD] = 0;            //
                sys_data.data_cfg[CFG_CALC_PH_VRSI] = 0;        //

                sys_data.data_cfg[CFG_VRSI_BIASED] = 0;         //
                sys_data.data_cfg[CFG_VRSI_BIASED_STD] = 0;     //
                sys_data.data_cfg[CFG_VRSE_BIASED] = 0;         //
                sys_data.data_cfg[CFG_VRSE_BIASED_STD] = 0;     //

                sys_data.data_cfg[CFG_OPTODE] = 0;
                sys_data.data_cfg[CFG_CTD] = TYPE_CTD_NOTDEFD;
                sys_data.data_cfg[CFG_OCR] = 0;
#endif

#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1
                sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 1;        // t
#endif
                sys_data.data_cfg[CFG_BIAS_BAT_POS] = 1;        // u
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1
                sys_data.data_cfg[CFG_BIAS_BAT_NEG] = 1;        // v
#endif
                sys_data.data_cfg[CFG_BRD_TEMP] = 1;        // w
                sys_data.data_cfg[CFG_BRD_HUMIDITY] = 1;        // x

                sys_data.data_cfg[CFG_V_THERMISTOR] = 1;        // c
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 1;    // d
                sys_data.data_cfg[CFG_CALC_TEMP] = 1;           // e

#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1
                sys_data.data_cfg[CFG_VRSI] = 1;               // f
                sys_data.data_cfg[CFG_VRSI_STD] = 1;           // g
                sys_data.data_cfg[CFG_CALC_PH_VRSI] = 1;          // h
#endif
                sys_data.data_cfg[CFG_VRSE] = 1;               // i
                sys_data.data_cfg[CFG_VRSE_STD] = 1;           // j
                sys_data.data_cfg[CFG_CALC_PH_VRSE] = 1;          // k

#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1
                sys_data.data_cfg[CFG_VRSI_BIASED] = 1;        // l
                sys_data.data_cfg[CFG_VRSI_BIASED_STD] = 1;    // m
                sys_data.data_cfg[CFG_VRSE_BIASED] = 1;        // n
                sys_data.data_cfg[CFG_VRSE_BIASED_STD] = 1;    // o
#endif
                sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 1;     // p
                sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 1; // q
                sys_data.data_cfg[CFG_I_COUNTER] = 1;           // r
                sys_data.data_cfg[CFG_I_SUBSTRATE] = 1;         // s

#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1
                sys_data.data_cfg[CFG_OPTODE] = 1;              // V   // OCR is a special case for MFET only, connected on Optode port
                sys_data.data_cfg[CFG_OCR] = 0;
#endif

                sys_data.data_cfg[CFG_CTD] = TYPE_CTD_NOTDEFD;      //1;                 // W
#if BOARD_MPHOX >= 1
                //sys_data.data_cfg[CFG_CTD] = TYPE_CTD_NOTDEFD;      //1;                 // W
                user_select_ctd();
#endif

                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.fast_mode = 1;                         // Z
                //ABCDELMRSTU
#if BOARD_NANOFET >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 0;
                sys_data.data_cfg[CFG_BIAS_BAT_NEG] = 0;        //

                sys_data.data_cfg[CFG_VRSI] = 0;                //
                sys_data.data_cfg[CFG_VRSI_STD] = 0;            //
                sys_data.data_cfg[CFG_CALC_PH_VRSI] = 0;        //

                sys_data.data_cfg[CFG_VRSI_BIASED] = 0;         //
                sys_data.data_cfg[CFG_VRSI_BIASED_STD] = 0;     //
                sys_data.data_cfg[CFG_VRSE_BIASED] = 0;         //
                sys_data.data_cfg[CFG_VRSE_BIASED_STD] = 0;     //

                sys_data.data_cfg[CFG_OPTODE] = 0;
                sys_data.data_cfg[CFG_CTD] = TYPE_CTD_NOTDEFD;
                sys_data.data_cfg[CFG_OCR] = 0;
#endif

                sys_data.data_cfg[CFG_SAMPLE_NUM] = 1;          // A
                sys_data.data_cfg[CFG_TIMESTAMP] = TYPE_US_DATETIME;            // B
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 1;        // C
#endif
                sys_data.data_cfg[CFG_BIAS_BAT_POS] = 1;        // D  // NEW
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_BIAS_BAT_NEG] = 1;        // E
#endif
                sys_data.data_cfg[CFG_BRD_TEMP] = 0;        // f
                sys_data.data_cfg[CFG_BRD_HUMIDITY] = 0;        // g

                sys_data.data_cfg[CFG_V_THERMISTOR] = 0;        // h
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 0;    //
                sys_data.data_cfg[CFG_CALC_TEMP] = 0;           // i

                sys_data.data_cfg[CFG_VRSI] = 0;               // j
                sys_data.data_cfg[CFG_VRSI_STD] = 0;           //
                sys_data.data_cfg[CFG_CALC_PH_VRSI] = 0;          // k

                sys_data.data_cfg[CFG_VRSE] = 1;               // L
                sys_data.data_cfg[CFG_VRSE_STD] = 1;           //
                sys_data.data_cfg[CFG_CALC_PH_VRSE] = 0;          // M

                sys_data.data_cfg[CFG_VRSI_BIASED] = 0;        // n
                sys_data.data_cfg[CFG_VRSI_BIASED_STD] = 0;    // o
                sys_data.data_cfg[CFG_VRSE_BIASED] = 0;        // p
                sys_data.data_cfg[CFG_VRSE_BIASED_STD] = 0;    // q

                sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 1;     // R
                sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 1; // S
                sys_data.data_cfg[CFG_I_COUNTER] = 1;           // T
                sys_data.data_cfg[CFG_I_SUBSTRATE] = 1;         // U

                sys_data.data_cfg[CFG_OPTODE] = 0;              // v
//#if BOARD_MPHOX >= 1
                sys_data.data_cfg[CFG_CTD] = TYPE_CTD_NOTDEFD;                 // w
//#endif
                sys_data.data_cfg[CFG_OCR] = 0;

                // restore sample rates 9 Apr 2022, prevent user error when switching between 'use case' configs that modify ADS1248 sampling parms
                uprintf("Default ADS1248 sps and trial settings\r\n");
                ads1248_sampling_defaults();
                break;

            case '3':           // Updated to add Calc Temp 23 Mar 2021   MFET Default
                    //Default for MFET fields
                // A,B,C,D,E,F,G,H,I,J,R,S,T,U
#if BOARD_NANOFET >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 0;
                sys_data.data_cfg[CFG_BIAS_BAT_NEG] = 0;        //

                sys_data.data_cfg[CFG_VRSI] = 0;                //
                sys_data.data_cfg[CFG_VRSI_STD] = 0;            //
                sys_data.data_cfg[CFG_CALC_PH_VRSI] = 0;        //

                sys_data.data_cfg[CFG_VRSI_BIASED] = 0;         //
                sys_data.data_cfg[CFG_VRSI_BIASED_STD] = 0;     //
                sys_data.data_cfg[CFG_VRSE_BIASED] = 0;         //
                sys_data.data_cfg[CFG_VRSE_BIASED_STD] = 0;     //

                sys_data.data_cfg[CFG_OPTODE] = 0;
                sys_data.data_cfg[CFG_CTD] = TYPE_CTD_NOTDEFD;
                sys_data.data_cfg[CFG_OCR] = 0;
#endif


                sys_data.data_cfg[CFG_SAMPLE_NUM] = 1;          // A
                sys_data.data_cfg[CFG_TIMESTAMP] = TYPE_US_DATETIME;            // B
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 1;        // C
#endif
                sys_data.data_cfg[CFG_BIAS_BAT_POS] = 1;        // D
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_BIAS_BAT_NEG] = 1;        // E
#endif
                sys_data.data_cfg[CFG_BRD_TEMP] = 1;        // F
                sys_data.data_cfg[CFG_BRD_HUMIDITY] = 1;        // G

                sys_data.data_cfg[CFG_V_THERMISTOR] = 1;        // H
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 1;    //
                sys_data.data_cfg[CFG_CALC_TEMP] = 1;           // I
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_VRSI] = 1;               // J
                sys_data.data_cfg[CFG_VRSI_STD] = 1;           //
                sys_data.data_cfg[CFG_CALC_PH_VRSI] = 1;          // K
#endif
                sys_data.data_cfg[CFG_VRSE] = 0;               // l
                sys_data.data_cfg[CFG_VRSE_STD] = 0;           //
                sys_data.data_cfg[CFG_CALC_PH_VRSE] = 0;          // m

                sys_data.data_cfg[CFG_VRSI_BIASED] = 0;        // n
                sys_data.data_cfg[CFG_VRSI_BIASED_STD] = 0;    // o
                sys_data.data_cfg[CFG_VRSE_BIASED] = 0;        // p
                sys_data.data_cfg[CFG_VRSE_BIASED_STD] = 0;    // q

                sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 1;     // R
                sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 1; // S
                sys_data.data_cfg[CFG_I_COUNTER] = 1;           // T
                sys_data.data_cfg[CFG_I_SUBSTRATE] = 1;         // U

                sys_data.data_cfg[CFG_OPTODE] = 0;              // v
                sys_data.data_cfg[CFG_CTD] = TYPE_CTD_NOTDEFD;                 // w
                //A,B,C,D,E,F,G,L,M,P,Q,R,S,T,U,V,W,X
                sys_data.data_cfg[CFG_OCR] = 0;

                // restore sample rates 9 Apr 2022, prevent user error when switching between 'use case' configs that modify ADS1248 sampling parms
                uprintf("Default ADS1248 sps and trial settings\r\n");
                ads1248_sampling_defaults();
                break;


            case '4':
                //sys_data.fast_mode = 2;
                //Use Case: MPHOX/ nsFOCE, fields for use with another master controller (time not needed).  Defaults for Durafet, not deepsee durafet
                //A,C,D,E,F,G,H,I,J,K,R,S,T,U
#if BOARD_NANOFET >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 0;
                sys_data.data_cfg[CFG_BIAS_BAT_NEG] = 0;        //

                sys_data.data_cfg[CFG_VRSI] = 0;                //
                sys_data.data_cfg[CFG_VRSI_STD] = 0;            //
                sys_data.data_cfg[CFG_CALC_PH_VRSI] = 0;        //

                sys_data.data_cfg[CFG_VRSI_BIASED] = 0;         //
                sys_data.data_cfg[CFG_VRSI_BIASED_STD] = 0;     //
                sys_data.data_cfg[CFG_VRSE_BIASED] = 0;         //
                sys_data.data_cfg[CFG_VRSE_BIASED_STD] = 0;     //

                sys_data.data_cfg[CFG_OPTODE] = 0;
                sys_data.data_cfg[CFG_CTD] = TYPE_CTD_NOTDEFD;
                sys_data.data_cfg[CFG_OCR] = 0;
#endif
                sys_data.data_cfg[CFG_SAMPLE_NUM] = 1;          // A
                sys_data.data_cfg[CFG_TIMESTAMP] = TYPE_US_DATETIME;            // B
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 1;        // C
#endif
                sys_data.data_cfg[CFG_BIAS_BAT_POS] = 1;        // D
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_BIAS_BAT_NEG] = 1;        // E
#endif
                sys_data.data_cfg[CFG_BRD_TEMP] = 1;            // F
                sys_data.data_cfg[CFG_BRD_HUMIDITY] = 1;        // G

                sys_data.data_cfg[CFG_V_THERMISTOR] = 1;        // H
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 1;    //
                sys_data.data_cfg[CFG_CALC_TEMP] = 1;           // I
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_VRSI] = 1;               // J
                sys_data.data_cfg[CFG_VRSI_STD] = 1;           //
                sys_data.data_cfg[CFG_CALC_PH_VRSI] = 1;          // K
#endif
                sys_data.data_cfg[CFG_VRSE] = 1;               // L
                sys_data.data_cfg[CFG_VRSE_STD] = 1;           //
                sys_data.data_cfg[CFG_CALC_PH_VRSE] = 1;          // M

                sys_data.data_cfg[CFG_VRSI_BIASED] = 0;        // n
                sys_data.data_cfg[CFG_VRSI_BIASED_STD] = 0;    // o
                sys_data.data_cfg[CFG_VRSE_BIASED] = 0;        // p
                sys_data.data_cfg[CFG_VRSE_BIASED_STD] = 0;    // q

                sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 1;     // R
                sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 1; // S
                sys_data.data_cfg[CFG_I_COUNTER] = 1;           // T
                sys_data.data_cfg[CFG_I_SUBSTRATE] = 1;         // U

                sys_data.data_cfg[CFG_OCR] = 0;
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_OPTODE] = 1;              // V
                sys_data.data_cfg[CFG_OCR] = 0;
#endif
                sys_data.data_cfg[CFG_CTD] = TYPE_CTD_NOTDEFD;
#if BOARD_MPHOX >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_CTD] = TYPE_SBE37_MICROCAT;                 // W   MicroCAT is default
                user_select_ctd();
#endif
                sys_data.app_cfg[APPCFG_DEPLOY_UARTECHO] =  1;      // echo deployment command characters
                sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 1;            // MicroSD enabled for logging
                uprintf("MicroSD data logging is enabled\r\n");
                uprintf("Console echo of deployment commands is enabled\r\n");

                // restore sample rates 9 Apr 2022, prevent user error when switching between 'use case' configs that modify ADS1248 sampling parms
                uprintf("Default ADS1248 sps and trial settings\r\n");
                ads1248_sampling_defaults();

                break;

            case '5':
                //sys_data.fast_mode = 2;
                //Use Case: MPHOX m2m/ nsFOCE, fields for use with another master controller (time not needed).  Defaults for Durafet, not deepsee durafet
                //A,C,D,E,F,G,H,I,J,K,N,R,S,T,U
#if BOARD_NANOFET >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 0;
                sys_data.data_cfg[CFG_BIAS_BAT_NEG] = 0;        //

                sys_data.data_cfg[CFG_VRSI] = 0;                //
                sys_data.data_cfg[CFG_VRSI_STD] = 0;            //
                sys_data.data_cfg[CFG_CALC_PH_VRSI] = 0;        //

                sys_data.data_cfg[CFG_VRSI_BIASED] = 0;         //
                sys_data.data_cfg[CFG_VRSI_BIASED_STD] = 0;     //
                sys_data.data_cfg[CFG_VRSE_BIASED] = 0;         //
                sys_data.data_cfg[CFG_VRSE_BIASED_STD] = 0;     //

                sys_data.data_cfg[CFG_OPTODE] = 0;
                sys_data.data_cfg[CFG_CTD] = TYPE_CTD_NOTDEFD;
                sys_data.data_cfg[CFG_OCR] = 0;
#endif

                sys_data.data_cfg[CFG_SAMPLE_NUM] = 1;          // A
                sys_data.data_cfg[CFG_TIMESTAMP] = 0;            // b
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 1;        // C
#endif
                sys_data.data_cfg[CFG_BIAS_BAT_POS] = 1;        // D
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_BIAS_BAT_NEG] = 1;        // E
#endif
                sys_data.data_cfg[CFG_BRD_TEMP] = 1;        // F
                sys_data.data_cfg[CFG_BRD_HUMIDITY] = 1;        // G

                sys_data.data_cfg[CFG_V_THERMISTOR] = 1;        // H
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 1;    //
                sys_data.data_cfg[CFG_CALC_TEMP] = 1;           // I
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_VRSI] = 1;               // J
                sys_data.data_cfg[CFG_VRSI_STD] = 1;           //
                sys_data.data_cfg[CFG_CALC_PH_VRSI] = 1;          // K
#endif
                sys_data.data_cfg[CFG_VRSE] = 0;               // l
                sys_data.data_cfg[CFG_VRSE_STD] = 0;           //
                sys_data.data_cfg[CFG_CALC_PH_VRSE] = 0;          // m
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_VRSI_BIASED] = 1;        // N     // New 18 Aug 2021 - 28 Dec 2021 (No longer required to calc pH, leaving the field on to keep compat with nsFOCE labview parsing
                sys_data.data_cfg[CFG_VRSI_BIASED_STD] = 0;    // o
                sys_data.data_cfg[CFG_VRSE_BIASED] = 0;        // p
                sys_data.data_cfg[CFG_VRSE_BIASED_STD] = 0;    // q
#endif
                sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 1;     // R
                sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 1; // S
                sys_data.data_cfg[CFG_I_COUNTER] = 1;           // T
                sys_data.data_cfg[CFG_I_SUBSTRATE] = 1;         // U

                sys_data.data_cfg[CFG_OPTODE] = 0;              // v
                sys_data.data_cfg[CFG_CTD] = TYPE_CTD_NOTDEFD;                 // w
                sys_data.data_cfg[CFG_OCR] = 0;

                sys_data.app_cfg[APPCFG_DEPLOY_UARTECHO] =  0;          // Disable Echo
                sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 0;            // Disable MicroSD card
                uprintf("MicroSD data logging is Disabled\r\n");
                uprintf("Console echo of deployment commands is disabled\r\n");

                // restore sample rates 9 Apr 2022, prevent user error when switching between 'use case' configs that modify ADS1248 sampling parms
                uprintf("Default ADS1248 sps and trial settings\r\n");
                ads1248_sampling_defaults();
                break;


            case '6':
                //Use Case: nanoFET default, fields
                // A,B,D,F,G,H,I,L,R,S,T,U
                sys_data.data_cfg[CFG_SAMPLE_NUM] = 1;          // A
                sys_data.data_cfg[CFG_TIMESTAMP] = TYPE_US_DATETIME;            // B

                sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 0;        // c
                sys_data.data_cfg[CFG_BIAS_BAT_POS] = 1;        // D
                sys_data.data_cfg[CFG_BIAS_BAT_NEG] = 0;        // e
                sys_data.data_cfg[CFG_BRD_TEMP] = 1;        // F
                sys_data.data_cfg[CFG_BRD_HUMIDITY] = 1;        // G

                sys_data.data_cfg[CFG_V_THERMISTOR] = 1;        // H
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 1;    //
                sys_data.data_cfg[CFG_CALC_TEMP] = 1;           // I

                sys_data.data_cfg[CFG_VRSI] = 0;               // j
                sys_data.data_cfg[CFG_VRSI_STD] = 0;           //
                sys_data.data_cfg[CFG_CALC_PH_VRSI] = 0;          // k

                sys_data.data_cfg[CFG_VRSE] = 1;               // L
                sys_data.data_cfg[CFG_VRSE_STD] = 1;           //
                sys_data.data_cfg[CFG_CALC_PH_VRSE] = 0;          // m

                sys_data.data_cfg[CFG_VRSI_BIASED] = 0;        // n
                sys_data.data_cfg[CFG_VRSI_BIASED_STD] = 0;    // o
                sys_data.data_cfg[CFG_VRSE_BIASED] = 0;        // p
                sys_data.data_cfg[CFG_VRSE_BIASED_STD] = 0;    // q

                sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 1;     // R
                sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 1; // S
                sys_data.data_cfg[CFG_I_COUNTER] = 1;           // T
                sys_data.data_cfg[CFG_I_SUBSTRATE] = 1;         // U

                sys_data.data_cfg[CFG_OPTODE] = 0;              // v
                sys_data.data_cfg[CFG_CTD] = TYPE_CTD_NOTDEFD;                 // w
                sys_data.data_cfg[CFG_OCR] = 0;

                // restore sample rates 9 Apr 2022, prevent user error when switching between 'use case' configs that modify ADS1248 sampling parms
                uprintf("Default ADS1248 sps and trial settings\r\n");
                ads1248_sampling_defaults();

                sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 0;            // Disable Datalogging, not present on nanoFET
                uprintf("Data logging is Disabled\r\n");

                break;


            case '7':
                uprintf("\r\nMFET config and fast sample for wire walker\r\n");
                // MFET fast sample, wire walker
                //time stamp (posix msec)
                // Humidity
                //Vrse (20Hz, 5 samples)
                //Vrse_std
                //Vk (160 Hz, 2 samples)
                //Vk_std
                //Ik (160Hz, 1 sample)
                //Ib (160Hz,1 sample)

                // A,B,D,F,G,H,I,L,R,S,T,U
#if BOARD_NANOFET >= 1   // Not available on nanoFET
                sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 0;
                sys_data.data_cfg[CFG_BIAS_BAT_NEG] = 0;        //

                sys_data.data_cfg[CFG_VRSI] = 0;                //
                sys_data.data_cfg[CFG_VRSI_STD] = 0;            //
                sys_data.data_cfg[CFG_CALC_PH_VRSI] = 0;        //

                sys_data.data_cfg[CFG_VRSI_BIASED] = 0;         //
                sys_data.data_cfg[CFG_VRSI_BIASED_STD] = 0;     //
                sys_data.data_cfg[CFG_VRSE_BIASED] = 0;         //
                sys_data.data_cfg[CFG_VRSE_BIASED_STD] = 0;     //

                sys_data.data_cfg[CFG_OPTODE] = 0;
                sys_data.data_cfg[CFG_CTD] = TYPE_CTD_NOTDEFD;
                sys_data.data_cfg[CFG_OCR] = 0;
#endif

                sys_data.data_cfg[CFG_SAMPLE_NUM] = 0;          // A
                sys_data.data_cfg[CFG_TIMESTAMP] = TYPE_EPOCH_MSEC;            // B

                sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 0;        // c
                sys_data.data_cfg[CFG_BIAS_BAT_POS] = 0;        // D
                sys_data.data_cfg[CFG_BIAS_BAT_NEG] = 0;        // e
                sys_data.data_cfg[CFG_BRD_TEMP] = 0;           // F
                sys_data.data_cfg[CFG_BRD_HUMIDITY] = 1;        // G

                sys_data.data_cfg[CFG_V_THERMISTOR] = 0;        // H
                sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 0;    //
                sys_data.data_cfg[CFG_CALC_TEMP] = 0;           // I

                sys_data.data_cfg[CFG_VRSI] = 0;               // j
                sys_data.data_cfg[CFG_VRSI_STD] = 0;           //
                sys_data.data_cfg[CFG_CALC_PH_VRSI] = 0;          // k

                sys_data.data_cfg[CFG_VRSE] = 1;               // L
                sys_data.data_cfg[CFG_VRSE_STD] = 1;           //
                sys_data.data_cfg[CFG_CALC_PH_VRSE] = 0;          // m

                sys_data.data_cfg[CFG_VRSI_BIASED] = 0;        // n
                sys_data.data_cfg[CFG_VRSI_BIASED_STD] = 0;    // o
                sys_data.data_cfg[CFG_VRSE_BIASED] = 0;        // p
                sys_data.data_cfg[CFG_VRSE_BIASED_STD] = 0;    // q

                sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 1;     // R
                sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 1; // S
                sys_data.data_cfg[CFG_I_COUNTER] = 1;           // T
                sys_data.data_cfg[CFG_I_SUBSTRATE] = 1;         // U

                sys_data.data_cfg[CFG_OPTODE] = 0;              // v
                sys_data.data_cfg[CFG_CTD] = 0;                 // w
                sys_data.data_cfg[CFG_OCR] = 0;

                // Yui's request for RBR (100hz -> 160hz)
                //Vrse (20Hz, 5 samples)
                //Vrse_std
                //Vk (100 Hz, 1 sample)
                //Ik (100Hz, 1 sample)
                //Ib (100Hz,1 sample)

                uprintf("Changes from default ADS1248 sps and trials:\r\n");
                sys_data.Vrse_sps = 20;
                uprintf("   Vrse_sps = %u\r\n", sys_data.Vrse_sps);
                sys_data.Vrse_trials = 5;
                uprintf("   Vrse_trials = %u\r\n", sys_data.Vrse_trials);

                sys_data.Vk_sps = 320;
                uprintf("   Vk_sps = %u\r\n", sys_data.Vk_sps);
                sys_data.Vk_trials = 3;
                uprintf("   Vk_trials = %u\r\n", sys_data.Vk_trials);
                sys_data.Ik_sps = 160;
                uprintf("   Ik_sps = %u\r\n", sys_data.Ik_sps);
                sys_data.Ik_trials = 1;
                uprintf("   Ik_trials = %u\r\n", sys_data.Ik_trials);

                sys_data.Ib_sps = 160;
                uprintf("   Ib_sps = %u\r\n", sys_data.Ib_sps);
                sys_data.Ib_trials = 1;
                uprintf("   Ib_trials = %u\r\n", sys_data.Ib_trials);

                uprintf("\r\n");
                sys_data.sampling_period = 2;
                uprintf("Sampling period = %u\r\n", sys_data.sampling_period);


                sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 0;            // Disable MicroSD card
                uprintf("MicroSD data logging is Disabled\r\n");
                sys_data.data_cfg[CFG_TIMESTAMP] = TYPE_EPOCH_MSEC;   //Timestamp in Posix msec (Epoch msec)
                uprintf("Timestamp in Epoch millisec format\r\n");
                break;

            case '8':
                break;


            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("\r\n\r\nError storing system data.\r\n");
                }
                else
                    uprintf("\r\n\r\nSystem data stored. (910) -- Press enter to bring up main menu\r\n");
                return;

        }  // end of switch statement

    }
}







void print_all_metadata(void)
{
    time_t  current_time;

    current_time = ROM_HibernateRTCGet();

    print_write_metadata_header(current_time, 1, 0);

}

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

    uprintf("\r\nEnter data file name (no spaces, 8.3 format) [%s]: ", sys_data.fileName);  // 8 + 1 + 3 + 1 = 13  (null terminate)
    if( getUserInput(buff, 13) ) // was MAX_FILENAME-1) )  // storage size is 80, user input size was 100 - fixed a BUG!
    {
        strcpy(sys_data.fileName, buff);
        uprintf("\r\nFile name now: %s\r\n", sys_data.fileName);
    }

    uprintf("\r\nEnter user initials [%s]: ", sys_data.user);
    if( getUserInput(buff, MAX_USER_INITIALS-1) )       // was 10 user initials
    {
        strcpy(sys_data.user, buff);
        uprintf("\r\nUser initials now: %s\r\n", sys_data.user);
    }

    //char board_SN[MAX_BOARD_SN];   MAX_BOARD_SN 30
#if BOARD_MFET >= 1
    uprintf("\r\nEnter MFET Serial # [%s]: ", sys_data.board_SN);
#endif
#if BOARD_MPHOX >= 1
    uprintf("\r\nEnter MPHOX Serial # [%s]: ", sys_data.board_SN);
#endif
#if BOARD_NANOFET >= 1
    uprintf("\r\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("\r\nBoard Serial #: %s\r\n", sys_data.board_SN);
    }


    // char mcap_SN[MAX_MCAP_SN];  MAX_MCAP_SN  30
#if BOARD_MFET >= 1 || BOARD_MPHOX >= 1
    uprintf("\r\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("\r\nMCAP Serial #: %s\r\n", sys_data.mcap_SN);
    }
#endif


    // char board_fab_note[MAX_board_fab_note];   MAX_board_fab_note 80
    uprintf("\r\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("\r\nBoard Fab notes: %s\r\n", sys_data.board_fab_note);
    }

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

    //char durafet_SN[MAX_DURAFET_SN];  30
    uprintf("\r\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("\r\nDurafet Serial #: %s\r\n", sys_data.durafet_SN);
    }


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

#if BOARD_MPHOX >= 1
    uprintf("\r\nEnter Conductivity Serial # [%s]: ", sys_data.ctd_SN);
    if( getUserInput(buff, MAX_CTD_SN-1) )       //
    {
        strcpy(sys_data.ctd_SN, buff);
        uprintf("\r\nConductivity Serial #: %s\r\n", sys_data.ctd_SN);
    }

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


}



// 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
{
    return(print_write_metadata_header(currentTime, 0, 1));
    //return 0;
}




int print_write_data_header(uint32_t printFlg, uint32_t writeFlg)
{
    struct tm *time_struct;
    char buff[TIMESTAMPLENGTH];
    FIL fileObject;     // File object
    FRESULT fresult;
    UINT bw;
    int retVal;
    uint32_t indx;

    retVal = 0;     // assume a good return (1 is error due to SD card

    indx = 0;

    uprintf("\r\n\r\n");

    if(sys_data.data_cfg[CFG_SAMPLE_NUM] > 0)       { indx += sprintf(&prnBuf[indx], " SampNum\t");     }
    if(sys_data.data_cfg[CFG_TIMESTAMP] == TYPE_US_DATETIME)
    {
        if(sys_data.data_cfg[CFG_TIMESTAMP] > 0)         { indx += sprintf(&prnBuf[indx], "     MM/DD/YYYY HH:MM:SS\t");   }
    }
    if(sys_data.data_cfg[CFG_TIMESTAMP] == TYPE_EPOCH_MSEC)
    {
        if(sys_data.data_cfg[CFG_TIMESTAMP] > 0)         { indx += sprintf(&prnBuf[indx], "Epoch millisec\t");   }   //if(sys_data.data_cfg[CFG_TIMESTAMP] > 0)         { indx += sprintf(&prnBuf[indx], "     Epoch milliseconds \t");   }
    }


//--- board sensors

    if(sys_data.data_cfg[CFG_VIN_BAT_VOLT] > 0)     { indx += sprintf(&prnBuf[indx], "VbatMain\t");     }
    if(sys_data.data_cfg[CFG_BIAS_BAT_POS] > 0)     { indx += sprintf(&prnBuf[indx], "VbiasPos\t");     }
    if(sys_data.data_cfg[CFG_BIAS_BAT_NEG] > 0)     { indx += sprintf(&prnBuf[indx], "VbiasNeg\t");     }
    if(sys_data.data_cfg[CFG_BRD_TEMP] > 0)         { indx += sprintf(&prnBuf[indx], " TC_cont\t");     }
    if(sys_data.data_cfg[CFG_BRD_HUMIDITY] > 0)     { indx += sprintf(&prnBuf[indx], "Humidity\t");     }

//--- pH voltages
    if(sys_data.data_cfg[CFG_V_THERMISTOR] > 0)     { indx += sprintf(&prnBuf[indx], "  Vtherm\t");     }
    if(sys_data.data_cfg[CFG_V_THERMISTOR_STD] > 0) { indx += sprintf(&prnBuf[indx], "VthrmStd\t");     }
    if(sys_data.data_cfg[CFG_CALC_TEMP] > 0)        { indx += sprintf(&prnBuf[indx], " TC_Dfet\t");     }
//---

    if(sys_data.data_cfg[CFG_VRSI] > 0)             { indx += sprintf(&prnBuf[indx], "    Vrsi\t");     }
    if(sys_data.data_cfg[CFG_VRSI_STD] > 0)         { indx += sprintf(&prnBuf[indx], "Vrsi_std\t");     }
    if(sys_data.data_cfg[CFG_CALC_PH_VRSI] > 0)     { indx += sprintf(&prnBuf[indx], "pHintEst\t");     }
    if(sys_data.data_cfg[CFG_VRSE] > 0)             { indx += sprintf(&prnBuf[indx], "    Vrse\t");     }
    if(sys_data.data_cfg[CFG_VRSE_STD] > 0)         { indx += sprintf(&prnBuf[indx], "Vrse_std\t");     }
    if(sys_data.data_cfg[CFG_CALC_PH_VRSE] > 0)     { indx += sprintf(&prnBuf[indx], "pHextEst\t");     }

//---

    if(sys_data.data_cfg[CFG_VRSI_BIASED] > 0)      { indx += sprintf(&prnBuf[indx], "  Vrsi_B\t");     }
    if(sys_data.data_cfg[CFG_VRSI_BIASED_STD] > 0)  { indx += sprintf(&prnBuf[indx], "VrsiBstd\t");     }
    if(sys_data.data_cfg[CFG_VRSE_BIASED] > 0)      { indx += sprintf(&prnBuf[indx], "  Vrse_B\t");     }
    if(sys_data.data_cfg[CFG_VRSE_BIASED_STD] > 0)  { indx += sprintf(&prnBuf[indx], "VrseBstd\t");     }


//--- ISFET diagnostics
    if(sys_data.data_cfg[CFG_V_COUNTER_ELECT] > 0)  { indx += sprintf(&prnBuf[indx], "      Vk\t");     }
    if(sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] > 0) { indx += sprintf(&prnBuf[indx], "  Vk_std\t");  }
    if(sys_data.data_cfg[CFG_I_COUNTER] > 0)        { indx += sprintf(&prnBuf[indx], "      Ik\t");     }
    if(sys_data.data_cfg[CFG_I_SUBSTRATE] > 0)      { indx += sprintf(&prnBuf[indx], "      Ib\t");     }



//---- External Instruments

    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");   }
    if(sys_data.data_cfg[CFG_CTD] > 0)
    {                                             //01234567
        if((sys_data.data_cfg[CFG_CTD]) == 1)       { indx += sprintf(&prnBuf[indx], "TC_MCat\tCond\tpSal\tPres\tDate_MC\tTime_MC\t");   } //if(ctd.type == 1)        // microCAT SBE37
        if((sys_data.data_cfg[CFG_CTD]) == 2)       { indx += sprintf(&prnBuf[indx], "Cond_PN\tCond_SN\tCond\tTemp\tSal\tDensity \tSSpeed\t");   }   //if(ctd.type == 2)        // aanderaa 5860
    }
    if(sys_data.data_cfg[CFG_OCR] > 0)              { indx += sprintf(&prnBuf[indx], "OCR_PN  \tChan_1 \tChan_2 \tChan_3 \tChan_4 \t");   }

    if(sys_data.pump_seq_type == 2)                 { indx += sprintf(&prnBuf[indx], "   Pump\t");   }

    // fix trailing tab 28 Dec 2021
    indx--;
    prnBuf[indx] = '\r';        // line termination is CR-LF (0x0d, 0x0a)  25 Mar 2022   Old UARTwrite would insert \r (bad practice)
    indx++;
    prnBuf[indx] = '\n';
    indx++;
    prnBuf[indx] = 0;

    if(printFlg == 1) UARTwrite(prnBuf, strlen(prnBuf));

    // BUG FIX 28 Dec 2021 (does not write data header due to missing f_close)
    if( (sys_data.app_cfg[APPCFG_MICROSD_ENABLE] == 1) && (writeFlg == 1) )
    {
        // 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\r\n", StringFromFresult(fresult));
            retVal = 1;
            writeFlg = 0;
            //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\r\n", StringFromFresult(fresult));
            retVal = 1;
            writeFlg = 0;
            //return 1;
        }

        // Write the formatted data string in the prnBuf buffer to the SD card
         fresult = f_write( &fileObject, prnBuf, strlen(prnBuf), (UINT*)&bw);
         if(fresult != FR_OK)
         {
             uprintf("f_write error: %s\r\n", StringFromFresult(fresult));
         }

        sys_samp.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\r\n", StringFromFresult(fresult));
            //return 1;
            retVal = 1;
            writeFlg = 0;
        }
    }

    if(printFlg == 1)    wait_consoleTx();

    return(retVal);

}

void print_data_header(void)
{
    print_write_data_header(1,0);

}


int write_data_header(void)
{
    return(print_write_data_header(0,1));
}


/*
 * stub for older get_header (used in COMMAND mode gh
 */
void get_header(void)
{
    print_write_data_header(1,0);
}

/*
 * enter_deployment_note with timeout
 */
int enter_deployment_note(uint32_t timeout)
{
    int byteCnt = 0;
    char noteBuf[84];

    noteBuf[0] = ' ';
    noteBuf[1] = 0x00;
    byteCnt = 1;

    sys_data.deploy_note[0] = ' ';
    sys_data.deploy_note[1] = 0;
    uprintf("\r\nEnter Deployment Note [ ]: ");
    if( getUserInputTimeLimit(noteBuf, (MAX_DEPLOY_NOTE-4), timeout) )
    {
        byteCnt = strcpy(sys_data.deploy_note, noteBuf);
        uprintf("\r\n%s\r\n", sys_data.deploy_note);
    }

    return(byteCnt);
}








/*
 * print_write_metadata_header() was written to improve maintainability and consistency of formatted output
 *
 * replaces print_metadata_header and write_metadata_header
 */

int print_write_metadata_header(const time_t currentTime, uint32_t printFlg, uint32_t writeFlg)
{

    struct tm *time_struct;
    char buff[TIMESTAMPLENGTH];
    FIL fileObject;     // File object
    FRESULT fresult;
    UINT bw;
    int retVal;

    retVal = 0;     // assume a good return (1 is error due to SD card

    if(sys_data.app_cfg[APPCFG_MICROSD_ENABLE] == 0)        // fix 6 Aug 2021
    {
        retVal = 0;  // pretend it's good
        writeFlg = 0;
    }

    if(writeFlg == 1)
    {

        // 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\r\n", StringFromFresult(fresult));
            //return 1;
            retVal = 1;
            writeFlg = 0;
        }

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

    }

    if(writeFlg == 1)   sd_fprintf(&fileObject, "\r\n\r\n");
    if(printFlg == 1)                   uprintf("\r\n\r\n");
    if(writeFlg == 1)   sd_fprintf(&fileObject, "//++************** Deployment Settings ***************\r\n");
    if(printFlg == 1)                   uprintf("//++************** Deployment Settings ***************\r\n");

    if(writeFlg == 1) sd_fprintf(&fileObject, "// Firmware version: \t%s\r\n", sys_data.qa.firmware_version);
    if(printFlg == 1)                 uprintf("// Firmware version: \t%s\r\n", sys_data.qa.firmware_version);


    if(writeFlg == 1) sd_fprintf(&fileObject, "// Sampling period (s)\t%u\r\n", sys_data.sampling_period);
    if(printFlg == 1)                 uprintf("// Sampling period (s)\t%u\r\n", sys_data.sampling_period);

    if(sys_data.sample_aligned)
    {
        if(writeFlg == 1) sd_fprintf(&fileObject, "// Samples hour align:\tYes\r\n");
        if(printFlg == 1)                 uprintf("// Samples hour align:\tYes\r\n");
    }
    else
    {
        if(writeFlg == 1) sd_fprintf(&fileObject, "// Samples hour align:\tNo\r\n");
        if(printFlg == 1)                 uprintf("// Samples hour align:\tNo\r\n");
    }

    if(writeFlg == 1) sd_fprintf(&fileObject, "// Vrsi sps,trials: \t%u, %u\r\n", sys_data.Vrsi_sps, sys_data.Vrsi_trials);
    if(printFlg == 1)                 uprintf("// Vrsi sps,trials: \t%u, %u\r\n", sys_data.Vrsi_sps, sys_data.Vrsi_trials);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// Vrse sps,trials: \t%u, %u\r\n", sys_data.Vrse_sps, sys_data.Vrse_trials);
    if(printFlg == 1)                 uprintf("// Vrse sps,trials: \t%u, %u\r\n", sys_data.Vrse_sps, sys_data.Vrse_trials);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// Vtherm sps,trials\t%u, %u\r\n", sys_data.Vtherm_sps, sys_data.Vtherm_trials);
    if(printFlg == 1)                 uprintf("// Vtherm sps,trials\t%u, %u\r\n", sys_data.Vtherm_sps, sys_data.Vtherm_trials);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// Ik sps, trials:   \t%u, %u\r\n", sys_data.Ik_sps, sys_data.Ik_trials);
    if(printFlg == 1)                 uprintf("// Ik sps, trials:   \t%u, %u\r\n", sys_data.Ik_sps, sys_data.Ik_trials);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// Vk sps, trials:   \t%u, %u\r\n", sys_data.Vk_sps, sys_data.Vk_trials);
    if(printFlg == 1)                 uprintf("// Vk sps, trials:   \t%u, %u\r\n", sys_data.Vk_sps, sys_data.Vk_trials);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// Ib sps, trials:   \t%u, %u\r\n", sys_data.Ib_sps, sys_data.Ib_trials);
    if(printFlg == 1)                 uprintf("// Ib sps, trials:   \t%u, %u\r\n", sys_data.Ib_sps, sys_data.Ib_trials);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// Vb sps, trials:   \t%u, %u\r\n", sys_data.Vb_sps, sys_data.Vb_trials);
    if(printFlg == 1)                 uprintf("// Vb sps, trials:   \t%u, %u\r\n", sys_data.Vb_sps, sys_data.Vb_trials);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// Vbias sps,trials: \t%u, %u\r\n", sys_data.Vbias_sps, sys_data.Vbias_trials);
    if(printFlg == 1)                 uprintf("// Vbias sps,trials: \t%u, %u\r\n", sys_data.Vbias_sps, sys_data.Vbias_trials);




    if(sys_data.pump1_ontime > 0)
    {
        if(sys_data.start_pump_time > 0)            // new 24 Feb 2022
        {
            time_struct = localtime(&sys_data.start_pump_time);
            strftime(buff, sizeof(buff),"// Pump delay until:\t%Y/%m/%d %H:%M:%S\r\n", time_struct);
        }
        else
        {
            sprintf(buff, "// Pump start delay: \t0\r\n");
        }

        if(writeFlg == 1)
        {
            fresult = f_write(&fileObject, buff, strlen(buff), &bw);
            if(fresult != FR_OK)
            {
                uprintf("Current time f_write error: %s\r\n", StringFromFresult(fresult));
                //return 1;
                retVal = 1;
                writeFlg = 0;
            }
        }
        if(printFlg == 1)  uprintf("%s", buff);
    }

    if(sys_data.pump1_ontime == 0)
    {
        if(writeFlg == 1) sd_fprintf(&fileObject, "// Pump on time (s):\t%u\r\n", sys_data.pump1_ontime);
        if(printFlg == 1)                 uprintf("// Pump on time (s):\t%u\r\n", sys_data.pump1_ontime);
    }

    if((sys_data.pump1_ontime > 0) && (sys_data.pump_seq_type == TYPE_PUMP_SINGLE))
    {
        if(writeFlg == 1) sd_fprintf(&fileObject, "// Pump seq type:   \tPUMP_SINGLE\r\n");
        if(printFlg == 1)                 uprintf("// Pump seq type:   \tPUMP_SINGLE\r\n");

        if(sys_data.test_mode)
        {
            if(writeFlg == 1) sd_fprintf(&fileObject, "// Pump on time (s):\t%u  (TEST MODE, pump disabled)\r\n", sys_data.pump1_ontime);
            if(printFlg == 1)                 uprintf("// Pump on time (s):\t%u  (TEST MODE, pump disabled)\r\n", sys_data.pump1_ontime);
        }
        else
        {
            if(writeFlg == 1) sd_fprintf(&fileObject, "// Pump on time (s):\t%u\r\n", sys_data.pump1_ontime);
            if(printFlg == 1)                 uprintf("// Pump on time (s):\t%u\r\n", sys_data.pump1_ontime);
        }
    }

    if((sys_data.pump1_ontime > 0) && (sys_data.pump_seq_type == TYPE_2PUMP_BEAMSV1))
    {
        if(writeFlg == 1) sd_fprintf(&fileObject, "// Pump seq type:   \t2PUMP_BEAMSV1\r\n");
        if(printFlg == 1)                 uprintf("// Pump seq type:   \t2PUMP_BEAMSV1\r\n");

        if(writeFlg == 1) sd_fprintf(&fileObject, "// Pump1 on time (s):\t%u\r\n", sys_data.pump1_ontime);
        if(printFlg == 1)                 uprintf("// Pump1 on time (s):\t%u\r\n", sys_data.pump1_ontime);
        if(writeFlg == 1) sd_fprintf(&fileObject, "// Pump2 on time (s):\t%u\r\n", sys_data.pump2_ontime);
        if(printFlg == 1)                 uprintf("// Pump2 on time (s):\t%u\r\n", sys_data.pump2_ontime);
        if(writeFlg == 1) sd_fprintf(&fileObject, "// Pump1 cycles:     \t%u\r\n", sys_data.pump1_cycles);
        if(printFlg == 1)                 uprintf("// Pump1 cycles:     \t%u\r\n", sys_data.pump1_cycles);
        if(writeFlg == 1) sd_fprintf(&fileObject, "// Pump2 cycles:     \t%u\r\n", sys_data.pump2_cycles);
        if(printFlg == 1)                 uprintf("// Pump2 cycles:     \t%u\r\n", sys_data.pump2_cycles);
    }

    if((sys_data.pump1_ontime > 0) && (sys_data.pump_seq_type > TYPE_2PUMP_BEAMSV1))
    {
        if(writeFlg == 1) sd_fprintf(&fileObject, "// Hey there, add pump sequencer metadata for new seq_type=%u\t%u\r\n", sys_data.pump_seq_type);

    }

    if(sys_data.sampleCnt_duty_on > 0)
    {
        if(writeFlg == 1) sd_fprintf(&fileObject, "// Exp Duty Cycle On \t%u\r\n", sys_data.sampleCnt_duty_on);
        if(printFlg == 1)                 uprintf("// Exp Duty Cycle On \t%u\r\n", sys_data.sampleCnt_duty_on);
        if(writeFlg == 1) sd_fprintf(&fileObject, "// Exp Duty Cycle Off\t%u\r\n", sys_data.sampleCnt_duty_off);
        if(printFlg == 1)                 uprintf("// Exp Duty Cycle Off\t%u\r\n", sys_data.sampleCnt_duty_on);

    }


#ifdef NOCODE
    if(sys_data.test_mode)
    {
        if(writeFlg == 1) sd_fprintf(&fileObject, "// Pump on time (s):\t%u  (TEST MODE, pump disabled)\r\n", sys_data.pump1_ontime);
        if(printFlg == 1)                 uprintf("// Pump on time (s):\t%u  (TEST MODE, pump disabled)\r\n", sys_data.pump1_ontime);
    }
    else
    {
        if(writeFlg == 1) sd_fprintf(&fileObject, "// Pump on time (s):\t%u\r\n", sys_data.pump1_ontime);
        if(printFlg == 1)                 uprintf("// Pump on time (s):\t%u\r\n", sys_data.pump1_ontime);
    }
#endif


    if(writeFlg == 1) sd_fprintf(&fileObject, "// Low battery voltage:\t%.1f\r\n", sys_data.low_batt_volt);
    if(printFlg == 1)                 uprintf("// Low battery voltage:\t%.1f\r\n", sys_data.low_batt_volt);

    if(sys_data.output == 1)
    {                                              // Low battery voltage:\t%.1f\r\n"
        if(writeFlg == 1) sd_fprintf(&fileObject, "// Output mode:        \tNormal\r\n");
        if(printFlg == 1)                 uprintf("// Output mode:        \tNormal\r\n");

    }
    if(sys_data.output == 2)
    {
        if(writeFlg == 1) sd_fprintf(&fileObject, "// Output mode:        \tVerbose\r\n");
        if(printFlg == 1)                 uprintf("// Output mode:        \tVerbose\r\n");
    }

    time_struct = localtime(&sys_data.deploy_time);
    strftime(buff, sizeof(buff),"// Deploy time:   \t%Y/%m/%d %H:%M:%S\r\n", time_struct);
    if(writeFlg == 1)
    {
        fresult = f_write(&fileObject, buff, strlen(buff), &bw);
        if(fresult != FR_OK)
        {
            uprintf("Current time f_write error: %s\r\n", StringFromFresult(fresult));
            //return 1;
            retVal = 1;
            writeFlg = 0;
        }
    }
    if(printFlg == 1)  uprintf("%s", buff);

    // Store timezone
    if(sys_data.GMT)
    {
        if(writeFlg == 1)   sd_fprintf(&fileObject, "// Time zone:       \tGMT\r\n");
        if(printFlg == 1)                   uprintf("// Time zone:       \tGMT\r\n");
    }
    else
    {
        if(writeFlg == 1)   sd_fprintf(&fileObject, "// Time zone:       \tLocal\r\n");
        if(printFlg == 1)                   uprintf("// Time zone:       \tLocal\r\n");
    }


    if(printFlg == 1)    wait_consoleTx();       // defd in uartstdio.c  TODO add timeout


    if(writeFlg == 1) sd_fprintf(&fileObject, "// TCOffset:     \t%f\r\n", sys_data.TCOffset);
    if(printFlg == 1)                 uprintf("// TCOffset:     \t%f\r\n", sys_data.TCOffset);
    if(writeFlg == 1) sd_fprintf(&fileObject, "// k0int:        \t%f\r\n", sys_data.k0int);
    if(printFlg == 1)                 uprintf("// k0int:        \t%f\r\n", sys_data.k0int);
    if(writeFlg == 1) sd_fprintf(&fileObject, "// k0ext:        \t%f\r\n", sys_data.k0ext);
    if(printFlg == 1)                 uprintf("// k0ext:        \t%f\r\n", sys_data.k0ext);
    if(writeFlg == 1) sd_fprintf(&fileObject, "// k2int:        \t%f\r\n", sys_data.k2int);
    if(printFlg == 1)                 uprintf("// k2int:        \t%f\r\n", sys_data.k2int);
    if(writeFlg == 1) sd_fprintf(&fileObject, "// k2ext:        \t%f\r\n", sys_data.k2ext);
    if(printFlg == 1)                 uprintf("// k2ext:        \t%f\r\n", sys_data.k2ext);
    if(writeFlg == 1) sd_fprintf(&fileObject, "// Def Sal (ppt):\t%f\r\n", sys_data.default_sal);
    if(printFlg == 1)                 uprintf("// Def Sal (ppt):\t%f\r\n", sys_data.default_sal);
    if(writeFlg == 1) sd_fprintf(&fileObject, "// Offset Ik:    \t%f\r\n", sys_data.offset_Ik);
    if(printFlg == 1)                 uprintf("// Offset Ik:    \t%f\r\n", sys_data.offset_Ik);
    if(writeFlg == 1) sd_fprintf(&fileObject, "// Offset Ib:    \t%f\r\n", sys_data.offset_Ib);
    if(printFlg == 1)                 uprintf("// Offset Ib:    \t%f\r\n", sys_data.offset_Ib);
    if(sys_data.app_cfg[APPCFG_TEMPC_SH_ALG] == 0)
    {
        if(writeFlg == 1) sd_fprintf(&fileObject, "// S-H c0        \t%f\r\n", sys_data.quadTherm_c0);
        if(printFlg == 1)                 uprintf("// s-h c0        \t%f\r\n", sys_data.quadTherm_c0);
        if(writeFlg == 1) sd_fprintf(&fileObject, "// S-H c1        \t%f\r\n", sys_data.quadTherm_c1);
        if(printFlg == 1)                 uprintf("// s-h c1        \t%f\r\n", sys_data.quadTherm_c1);
        if(writeFlg == 1) sd_fprintf(&fileObject, "// S-H c2        \t%f\r\n", sys_data.quadTherm_c2);
        if(printFlg == 1)                 uprintf("// s-h c2        \t%f\r\n", sys_data.quadTherm_c2);
        if(writeFlg == 1) sd_fprintf(&fileObject, "// S-H c3        \t%f\r\n", sys_data.quadTherm_c3);
        if(printFlg == 1)                 uprintf("// s-h c3        \t%f\r\n", sys_data.quadTherm_c3);
    }
    if(sys_data.app_cfg[APPCFG_TEMPC_SH_ALG] == 1)
    {
        if(writeFlg == 1) sd_fprintf(&fileObject, "// S-H A         \t%f\r\n", sys_data.shTherm_A);
        if(printFlg == 1)                 uprintf("// s-h A         \t%f\r\n", sys_data.shTherm_A);
        if(writeFlg == 1) sd_fprintf(&fileObject, "// S-H B         \t%f\r\n", sys_data.shTherm_B);
        if(printFlg == 1)                 uprintf("// s-h B         \t%f\r\n", sys_data.shTherm_B);
        if(writeFlg == 1) sd_fprintf(&fileObject, "// S-H C         \t%f\r\n", sys_data.shTherm_C);
        if(printFlg == 1)                 uprintf("// s-h C         \t%f\r\n", sys_data.shTherm_C);
    }
    if(writeFlg == 1)   sd_fprintf(&fileObject, "// Version Info: \t%s\r\n", VERSION);
    if(printFlg == 1)                   uprintf("// Version Info: \t%s\r\n", VERSION);


    // Store the tab delimited deployment header. (Excel treats quoted string as text)
    if(writeFlg == 1) sd_fprintf(&fileObject, "// File name:     \t%s\r\n", sys_data.fileName);
    if(printFlg == 1)                 uprintf("// File name:     \t%s\r\n", sys_data.fileName);
    if(writeFlg == 1) sd_fprintf(&fileObject, "// User initials: \t%s\r\n", sys_data.user);
    if(printFlg == 1)                 uprintf("// User initials: \t%s\r\n", sys_data.user);

    if(printFlg == 1)    wait_consoleTx();       // defd in uartstdio.c  TODO add timeout

    if(writeFlg == 1) sd_fprintf(&fileObject, "// Board SN:      \t%s\r\n", sys_data.board_SN);
    if(printFlg == 1)                 uprintf("// Board SN:      \t%s\r\n", sys_data.board_SN);
//#if BOARD_MPHOX == 1 || BOARD_MFET >= 1
    if(writeFlg == 1) sd_fprintf(&fileObject, "// MCAP SN:       \t%s\r\n", sys_data.mcap_SN);
    if(printFlg == 1)                 uprintf("// MCAP SN:       \t%s\r\n", sys_data.mcap_SN);
//#endif
    if(writeFlg == 1) sd_fprintf(&fileObject, "// DuraFET SN:    \t%s\r\n", sys_data.durafet_SN);
    if(printFlg == 1)                 uprintf("// DuraFET SN:    \t%s\r\n", sys_data.durafet_SN);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// Optode SN:     \t%s\r\n", sys_data.optode_SN);
    if(printFlg == 1)                 uprintf("// Optode SN:     \t%s\r\n", sys_data.optode_SN);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// CTD SN:        \t%s\r\n", sys_data.ctd_SN);
    if(printFlg == 1)                 uprintf("// CTD SN:        \t%s\r\n", sys_data.ctd_SN);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// Pump SN:       \t%s\r\n", sys_data.pump_SN);
    if(printFlg == 1)                 uprintf("// Pump SN:       \t%s\r\n", sys_data.pump_SN);
    if(writeFlg == 1) sd_fprintf(&fileObject, "// Package name:  \t%s\r\n", sys_data.package_name);
    if(printFlg == 1)                 uprintf("// Package name:  \t%s\r\n", sys_data.package_name);
    if(writeFlg == 1) sd_fprintf(&fileObject, "// Fab Note:      \t%s\r\n", sys_data.board_fab_note);
    if(printFlg == 1)                 uprintf("// Fab Note:      \t%s\r\n", sys_data.board_fab_note);
    if(writeFlg == 1) sd_fprintf(&fileObject, "// Deploy note:   \t%s\r\n", sys_data.deploy_note);
    if(printFlg == 1)                 uprintf("// Deploy note:   \t%s\r\n", sys_data.deploy_note);


    // HACK, problem with passing pointers and short on time to code (arrgg)
    if(writeFlg == 1)
    {
        sys_samp.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\r\n", StringFromFresult(fresult));
            //return 1;
            retVal = 1;
            writeFlg = 0;
        }
    }

    // BUG 28 Dec 2021, write_config_data fields is NOT writing to uSD  (problem with fopen, fclose)
    print_write_config_data_fields(printFlg, writeFlg, 1);  // new 27 Jul 2021  2 prints // pad


    if(writeFlg == 1)
    {

        // 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\r\n", StringFromFresult(fresult));
            //return 1;
            retVal = 1;
            writeFlg = 0;
        }

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

    }



    if(writeFlg == 1) sd_fprintf(&fileObject, "//--**************************************************\r\n");
    if(printFlg == 1)                 uprintf("//--**************************************************\r\n");

    if(writeFlg == 1) sd_fprintf(&fileObject, "\r\n\r\n");
    if(printFlg == 1)                 uprintf("\r\n\r\n");


    if(writeFlg == 1)
    {
        sys_samp.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\r\n", StringFromFresult(fresult));
            //return 1;
            retVal = 1;
            writeFlg = 0;
        }
    }

    if(printFlg == 1)    wait_consoleTx();       // defd in uartstdio.c  TODO add timeout

    //return 0;  // all went well, return 0 for OK
    return(retVal);

}


void print_metadata_header(const time_t currentTime)
{
    print_write_metadata_header(currentTime, 1, 0);

}



void print_sys_data_structure(void)
{
    uprintf("\r\n");
    uprintf("// ------ sys_data EEPROM structure, size = %u ---- \r\n", sizeof(struct systemData));
    uprintf("// sampling_period: %u\r\n", sys_data.sampling_period);
    uprintf("// chksum:          %u\r\n", sys_data.chksum);
    uprintf("// averaging_interval: %u\r\n", sys_data.averaging_interval);
    uprintf("// pump1_ontime: %u\r\n", sys_data.pump1_ontime);
    uprintf("// low_batt_volt: %.2f\r\n", sys_data.low_batt_volt);
    uprintf("\r\n");
    uprintf("// TCOffset: %.6f\r\n", sys_data.TCOffset);
    uprintf("// k0ext: %.6f\r\n", sys_data.k0ext);
    uprintf("// k0int: %.6f\r\n", sys_data.k0int);
    uprintf("// k2ext: %.6f\r\n", sys_data.k2ext);
    uprintf("// k2int: %.6f\r\n", sys_data.k2int);
    uprintf("// quadTherm_c0: %.11lf\r\n", sys_data.quadTherm_c0);
    uprintf("// quadTherm_c2: %.11lf\r\n", sys_data.quadTherm_c1);
    uprintf("// quadTherm_c3: %.11lf\r\n", sys_data.quadTherm_c2);
    uprintf("// quadTherm_c4: %.11lf\r\n", sys_data.quadTherm_c3);
    uprintf("// shTherm_A: %.11lf\r\n", sys_data.shTherm_A);                // steinhart-hart coefficient A
    uprintf("// shTherm_B: %.11lf\r\n", sys_data.shTherm_B);                // steinhart-hart coefficient C
    uprintf("// shTherm_C: %.11lf\r\n", sys_data.shTherm_C);                // steinhart-hart coefficient B
    uprintf("// default_sal: %.6f\r\n", sys_data.default_sal);
    uprintf("// sensor_sal: %.6f\r\n", sys_samp.sensor_sal);

    uprintf("//\r\n");
    wait_consoleTx();

    uprintf("// Vrsi_sps: %u\r\n", sys_data.Vrsi_sps);
    uprintf("// Vrsi_trials: %u\r\n", sys_data.Vrsi_trials);
    uprintf("// Vrse_sps: %u\r\n", sys_data.Vrse_sps);
    uprintf("// Vrse_trials: %u\r\n", sys_data.Vrse_trials);
    uprintf("// Vtherm_sps: %u\r\n", sys_data.Vtherm_sps);
    uprintf("// Vtherm_trials: %u\r\n", sys_data.Vtherm_trials);
    uprintf("// Ik_sps: %u\r\n", sys_data.Ik_sps);
    uprintf("// Ik_trials: %u\r\n", sys_data.Ik_trials);
    uprintf("// Vk_sps: %u\r\n", sys_data.Vk_sps);
    uprintf("// Vk_trials: %u\r\n", sys_data.Vk_trials);
    uprintf("// Ib_sps: %u\r\n", sys_data.Ib_sps);
    uprintf("// Ib_trials: %u\r\n", sys_data.Ib_trials);
    uprintf("// Vb_sps: %u\r\n", sys_data.Vb_sps);
    uprintf("// Vb_trials: %u\r\n", sys_data.Vb_trials);
    uprintf("// Vbias_sps: %u\r\n", sys_data.Vbias_sps);
    uprintf("// Vbias_trials: %u\r\n", sys_data.Vbias_trials);
    uprintf("// offset_Ik: %u\r\n", sys_data.offset_Ik);
    uprintf("// offset_Ib: %u\r\n", sys_data.offset_Ib);

    uprintf("//\r\n");
    wait_consoleTx();

    uprintf("// output: %u\r\n", sys_data.output);
    uprintf("// test_mode: %u\r\n", sys_data.test_mode);
    uprintf("// fast_mode: %u\r\n", sys_data.fast_mode);

    uprintf("// solenoid_on2hold_msec: %u msec\r\n", sys_data.solenoid_on2hold_msec);
    uprintf("// solenoid_hold_pwm: %u\r\n", sys_data.solenoid_hold_pwm);
    uprintf("// solenoid_holdtime: %u sec\r\n", sys_data.solenoid_holdtime);

    uprintf("// baud_rate: %u\r\n", sys_data.baud_rate);
    uprintf("//\r\n");
    wait_consoleTx();

    print_write_config_data_fields(1,0,1);
    wait_consoleTx();

    uprintf("//\r\n");
    uprintf("// app_cfg[APPCFG_SAMPLING_DIAG]: %u\r\n", sys_data.app_cfg[APPCFG_SAMPLING_DIAG]);
    uprintf("// app_cfg[APPCFG_TEMPC_SH_ALG]: %u\r\n", sys_data.app_cfg[APPCFG_TEMPC_SH_ALG]);
    uprintf("// app_cfg[APPCFG_MICROSD_ENABLE]: %u\r\n", sys_data.app_cfg[APPCFG_MICROSD_ENABLE]);
    uprintf("// app_cfg[APPCFG_MENU_LEVEL]: %u\r\n", sys_data.app_cfg[APPCFG_MENU_LEVEL]);
    uprintf("// app_cfg[APPCFG_DEPLOY_UARTECHO]: %u\r\n", sys_data.app_cfg[APPCFG_DEPLOY_UARTECHO]);
    uprintf("// app_cfg[APPCFG_EXEC_SWITCHERONI]: %u\r\n", sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI]);
    uprintf("//\r\n");
    wait_consoleTx();

    uprintf("// GMT: %u\r\n", sys_data.GMT);
    uprintf("// sample_aligned: %u\r\n", sys_data.sample_aligned);
    uprintf("// deploy_time: %u\r\n", sys_data.deploy_time);
    uprintf("// start_pump_time: ");       print_time_t_Time(sys_data.start_pump_time);

    uprintf("// pHOffset: %.6f\r\n", sys_data.pHOffset);
    uprintf("// pHSlope:  %.6f\r\n", sys_data.pHSlope);
    uprintf("// TCSlope: %.6f\r\n", sys_data.TCSlope);
    uprintf("// sensor_ctd_TC:  %.6f\r\n", sys_data.sensor_ctd_TC);
    uprintf("// sensor_optode_TC:  %.6f\r\n", sys_data.sensor_optode_TC);

    uint32_t indx;
    for(indx=0; indx<4; indx++)   uprintf("// spare[%u] : %.6f\r\n", indx, sys_data.spare[indx]);

    wait_consoleTx();

    uprintf("// fileName: %s\r\n", sys_data.fileName);
    uprintf("// user: %s\r\n", sys_data.user);
    uprintf("// board_SN: %s\r\n", sys_data.board_SN);
    uprintf("// mcap_SN: %s\r\n", sys_data.mcap_SN);
    uprintf("// durafet_SN: %s\r\n", sys_data.durafet_SN);
    uprintf("// package_name: %s\r\n", sys_data.package_name);
    uprintf("// optode_SN: %s\r\n", sys_data.optode_SN);
    uprintf("// ctd_SN: %s\r\n", sys_data.ctd_SN);
    uprintf("// pump_SN: %s\r\n", sys_data.pump_SN);
    uprintf("// deploy_note: %s\r\n", sys_data.deploy_note);
    uprintf("// board_fab_note: %s\r\n", sys_data.board_fab_note);
    uprintf("//\r\n");

    wait_consoleTx();
    //uprintf("// state: %u\r\n", sys_samp.state);
    //uprintf("// nextWakeUp: %u\r\n", sys_samp.nextWakeUp);
    //uprintf("// next_gdata_fptr: %u\r\n", sys_samp.next_gdata_fptr);
    //uprintf("// current_sample: %u\r\n", sys_samp.current_sample);
    //uprintf("// AD24_std: %.6f\r\n", sys_samp.AD24_std);


}



void ads1248_sampling_defaults(void)
{
    sys_data.Vtherm_trials = VTHERM_TRIALS;
    sys_data.Vtherm_sps = VTHERM_SPS;

    sys_data.Vrsi_trials = VRSI_TRIALS;
    sys_data.Vrsi_sps = VRSI_SPS;

    sys_data.Vrse_trials = VRSE_TRIALS;
    sys_data.Vrse_sps = VRSE_SPS;

    sys_data.Ik_trials = IK_TRIALS;
    sys_data.Ik_sps = IK_SPS;

    sys_data.Vk_trials = VK_TRIALS;
    sys_data.Vk_sps = VK_SPS;

    sys_data.Ib_trials = IB_TRIALS;
    sys_data.Ib_sps = IB_SPS;

    sys_data.Vb_trials = VB_TRIALS;
    sys_data.Vb_sps = VB_SPS;

    sys_data.Vbias_trials = VBIAS_TRIALS;
    sys_data.Vbias_sps = VBIAS_SPS;       // used for vbias bat
}



void config_sys_data_default_init(void)
{
    sys_data.deploy_time = ROM_HibernateRTCGet();

    sys_data.low_batt_volt = 9.2;
#if BOARD_MFET >= 1
    sys_data.low_batt_volt = 5.5;
#endif
#if BOARD_MPHOX >= 1
    sys_data.low_batt_volt = 10.0;
#endif
#if BOARD_NANOFET >= 1
    sys_data.low_batt_volt = 5.5;
#endif
    sys_data.sampling_period = 0;
    sys_data.chksum = 0;           // was sample average
    sys_data.averaging_interval = 60;
    sys_data.sample_aligned = false;
    sys_data.GMT = false;                       //456 GMT or Local time
    sys_data.sample_aligned = true;            //460 Sample aligned to hour
    sys_data.pump1_ontime = 0;
    sys_data.TCOffset = 0.0;
    sys_data.k0ext = -1.3;
    sys_data.k0int = -0.4;
    sys_data.k2ext = -0.001081;
    sys_data.k2int = -0.001455;


    // steinhart-hart coefficients for thermistor (why are the 4 coeff, thought there should only be 3)
    sys_data.quadTherm_c0 = 340.9819863;
    sys_data.quadTherm_c1 = -9.10257E-05;  // -0.0000910257
    sys_data.quadTherm_c2 = -95.08806667;
    sys_data.quadTherm_c3 = 0.965370274;

    sys_data.shTherm_A = 0.002108508173;
    sys_data.shTherm_B = 0.00007979204727;
    sys_data.shTherm_C = 0.0000006535076315;

    sys_data.default_sal = 35.0;
    sys_samp.sensor_sal = 0.0;

    ads1248_sampling_defaults();
#ifdef MOVEDTO_ROUTINE
    ads1248_sampling_defaults();
    sys_data.Vtherm_trials = VTHERM_TRIALS;
    sys_data.Vtherm_sps = VTHERM_SPS;

    sys_data.Vrsi_trials = VRSI_TRIALS;
    sys_data.Vrsi_sps = VRSI_SPS;

    sys_data.Vrse_trials = VRSE_TRIALS;
    sys_data.Vrse_sps = VRSE_SPS;

    sys_data.Ik_trials = IK_TRIALS;
    sys_data.Ik_sps = IK_SPS;

    sys_data.Vk_trials = VK_TRIALS;
    sys_data.Vk_sps = VK_SPS;

    sys_data.Ib_trials = IB_TRIALS;
    sys_data.Ib_sps = IB_SPS;

    sys_data.Vb_trials = VB_TRIALS;
    sys_data.Vb_sps = VB_SPS;

    sys_data.Vbias_trials = VBIAS_TRIALS;
    sys_data.Vbias_sps = VBIAS_SPS;       // used for vbias bat
#endif
    sys_data.offset_Ik = 0.000800;             // 800uV or so, tbd measure a QA step.
    sys_data.offset_Ib = 0.000800;

    sys_data.output = NORMAL;
    sys_data.test_mode = 0;
    sys_data.fast_mode = 1;
    sys_data.solenoid_on2hold_msec = 100;   // hit
    sys_data.solenoid_hold_pwm = 40;        // hold
    sys_data.solenoid_holdtime = 10;        // seconds






    //state;                      //430 IDLE, DEPLOYED, COMMAND,  NOT USER MODIFIABLE                        <<<<<------
    //uint32_t nextWakeUp;            //434 Next intended RTC match (wake-up time) NOT USER MODIFIABLE           <<<<<------
    //unsigned long next_gdata_fptr;  //438 The file position of the next gdata sample. NOT USER MODIFIABLE      <<<<<------
    //unsigned int current_sample;    //442 The current data record to be stored. NOT USER MODIFIABLE            <<<<<------
    //float AD24_std;                 //464 standard deviation for AD24                                          <<<<--------
    sys_samp.state = IDLE;
    //sys_data.nextWakeUp = current_time + 30;
    sys_samp.nextWakeUp = ROM_HibernateRTCGet()+sys_data.sampling_period;
    sys_samp.next_gdata_fptr = 0;
    sys_samp.AD24_std = 0.0;
    sys_samp.current_sample = 0;
    sys_samp.start_pump_cntdown = 0;

    sys_data.deploy_time = 0;
    sys_data.start_pump_time = 0;         // Wakeup on sampling interval, but check the 'start deployment time' before actual pumping/sampling 16 Feb 2022

    sys_data.pump_seq_type = TYPE_PUMP_SINGLE;             // 0) legacy single pump, 1) BEAMS v1 dual pump seq, 2) BEAMS v2
    //uint32_t pump_seq_state;          // defd in FRAM volatile data struct
    sys_data.sampleCnt_duty_on = 0;         // duty cycle for extending experiment.   3 days on, 5 days off.   Number of 'sample periods' on
    sys_data.sampleCnt_duty_off = 0;        // in sample periods.    Accept input in hours, translate to sample periods (keep implementation simple for now).
    //uint32_t sampling_interval;         // = 1 min  (see sampling_period above)
    sys_data.pump1_cycles = 1;                   // = 10 cycles
    sys_data.pump2_cycles = 0;                   // = 5 cycles
    sys_data.pump1_ontime = 0;
    sys_data.pump2_ontime = 0;

    sys_data.baud_rate = 115200L;
    int indx;
    for(indx=0; indx<MAX_NUMOF_CONFIG_FIELDS; indx++)
        sys_data.data_cfg[indx] = 0;


    sys_data.pHOffset = 0.0;
    sys_data.pHSlope = 1.0;
    sys_data.TCSlope = 1.0;
    sys_data.sensor_ctd_TC = 0.0;
    sys_data.sensor_optode_TC = 0.0;

    sys_data.spare[0] = 0.0;
    sys_data.spare[1] = 0.0;
    sys_data.spare[2] = 0.0;
    sys_data.spare[3] = 0.0;


    sys_data.diag = 0;                      // diagnostics, enables sample time measurement
    sys_data.debug_flag = 0;                // diagnostic printf (dbg_printf() enabled)
    sys_data.GMT = false;                       //456 GMT or Local time
    sys_data.sample_aligned = false;            //460 Sample aligned to hour

    sys_data.pHOffset = 0.0;
    sys_data.pHSlope = 1.0;
    sys_data.fast_mode = 1;

    strcpy(sys_data.fileName, "noname.txt");
    strcpy(sys_data.user, "abc");
    strcpy(sys_data.board_SN, " ");
    strcpy(sys_data.board_fab_note, " ");
    strcpy(sys_data.mcap_SN, " ");
    strcpy(sys_data.durafet_SN, " ");
    strcpy(sys_data.optode_SN, " ");
    strcpy(sys_data.ctd_SN, " ");
    strcpy(sys_data.pump_SN, " ");
    strcpy(sys_data.package_name, " ");   // instrument package name, ex. underway system, glider pH
    strcpy(sys_data.deploy_note, " ");

    sys_data.data_cfg[CFG_SAMPLE_NUM] = 1;          // A
    sys_data.data_cfg[CFG_TIMESTAMP] = 1;            // B

    sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 1;        // C
    sys_data.data_cfg[CFG_BIAS_BAT_POS] = 1;        // D
    sys_data.data_cfg[CFG_BIAS_BAT_NEG] = 1;        // E

    sys_data.data_cfg[CFG_BRD_TEMP] = 1;            // F
    sys_data.data_cfg[CFG_BRD_HUMIDITY] = 1;        // G

    sys_data.data_cfg[CFG_V_THERMISTOR] = 1;        // H
    sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 1;    //
    sys_data.data_cfg[CFG_CALC_TEMP] = 1;           // I

    sys_data.data_cfg[CFG_VRSI] = 1;               // J
    sys_data.data_cfg[CFG_VRSI_STD] = 1;           //
    sys_data.data_cfg[CFG_CALC_PH_VRSI] = 1;          // K

    sys_data.data_cfg[CFG_VRSE] = 1;               // L
    sys_data.data_cfg[CFG_VRSE_STD] = 1;           //
    sys_data.data_cfg[CFG_CALC_PH_VRSE] = 0;          // m


    sys_data.data_cfg[CFG_VRSI_BIASED] = 1;        // N
    sys_data.data_cfg[CFG_VRSI_BIASED_STD] = 0;    // o
    sys_data.data_cfg[CFG_VRSE_BIASED] = 0;        // p
    sys_data.data_cfg[CFG_VRSE_BIASED_STD] = 0;    // q

    sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 1;     // R
    sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 1; //
    sys_data.data_cfg[CFG_I_COUNTER] = 1;           // T
    sys_data.data_cfg[CFG_I_SUBSTRATE] = 1;         // U

    sys_data.data_cfg[CFG_OPTODE] = 0;              // v
    sys_data.data_cfg[CFG_CTD] = TYPE_CTD_NOTDEFD;                 // w

    sys_data.data_cfg[CFG_OCR] = 0;
    sys_data.data_cfg[CFG_SPARE2] = 0;
    sys_data.data_cfg[CFG_SPARE3] = 0;
    sys_data.data_cfg[CFG_SPARE4] = 0;
    sys_data.data_cfg[CFG_SPARE5] = 0;
    sys_data.data_cfg[CFG_SPARE6] = 0;

    sys_data.app_cfg[APPCFG_SAMPLING_DIAG] = 0;
    sys_data.app_cfg[APPCFG_TEMPC_SH_ALG] = 0;
    sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 1;        // enable micro sd card
    sys_data.app_cfg[APPCFG_MENU_LEVEL] = 0;
    sys_data.app_cfg[APPCFG_DEPLOY_UARTECHO] = 1;       // 1 Echo ON
    sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] = 0;
    sys_data.app_cfg[APPCFG_SPARE6] = 0;
    sys_data.app_cfg[APPCFG_SPARE7] = 0;
    sys_data.app_cfg[APPCFG_SPARE8] = 0;
    sys_data.app_cfg[APPCFG_SPARE9] = 0;
    sys_data.app_cfg[APPCFG_SPARE10] = 0;
    sys_data.app_cfg[APPCFG_SPARE11] = 0;
    sys_data.app_cfg[APPCFG_SPARE12] = 0;
    sys_data.app_cfg[APPCFG_SPARE13] = 0;
    sys_data.app_cfg[APPCFG_SPARE14] = 0;
    sys_data.app_cfg[APPCFG_SPARE15] = 0;


#if BOARD_NANOFET >= 1
    sys_data.data_cfg[CFG_SAMPLE_NUM] = 1;          // A
    sys_data.data_cfg[CFG_TIMESTAMP] = 1;            // B

    sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 0;        // c
    sys_data.data_cfg[CFG_BIAS_BAT_POS] = 1;        // D
    sys_data.data_cfg[CFG_BIAS_BAT_NEG] = 0;        // e

    sys_data.data_cfg[CFG_BRD_TEMP] = 1;            // F
    sys_data.data_cfg[CFG_BRD_HUMIDITY] = 1;        // G

    sys_data.data_cfg[CFG_V_THERMISTOR] = 1;        // H
    sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 1;    //
    sys_data.data_cfg[CFG_CALC_TEMP] = 1;           // I

    sys_data.data_cfg[CFG_VRSI] = 0;               // j
    sys_data.data_cfg[CFG_VRSI_STD] = 0;           //
    sys_data.data_cfg[CFG_CALC_PH_VRSI] = 0;          // K

    sys_data.data_cfg[CFG_VRSE] = 1;               // L
    sys_data.data_cfg[CFG_VRSE_STD] = 1;           //
    sys_data.data_cfg[CFG_CALC_PH_VRSE] = 0;          // m


    sys_data.data_cfg[CFG_VRSI_BIASED] = 0;        // n
    sys_data.data_cfg[CFG_VRSI_BIASED_STD] = 0;    // o
    sys_data.data_cfg[CFG_VRSE_BIASED] = 0;        // p
    sys_data.data_cfg[CFG_VRSE_BIASED_STD] = 0;    // q

    sys_data.data_cfg[CFG_V_COUNTER_ELECT] = 1;     // R
    sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] = 1; //
    sys_data.data_cfg[CFG_I_COUNTER] = 1;           // T
    sys_data.data_cfg[CFG_I_SUBSTRATE] = 1;         // U

    sys_data.data_cfg[CFG_OPTODE] = 0;              // v
    sys_data.data_cfg[CFG_CTD] = TYPE_CTD_NOTDEFD;                 // w

    sys_data.data_cfg[CFG_SPARE1] = 0;
    sys_data.data_cfg[CFG_SPARE2] = 0;
    sys_data.data_cfg[CFG_SPARE3] = 0;
    sys_data.data_cfg[CFG_SPARE4] = 0;
    sys_data.data_cfg[CFG_SPARE5] = 0;
    sys_data.data_cfg[CFG_SPARE6] = 0;

    sys_data.app_cfg[APPCFG_SAMPLING_DIAG] = 0;
    sys_data.app_cfg[APPCFG_TEMPC_SH_ALG] = 0;
    sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 0;        // disable micro sd card
    sys_data.app_cfg[APPCFG_MENU_LEVEL] = 0;
    sys_data.app_cfg[APPCFG_DEPLOY_UARTECHO] = 1;       // 1 Echo ON
    sys_data.app_cfg[APPCFG_SPARE5] = 0;
    sys_data.app_cfg[APPCFG_SPARE6] = 0;
    sys_data.app_cfg[APPCFG_SPARE7] = 0;
    sys_data.app_cfg[APPCFG_SPARE8] = 0;
    sys_data.app_cfg[APPCFG_SPARE9] = 0;
    sys_data.app_cfg[APPCFG_SPARE10] = 0;
    sys_data.app_cfg[APPCFG_SPARE11] = 0;
    sys_data.app_cfg[APPCFG_SPARE12] = 0;
    sys_data.app_cfg[APPCFG_SPARE13] = 0;
    sys_data.app_cfg[APPCFG_SPARE14] = 0;
    sys_data.app_cfg[APPCFG_SPARE15] = 0;
#endif

    config_qa_data_init();

}


void config_qa_data_init(void)
{

    sys_data.qa.microSD = 0;            // microSD
    sys_data.qa.time = 0;               // time of QA
    sys_data.qa.test_time = 0;          // time it took to run QA
    sys_data.qa.eeprom = 0;
    sys_data.qa.sys_data_init = 0;      // was the data initialized
    sys_data.qa.fram = 0;
    sys_data.qa.adc12onchip = 0;
    sys_data.qa.adc24 = 0;              // how many of the ADC fields are out of expected Jensenian range


    sys_data.qa.Vrsi = 0.0;
    sys_data.qa.Vrsi_std = 0.0;
    sys_data.qa.Vrsi_err = 0.0;
    sys_data.qa.Vrse = 0.0;
    sys_data.qa.Vrse_std = 0.0;
    sys_data.qa.Vrse_err = 0.0;
    sys_data.qa.Vtherm = 0.0;
    sys_data.qa.Vtherm_std = 0.0;
    sys_data.qa.Vtherm_err = 0.0;

    sys_data.qa.Ik = 0.0;
    sys_data.qa.Ik_std = 0.0;
    sys_data.qa.Ik_err = 0.0;

    sys_data.qa.Vk = 0.0;
    sys_data.qa.Vk_std = 0.0;
    sys_data.qa.Vk_err = 0.0;

    sys_data.qa.Ib = 0.0;
    sys_data.qa.Ib_std = 0.0;
    sys_data.qa.Ib_err = 0.0;

    sys_data.qa.Vb = 0.0;
    sys_data.qa.Vb_std = 0.0;
    sys_data.qa.Vb_err = 0.0;

    sys_data.qa.Vbias_pos = 0.0;
    sys_data.qa.Vbias_neg = 0.0;

    sys_data.qa.aux_pwr1 = 0;
    sys_data.qa.aux_pwr2 = 0;
    sys_data.qa.aux_pwr3 = 0;

    sys_data.qa.ctd = 0;
    sys_data.qa.optode = 0;
    sys_data.qa.comm_pwr = 0;

    strcpy(sys_data.qa.tester, "Count Zero");
    strcpy(sys_data.qa.firmware_version, "Version Not Defined");


}

uint32_t edit_uint(uint32_t *uint_data, uint32_t negLim, uint32_t posLim)
{
    uint32_t temp;
    char buff[24];

    temp = 0;
    if(getUserInput(buff, 20))
    {
        if(sscanf(buff, "%u", &temp) == 1)
        {
             *uint_data = temp;

        }
    }
    return(temp);
}


float edit_float(float *float_data, float negLim, float posLim)
{
    float temp;
    char buff[24];

    temp = 0.0;

    if(getUserInput(buff, 20))
    {
        if(sscanf(buff, "%f", &temp) == 1)
        {
             *float_data = temp;
             //return(temp);
        }
    }
    return(temp);
}

uint32_t edit_string(char *char_data, uint32_t max_chars)
{
    char buff[128];

    if( getUserInput(buff, max_chars) )
    {
        strcpy(char_data, buff);        // oops: strcpy(*char_data, buff);
        //uprintf("\r\nFile name now: %s\r\n", sys_data.fileName);
    }

    return(strlen(buff));
}


double edit_double(double *double_data, double negLim, double posLim)
{
    double temp;
    char buff[24];

    temp = 0.0;

    if(getUserInput(buff, 20))
    {
        if(sscanf(buff, "%lf", &temp) == 1)     // BUG fix %f to %lf
        {
             *double_data = temp;
             //return(temp);
        }
    }
    return(temp);
}


void edit_appcfg_fields(void)
{
    int response;

    uint32_t  old, new;

    //microsd_logging();
    old = sys_data.app_cfg[APPCFG_MICROSD_ENABLE];
    if(sys_data.app_cfg[APPCFG_MICROSD_ENABLE] == 1)
    {
        response = yesOrNoMenuChoice("\r\n\r\nEnable MicroSD logging? (Y/N) [Y]? ", YES);
        if(response == YES)
        {
            sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 1;
        }
        else
        {
            sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 0;
        }
        storeSysDataVariables();
    }
    else
    {
        response = yesOrNoMenuChoice("\r\n\r\nEnable MicroSD logging? (Y/N) [N]? ", NO);
        if(response == YES)
        {
            sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 1;
        }
        else
        {
            sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 0;
        }
        storeSysDataVariables();
    }

    if(sys_data.app_cfg[APPCFG_MICROSD_ENABLE] == 1)
        uprintf("MicroSD logging is Enabled\r\n\r\n");
    else
        uprintf("MicroSD card DISabled, no Logging\r\n\r\n");

    if((old == 0) && (sys_data.app_cfg[APPCFG_MICROSD_ENABLE] == 1))
    {
        // init the filesystem
        if( uSD_present() )
        {
            uprintf("\r\nMicroSD card is Initialized....\r\n");
            Init_SDCard();
            microSD_flg = 1;
        }
        else
        {
            uprintf("\r\nError: MicroSD card is not detected\r\n");
            microSD_flg = 0;
        }
    }

    //---------------------------------------------------------------


    // console echo enable/disable
    if(sys_data.app_cfg[APPCFG_DEPLOY_UARTECHO] == 1)
    {
        response = yesOrNoMenuChoice("\r\n\r\nEnable character echo for deployment commands? (Y/N) [Y]? ", YES);
        if(response == YES)
        {
            sys_data.app_cfg[APPCFG_DEPLOY_UARTECHO] = 1;
        }
        else
        {
            sys_data.app_cfg[APPCFG_DEPLOY_UARTECHO] = 0;
        }
        storeSysDataVariables();
    }
    else
    {
        response = yesOrNoMenuChoice("\r\n\r\nEnable character echo for deployment commands? (Y/N) [N]? ", NO);
        if(response == YES)
        {
            sys_data.app_cfg[APPCFG_DEPLOY_UARTECHO] = 1;
        }
        else
        {
            sys_data.app_cfg[APPCFG_DEPLOY_UARTECHO] = 0;
        }
        storeSysDataVariables();
    }

    if(sys_data.app_cfg[APPCFG_DEPLOY_UARTECHO] == 1)
        uprintf("Deployment command character echo is Enabled (typical case)\r\n\r\n");
    else
        uprintf("Deployment command character echo Disabled for m2m\r\n\r\n");


}


void copy_edit_sys_data_structure(void)
{
    char buff[68];
    uint32_t temp;
    int response;



    uprintf("// ------ sys_data structure, size = %u ---- \r\n", sizeof(struct systemData));

    while(1)
    {
        uprintf("\r\nFirst 5 sys_data fields:\r\n\r\n");

        uprintf("sampling_period [%u] sec: ", sys_data.sampling_period);
        edit_uint(&sys_data.sampling_period, 0, 6000);

        uprintf("sampling_average [%u] sec: ", sys_data.chksum);
        //edit_uint(&sys_data.sampling_period, 0, 300);

        uprintf("averaging_interval: [%u] sec: ", sys_data.averaging_interval);
        edit_uint(&sys_data.averaging_interval, 0, 360);

        uprintf("pump1_ontime [%u] sec: ", sys_data.pump1_ontime);
        edit_uint(&sys_data.pump1_ontime, 0, 3600);

        uprintf("low_batt_volt [%.1f]: ", sys_data.low_batt_volt);
        edit_float(&sys_data.k0ext, 5.5, 18.0);

        //uprintf("\r\n");
        response = yesOrNoMenuChoice("\r\n\r\nRe-visit? (Y/N) [N]? ", NO);
        if(response == NO)
            {
            uprintf("\r\n");
            break;
            }
    }
    //----
    while(1)
    {
        uprintf("\r\nSecond batch of 13 sys_data fields:\r\n\r\n");

        uprintf("TCOffset [%.6f]: ", sys_data.TCOffset);
        edit_float(&sys_data.TCOffset, -10.0, 10.0);

        uprintf("k0ext [%.6f]: ", sys_data.k0ext);
        edit_float(&sys_data.k0ext, -10.0, 10.0);

        uprintf("k0int [%.6f]: ", sys_data.k0int);
        edit_float(&sys_data.k0int, -10.0, 10.0);

        uprintf("k2ext [%.6f]: ", sys_data.k2ext);
        edit_float(&sys_data.k2ext, -10.0, 10.0);

        uprintf("k2int [%.6f]: ", sys_data.k2int);
        edit_float(&sys_data.k2int, -10.0, 10.0);

        uprintf("quadTherm_c0 [%.11f]: ", sys_data.quadTherm_c0);
        edit_double(&sys_data.quadTherm_c0, -10.0, 10.0);

        uprintf("quadTherm_c1 [%.11f]: ", sys_data.quadTherm_c1);
        edit_double(&sys_data.quadTherm_c1, -10.0, 10.0);

        uprintf("quadTherm_c2 [%.11f]: ", sys_data.quadTherm_c2);
        edit_double(&sys_data.quadTherm_c2, -10.0, 10.0);

        uprintf("quadTherm_c3 [%.11f]: ", sys_data.quadTherm_c3);
        edit_double(&sys_data.quadTherm_c3, -10.0, 10.0);

        uprintf("shTherm_A [%.11f]: ", sys_data.shTherm_A);
        edit_double(&sys_data.shTherm_A, -10.0, 10.0);

        uprintf("shTherm_B [%.11f]: ", sys_data.shTherm_B);
        edit_double(&sys_data.shTherm_B, -10.0, 10.0);

        uprintf("default_sal [%.3f]: ", sys_data.default_sal);
        edit_float(&sys_data.default_sal, 0, 50.0);

        uprintf("sensor_sal [%.3f]: ", sys_samp.sensor_sal);
        edit_float(&sys_samp.sensor_sal, 0, 50.0);

        response = yesOrNoMenuChoice("\r\n\r\nRe-visit? (Y/N) [N]? ", NO);
        if(response == NO)
            break;
    }
    //----
    while(1)
    {
        uprintf("\r\nThird batch of 20 sys_data fields:\r\n\r\n");

        uprintf("Vrsi_sps [%u]: ", sys_data.Vrsi_sps);
        edit_uint(&sys_data.Vrsi_sps, 0, 80);

        uprintf("Vrsi_trials [%u]: ", sys_data.Vrsi_trials);
        edit_uint(&sys_data.Vrsi_trials, 0, 80);

        uprintf("Vrse_sps [%u]: ", sys_data.Vrse_sps);
        edit_uint(&sys_data.Vrse_sps, 0, 80);

        uprintf("Vrse_trials [%u]: ", sys_data.Vrse_trials);
        edit_uint(&sys_data.Vrse_trials, 0, 80);

        uprintf("Vtherm_sps [%u]: ", sys_data.Vtherm_sps);
        edit_uint(&sys_data.Vtherm_sps, 0, 80);

        uprintf("Vtherm_trials [%u]: ", sys_data.Vtherm_trials);
        edit_uint(&sys_data.Vtherm_trials, 0, 80);

        uprintf("Vtherm_trials [%u]: ", sys_data.Vtherm_trials);
        edit_uint(&sys_data.Vtherm_trials, 0, 80);

        uprintf("Ik_sps [%u]: ", sys_data.Ik_sps);
        edit_uint(&sys_data.Ik_sps, 0, 80);

        uprintf("Ik_trials [%u]: ", sys_data.Ik_trials);
        edit_uint(&sys_data.Ik_trials, 0, 80);

        uprintf("Vk_sps [%u]: ", sys_data.Vk_sps);
        edit_uint(&sys_data.Vk_sps, 0, 80);

        uprintf("Vk_trials [%u]: ", sys_data.Vk_trials);
        edit_uint(&sys_data.Vk_trials, 0, 80);

        uprintf("Ib_sps [%u]: ", sys_data.Ib_sps);
        edit_uint(&sys_data.Ib_sps, 0, 80);

        uprintf("Ib_trials [%u]: ", sys_data.Ib_trials);
        edit_uint(&sys_data.Ib_trials, 0, 80);

        uprintf("Vb_sps [%u]: ", sys_data.Vb_sps);
        edit_uint(&sys_data.Vb_sps, 0, 80);

        uprintf("Vb_trials [%u]: ", sys_data.Vb_trials);
        edit_uint(&sys_data.Vb_trials, 0, 80);

        uprintf("Vbias_sps [%u]: ", sys_data.Vbias_sps);
        edit_uint(&sys_data.Vbias_sps, 0, 80);

        uprintf("Vbias_trials [%u]: ", sys_data.Vbias_trials);
        edit_uint(&sys_data.Vbias_trials, 0, 80);

        uprintf("offset_Ik [%u]: ", sys_data.offset_Ik);
        edit_uint(&sys_data.offset_Ik, 0, 80);

        uprintf("offset_Ib [%u]: ", sys_data.offset_Ib);
        edit_uint(&sys_data.offset_Ib, 0, 80);

        response = yesOrNoMenuChoice("\r\n\r\nRe-visit? (Y/N) [N]? ", NO);
        if(response == NO)
            break;
    }
    //----
    while(1)
    {
        uprintf("\r\nFourth batch of 7 sys_data fields:\r\n\r\n");

        uprintf("output [%u]: ", sys_data.output);
        edit_uint(&sys_data.output, 0, 5);

        uprintf("test_mode [%u]: ", sys_data.test_mode);
        edit_uint(&sys_data.test_mode, 0, 80);

        uprintf("fast_mode [%u]: ", sys_data.fast_mode);
        edit_uint(&sys_data.fast_mode, 0, 80);

        uprintf("solenoid_on2hold_msec [%u]: ", sys_data.solenoid_on2hold_msec);
        edit_uint(&sys_data.solenoid_on2hold_msec, 0, 80);

        uprintf("solenoid_hold_pwm [%u]: ", sys_data.solenoid_hold_pwm);
        edit_uint(&sys_data.solenoid_hold_pwm, 0, 80);

        uprintf("solenoid_holdtime [%u]: ", sys_data.solenoid_holdtime);
        edit_uint(&sys_data.solenoid_holdtime, 0, 80);

        uprintf("baud_rate [%u]: ", sys_data.baud_rate);
        edit_uint(&sys_data.baud_rate, 0, 500000);

        response = yesOrNoMenuChoice("\r\n\r\nRe-visit? (Y/N) [N]? ", NO);
        if(response == NO)
            break;
    }
    //----

    while(1)
    {
        uprintf("\r\nFifth batch of 32 sys_data fields:\r\n\r\n");

        // data cfg  MAX_NUMOF_CONFIG_FIELDS
        //print_write_config_data_fields(1,0,0);
        uprintf("sys_data.data_cfg[CFG_SAMPLE_NUM] [%u]: ", sys_data.data_cfg[CFG_SAMPLE_NUM]);
        edit_uint(&sys_data.data_cfg[CFG_SAMPLE_NUM], 0, 5);
        uprintf("sys_data.data_cfg[CFG_TIMESTAMP] [%u]: ", sys_data.data_cfg[CFG_TIMESTAMP]);
        edit_uint(&sys_data.data_cfg[CFG_TIMESTAMP], 0, 5);
        uprintf("sys_data.data_cfg[CFG_V_THERMISTOR] [%u]: ", sys_data.data_cfg[CFG_V_THERMISTOR]);
        edit_uint(&sys_data.data_cfg[CFG_V_THERMISTOR], 0, 5);
        sys_data.data_cfg[CFG_V_THERMISTOR_STD] = sys_data.data_cfg[CFG_V_THERMISTOR];
        uprintf("sys_data.data_cfg[CFG_V_THERMISTOR_STD] [%u]: ", sys_data.data_cfg[CFG_V_THERMISTOR_STD]);
        edit_uint(&sys_data.data_cfg[CFG_V_THERMISTOR_STD], 0, 5);
        uprintf("sys_data.data_cfg[CFG_CALC_TEMP] [%u]: ", sys_data.data_cfg[CFG_CALC_TEMP]);
        edit_uint(&sys_data.data_cfg[CFG_CALC_TEMP], 0, 5);
        uprintf("sys_data.data_cfg[CFG_VRSI] [%u]: ", sys_data.data_cfg[CFG_VRSI]);
        edit_uint(&sys_data.data_cfg[CFG_VRSI], 0, 5);
        uprintf("sys_data.data_cfg[CFG_VRSI_STD] [%u]: ", sys_data.data_cfg[CFG_VRSI_STD]);
        edit_uint(&sys_data.data_cfg[CFG_VRSI_STD], 0, 5);
        uprintf("sys_data.data_cfg[CFG_CALC_PH_VRSI] [%u]: ", sys_data.data_cfg[CFG_CALC_PH_VRSI]);
        edit_uint(&sys_data.data_cfg[CFG_CALC_PH_VRSI], 0, 5);
        uprintf("sys_data.data_cfg[CFG_VRSE] [%u]: ", sys_data.data_cfg[CFG_VRSE]);
        edit_uint(&sys_data.data_cfg[CFG_VRSE], 0, 5);
        uprintf("sys_data.data_cfg[CFG_VRSE_STD] [%u]: ", sys_data.data_cfg[CFG_VRSE_STD]);
        edit_uint(&sys_data.data_cfg[CFG_VRSE_STD], 0, 5);
        uprintf("sys_data.data_cfg[CFG_CALC_PH_VRSE] [%u]: ", sys_data.data_cfg[CFG_CALC_PH_VRSE]);
        edit_uint(&sys_data.data_cfg[CFG_CALC_PH_VRSE], 0, 5);
        uprintf("sys_data.data_cfg[CFG_VRSI_BIASED] [%u]: ", sys_data.data_cfg[CFG_VRSI_BIASED]);
        edit_uint(&sys_data.data_cfg[CFG_VRSI_BIASED], 0, 5);
        uprintf("sys_data.data_cfg[CFG_VRSI_BIASED_STD] [%u]: ", sys_data.data_cfg[CFG_VRSI_BIASED_STD]);
        edit_uint(&sys_data.data_cfg[CFG_VRSI_BIASED_STD], 0, 5);
        uprintf("sys_data.data_cfg[CFG_VRSE_BIASED] [%u]: ", sys_data.data_cfg[CFG_VRSE_BIASED]);
        edit_uint(&sys_data.data_cfg[CFG_VRSE_BIASED], 0, 5);
        uprintf("sys_data.data_cfg[CFG_VRSE_BIASED_STD] [%u]: ", sys_data.data_cfg[CFG_VRSE_BIASED_STD]);
        edit_uint(&sys_data.data_cfg[CFG_VRSE_BIASED_STD], 0, 5);
        uprintf("sys_data.data_cfg[CFG_V_COUNTER_ELECT] [%u]: ", sys_data.data_cfg[CFG_V_COUNTER_ELECT]);
        edit_uint(&sys_data.data_cfg[CFG_V_COUNTER_ELECT], 0, 5);
        uprintf("sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] [%u]: ", sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD]);
        edit_uint(&sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD], 0, 5);
        uprintf("sys_data.data_cfg[CFG_I_COUNTER] [%u]: ", sys_data.data_cfg[CFG_I_COUNTER]);
        edit_uint(&sys_data.data_cfg[CFG_I_COUNTER], 0, 5);
        uprintf("sys_data.data_cfg[CFG_I_SUBSTRATE] [%u]: ", sys_data.data_cfg[CFG_I_SUBSTRATE]);
        edit_uint(&sys_data.data_cfg[CFG_I_SUBSTRATE], 0, 5);
        uprintf("sys_data.data_cfg[CFG_VIN_BAT_VOLT] [%u]: ", sys_data.data_cfg[CFG_VIN_BAT_VOLT]);
        edit_uint(&sys_data.data_cfg[CFG_VIN_BAT_VOLT], 0, 5);
        uprintf("sys_data.data_cfg[CFG_BIAS_BAT_POS] [%u]: ", sys_data.data_cfg[CFG_BIAS_BAT_POS]);
        edit_uint(&sys_data.data_cfg[CFG_BIAS_BAT_POS], 0, 5);
        uprintf("sys_data.data_cfg[CFG_BIAS_BAT_NEG] [%u]: ", sys_data.data_cfg[CFG_BIAS_BAT_NEG]);
        edit_uint(&sys_data.data_cfg[CFG_BIAS_BAT_NEG], 0, 5);
        uprintf("sys_data.data_cfg[CFG_BRD_TEMP] [%u]: ", sys_data.data_cfg[CFG_BRD_TEMP]);
        edit_uint(&sys_data.data_cfg[CFG_BRD_TEMP], 0, 5);
        uprintf("sys_data.data_cfg[CFG_BRD_HUMIDITY] [%u]: ", sys_data.data_cfg[CFG_BRD_HUMIDITY]);
        edit_uint(&sys_data.data_cfg[CFG_BRD_HUMIDITY], 0, 5);
        uprintf("sys_data.data_cfg[CFG_OPTODE] [%u]: ", sys_data.data_cfg[CFG_OPTODE]);
        edit_uint(&sys_data.data_cfg[CFG_OPTODE], 0, 5);
        uprintf("sys_data.data_cfg[CFG_CTD] [%u]: ", sys_data.data_cfg[CFG_CTD]);
        edit_uint(&sys_data.data_cfg[CFG_CTD], 0, 5);

        uprintf("sys_data.data_cfg[CFG_OCR] [%u]: ", sys_data.data_cfg[CFG_OCR]);    // was uprintf("sys_data.data_cfg[CFG_SPARE1] [%u]: ", sys_data.data_cfg[CFG_SPARE1]);
        edit_uint(&sys_data.data_cfg[CFG_OCR], 0, 5);
        uprintf("sys_data.data_cfg[CFG_SPARE2] [%u]: ", sys_data.data_cfg[CFG_SPARE2]);
        edit_uint(&sys_data.data_cfg[CFG_SPARE2], 0, 5);
        uprintf("sys_data.data_cfg[CFG_SPARE3] [%u]: ", sys_data.data_cfg[CFG_SPARE3]);
        edit_uint(&sys_data.data_cfg[CFG_SPARE3], 0, 5);
        uprintf("sys_data.data_cfg[CFG_SPARE4] [%u]: ", sys_data.data_cfg[CFG_SPARE4]);
        edit_uint(&sys_data.data_cfg[CFG_SPARE4], 0, 5);
        uprintf("sys_data.data_cfg[CFG_SPARE5] [%u]: ", sys_data.data_cfg[CFG_SPARE5]);
        edit_uint(&sys_data.data_cfg[CFG_SPARE5], 0, 5);
        uprintf("sys_data.data_cfg[CFG_SPARE6] [%u]: ", sys_data.data_cfg[CFG_SPARE6]);
        edit_uint(&sys_data.data_cfg[CFG_SPARE6], 0, 5);
        //uprintf("sys_data.data_cfg[] [%u]: ", sys_data.data_cfg[]);
        //edit_uint(&sys_data.data_cfg[], 0, 5);

        response = yesOrNoMenuChoice("\r\n\r\nRe-visit? (Y/N) [N]? ", NO);
        if(response == NO)
            break;
    }
    //----
    while(1)
    {
        uprintf("\r\nSixth batch of 8 sys_data fields:\r\n\r\n");

        // app cfg   MAX_NUMOF_APP_CONFIG_FIELDS
        uprintf("app_cfg[APPCFG_SAMPLING_DIAG] [%u]: ", sys_data.app_cfg[APPCFG_SAMPLING_DIAG]);
        edit_uint(&sys_data.app_cfg[APPCFG_SAMPLING_DIAG], 0, 500000);

        uprintf("app_cfg[APPCFG_TEMPC_SH_ALG] [%u]: ", sys_data.app_cfg[APPCFG_TEMPC_SH_ALG]);
        edit_uint(&sys_data.app_cfg[APPCFG_TEMPC_SH_ALG], 0, 500);

        uprintf("app_cfg[APPCFG_MICROSD_ENABLE] [%u]: ", sys_data.app_cfg[APPCFG_MICROSD_ENABLE]);
        edit_uint(&sys_data.app_cfg[APPCFG_MICROSD_ENABLE], 0, 5);
        //microSD_flg = sys_data.app_cfg[APPCFG_MICROSD_ENABLE];      // deprecated 6 Aug 2021

        uprintf("app_cfg[APPCFG_MENU_LEVEL] [%u]: ", sys_data.app_cfg[APPCFG_MENU_LEVEL]);
        edit_uint(&sys_data.app_cfg[APPCFG_MENU_LEVEL], 0, 500);

        uprintf("app_cfg[APPCFG_DEPLOY_UARTECHO] [%u]: ", sys_data.app_cfg[APPCFG_DEPLOY_UARTECHO]);
        edit_uint(&sys_data.app_cfg[APPCFG_DEPLOY_UARTECHO], 0, 500);

        uprintf("app_cfg[APPCFG_EXEC_SWITCHERONI] [%u]: ", sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI]);
        edit_uint(&sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI], 0, 500);

        // No edit for spare appcfg
        sys_data.app_cfg[APPCFG_SPARE6] = 0;
        sys_data.app_cfg[APPCFG_SPARE7] = 0;
        sys_data.app_cfg[APPCFG_SPARE8] = 0;
        sys_data.app_cfg[APPCFG_SPARE9] = 0;
        sys_data.app_cfg[APPCFG_SPARE10] = 0;
        sys_data.app_cfg[APPCFG_SPARE11] = 0;
        sys_data.app_cfg[APPCFG_SPARE12] = 0;
        sys_data.app_cfg[APPCFG_SPARE13] = 0;
        sys_data.app_cfg[APPCFG_SPARE14] = 0;
        sys_data.app_cfg[APPCFG_SPARE15] = 0;


        //uprintf("app_cfg[APPCFG_SPARE7] [%u]: ", sys_data.app_cfg[APPCFG_SPARE7]);
        //edit_uint(&sys_data.app_cfg[APPCFG_SPARE7], 0, 500);

        response = yesOrNoMenuChoice("\r\n\r\nRe-visit? (Y/N) [N]? ", NO);
        if(response == NO)
            break;
    }
    //----

    while(1)
    {
        uprintf("\r\nSeventh batch of 14 sys_data fields:\r\n\r\n");

        uprintf("GMT [%u]: ", sys_data.GMT);
        edit_uint(&sys_data.GMT, 0, 80);

        uprintf("sample_aligned [%u]: ", sys_data.sample_aligned);
        edit_uint(&sys_data.sample_aligned, 0, 80);

        sys_data.deploy_time = 0;
        uprintf("deploy_time [%u]: ", sys_data.deploy_time);
        edit_uint(&sys_data.deploy_time, 0, 80);

        sys_data.start_pump_time = ROM_HibernateRTCGet();
        uprintf("start_pump_time [%u]: ", sys_data.start_pump_time);
        edit_uint(&sys_data.start_pump_time, 0, 80);

        sys_samp.start_pump_cntdown = sys_data.start_pump_time - ROM_HibernateRTCGet();
        uprintf("start_pump_cntdown [%u]: ", sys_samp.start_pump_cntdown);
        edit_uint(&sys_samp.start_pump_cntdown, 0, 80);

        uprintf("diag [%u]: ", sys_data.diag);
        edit_uint(&sys_data.diag, 0, 80);

        uprintf("debug_flag [%u]: ", sys_data.debug_flag);
        edit_uint(&sys_data.debug_flag, 0, 80);
        dbg_flag = sys_data.debug_flag;

        uprintf("pHOffset [%.6f]: ", sys_data.pHOffset);
        edit_float(&sys_data.pHOffset, -1.0, 1.0);

        uprintf("pHSlope [%.6f]: ", sys_data.pHSlope);
        edit_float(&sys_data.pHSlope, -1.0, 1.0);

        uprintf("TCSlope [%.6f]: ", sys_data.TCSlope);
        edit_float(&sys_data.TCSlope, -1.0, 1.0);

        uprintf("sensor_ctd_TC [%.6f]: ", sys_data.sensor_ctd_TC);
        edit_float(&sys_data.sensor_ctd_TC, -1.0, 1.0);

        uprintf("sensor_optode_TC [%.6f]: ", sys_data.sensor_optode_TC);
        edit_float(&sys_data.sensor_optode_TC, -1.0, 1.0);

        uprintf("spare[0] [%.6f]: ", sys_data.spare[0]);
        edit_float(&sys_data.spare[0], -1.0, 1.0);

        uprintf("spare[1] [%.6f]: ", sys_data.spare[1]);
        edit_float(&sys_data.spare[1], -1.0, 1.0);

        uprintf("spare[2] [%.6f]: ", sys_data.spare[2]);
        edit_float(&sys_data.spare[2], -1.0, 1.0);

        uprintf("spare[3] [%.6f]: ", sys_data.spare[3]);
        edit_float(&sys_data.spare[3], -1.0, 1.0);


        response = yesOrNoMenuChoice("\r\n\r\nRe-visit? (Y/N) [N]? ", NO);
        if(response == NO)
            break;
    }
    //----

    // pump sequencer variables
    while(1)
    {
        uprintf("\r\nEighth batch of 7 sys_data fields:\r\n\r\n");

        //uint32_t pump_seq_type;             // 0) legacy single pump, 1) BEAMS v1 dual pump seq, 2) BEAMS v2

        uprintf("pump_seq_type [%u]: ", sys_data.pump_seq_type);
        edit_uint(&sys_data.pump_seq_type, 0, 80);

        //uint32_t sampleCnt_duty_on;         // duty cycle for extending experiment.   3 days on, 5 days off.   Number of 'sample periods' on
        uprintf("sampleCnt_duty_on [%u]: ", sys_data.sampleCnt_duty_on);
        edit_uint(&sys_data.sampleCnt_duty_on, 0, 80);

        //uint32_t sampleCnt_duty_off;        // in sample periods.    Accept input in hours, translate to sample periods (keep implementation simple for now).
        uprintf("sampleCnt_duty_off [%u]: ", sys_data.sampleCnt_duty_off);
        edit_uint(&sys_data.sampleCnt_duty_off, 0, 80);

        //uint32_t pump1_cycles;                   // = 10 cycles
        uprintf("pump1_cycles [%u]: ", sys_data.pump1_cycles);
        edit_uint(&sys_data.pump1_cycles, 0, 80);

        //uint32_t pump2_cycles;                   // = 5 cycles
        uprintf("pump2_cycles [%u]: ", sys_data.pump2_cycles);
        edit_uint(&sys_data.pump2_cycles, 0, 80);

        //uint32_t pump1_ontime;          //20 Active pump time;                 // = 30 cycles
        uprintf("pump1_ontime [%u]: ", sys_data.pump1_ontime);
        edit_uint(&sys_data.pump1_ontime, 0, 80);

        //uint32_t pump2_ontime;                 // = 10 cycles
        uprintf("pump2_ontime [%u]: ", sys_data.pump2_ontime);
        edit_uint(&sys_data.pump2_ontime, 0, 80);

        response = yesOrNoMenuChoice("\r\n\r\nRe-visit? (Y/N) [N]? ", NO);
        if(response == NO)
            break;

    }




    while(1)
    {
        uprintf("\r\nNineth batch of 11 sys_data fields:\r\n\r\n");

        uprintf("Filename [%s]: ", sys_data.fileName);
        edit_string(&sys_data.fileName, MAX_FILENAME);
        //uprintf("  %s\r\n\r\n", sys_data.fileName);

        uprintf("User Initials [%s]: ", sys_data.user);
        edit_string(&sys_data.user, MAX_USER_INITIALS);

        uprintf("board_SN [%s]: ", sys_data.board_SN);
        edit_string(&sys_data.board_SN, MAX_BOARD_SN);

        uprintf("mcap_SN [%s]: ", sys_data.mcap_SN);
        edit_string(&sys_data.mcap_SN, MAX_MCAP_SN);

        uprintf("durafet_SN [%s]: ", sys_data.durafet_SN);
        edit_string(&sys_data.durafet_SN, MAX_DURAFET_SN);

        uprintf("package_name [%s]: ", sys_data.package_name);
        edit_string(&sys_data.package_name, MAX_PACKAGE_NAME);

        uprintf("optode_SN [%s]: ", sys_data.optode_SN);
        edit_string(&sys_data.optode_SN, MAX_OPTODE_SN);

        uprintf("ctd_SN [%s]: ", sys_data.ctd_SN);
        edit_string(&sys_data.ctd_SN, MAX_CTD_SN);

        uprintf("pump_SN [%s]: ", sys_data.pump_SN);
        edit_string(&sys_data.pump_SN, MAX_PUMP_SN);

        uprintf("board_fab_note [%s]: ", sys_data.board_fab_note);
        edit_string(&sys_data.board_fab_note, MAX_BOARD_FABNOTE);

        uprintf("deploy_note [%s]: ", sys_data.deploy_note);
        edit_string(&sys_data.deploy_note, MAX_DEPLOY_NOTE);

        uprintf("\r\nOld firmware version: %s\r\n", sys_data.qa.firmware_version);
        uprintf("New firmware version: %s\r\n", VERSION);
        strcpy(sys_data.qa.firmware_version, VERSION);

        uprintf("\r\nIf the old firmware version is corrupt or shifted, please re-run QA routine\r\n\r\n");

        response = yesOrNoMenuChoice("\r\n\r\nRe-visit? (Y/N) [N]? ", NO);
        if(response == NO)
            break;
    }

    uprintf("\r\nEEPROM sys_data copy/edit is complete\r\n\r\n");

    //uprintf(" [%s]: ", sys_data.);
    //edit_string(&sys_data., MAX);

    //uprintf(" [%.6f]: ", sys_data.);
    //edit_float(&sys_data., -1.0, 1.0);

    //uprintf(" [%u]: ", sys_data.);
    //edit_uint(&sys_data., 0, 80);
    //print_sys_data_structure();

    storeSysDataVariables();

}
