/*
 * 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 "main.h"
#include "system.h"
#include "config.h"

#include "user_io.h"
#include "ads1248_iso.h"
#include "ads1248_noniso.h"
#include "i2c_fram.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
#include "test.h"
#include "ymodem.h"

#include "apf.h"
#include "apf_init.h"
#include "apf_util.h"
#include "serial_cmd_fxn.h"
#include "init_defaults.h"

extern FIL FileObject;      // for import and read cal file on MFET

extern int dbg_flag;
extern struct ctdDriver ctd;

#if USE_CONFIGURATION_MENU >= 1
#define USE_ADVANCED_MENU 1
#endif

#if USE_ADVANCED_MENU >= 1

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)
    {
        prn_nl(); uprintf("Enter 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;
                    prn_nl(); uprintf("pH Vint data rate now %d sps", sys_data.Vrsi_sps); prn_nl(); prn_nl();
                    break;
                }
                else
				{					
					prn_nl(); uprintf("Enter 5, 10, 20, 40, 80, 160, 320, 640, 1000, or 2000");
				}
                continue;
            }
            else break;
        }
        else break;
    }

    break;


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


#endif



    while(1)
    {
        prn_nl();
        uprintf("Third batch of 20 sys_data fields:"); prn_nl(); prn_nl();

        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;

    }

}

void advanced_setup_menu(void)
{
    char input;
    int response;
    time_t current_time;


    while(1)
    {
        uprintf("A -- App Config Fields");  prn_nl();
        uprintf("D -- assign Default values to EEPROM sys_data and FRAM sys_samp structures");  prn_nl();
        uprintf("E -- Edit/Copy EEPROM sys_data structure");  prn_nl();
        uprintf("S -- Print EEPROM Sys_data structure");  prn_nl();              //
        uprintf("T -- Print FRAM sys_samp sampling and pump sequence data structure");  prn_nl();
        uprintf("I -- Init FRAM sys_samp data structure");  prn_nl();
        uprintf("Z -- ADC 24bit Sampling Parameters");  prn_nl();
        // reset_defaults - sys_data and sys_samp

        uprintf("M -- MetaData");  prn_nl();
        uprintf("R -- print QA Report");  prn_nl();
        uprintf("Q -- QA and setup after board manufacture");  prn_nl();
        // T print sys_data
        uprintf("V -- debug print flag (v to clear, V to set)");  prn_nl();
        uprintf("9 -- Exit to Main Menu");  prn_nl();
        prn_nl();
        uprintf("Enter Selection [9]: ");

        // Get user's selection with a timeout
        UARTFlushRx();
        //timer = CONFIG_MENU_TIMEOUT_SEC + read_hib_rtcc();

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

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

        switch(input)
        {
            case 'A':
            case 'a':
                edit_appcfg_fields();
                break;

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

            case 'd':
            case 'D':
                prn_nl(); prn_nl();
                response = yesOrNoMenuChoice("Assign defaults will reset ALL custom config and setup data, do you wish to proceed? [N]? ", NO);
                if(response == YES)
                {
#if BOARD_MSC == 3
                    apf_defaults();
#else
                    base_defaults();
#endif // #if BOARD_MSC == 3

#ifdef APFDEFAULTS
                    wdog_pet();
                    init_sys_data_default();
                    init_sys_samp_default();            // saves to fram
                    wdog_pet();

                    apf_init_apf_struct_defaults();    //apf_init.c

                    // init apf struct (rename routine)
                    apf_init_apfArray_struct_defaults();         //defd in apf_init.c, init apf. struct

                    wdog_pet();

                    //APF todo, set the defaults or APF
                    eeprom_sys_data_store();
                    prn_nl(); uprintf("Defaults assigned and stored in EEPROM for sys_data and FRAM for sys_samp structures"); prn_nl(); prn_nl();
                    //retrieveSysDataVariables();
                    print_sys_data_structure();
                    prn_nl(); prn_nl();

                    print_sys_samp_data_structure();
                    prn_nl(); prn_nl();
                    print_isus_header();
                    prn_nl(); prn_nl();
                    print_dura_header();
                    prn_nl();  prn_nl();


                    prn_nl();  prn_nl(); prn_nl();
#endif
                }

                break;

            case 'e':
            case 'E':
                copy_edit_sys_data_structure();
                break;

            case 'T':
            case 't':
                print_sys_samp_data_structure();
                break;

            case 'I':
            case 'i':
                fram_sys_samp_defaults();
                print_sys_samp_data_structure();
                break;

            case 'F':
            case 'f':
                prn_nl(); uprintf("fram test:"); prn_nl();  prn_nl();
                if( fram_probe(NULL) != 1)           // read the manufacturer id, or read byte signature in the case of no manufactuerer id
                {
                    prn_nl(); uprintf("ERROR: FRAM probe fails");  prn_nl();
                }
                else
                {
                    prn_nl(); uprintf("PASS: FRAM probe");  prn_nl();
                }

                print_sys_samp_data_structure();

                fram_test();

                prn_nl(); uprintf("fram sys samp volatile data restore"); prn_nl();  prn_nl();
                fram_sys_samp_store();

                break;

            case 'M':
            case 'm':
                // print metadata header
                current_time = read_hib_rtcc();
                print_write_metadata_header(current_time, 1, 0);
                break;

            case 'Q':
            case 'q':
                prn_nl();  prn_nl();
                response = yesOrNoMenuChoice("QA for new board, this will wipe out ALL config and setup data, do you wish to proceed? [N]? ", NO);
                if(response == YES)
                {
                    board_qa_and_init(1); // pass in 1 for init of Flash mem
                }

                break;

            case 'R':
            case 'r':           // was P 10 Apr 2022
                prn_nl(); prn_nl(); uprintf("QA Report:  ");  prn_nl();  prn_nl();
                print_qa_report();
                break;

            case 'S':
            case 's':
                if(sys_data.app_cfg[APPCFG_MENU_LEVEL] == 1)
                {
                    uprintf("sys_data structure:");  prn_nl(); prn_nl();
                    print_sys_data_structure();

                    prn_nl();  prn_nl();
                    uint32_t temp;
                    temp = sizeof(struct systemData);
                    uprintf("sizeof sys_data = %u", temp);  prn_nl();

                    temp = MAP_EEPROMSizeGet(); // Get EEPROM Size
                    uprintf("EEPROM Size %d bytes", temp);  prn_nl();

                }
                break;

            case 'v':
                sys_data.debug_flag = 0;
                prn_nl(); uprintf("sys_data.debug_flag is OFF"); prn_nl();
                break;
            case 'V':
                sys_data.debug_flag = 1;
                prn_nl(); dbg_printf("nsys_data.debug_flag is ON"); prn_nl();
                break;

            case 'z':
            case 'Z':
                config_adc24_sampling_parms();
                break;

            default: //Exit
                // Write the sys_data struct into EEPROM.  Last argument ensures # of bytes is multiple of 4
                if(eeprom_sys_data_store())                     //if(EEPROMProgram((uint32_t*) &sys_data, 0x400, (sizeof(sys_data) + 3) & ~3))
                {
                    prn_nl(); prn_nl(); uprintf("Error storing system data.");  prn_nl();
                }
                else
				{					
					prn_nl(); prn_nl(); uprintf("System data stored.  ");  prn_nl();
				}
                return;
        }
    }
}

#endif // USE_ADVANCED_MENU

#if USE_CONFIGURATION_MENU >= 1
/********************************************************************************************
 *  Configuration Menu, aka config_menu
 ********************************************************************************************/
void configuration_menu(void)
{
    char input, buff[100];
    int response;
    time_t usersTime, timer, current_time;
    unsigned long temp;


    while(1)
    {
        //print out config menu
		prn_nl(); prn_nl(); prn_nl();
        uprintf("Configuration Menu:");  prn_nl();
        uprintf("1 -- Set Clock");  prn_nl();
        uprintf("2 -- Change File Name");  prn_nl();
        uprintf("3 -- Set Deployment Parameters");  prn_nl();
        uprintf("4 -- Enter pH Sensor Calibration Coefficients");  prn_nl();
        uprintf("5 -- Calculate pH Sensor Calibration Coefficients");  prn_nl();
        uprintf("6 -- Change Baud Rate");  prn_nl();
        uprintf("7 -- Config Data Fields");  prn_nl();
        uprintf("8 -- Metadata Settings");  prn_nl();        // was a hidden menu requiring password
        prn_nl();
        uprintf("D -- Data Header, Sample Data, Sample Timing");  prn_nl();
        uprintf("E -- Export Calibration data");  prn_nl();
        uprintf("M -- Metadata");  prn_nl();
#if BOARD_MPHOX >= 1  || BOARD_MSC == 2
        uprintf("P -- Pump Sequencer Setup");  prn_nl();
#endif
        //prn_nl();
        uprintf("Y -- Advanced Setup Menu");  prn_nl();  // advanced_setup_menu
        prn_nl();
        uprintf("9 -- Exit to Main Menu");  prn_nl();
        prn_nl();
        uprintf("Enter Selection [9]: ");

        // Get user's selection with a timeout
        UARTFlushRx();
        //timer = CONFIG_MENU_TIMEOUT_SEC + read_hib_rtcc();

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

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

        switch(input)
        {
            case 'Y':
            case 'y':
                advanced_setup_menu();
                break;
#ifdef MOVEDMENU
            case 'z':
            case 'Z':
                config_adc24_sampling_parms();
                break;
#endif
#if BOARD_MPHOX >= 1  || BOARD_MSC == 2
            case 'P':
            case 'p':
                // Pump Sequencer Setup
                pump_sequencer_setup();
                break;
#endif
#ifdef MOVEDMENU
            case 'A':
            case 'a':
                edit_appcfg_fields();
                break;

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

            case 'c':
            case 'C':
                exercise_iso();
                break;
#endif
            case 'd':
                test_get_sample_timing();
                break;
            case 'D':
                test_get_sample_loop();
                break;

            case 'e':
            case 'E':
                export_pH_sensor_cal_coeff();
                break;

            case 'm':
            case 'M':
                current_time = read_hib_rtcc();
                print_write_metadata_header(current_time, 1, 0);
                break;

#ifdef MAKESAMEASTESTDd
            case 'd':
            case 'D':
            //case ' ':
                //print_config_data_fields();
                prn_nl(); uprintf(" Data Fields:"); prn_nl();  prn_nl();
                print_write_config_data_fields(1,0,1);  // print with pad of // 
                prn_nl();  prn_nl();
                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
#ifdef MOVEDMENU
            case 'e':
            case 'E':
                copy_edit_sys_data_structure();
                break;
#endif
#ifdef OLDCODE
                xxx
            case 'm':
            case 'M':
                //microsd_logging();
                if(sys_data.app_cfg[APPCFG_MICROSD_ENABLE] == 1)
                {
					prn_nl(); prn_nl();
                    response = yesOrNoMenuChoice("Disable MicroSD logging? (Y/N) [N]? ", NO);
                    if(response == YES)
                    {
                        sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 0;
                        eeprom_sys_data_store();
                    }
                }
                else
                {
					prn_nl(); prn_nl();
                    response = yesOrNoMenuChoice("Enable MicroSD logging? (Y/N) [N]? ", NO);
                    if(response == YES)
                    {
                        sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 1;
                        eeprom_sys_data_store();
                    }
                }

                if(sys_data.app_cfg[APPCFG_MICROSD_ENABLE] == 1)
				{
                    uprintf("MicroSD logging is Enabled"); prn_nl();  prn_nl();
				}
                else
				{
                    uprintf("MicroSD card DISabled, no Logging"); prn_nl();  prn_nl();
				}
                break;
#endif
            case '1':  // Set Clock
				prn_nl();  prn_nl();
                response = yesOrNoMenuChoice("Is time GMT? (Y/N) [N]? ", NO);
                if(response == YES) sys_data.GMT = true;
                else sys_data.GMT = false;

                usersTime = getDateAndTime();

                if(usersTime)
                {
                    MAP_HibernateRTCSet(usersTime); // Set time if user entered valid time
                    prn_nl();
                    uprintf("Time now: ");
                    printCurrentTime();
                    if(sys_data.GMT) uprintf(" GMT");
                    else uprintf(" Local");
					prn_nl();  prn_nl();
                    uprintf("Note: Daylight Savings not observed. Use GMT when this will be an issue.");  prn_nl();
                }
                break;

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

				prn_nl();  prn_nl();
                uprintf("Enter user initials [%s]: ", sys_data.user);

                if( getUserInput(buff, MAX_USER_INITIALS) )
                {
                    strcpy(sys_data.user, buff);
					prn_nl(); uprintf("User initials now: %s", sys_data.user); prn_nl();
                }
                break;

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

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

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

                while(1)
                {
                    prn_nl(); uprintf("Enter 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)
                            {
                                prn_nl();
                                uprintf("Sample period is zero - polled mode");  prn_nl();
                            }


                            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
                                {
                                    prn_nl();
                                    uprintf("Sample period must evenly divide hour (e.g. 5, 10, 15, 20, 30 minutes)");
                                    continue;
                                }
                            }

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

                            continue;
                        } // scanf
                        else break;

                    }
                    else break;
                }
#if BOARD_MPHOX >= 1  || BOARD_MSC == 2
                pump_sequencer_setup();
#endif

#if BOARD_MFET >= 1 || BOARD_MPHOX >= 1  || BOARD_MSC == 2
                float ftemp;
                float fVbat;
                // Low battery voltage
                while(1)
                    {
#if BOARD_MFET >= 1
                        sprintf(buff, "\r\nEnter low battery_voltage (ex. 5.5 V) [%.1f V]: ", sys_data.dura_vin_min_volt);
#endif
#if BOARD_MPHOX >= 1  || BOARD_MSC == 2
                        sprintf(buff, "\r\nEnter low battery_voltage (ex. 10.5 V with Pump) [%.1f V]: ", sys_data.dura_vin_min_volt);
#endif
#if BOARD_NANOFET >= 1
                        //sprintf(buff, "\r\nEnter low battery_voltage (ex. 5.5 V) [%.1f V]: ", sys_data.dura_vin_min_volt);
                        sprintf(buff, "\r\nBattery voltage check not available on NanoFET  [%.1f V]: ", sys_data.dura_vin_min_volt);
#endif
#if BOARD_MSC == 3
                        sprintf(buff, "\r\nEnter DURA min battery_voltage (ex. 8.0) [%.1f V]: ", sys_data.dura_vin_min_volt);
#endif
                        uprintf("%s", buff);
                        if(getUserInput(buff, strlen(buff) ))
                        {
                            if(sscanf(buff, "%f", &ftemp) == 1)
                            {
                                if(ftemp >= 0 && ftemp <= 30)
                                {
                                    sys_data.dura_vin_min_volt = ftemp;
                                    sprintf(buff, "\r\nLow battery_voltage now [%.1f V]\r\n\r\n", sys_data.dura_vin_min_volt);
                                    uprintf("%s", buff);
                                break;
                                }
                                else
                                {
                                    prn_nl();
                                    uprintf("Enter voltage less than 30 V");
                                }
                                continue;
                            }
                            else
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }  //while(1)
#endif

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

                input = get_key();

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

                        case '2': sys_data.output = VERBOSE;
							prn_nl(); prn_nl(); uprintf("Output mode now: VERBOSE");
                            break;
                    }

                }

                // Error check the setup

                uint32_t sampTimeEst;
                sampTimeEst = sys_data.pump1_ontime * 1000;


                if((sys_data.data_cfg[CFG_UART3_INST] > INST_OPTODE_NOTDEFD) ||  (sys_data.data_cfg[CFG_UART4_INST] > INST_CTD_NOTDEFD))
                    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)
                    {
                        prn_nl();
                        uprintf("Error: Estimated sample time = %.2f sec, is greater than sample period = %u sec.  Increase sample period", (float)sampTimeEst/1000.0, sys_data.sampling_period);
                        prn_nl();
                    }
                    else
                    {
                        prn_nl();
                        uprintf("Estimated sample time = %.2f sec in polled mode (sample period is 0)", (float)sampTimeEst/1000.0, sys_data.sampling_period);  // bug fix 22 Jul 2021
                        prn_nl();
                    }
                }
                else
                {
                    prn_nl();
                    uprintf("Estimated sample time = %.2f sec, sample period = %u sec", (float)sampTimeEst/1000.0, sys_data.sampling_period);
                    prn_nl();
                }

                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
                prn_nl();
                uprintf("Metadata Settings:"); prn_nl();

                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;
                                prn_nl(); uprintf("pH Vint data rate now %d sps", sys_data.Vrsi_sps); prn_nl(); prn_nl(); 
                                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;
                                prn_nl(); uprintf("pH Vint gain now %d", sys_data.Vint_gain); prn_nl(); prn_nl(); 
                                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(eeprom_sys_data_store())                     //if(EEPROMProgram((uint32_t*) &sys_data, 0x400, (sizeof(sys_data) + 3) & ~3))
                {
                    prn_nl(); prn_nl();
                    uprintf("Error storing system data.");  prn_nl();
                }
                else
                {
                    prn_nl(); prn_nl();
                    uprintf("System data stored.  -- Press enter to bring up main menu"); prn_nl();
                }
                return;
        }
    }
}

#endif // USE_CONFIG_MENU >= 1

void pump_sequencer_setup(void)
{

    char buff[100];
    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;

        // initialize pump seq volatile vars
        sys_samp.pump_seq_state = 0;  //ST_SEQ_NADA, disables pump sequencer
        sys_samp.pump1_cnt = 0;
        sys_samp.pump2_cnt = 0;

        fram_sys_samp_store();

        prn_nl();
        uprintf("Enter Pump Sequence Type (1=Single, 2=Two Pump Alt BEAMSv1, 3=Two Pump BEAMSv2, 4=Self Cal [%d]: ", sys_data.pump_seq_type);
        if(getUserInput(buff, 2))
        {
            if(sscanf(buff, "%d", &temp) == 1)
            {
                // from system.h
                // #define TYPE_PUMP_NOTDEFD       0
                // #define TYPE_PUMP_SINGLE        1
                // #define TYPE_2PUMP_BEAMSV1      2
                // #define TYPE_2PUMP_BEAMSV2      3
                // #define TYPE_PUMP_SELFCAL       4
                //if(temp == 1 || temp == 2 || temp == 3)
                if(temp == 0)
                {
                    sys_data.pump_seq_type = temp;
                    prn_nl(); uprintf("Pump Sequence Type = %d, Disabled", sys_data.pump_seq_type); prn_nl(); prn_nl(); 
                }
                if(temp == 1 || temp == 2|| temp == 3|| temp == 4)
                {
                    sys_data.pump_seq_type = temp;
                    prn_nl();
                    uprintf("Pump Sequence Type = %d", sys_data.pump_seq_type);
                    prn_nl(); prn_nl();
                    break;
                }
                else
                {
                    prn_nl();
                    uprintf("Enter 1,2,3,4 to select pump sequencer, 0 to disable");
                }
                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("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.", sys_data.pump1_ontime); prn_nl(); prn_nl(); 
                        break;
                    }
                    else uprintf("\r\nEnter time less than 3600 sec");
                    continue;
                }
                else
                    break;
            }
            else
                break;
        }
    }

    prn_nl(); uprintf("Enter Experiment Delay Start feature is not yet implemented..."); prn_nl(); 
    prn_nl(); uprintf("Enter Experiment Duty Cycle feature is not yet implemented..."); prn_nl(); 
#ifdef FUTURECODE
    // Duty Cycle On
    while(1)
    {
        prn_nl();
        uprintf("Enter 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
                    prn_nl();
                    uprintf("Experiment Duty Cycle On Time = %d", sys_data.sampleCnt_duty_on/3600);
                    prn_nl(); prn_nl();
                    break;
                }
                else
                {
                    prn_nl();
                    uprintf("Enter a number less than 1000 hours");
                }
                continue;
            }
            else
                break;
        }
        else
            break;
    }

    // Duty Cycle Off
    if(sys_data.sampleCnt_duty_on > 0)
    {
        while(1)
        {
            prn_nl();
            uprintf("Enter 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
                        prn_nl(); uprintf("Experiment Duty Cycle On Time = %d", sys_data.sampleCnt_duty_off/3600); prn_nl(); prn_nl();
                        break;
                    }
                    else
                    {
                        prn_nl();
                        uprintf("Enter a number greater than 0, less than 1000 hours");
                    }
                    continue;
                }
                else break;
            }
            else break;
        }
    }
#endif


    if((sys_data.pump_seq_type == TYPE_2PUMP_BEAMSV1) || (sys_data.pump_seq_type == TYPE_2PUMP_BEAMSV2))
    {
        config_two_pump_beams_v1();
    }

}




void config_two_pump_beams_v1(void)
{
    char buff[100];
    uint32_t temp;


    // Pump 1 ontime (seconds)
    while(1)
    {
        prn_nl();
        uprintf("Enter 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", sys_data.pump1_ontime); prn_nl(); prn_nl();
                    break;
                }
                else
                {
                    prn_nl();
                    uprintf("Enter a number less than or equal to %d seconds", 5*3600);
                }
                continue;
            }
            else break;
        }
        else break;
    }

    // Pump 2 ontime (seconds)
    while(1)
    {
        prn_nl();
        uprintf("Enter 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
                    prn_nl(); uprintf("Pump2 run time = %d sec", sys_data.pump2_ontime); prn_nl(); prn_nl();
                    break;
                }
                else { prn_nl(); uprintf("Enter a number less than or equal to %d seconds", 5*3600); }
                continue;
            }
            else break;
        }
        else break;
    }


    // Pump 1 cycles
    while(1)
    {
        prn_nl();
        uprintf("Enter 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
                    prn_nl(); uprintf("Sampling cycles Pump1 = %d", sys_data.pump1_cycles); prn_nl(); prn_nl();
                    break;
                }
                else { prn_nl(); uprintf("Enter a number less than 1000 cycles"); }
                continue;
            }
            else break;
        }
        else break;
    }




    // Pump 2 cycles
    while(1)
    {
        prn_nl();
        uprintf("Enter 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
                    prn_nl(); uprintf("Sampling cycles Pump2 = %d", sys_data.pump2_cycles); prn_nl(); prn_nl();
                    break;
                }
                else { prn_nl(); uprintf("Enter a number less than 1000 cycles"); }
                continue;
            }
            else break;
        }
        else break;
    }
}


void config_two_pump_beams_v2(void)
{
    char buff[100];
    uint32_t temp;

    //Sampling routine will change to: turn pump1 on for X minutes, and while pump is on, keep polling sensors at Y second intervals. Then switch to pump2, then back to pump1, etc.
    //This is a significant hit to the power budget since we will constantly be operating a pump. To extend battery life (goal is to do long term benthic flux measurements), it would be great if we have some duty cycle on the order of days. So like 3 days on, 3 days off, etc; all user configurable.

    // Pump 1 ontime (seconds)
    while(1)
    {
        prn_nl();
        uprintf("Enter 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", sys_data.pump1_ontime); prn_nl(); prn_nl();
                    break;
                }
                else { prn_nl(); uprintf("Enter a number less than or equal to %d seconds", 5*3600); }
                continue;
            }
            else break;
        }
        else break;
    }

    // Pump 2 ontime (seconds)
    while(1)
    {
        prn_nl(); uprintf("Enter 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
                    prn_nl(); uprintf("Pump2 run time = %d sec", sys_data.pump2_ontime); prn_nl(); prn_nl();
                    break;
                }
                else { prn_nl(); uprintf("Enter a number less than or equal to %d seconds", 5*3600);  }
                continue;
            }
            else break;
        }
        else break;
    }


    // Pump 1 cycles
    while(1)
    {
        prn_nl();
        uprintf("Enter 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
                    prn_nl(); uprintf("Sampling cycles Pump1 = %d", sys_data.pump1_cycles); prn_nl(); prn_nl();
                    break;
                }
                else { prn_nl(); uprintf("Enter a number less than 1000 cycles"); }
                continue;
            }
            else break;
        }
        else break;
    }




    // Pump 2 cycles
    while(1)
    {
        prn_nl();
        uprintf("Enter 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
                    prn_nl(); uprintf("Sampling cycles Pump2 = %d", sys_data.pump2_cycles); prn_nl(); prn_nl();
                    break;
                }
                else { prn_nl(); uprintf("Enter a number less than 1000 cycles"); }
                continue;
            }
            else break;
        }
        else break;
    }
}

void config_self_cal(void)
{
    char buff[100];
    uint32_t temp;

    // Pump 1 ontime (seconds)
    while(1)
    {
        prn_nl();
        uprintf("Enter 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", sys_data.pump1_ontime); prn_nl(); prn_nl();
                    break;
                }
                else { prn_nl(); uprintf("Enter a number less than or equal to %d seconds", 5*3600); }
                continue;
            }
            else break;
        }
        else break;
    }

    // Pump 2 ontime (seconds)
    while(1)
    {
        prn_nl();
        uprintf("Enter 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
                    prn_nl(); uprintf("Pump2 run time = %d sec", sys_data.pump2_ontime); prn_nl(); prn_nl();
                    break;
                }
                else { prn_nl(); uprintf("Enter a number less than or equal to %d seconds", 5*3600); }
                continue;
            }
            else break;
        }
        else break;
    }


    // Pump 1 cycles
    while(1)
    {
        prn_nl();
        uprintf("Enter 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
                    prn_nl(); uprintf("Sampling cycles Pump1 = %d", sys_data.pump1_cycles); prn_nl(); prn_nl();
                    break;
                }
                else { prn_nl(); uprintf("Enter a number less than 1000 cycles"); }
                continue;
            }
            else break;
        }
        else break;
    }




    // Pump 2 cycles
    while(1)
    {
        prn_nl();
        uprintf("Enter 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
                    prn_nl(); uprintf("Sampling cycles Pump2 = %d", sys_data.pump2_cycles); prn_nl(); prn_nl();
                    break;
                }
                else { prn_nl(); uprintf("Enter a number less than 1000 cycles"); }
                continue;
            }
            else break;
        }
        else break;
    }
}

//thomthom

// custom fgets for parsing strings terminated by carriage return, aka efgets
// uses global variable FileObject (assumed open for reading)
// writes the result in array pointed by bufPtr
void efgets(char *bufPtr)
{
    uint32_t indx2;
    UINT br;

    for(indx2=0; indx2<24; indx2++)
    {
        f_read(&FileObject, bufPtr+indx2, 1, &br);

        if(*(bufPtr+indx2) == 0x0d)
        {
            *(bufPtr+indx2) = 0;
        }
        if(*(bufPtr+indx2) == 0x0a)
        {
            *(bufPtr+indx2) = 0;
            return;
        }
    }

}

// read from ymodem packet to string buffer
char* egets(char *linePtr, char *bufPtr)
{
    uint32_t indx2;

#define MAX_STRLINE_CAL_FILE       32

    for(indx2=0; indx2<MAX_STRLINE_CAL_FILE; indx2++)
    {
        *(linePtr+indx2) = *(bufPtr+indx2);

        if(*(bufPtr+indx2) == 0x0d)
        {
            *(linePtr+indx2) = 0;
        }
        if(*(bufPtr+indx2) == 0x0a)
        {
            *(linePtr+indx2) = 0;
            return((bufPtr+indx2+1));       // return pointer to start of next string
        }
    }

    return((bufPtr+indx2));     // not sure what to return - this is an error state

}

// pass in pointer to ymodem data packet
void parse_cal_packet(char *bufPtr)
{
    char line[80];

    //char cal_filename[16];  //was 16 16 Oct 2023
    char sensor_SN[16];  //--> sensor_SN[8]
    char isfet_SN[16];  // --> isfet_SN[8]
    char ise_SN[16];    //  --> ise_SN[8]
    char PT_Cal_date[16];
    float k2_C0 = 0.0;
    float k2_C1 = 0.0;
    float k2_C2 = 0.0;
    float k2_C3 = 0.0;
    float fP_0 = 0.0;
    float fP_1 = 0.0;
    float fP_2 = 0.0;
    float fP_3 = 0.0;
    float fP_4 = 0.0;
    float fP_5 = 0.0;
    float fP_6 = 0.0;
    char k0_Cal_date[16];
    float k0_HCl = 0.0;
    float k0_SW = 0.0;
    float k0std_SW = 0.0;
    char service_date[16];

    uint32_t indx;


    bufPtr = egets(line, bufPtr);
    sscanf(line, "Sensor_SN,%s", sensor_SN);

    bufPtr = egets(line, bufPtr);
    sscanf(line, "ISFET_SN,%s", isfet_SN);

    bufPtr = egets(line, bufPtr);
    sscanf(line, "ISE_SN,%s", ise_SN);

    for(indx=0; indx<sizeof(PT_Cal_date); indx++)       // Not needed.
        PT_Cal_date[indx] = 0;

    bufPtr = egets(line, bufPtr);
    sscanf(line, "PT_Cal_date,%s", PT_Cal_date);

    PT_Cal_date[10] = 0;        // fixing an extra letter bug

    bufPtr = egets(line, bufPtr);
    sscanf(line, "k2_C0,%f", &k2_C0);

    bufPtr = egets(line, bufPtr);
    sscanf(line, "k2_C1,%f", &k2_C1);

    bufPtr = egets(line, bufPtr);
    sscanf(line, "k2_C2,%f", &k2_C2);

    bufPtr = egets(line, bufPtr);
    sscanf(line, "k2_C3,%f", &k2_C3);

    bufPtr = egets(line, bufPtr);
    sscanf(line, "fP_0,%f", &fP_0);

    bufPtr = egets(line, bufPtr);
    sscanf(line, "fP_1,%f", &fP_1);

    bufPtr = egets(line, bufPtr);
    sscanf(line, "fP_2,%f", &fP_2);

    bufPtr = egets(line, bufPtr);
    sscanf(line, "fP_3,%f", &fP_3);

    bufPtr = egets(line, bufPtr);
    sscanf(line, "fP_4,%f", &fP_4);

    bufPtr = egets(line, bufPtr);
    sscanf(line, "fP_5,%f", &fP_5);

    bufPtr = egets(line, bufPtr);
    sscanf(line, "fP_6,%f", &fP_6);

    bufPtr = egets(line, bufPtr);
    sscanf(line, "k0_Cal_date,%s", k0_Cal_date);

    bufPtr = egets(line, bufPtr);
    sscanf(line, "k0_HCl,%f", &k0_HCl);

    bufPtr = egets(line, bufPtr);
    sscanf(line, "k0_SW,%f", &k0_SW);

    bufPtr = egets(line, bufPtr);
    sscanf(line, "k0std_SW,%f", &k0std_SW);

    bufPtr = egets(line, bufPtr);
    sscanf(line, "service_date,%s", service_date);


    strncpy(sys_data.sensor_SN, sensor_SN, 7);  //--> sensor_SN[8]
    sys_data.sensor_SN[MAX_SENSOR_SN-1] = 0;
    strncpy(sys_data.isfet_SN, isfet_SN, 7);  // --> isfet_SN[8]
    sys_data.isfet_SN[MAX_ISFET_SN-1] = 0;
    strncpy(sys_data.ise_SN, ise_SN, 7);    //  --> ise_SN[8]
    sys_data.ise_SN[MAX_ISE_SN-1] = 0;
    strncpy(sys_data.PT_Cal_date, PT_Cal_date, 10);  // --> PT_Cal_date[12]
    sys_data.PT_Cal_date[MAX_PT_CAL_DATE-1] = 0;
    sys_data.K2_Cal[0] = k2_C0;
    sys_data.K2_Cal[1] = k2_C1;
    sys_data.K2_Cal[2] = k2_C2;
    sys_data.K2_Cal[3] = k2_C3;
    sys_data.fP_Cal[0] = fP_0;
    sys_data.fP_Cal[1] = fP_1;
    sys_data.fP_Cal[2] = fP_2;
    sys_data.fP_Cal[3] = fP_3;
    sys_data.fP_Cal[4] = fP_4;
    sys_data.fP_Cal[5] = fP_5;
    sys_data.fP_Cal[6] = fP_6;
    strncpy(sys_data.k0_Cal_date, k0_Cal_date, 10);
    sys_data.k0_Cal_date[10] = 0;
    sys_data.k0_HCL = k0_HCl;
    sys_data.k0_SW = k0_SW;
    sys_data.k0std_SW = k0std_SW;
    strncpy(sys_data.service_date, service_date, 10);
    sys_data.service_date[10] = 0;
}


//thomthom
void import_ymodem_cal_coeff(void)
{
    int response;
    int indx;

    //run ymodem, transfer a '*.cal' file, parse and store in sys_data variables
    // ymodem modified to operate without the filesystem.
    prn_nl(); prn_nl();
    response = yesOrNoMenuChoice("Transfer Cal file via Teraterm YMODEM? (Y/N) [N]? ", NO);
    if(response == NO)
    {
        return;
    }

    uprintf("OK!  Calling ymodem_receive...(Ctrl-C to cancel)"); prn_nl();
    wait_consoleTx();       //wait for transmit
    uprintf("TeraTerm: File->Transfer->Ymodem->Send *.cal file"); prn_nl();
    wait_consoleTx();       //wait for transmit
    if(sys_data.baud_rate != 115200)
    {
        uprintf("   Note: 15 sec delay after transfer for slow baud ymodem workaround");  prn_nl();
        wait_consoleTx();       //wait for transmit
    }

    calFileFlg = 1;
    {
        char* argv[] = {"yr", NULL};
        ymodem_receive(1, argv);      //calls parse_cal_packet(char *bufPtr);
    }



    if(sys_data.baud_rate != 115200)
    {
        for(indx=0; indx<8; indx++)
        {
            uprintf("   delay..."); prn_nl();
            delay_msec(2000);
        }

        UARTFlushRx();
    }

    prn_nl(); prn_nl();

}


void set_cal_filename(char *filename_ptr)
{
    int len;

    len = strlen(filename_ptr);
    if(len >= MAX_CAL_FILENAME)
        len = MAX_CAL_FILENAME-1;
    strncpy(sys_data.cal_filename, filename_ptr, len);   //was 12
    sys_data.cal_filename[len] = 0;      //8.cal // was 12
}

// This import function is for test/development
// called for test from main menu with 'i' - needs to read line at a time (fread)
// test func
void import_pH_sensor_cal_coeff(void)
{
    char line[80];

    // Declare variables to store the data read from the file.

    char cal_filename[16];
    char sensor_SN[16];  //--> sensor_SN[8]
    char isfet_SN[16];  // --> isfet_SN[8]
    char ise_SN[16];    //  --> ise_SN[8]
    char PT_Cal_date[16];
    float k2_C0;
    float k2_C1;
    float k2_C2;
    float k2_C3;
    float fP_0;
    float fP_1;
    float fP_2;
    float fP_3;
    float fP_4;
    float fP_5;
    float fP_6;
    char k0_Cal_date[16];
    float k0_HCl;
    float k0_SW;
    float k0std_SW;
    char service_date[16];

    uint32_t file_size;
    FRESULT fresult;

    UARTEchoSet(false);     // Disable console echo

    strcpy(cal_filename, "DF384.cal");

    // Open the file for reading.
    fresult = f_open(&FileObject, cal_filename, FA_READ);
    if(fresult != FR_OK)
    {
        uprintf("f_open error: %s\n", StringFromFresult(fresult) );
        //error = -1;
        //goto abort;
        UARTEchoSet(true);      // Enable console echo
        return;
    }

    file_size = f_size(&FileObject); // Set file size
    //uprintf("File size = %lu", file_size);  prn_nl();

    uprintf("importing %s, %lu bytes...", cal_filename, file_size); prn_nl();
    UARTFlushTx(false);

    //efgets(line);
    //uprintf("%s", line); prn_nl();
    //sscanf(line, "Filename,%s", cal_filename);
    efgets(line);
    uprintf("%s", line); prn_nl();
    sscanf(line, "Sensor_SN,%s", sensor_SN);
    efgets(line);
    uprintf("%s", line); prn_nl();
    sscanf(line, "ISFET_SN,%s", isfet_SN);
    efgets(line);
    uprintf("%s", line); prn_nl();
    sscanf(line, "ISE_SN,%s", isfet_SN);
    efgets(line);
    uprintf("%s", line); prn_nl();
    sscanf(line, "PT_Cal_date,%s", PT_Cal_date);
    efgets(line);
    uprintf("%s\r\n", line);
    sscanf(line, "k2_C0,%f", &k2_C0);
    efgets(line);
    uprintf("%s", line); prn_nl();
    sscanf(line, "k2_C1,%f", &k2_C1);
    efgets(line);
    uprintf("%s", line);  prn_nl();
    sscanf(line, "k2_C2,%f", &k2_C2);
    efgets(line);
    uprintf("%s", line); prn_nl();
    sscanf(line, "k2_C3,%f", &k2_C3);
    efgets(line);
    uprintf("%s", line);  prn_nl();
    sscanf(line, "fP_0,%f", &fP_0);
    efgets(line);
    uprintf("%s", line);  prn_nl();
    sscanf(line, "fP_1,%f", &fP_1);
    efgets(line);
    uprintf("%s", line);  prn_nl();
    sscanf(line, "fP_2,%f", &fP_2);
    efgets(line);
    uprintf("%s", line);  prn_nl();
    sscanf(line, "fP_3,%f", &fP_3);
    efgets(line);
    uprintf("%s", line);  prn_nl();
    sscanf(line, "fP_4,%f", &fP_4);
    efgets(line);
    uprintf("%s", line); prn_nl();
    sscanf(line, "fP_5,%f", &fP_5);
    efgets(line);
    uprintf("%s", line); prn_nl();
    sscanf(line, "fP_6,%f", &fP_6);
    efgets(line);
    uprintf("%s", line); prn_nl();
    sscanf(line, "k0_Cal_date,%s", k0_Cal_date);
    efgets(line);
    uprintf("%s", line); prn_nl();
    sscanf(line, "k0_HCl,%f", &k0_HCl);
    efgets(line);
    uprintf("%s", line); prn_nl();
    sscanf(line, "k0_SW,%f", &k0_SW);
    efgets(line);
    uprintf("%s", line); prn_nl();
    sscanf(line, "k0std_SW,%f", &k0std_SW);
    efgets(line);
    uprintf("%s", line); prn_nl();
    sscanf(line, "service_date,%s", service_date);

    prn_nl(); prn_nl();

    // Print the data that was read.
    uprintf("Filename: %s", cal_filename);  prn_nl();
    uprintf("Sensor_SN: %s", sensor_SN);  prn_nl();
    uprintf("ISFET_SN: %s", isfet_SN); prn_nl();
    uprintf("ISE_SN: %s", ise_SN);  prn_nl();
    uprintf("PT_Cal_date: %s", PT_Cal_date); prn_nl();
    uprintf("k2_C0: %e", k2_C0);  prn_nl();
    uprintf("k2_C1: %e", k2_C1); prn_nl();
    uprintf("k2_C2: %e", k2_C2); prn_nl();
    uprintf("k2_C3: %e", k2_C3); prn_nl();
    uprintf("fP_0: %e", fP_0); prn_nl();
    uprintf("fP_1: %e", fP_1); prn_nl();
    uprintf("fP_2: %e", fP_2); prn_nl();
    uprintf("fP_3: %e", fP_3); prn_nl();
    uprintf("fP_4: %e", fP_4); prn_nl();
    uprintf("fP_5: %e", fP_5); prn_nl();
    uprintf("fP_6: %e", fP_6); prn_nl();
    uprintf("k0_Cal_date: %s", k0_Cal_date); prn_nl();
    uprintf("k0_HCl: %e", k0_HCl);  prn_nl();
    uprintf("k0_SW: %e", k0_SW); prn_nl();
    uprintf("k0std_SW: %e", k0std_SW); prn_nl();
    uprintf("service_date: %s", service_date); prn_nl();

    strcpy(sys_data.cal_filename, cal_filename);
    strcpy(sys_data.sensor_SN, sensor_SN);
    strcpy(sys_data.isfet_SN, isfet_SN);
    strcpy(sys_data.ise_SN, ise_SN);

    //sys_data.PT_Cal_date
    sys_data.K2_Cal[0] = k2_C0;
    sys_data.K2_Cal[1] = k2_C1;
    sys_data.K2_Cal[2] = k2_C2;
    sys_data.K2_Cal[3] = k2_C3;
    sys_data.fP_Cal[0] = fP_0;
    sys_data.fP_Cal[1] = fP_1;
    sys_data.fP_Cal[2] = fP_2;
    sys_data.fP_Cal[3] = fP_3;
    sys_data.fP_Cal[4] = fP_4;
    sys_data.fP_Cal[5] = fP_5;
    sys_data.fP_Cal[6] = fP_6;
    //sys_data.k0_Cal_date
    //sys_data.k0_HCL
    //sys_data.k0_SW
    //sys_data.k0std_SW
    strcpy(sys_data.service_date, service_date);

    prn_nl(); prn_nl();

    f_close(&FileObject);
    UARTEchoSet(true);      // Enable console echo

#ifdef NOCODE
    // Read the line from the file.
    rv = f_gets(line);

    // Use sscanf to read the data from the line.
    rv = sscanf(line, "%s,%s,%s,%s,%s,%f,%f,%f,%f,%f,%f,%f,%f,%s,%f,%f,%f",
                filename, sensorSN, ISFET_SN, ISE_SN, PT_Cal_date, &k2_C0, &k2_C1, &k2_C2, &k2_C3,
                &fP_0, &fP_1, &fP_2, &fP_3, &fP_4, &fP_5, &fP_6, &k0_Cal_date, &k0_HCl, &k0_SW, &k0std_SW);

    // Check if the read was successful.
    if (rv != 18) {
      printf("Error reading line: %s\n", line);
      return 1;
    }

    // Print the data that was read.
    printf("Filename: %s\n", filename);
    printf("SensorSN: %s\n", sensorSN);
    printf("ISFET_SN: %s\n", ISFET_SN);
    printf("ISE_SN: %s\n", ISE_SN);
    printf("PT_Cal_date: %s\n", PT_Cal_date);
    printf("k2_C0: %lf\n", k2_C0);
    printf("k2_C1: %lf\n", k2_C1);
    printf("k2_C2: %lf\n", k2_C2);
    printf("k2_C3: %lf\n", k2_C3);
    printf("fP_0: %lf\n", fP_0);
    printf("fP_1: %lf\n", fP_1);
    printf("fP_2: %lf\n", fP_2);
    printf("fP_3: %lf\n", fP_3);
    printf("fP_4: %lf\n", fP_4);
    printf("fP_5: %lf\n", fP_5);
    printf("fP_6: %lf\n", fP_6);
    printf("k0_Cal_date: %s\n", k0_Cal_date);
    printf("k0_HCl: %lf\n", k0_HCl);
    printf("k0_SW: %lf\n", k0_SW);
    printf("k0std_SW: %lf\n", k0std_SW);


#endif

}

// called as test function from main menu with 'g'.  From deploy mode, 'gc' Print to console the pH cal coefficients stored in sys_data
void get_pH_sensor_cal_coeff(void)
{
    int indx;
    int bufIndx;
    int prnIndx;


    bufIndx=0;
    prnIndx=0;

    bufIndx += sprintf((char *)&prnBuf[bufIndx], "%s\t", sys_data.sensor_SN);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "%s\t", sys_data.isfet_SN);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "%s\t", sys_data.ise_SN);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "%s\t", sys_data.PT_Cal_date);

    for(indx=0; indx<NUMOF_K2_CAL_FIELDS; indx++)
    {
        bufIndx += sprintf((char *)&prnBuf[bufIndx], "%e\t", sys_data.K2_Cal[indx]);
    }

    prnBuf[bufIndx] = 0;
    uprintf("%s", &prnBuf[prnIndx]);
    wait_consoleTx();
    prnIndx = bufIndx;

    for(indx=0; indx<NUMOF_FP_CAL_FIELDS; indx++)
    {
        bufIndx += sprintf((char *)&prnBuf[bufIndx], "%e\t", sys_data.fP_Cal[indx]);
    }

    bufIndx += sprintf((char *)&prnBuf[bufIndx], "%s\t", sys_data.k0_Cal_date);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "%e\t", sys_data.k0_HCL);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "%e\t", sys_data.k0_SW);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "%e\t", sys_data.k0std_SW);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "%s\r\n", sys_data.service_date);

    //bufIndx += sprintf((char *)&prnBuf[bufIndx], "\r\n");

    //uprintf("%s", prnBuf);
    prnBuf[bufIndx] = 0;
    uprintf("%s", &prnBuf[prnIndx]);
    wait_consoleTx();
    prnIndx = bufIndx;
}

// output cal coeff in format same as file
void export_pH_sensor_cal_coeff(void)
{
    int bufIndx;
    int prnIndx;


#ifdef CALFILEDEF
    Sensor_SN,DSD1234
    ISFET_SN,ISF1234
    ISE_SN,ISE1234
    PT_Cal_date,12/15/2022
    k2_C0,-9.641540E-04
    k2_C1,-1.610570E-09
    k2_C2,-4.624490E-12
    k2_C3,7.304790E-15
    fP_0,-1.270040E+00
    fP_1,-3.832110E-06
    fP_2,1.960530E-08
    fP_3,-3.195020E-11
    fP_4,2.544840E-14
    fP_5,-9.926440E-18
    fP_6,1.500790E-21
    k0_Cal_date,8/15/2023
    k0_HCl,-1.270010E+00
    k0_SW,-1.32E+00
    k0std_SW,1.20E-04
    service_date,11/30/2025
#endif

    prn_nl();

    bufIndx=0;
    prnIndx=0;

    //THOM APFTODO on newline

    bufIndx += sprintf((char *)&prnBuf[bufIndx], "Cal filename: %s\r\n\r\n", sys_data.cal_filename);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "Sensor_SN,%s\r\n", sys_data.sensor_SN);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "ISFET_SN,%s\r\n", sys_data.isfet_SN);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "ISE_SN,%s\r\n", sys_data.ise_SN);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "PT_Cal_date,%s\r\n", sys_data.PT_Cal_date);

    bufIndx += sprintf((char *)&prnBuf[bufIndx], "k2_C0,%e\r\n", sys_data.K2_Cal[0]);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "k2_C1,%e\r\n", sys_data.K2_Cal[1]);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "k2_C2,%e\r\n", sys_data.K2_Cal[2]);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "k2_C3,%e\r\n", sys_data.K2_Cal[3]);

    prnBuf[bufIndx] = 0;
    uprintf("%s", &prnBuf[prnIndx]);
    wait_consoleTx();
    prnIndx = bufIndx;

    bufIndx += sprintf((char *)&prnBuf[bufIndx], "fP_0,%e\r\n", sys_data.fP_Cal[0]);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "fP_1,%e\r\n", sys_data.fP_Cal[1]);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "fP_2,%e\r\n", sys_data.fP_Cal[2]);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "fP_3,%e\r\n", sys_data.fP_Cal[3]);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "fP_4,%e\r\n", sys_data.fP_Cal[4]);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "fP_5,%e\r\n", sys_data.fP_Cal[5]);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "fP_6,%e\r\n", sys_data.fP_Cal[6]);

    prnBuf[bufIndx] = 0;
    uprintf("%s", &prnBuf[prnIndx]);
    wait_consoleTx();
    prnIndx = bufIndx;

    bufIndx += sprintf((char *)&prnBuf[bufIndx], "k0_Cal_date,%s\r\n", sys_data.k0_Cal_date);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "k0_HCl,%e\r\n", sys_data.k0_HCL);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "k0_SW,%e\r\n", sys_data.k0_SW);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "k0std_SW,%e\r\n", sys_data.k0std_SW);
    bufIndx += sprintf((char *)&prnBuf[bufIndx], "service_date,%s\r\n", sys_data.service_date);

    //bufIndx += sprintf((char *)&prnBuf[bufIndx], "\r\n");

    //uprintf("%s", prnBuf);
    prnBuf[bufIndx] = 0;
    uprintf("%s", &prnBuf[prnIndx]);
    wait_consoleTx();
    prnIndx = bufIndx;

    prn_nl();
}


// called from 1) Config --> 4) enter pH cal
// uprintf("4 -- Enter pH Sensor Calibration Coefficients\r\n");
void enter_pH_sensor_cal_coeff(void)
{
    char buff[100];
    float ftemp;
    double dtemp;
    uint32_t indx;


    // TODO: rework the data entry from while1's to functions

    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)"); prn_nl(); prn_nl(); }
                continue;
            }
            else break;
        }
        else break;
    }


    //Eo_ext_25
    while(1)
    {
        // per Yui, 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)"); prn_nl(); prn_nl(); }
                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)"); prn_nl(); prn_nl(); }
                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)"); prn_nl(); prn_nl(); }
                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"); prn_nl(); prn_nl(); }
            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");  prn_nl();
        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"); prn_nl(); prn_nl(); }
            continue;
        }
        else break;

        }
        else break;
    }
    if(sys_data.app_cfg[APPCFG_TEMPC_SH_ALG] == 0)
    {
        prn_nl();
        uprintf("4 Var S-H coefficients for Thermistor to Temperature Celsius:");  prn_nl();
        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);
        prn_nl();
    }
    if(sys_data.app_cfg[APPCFG_TEMPC_SH_ALG] == 1)
    {
        prn_nl();
        uprintf("3 Var S-H coefficients for Thermistor to Temperature Celsius:");  prn_nl();
        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);
        prn_nl();
    }


    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)"); prn_nl(); prn_nl(); }
                    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)"); prn_nl(); prn_nl(); }
                    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)"); prn_nl(); prn_nl(); }
                    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)"); prn_nl(); prn_nl(); }
                    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 "); prn_nl(); prn_nl(); }
                    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 "); prn_nl(); prn_nl(); }
                    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 "); prn_nl(); prn_nl(); }
                    continue;
                }
                else break;
                }
            else break;
        }
    } // if 3 var
    //uprintf("\r\n*****Calibration Coefficients Saved*****\r\n\r\n");



    // thomthom
    // todo - ymodem finishes transfer rather than aborts
    import_ymodem_cal_coeff();

    MAP_SysCtlDelay(MILLISECOND * 200);
    UARTFlushRx();

    uprintf("cal_filename [%s]: ", sys_data.cal_filename);
    edit_string(&sys_data.cal_filename[0], MAX_CAL_FILENAME);
    uprintf("             [%s]\r\n", sys_data.cal_filename);

    uprintf("sensor_SN [%s]: ", sys_data.sensor_SN);
    edit_string(&sys_data.sensor_SN[0], MAX_SENSOR_SN);
    uprintf("          [%s]\r\n", sys_data.sensor_SN);

    uprintf("isfet_SN [%s]: ", sys_data.isfet_SN);
    edit_string(&sys_data.isfet_SN[0], MAX_ISFET_SN);
    uprintf("         [%s]\r\n", sys_data.isfet_SN);

    uprintf("ise_SN [%s]: ", sys_data.ise_SN);
    edit_string(&sys_data.ise_SN[0], MAX_ISE_SN);
    uprintf("       [%s]\r\n", sys_data.ise_SN);

    sys_data.PT_Cal_date[10] = 0;       // THOM BUG FIX

    uprintf("PT_Cal_date [%s]: ", sys_data.PT_Cal_date);
    edit_string(&sys_data.PT_Cal_date[0], MAX_K0_CAL_DATE);
    uprintf("            [%s]\r\n", sys_data.PT_Cal_date);




    for(indx=0; indx<NUMOF_FP_CAL_FIELDS; indx++)   // MAX_NUMOF_FP_CAL_FIELDS=12, NUMOF_K2_CAL_FIELDS=7    // defd in system.h
    {
        uprintf("Enter Fp C%u  [%e]: ", indx, sys_data.fP_Cal[indx]);
        ftemp = sys_data.fP_Cal[indx];
        edit_float(&sys_data.fP_Cal[indx], -500.0, 500.0);
        if(ftemp != sys_data.fP_Cal[indx])
            uprintf("             [%e]\r\n", indx, sys_data.fP_Cal[indx]);
    }

    for(indx=0; indx<NUMOF_K2_CAL_FIELDS; indx++)       // MAX_NUMOF_K2_CAL_FIELDS=6, NUMOF_K2_CAL_FIELDS=4
    {
        uprintf("Enter K2 C%u  [%e]: ", indx, sys_data.K2_Cal[indx]);
        ftemp = sys_data.K2_Cal[indx];
        edit_float(&sys_data.K2_Cal[indx], -500, 500);
        if(ftemp != sys_data.K2_Cal[indx])
            uprintf("             [%e]\r\n", indx, sys_data.K2_Cal[indx]);
    }


    uprintf("k0_Cal_date [%s]: ", sys_data.k0_Cal_date);
    edit_string(&sys_data.k0_Cal_date[0], MAX_K0_CAL_DATE);
    uprintf("            [%s]\r\n", sys_data.k0_Cal_date);

    uprintf("Enter k0_HCL  [%e]: ", sys_data.k0_HCL);
    ftemp = sys_data.k0_HCL;
    edit_float(&sys_data.k0_HCL, -500, 500);
    if(ftemp != sys_data.k0_HCL)
        uprintf("          [%e]\r\n", sys_data.k0_HCL);

    uprintf("Enter k0_SW  [%e]: ", sys_data.k0_SW);
    ftemp = sys_data.k0_SW;
    edit_float(&sys_data.k0_SW, -500, 500);
    if(ftemp != sys_data.k0_SW)
        uprintf("         [%e]\r\n", sys_data.k0_SW);

    uprintf("Enter k0std_SW  [%e]: ", sys_data.k0std_SW);
    ftemp = sys_data.k0std_SW;
    edit_float(&sys_data.k0std_SW, -500, 500);
    if(ftemp != sys_data.k0std_SW)
        uprintf("             [%e]\r\n", sys_data.k0std_SW);

    uprintf("service_date [%s]: ", sys_data.service_date);
    edit_string(&sys_data.service_date[0], MAX_SERVICE_DATE);
    uprintf("             [%s]\r\n", sys_data.service_date);

    eeprom_sys_data_store();        // New 5 Sep 2023

}

typedef struct tChooseList
{
    char    *lbl;
    int     val;
} tChooseList;

tChooseList OPTodeList[] = {{"Uart3 driver not", INST_OPTODE_NOTDEFD},
                            {"Aanderaa Optode",  INST_OPTODE},
                            {"Seabird OCR-504",  INST_OCR504},
                            {"NanoFET",          INST_NANOFET},
                            {"Pico pH",          INST_PICOPH} };

tChooseList CTDList[]    = {{ "type not",        INST_CTD_NOTDEFD },
                            { "SBE37 MicroCat",  INST_SBE37_MICROCAT },
                            { "Aanderaa 5860",   INST_AANDERAA_5860 } };

tChooseList TimeStampList[]={{"MM/DD/YYYY HH:MM:SS", TYPE_US_DATETIME },
                            { "MM/DD/YYYY HH:MM:SS", TYPE_US_DATETIME },
                            { "Epoch millisec",      TYPE_EPOCH_MSEC } };

int BaudRateList[] =        { 9600, 4800, 9600, 19200,  38400, 57600, 115200, 230400, 460800 };

#if USE_ADVANCED_MENU

void change_baud_rate(void)
{
    char input;

    //print out config menu
    prn_nl(); prn_nl(); prn_nl(); uprintf("Change Baud Rate - select baud menu item, change terminal baud rate, then hit 'V' to verify, sleep and wakeup");
    int optIdx = 1;
    prn_nl(); uprintf("V -- to verify");
    while (optIdx <= 8)
    {
        prn_nl(); uprintf("%d -- %u", optIdx, BaudRateList[optIdx]);
        optIdx++;
    }
    prn_nl(); uprintf("9 -- Exit");
    prn_nl(); uprintf("Enter Selection [9]: ");

    // Get user's selection with a timeout
    UARTFlushRx();
    while(1)
    {
        if( UARTRxBytesAvail() )
        {
            input = get_key();
            break;
        }
    }

    switch(input)
    {
        case 'V':
        case 'v':
            uprintf("\r\nBaud rate verify %u\r\n", sys_data.baud_rate);
            break;
        case '1' : case '2' : case '3': case '4': case'5': case'6': case'7': case'8':
            // 460800
            input -= '0';
            if (input > 0 && input < 9)
                sys_data.baud_rate = BaudRateList[input];
                uprintf("baud rate = %u\r\n", sys_data.baud_rate);
                wait_consoleTx();
                UARTStdioConfig(0, sys_data.baud_rate, 16000000);
            break;
        default :
            // Write the sys_data struct into EEPROM.
            if(eeprom_sys_data_store())
            {
                prn_nl(); prn_nl(); uprintf("Error storing system data."); prn_nl();
            }
            else
            {
                prn_nl(); prn_nl(); uprintf("System data stored.  -- Press enter to bring up main menu"); prn_nl();
            }
            break;
    }
}
#endif


// 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;
    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, f_size(&fileObject));
        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)                  prn_nl();
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1 || BOARD_MSC == 2 // 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  || BOARD_MSC == 2 || BOARD_NANOFET >= 1 // Not available on nanoFET, but we allow config - will measure as 0.0.  Glider usecase, MFET/NanoFET same data 6 Sept 2023
    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) prn_nl();

    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  || BOARD_MSC == 2  // 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  || BOARD_MSC == 2  // 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) prn_nl();

    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) prn_nl();

#if BOARD_MPHOX >= 1 || BOARD_MFET >= 1  || BOARD_MSC == 2  // 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_UART3_INST]);
    //if(writeFlg==1) sd_fprintf(&fileObject, "%sV -- Optode                   = %u\r\n", padString, sys_data.data_cfg[CFG_UART3_INST]);
    if(sys_data.data_cfg[CFG_UART3_INST] == INST_OPTODE_NOTDEFD)
    {
        if(printFlg==1)                 uprintf("%sV -- Optode port Uart3 driver = %u\r\n", padString, sys_data.data_cfg[CFG_UART3_INST]);
        if(writeFlg==1) sd_fprintf(&fileObject, "%sV -- Optode port Uart3 driver = %u\r\n", padString, sys_data.data_cfg[CFG_UART3_INST]);
    }
    if(sys_data.data_cfg[CFG_UART3_INST] == INST_OPTODE)
    {
        if(printFlg==1)                 uprintf("%sV -- Optode 4831              = %u\r\n", padString, sys_data.data_cfg[CFG_UART3_INST]);
        if(writeFlg==1) sd_fprintf(&fileObject, "%sV -- Optode 4831              = %u\r\n", padString, sys_data.data_cfg[CFG_UART3_INST]);
    }
    if(sys_data.data_cfg[CFG_UART3_INST] == INST_OCR504)
    {
        if(printFlg==1)                 uprintf("%sV -- OCR-504                  = %u\r\n", padString, sys_data.data_cfg[CFG_UART3_INST]);
        if(writeFlg==1) sd_fprintf(&fileObject, "%sV -- OCR-504                  = %u\r\n", padString, sys_data.data_cfg[CFG_UART3_INST]);
    }
    if(sys_data.data_cfg[CFG_UART3_INST] == INST_NANOFET)
    {
        if(printFlg==1)                 uprintf("%sV -- NanoFET pH               = %u\r\n", padString, sys_data.data_cfg[CFG_UART3_INST]);
        if(writeFlg==1) sd_fprintf(&fileObject, "%sV -- NanoFET pH               = %u\r\n", padString, sys_data.data_cfg[CFG_UART3_INST]);
    }
    if(sys_data.data_cfg[CFG_UART3_INST] == INST_PICOPH)
    {
        if(printFlg==1)                 uprintf("%sV -- Pico pH                  = %u\r\n", padString, sys_data.data_cfg[CFG_UART3_INST]);
        if(writeFlg==1) sd_fprintf(&fileObject, "%sV -- Pico pH                  = %u\r\n", padString, sys_data.data_cfg[CFG_UART3_INST]);
    }

#endif
#if BOARD_MPHOX >= 1
    if( sys_data.data_cfg[CFG_UART4_INST] == INST_CTD_NOTDEFD)
    {
        if(printFlg==1)                 uprintf("%sW -- CTD port / Uart4 driver  = %u\r\n", padString, sys_data.data_cfg[CFG_UART4_INST] - INST_CTD_NOTDEFD);
        if(writeFlg==1) sd_fprintf(&fileObject, "%sW -- CTD port / Uart4 driver  = %u\r\n", padString, sys_data.data_cfg[CFG_UART4_INST] - INST_CTD_NOTDEFD);
    }
    if( sys_data.data_cfg[CFG_UART4_INST] == INST_SBE37_MICROCAT)
    {
        if(printFlg==1)                 uprintf("%sW -- CTD SBE37 MicroCat       = %u\r\n", padString, sys_data.data_cfg[CFG_UART4_INST] - INST_CTD_NOTDEFD);
        if(writeFlg==1) sd_fprintf(&fileObject, "%sW -- CTD SBE37 MicroCat       = %u\r\n", padString, sys_data.data_cfg[CFG_UART4_INST] - INST_CTD_NOTDEFD);
    }
    if( sys_data.data_cfg[CFG_UART4_INST] == INST_AANDERAA_5860)
    {
        if(printFlg==1)                 uprintf("%sW -- CTD Aanderaa 5860        = %u\r\n", padString, sys_data.data_cfg[CFG_UART4_INST] - INST_CTD_NOTDEFD);
        if(writeFlg==1) sd_fprintf(&fileObject, "%sW -- CTD Aanderaa 5860        = %u\r\n", padString, sys_data.data_cfg[CFG_UART4_INST] - INST_CTD_NOTDEFD);
    }
#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;
        }
    }

    if (retVal != 0)
    {
        uprintf("%s: line %d Returns void %d! ", __FUNCTION__, __LINE__, retVal);
        prn_nl();
    }
}

// added for commandline / m2m
void print_config(void)
{
    uprintf("sampnum=%u\r\n", sys_data.data_cfg[CFG_SAMPLE_NUM]);

    if( sys_data.data_cfg[CFG_TIMESTAMP] == 0 || sys_data.data_cfg[CFG_TIMESTAMP] == TYPE_US_DATETIME)
    {
        //uprintf("timestamp=%u  MM/DD/YY HH:MM:SS\r\n", sys_data.data_cfg[CFG_TIMESTAMP]);
        uprintf("timestamp=%u\r\n", sys_data.data_cfg[CFG_TIMESTAMP]);
    }
    if( sys_data.data_cfg[CFG_TIMESTAMP] == TYPE_EPOCH_MSEC)
    {
        //uprintf("timestamp=%u,  Epoch millisec\r\n", sys_data.data_cfg[CFG_TIMESTAMP]);
        uprintf("timestamp=%u\r\n", sys_data.data_cfg[CFG_TIMESTAMP]);
    }

    // prn_nl();
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1  || BOARD_MSC == 3  // Not available on nanoFET
    uprintf("vbat=%u", sys_data.data_cfg[CFG_VIN_BAT_VOLT]); prn_nl();
#endif

    uprintf("biaspos=%u", sys_data.data_cfg[CFG_BIAS_BAT_POS]);  prn_nl();
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1  || BOARD_MSC == 2 || BOARD_NANOFET >= 1 // Not available on nanoFET, but we allow config - will measure as 0.0.  Glider usecase, MFET/NanoFET same data 6 Sept 2023
    uprintf("biasneg=%u\r\n", sys_data.data_cfg[CFG_BIAS_BAT_NEG]);
#endif
    uprintf("brdtemp=%u\r\n", sys_data.data_cfg[CFG_BRD_TEMP]);

    uprintf("brdhumid=%u\r\n", sys_data.data_cfg[CFG_BRD_HUMIDITY]);

    uprintf("vtherm=%u\r\n", sys_data.data_cfg[CFG_V_THERMISTOR]);

    uprintf("vtherm_std=%u\r\n", sys_data.data_cfg[CFG_V_THERMISTOR_STD]);

    uprintf("tempc=%u\r\n", sys_data.data_cfg[CFG_CALC_TEMP]);

#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1  || BOARD_MSC == 2  // Not available on nanoFET
    uprintf("vrsi=%u\r\n", sys_data.data_cfg[CFG_VRSI]);

    uprintf("vrsi_std=%u\r\n", sys_data.data_cfg[CFG_VRSI_STD]);

    uprintf("ph_vrsi=%u\r\n", sys_data.data_cfg[CFG_CALC_PH_VRSI]);
#endif

    uprintf("vrse=%u\r\n", sys_data.data_cfg[CFG_VRSE]);

    uprintf("vrse_std=%u\r\n", sys_data.data_cfg[CFG_VRSE_STD]);

    uprintf("ph_vrse=%u\r\n", sys_data.data_cfg[CFG_CALC_PH_VRSE]);


    uprintf("vk=%u\r\n", sys_data.data_cfg[CFG_V_COUNTER_ELECT]);

    uprintf("vk_std=%u\r\n", sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD]);

    uprintf("ik=%u\r\n", sys_data.data_cfg[CFG_I_COUNTER]);

    uprintf("ib=%u\r\n", sys_data.data_cfg[CFG_I_SUBSTRATE]);

    if (sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] == EXEC_DEPLOY)
    {
        uprintf("app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_DEPLOY");  prn_nl();
    }
    if (sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] == EXEC_FASTSAMP)
    {
        uprintf("app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_FASTSAMP");  prn_nl();
    }

    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]);
    if (sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] == EXEC_DEPLOY)
    {
        uprintf("app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_DEPLOY");  prn_nl();
    }
    if (sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] == EXEC_EDDY_COVARIANCE)
    {
        uprintf("app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_EDDY_COVARIANCE");  prn_nl();
    }
    if (sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] == EXEC_FASTSAMP)
    {
        uprintf("app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_FASTSAMP");  prn_nl();
    }
    uprintf("app_cfg[APPCFG_DEPLOY_UARTECHO] = %u\r\n", sys_data.app_cfg[APPCFG_DEPLOY_UARTECHO]);
    uprintf("app_cfg[APPCFG_FLOATMODE] = %u\r\n", sys_data.app_cfg[APPCFG_FLOATMODE]);
    uprintf("app_cfg[APPCFG_SER_LINETERM_MODE] = %u\r\n", sys_data.app_cfg[APPCFG_SER_LINETERM_MODE]);
    uprintf("app_cfg[APPCFG_SAMPLING_DIAG] = %u\r\n", sys_data.app_cfg[APPCFG_SAMPLING_DIAG]);

    uprintf("terminal_mode = %u\r\n", sys_data.terminal_mode);
    uprintf("autoSleepSec = %u\r\n", sys_data.autoSleepSec);
    uprintf("echo_flag = %u\r\n", sys_data.echo_flag);
}

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

}

int user_select_from_list(char *title, int numItems, tChooseList *cList, int initialIdx)
                          // char **list, int *values, int initialIdx)
{
    char input;
    int  selection = -1;
    char buffer[192];
    char optionBuf[92];
    int optIdx;
    int len;

    //  Select
    sprintf(buffer, "Select %s[%u]:", title, initialIdx - cList[0].val);

    optIdx = 1;
    while(optIdx <= numItems)
    {
        sprintf(optionBuf, " %d->%s,", optIdx, cList[optIdx].lbl);
        strcat(buffer, optionBuf);
        optIdx++;
    }
    len = strlen(buffer);
    buffer[len-1] = ' ';

    uprintf(buffer);
    sprintf(buffer, "Enter ");
    optIdx = 1;
    while(optIdx <= numItems)
    {
        sprintf(optionBuf, " %d or", optIdx);
        strcat(buffer, optionBuf);
        optIdx++;
    }
    strcat(buffer, " Ctrl-X <enter> to exit ");

    while(1)
    {
        if( UARTRxBytesAvail() )
        {
            input = get_key();
            prn_nl();
            if (input == 24)       // Ctrl-x
            {
                selection = 0;
            }
            else if (input >= '0')
            {
                input -= '0';
                if (input <= numItems)
                {
                    selection = input;
                }
            }
            if (selection >= 0)
            {
                uprintf("%s %s selected", title, cList[selection].lbl);  prn_nl();
                return cList[selection].val - cList[0].val;     // offset from the first list item
            }
            uprintf(buffer);
        }
    }
}


void user_select_ctd(void)
{
    sys_data.data_cfg[CFG_UART4_INST] = user_select_from_list("CTD port Uart4 Instrument driver", 2, CTDList, sys_data.data_cfg[CFG_UART4_INST]);
}

void user_select_optode(void)
{
    sys_data.data_cfg[CFG_UART3_INST] = user_select_from_list("Optode port Uart3 Instrument driver", 4, OPTodeList, sys_data.data_cfg[CFG_UART3_INST]);
}

void user_select_timestamp(void)
{
    sys_data.data_cfg[CFG_TIMESTAMP] = user_select_from_list("Timestamp type", 2, TimeStampList, sys_data.data_cfg[CFG_TIMESTAMP]);
}


void config_data_fields_all(int prnFlg)
{
    // 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_UART3_INST] = INST_OPTODE_NOTDEFD;
    sys_data.data_cfg[CFG_UART4_INST] = INST_CTD_NOTDEFD;
    //sys_data.data_cfg[CFG_OCR] = 0;
#endif

#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1  || BOARD_MSC == 2
    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  || BOARD_MSC == 2
    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  || BOARD_MSC == 2
    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  || BOARD_MSC == 2
    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  || BOARD_MSC == 2
    sys_data.data_cfg[CFG_UART3_INST] = INST_OPTODE;              // 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_UART4_INST] = INST_CTD_NOTDEFD;      //1;                 // W
#if BOARD_MPHOX >= 1  || BOARD_MSC == 2
    user_select_ctd();
#endif
    sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 1;            // Enable MicroSD card
    if(prnFlg == 1) uprintf("MicroSD card enabled");  prn_nl();
    sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_DEFAULT;
    if(prnFlg == 1) uprintf("Deploy mode sampling enabled, sleep between samples");  prn_nl();
}

void config_data_fields_none(int prnFlg)
{
    // 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_UART3_INST] = INST_OPTODE_NOTDEFD;              // y
    sys_data.data_cfg[CFG_UART4_INST] = INST_CTD_NOTDEFD;                 // z
    //sys_data.data_cfg[CFG_OCR] = 0;
    sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_DEPLOY;
}

void config_data_fields_glider(int prnFlg)
{
#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_UART3_INST] = INST_OPTODE_NOTDEFD;
    sys_data.data_cfg[CFG_UART4_INST] = INST_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  || BOARD_MSC == 2  // Not available on nanoFET
    sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 0;        // c  NEW, Vin is OFF for Glider use case
#endif
    sys_data.data_cfg[CFG_BIAS_BAT_POS] = 1;        // D  // NEW
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1  || BOARD_MSC == 2 // Not available on nanoFET, NEW 6 Sep 2023, allow for Glider config consistency between MFET/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_UART3_INST] = INST_OPTODE_NOTDEFD;              // v
    sys_data.data_cfg[CFG_UART4_INST] = INST_CTD_NOTDEFD;                 // w

    // restore sample rates 9 Apr 2022, prevent user error when switching between 'use case' configs that modify ADS1248 sampling parms
    if(prnFlg == 1) uprintf("Default ADS1248 sps and trial settings");  prn_nl();
    ads1248_sampling_defaults();
    sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_DEPLOY;
    if(prnFlg == 1) uprintf("Deploy mode sampling enabled, sleep between samples");  prn_nl();
}

void config_data_fields_mfet(int prnFlg)
{
#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_UART3_INST] = INST_OPTODE_NOTDEFD;
    sys_data.data_cfg[CFG_UART4_INST] = INST_CTD_NOTDEFD;
#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_UART3_INST] = INST_OPTODE_NOTDEFD;              // v
    sys_data.data_cfg[CFG_UART4_INST] = INST_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
    if(prnFlg == 1) uprintf("Default ADS1248 sps and trial settings");  prn_nl();
    ads1248_sampling_defaults();
    sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 1;            // Enable MicroSD card
    if(prnFlg == 1) uprintf("MicroSD card enabled");  prn_nl();
    sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_DEPLOY;
    if(prnFlg == 1) uprintf("Deploy mode sampling enabled, sleep between samples");  prn_nl();
}

void config_data_fields_mphox(int prnFlg)
{
#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_UART3_INST] = INST_OPTODE_NOTDEFD;
    sys_data.data_cfg[CFG_UART4_INST] = INST_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] = 0;        // 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] = 0;                // J
    sys_data.data_cfg[CFG_VRSI_STD] = 0;            //
    sys_data.data_cfg[CFG_CALC_PH_VRSI] = 0;        // 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_UART3_INST] = INST_OPTODE;// V
    //sys_data.data_cfg[CFG_OCR] = 0;
#endif
    sys_data.data_cfg[CFG_UART4_INST] = INST_CTD_NOTDEFD;
#if BOARD_MPHOX >= 1                                // Not available on nanoFET
    sys_data.data_cfg[CFG_UART4_INST] = INST_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
    if(prnFlg == 1) uprintf("MicroSD data logging is enabled");  prn_nl();
    if(prnFlg == 1) uprintf("Console echo of deployment commands is enabled");  prn_nl();

    // restore sample rates 9 Apr 2022, prevent user error when switching between 'use case' configs that modify ADS1248 sampling parms
    if(prnFlg == 1) uprintf("Default ADS1248 sps and trial settings");  prn_nl();
    ads1248_sampling_defaults();
    sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_DEPLOY;
    if(prnFlg == 1) uprintf("Deploy mode sampling mode enabled, sleep between samples");  prn_nl();
}

void config_data_fields_m2m_mphox(int prnFlg)
{
#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_UART3_INST] = INST_OPTODE_NOTDEFD;
    sys_data.data_cfg[CFG_UART4_INST] = INST_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  || BOARD_MSC == 2  // 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  || BOARD_MSC == 2  // 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  || BOARD_MSC == 2   // 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  || BOARD_MSC == 2  // 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_UART3_INST] = INST_OPTODE_NOTDEFD;              // v
    sys_data.data_cfg[CFG_UART4_INST] = INST_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
    if(prnFlg == 1) uprintf("MicroSD data logging is Disabled");  prn_nl();
    if(prnFlg == 1) uprintf("Console echo of deployment commands is disabled");  prn_nl();

    // restore sample rates 9 Apr 2022, prevent user error when switching between 'use case' configs that modify ADS1248 sampling parms
    if(prnFlg == 1) uprintf("Default ADS1248 sps and trial settings");  prn_nl();
    ads1248_sampling_defaults();
    sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_DEPLOY;
    if(prnFlg == 1) uprintf("Deploy mode sampling mode enabled, sleep between samples");  prn_nl();
}

void config_data_fields_nanofet(int prnFlg)
{
    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_UART3_INST] = INST_OPTODE_NOTDEFD;              // v
    sys_data.data_cfg[CFG_UART4_INST] = INST_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
    if(prnFlg == 1) uprintf("Default ADS1248 sps and trial settings");  prn_nl();
    ads1248_sampling_defaults();

    sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 0;            // Disable Datalogging, not present on nanoFET
    if(prnFlg == 1) uprintf("Data logging is Disabled");  prn_nl();
    sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_DEPLOY;
    if(prnFlg == 1) uprintf("Deploy mode sampling mode enabled, sleep between samples");  prn_nl();
}

void config_data_fields_wirewalker(int prnFlg)
{
#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_UART3_INST] = INST_OPTODE_NOTDEFD;
    sys_data.data_cfg[CFG_UART4_INST] = INST_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_UART3_INST] = INST_OPTODE_NOTDEFD;              // v
    sys_data.data_cfg[CFG_UART4_INST] = INST_CTD_NOTDEFD;                 // 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)

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

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

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

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


    sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 0;            // Disable MicroSD card
    if(prnFlg == 1) uprintf("MicroSD data logging is Disabled");  prn_nl();
    sys_data.data_cfg[CFG_TIMESTAMP] = TYPE_EPOCH_MSEC;   //Timestamp in Posix msec (Epoch msec)
    if(prnFlg == 1) uprintf("Timestamp in Epoch millisec format");  prn_nl();
    sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_FASTSAMP;
    if(prnFlg == 1) uprintf("Continuous sampling mode (databarf) enabled");  prn_nl();
}

// removing only the main menu
#if USE_CONFIGURATION_MENU >= 1

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

        //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");
        MAP_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  || BOARD_MSC == 2   // Not available on nanoFET
        uprintf("\r\n2 -- Use Case: GLIDER,          (A,B,C,D,L,M,R,T,U)"); // (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  removed E (bias neg) 13 Apr 2022
        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,F,G,H,I,L,M,R,T,U,V,W)");  //(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  removed E,J,K 13 Apr 2022
        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
        prn_nl();
        //if(sys_data.diag == 1) uprintf("\r\n8 -- get_sample() Flex Sampling = %u\t\t\t", sys_data.app_cfg[APPCFG_SAMP_FLEX]);

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

        // Get user's selection with a timeout
        UARTFlushRx();
        //timer = CONFIG_MENU_TIMEOUT_SEC + read_hib_rtcc();

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

            //if( timer <= read_hib_rtcc() ) 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  || BOARD_MSC == 2 || BOARD_NANOFET >= 1  // Not available on nanoFET  6 Sep 2023 - allow NanoFET config of negbias
                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  || BOARD_MSC == 2
                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  || BOARD_MSC == 2
                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  || BOARD_MSC == 2
                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  || BOARD_MSC == 2
                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  || BOARD_MSC == 2
                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  || BOARD_MSC == 2
                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  || BOARD_MSC == 2
                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_UART3_INST] = 0;
#endif
#if BOARD_MFET >= 1 || BOARD_MPHOX >= 1  || BOARD_MSC == 2
                user_select_optode();
                //sys_data.data_cfg[CFG_UART3_INST] = 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_UART3_INST] = INST_OPTODE_NOTDEFD;
                break;

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

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

            case '0':
                config_data_fields_none(1);
#ifdef NOCODE
                // 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_UART3_INST] = INST_OPTODE_NOTDEFD;              // y
                sys_data.data_cfg[CFG_UART4_INST] = INST_CTD_NOTDEFD;                 // z
                //sys_data.data_cfg[CFG_OCR] = 0;
                sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_DEPLOY;
#endif      //NOCODE
                break;

            case '1':
                // all set
                config_data_fields_all(1);
#ifdef NOCODE
                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_UART3_INST] = INST_OPTODE_NOTDEFD;
                sys_data.data_cfg[CFG_UART4_INST] = INST_CTD_NOTDEFD;
                //sys_data.data_cfg[CFG_OCR] = 0;
#endif

#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1  || BOARD_MSC == 2
                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  || BOARD_MSC == 2
                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  || BOARD_MSC == 2
                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  || BOARD_MSC == 2
                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  || BOARD_MSC == 2
                sys_data.data_cfg[CFG_UART3_INST] = INST_OPTODE;              // 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_UART4_INST] = INST_CTD_NOTDEFD;      //1;                 // W
#if BOARD_MPHOX >= 1  || BOARD_MSC == 2
                user_select_ctd();
#endif
                sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 1;            // Enable MicroSD card
                uprintf("MicroSD card enabled");  prn_nl();
                sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_DEFAULT;
                uprintf("Deploy mode sampling enabled, sleep between samples");  prn_nl();
#endif  //NOCODE
                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
                config_data_fields_glider(1);
#ifdef NOCODE
#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_UART3_INST] = INST_OPTODE_NOTDEFD;
                sys_data.data_cfg[CFG_UART4_INST] = INST_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   || BOARD_MSC == 2 // Not available on nanoFET
                sys_data.data_cfg[CFG_VIN_BAT_VOLT] = 0;        // c  NEW, Vin is OFF for Glider use case
#endif
                sys_data.data_cfg[CFG_BIAS_BAT_POS] = 1;        // D  // NEW
#if BOARD_MFET >= 2 || BOARD_MPHOX >= 1  || BOARD_MSC == 2 || BOARD_NANOFET >= 1 // Not available on nanoFET, NEW 6 Sep 2023, allow for Glider config consistency between MFET/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_UART3_INST] = INST_OPTODE_NOTDEFD;              // v
                sys_data.data_cfg[CFG_UART4_INST] = INST_CTD_NOTDEFD;                 // w

                // 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");  prn_nl();
                ads1248_sampling_defaults();
                sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_DEPLOY;
                uprintf("Deploy mode sampling enabled, sleep between samples");  prn_nl();
#endif  //NOCODE
                //TODO - add m2m setting?  Also, nanoFET should have uSD off
                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
                config_data_fields_mfet(1);
#ifdef NOCODE
#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_UART3_INST] = INST_OPTODE_NOTDEFD;
                sys_data.data_cfg[CFG_UART4_INST] = INST_CTD_NOTDEFD;
#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  || BOARD_MSC == 2   // 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  || BOARD_MSC == 2   // 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  || BOARD_MSC == 2   // 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_UART3_INST] = INST_OPTODE_NOTDEFD;              // v
                sys_data.data_cfg[CFG_UART4_INST] = INST_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");  prn_nl();
                ads1248_sampling_defaults();
                sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 1;            // Enable MicroSD card
                uprintf("MicroSD card enabled");  prn_nl();
                sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_DEPLOY;
                uprintf("Deploy mode sampling enabled, sleep between samples");  prn_nl();
#endif  //NOCODE
                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
                config_data_fields_mphox(1);
#ifdef NOCODE
#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_UART3_INST] = INST_OPTODE_NOTDEFD;
                sys_data.data_cfg[CFG_UART4_INST] = INST_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  || BOARD_MSC == 2  // 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   || BOARD_MSC == 2 // Not available on nanoFET
                sys_data.data_cfg[CFG_BIAS_BAT_NEG] = 0;        // 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  || BOARD_MSC == 2  // Not available on nanoFET
                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
#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  || BOARD_MSC == 2  // Not available on nanoFET
                sys_data.data_cfg[CFG_UART3_INST] = INST_OPTODE;              // V
                //sys_data.data_cfg[CFG_OCR] = 0;
#endif
                sys_data.data_cfg[CFG_UART4_INST] = INST_CTD_NOTDEFD;
#if BOARD_MPHOX >= 1  || BOARD_MSC == 2  // Not available on nanoFET
                sys_data.data_cfg[CFG_UART4_INST] = INST_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");  prn_nl();
                uprintf("Console echo of deployment commands is enabled");  prn_nl();

                // 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");  prn_nl();
                ads1248_sampling_defaults();
                sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_DEPLOY;
                uprintf("Deploy mode sampling mode enabled, sleep between samples");  prn_nl();
#endif  //NOCODE

                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
                config_data_fields_m2m_mphox(1);
#ifdef NOCODE
#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_UART3_INST] = INST_OPTODE_NOTDEFD;
                sys_data.data_cfg[CFG_UART4_INST] = INST_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  || BOARD_MSC == 2   // 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   || BOARD_MSC == 2  // 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  || BOARD_MSC == 2   // 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  || BOARD_MSC == 2  // 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_UART3_INST] = INST_OPTODE_NOTDEFD;              // v
                sys_data.data_cfg[CFG_UART4_INST] = INST_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");  prn_nl();
                uprintf("Console echo of deployment commands is disabled");  prn_nl();

                // 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");  prn_nl();
                ads1248_sampling_defaults();
                sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_DEPLOY;
                uprintf("Deploy mode sampling mode enabled, sleep between samples");  prn_nl();
#endif  //NOCODE
                break;


            case '6':
                //Use Case: nanoFET default, fields
                // A,B,D,F,G,H,I,L,R,S,T,U
                config_data_fields_nanofet(1);
#ifdef NOCODE
                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_UART3_INST] = INST_OPTODE_NOTDEFD;              // v
                sys_data.data_cfg[CFG_UART4_INST] = INST_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");  prn_nl();
                ads1248_sampling_defaults();

                sys_data.app_cfg[APPCFG_MICROSD_ENABLE] = 0;            // Disable Datalogging, not present on nanoFET
                uprintf("Data logging is Disabled");  prn_nl();
                sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_DEPLOY;
                uprintf("Deploy mode sampling mode enabled, sleep between samples");  prn_nl();
#endif  //NOCODE
                break;


            case '7':
                uprintf("\r\nMFET config and fast sample for wire walker");  prn_nl();
                // 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
#ifdef NOCODE
#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_UART3_INST] = INST_OPTODE_NOTDEFD;
                sys_data.data_cfg[CFG_UART4_INST] = INST_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_UART3_INST] = INST_OPTODE_NOTDEFD;              // v
                sys_data.data_cfg[CFG_UART4_INST] = INST_CTD_NOTDEFD;                 // 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:");  prn_nl();
                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);

                prn_nl();
                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");  prn_nl();
                sys_data.data_cfg[CFG_TIMESTAMP] = TYPE_EPOCH_MSEC;   //Timestamp in Posix msec (Epoch msec)
                uprintf("Timestamp in Epoch millisec format");  prn_nl();
                sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_FASTSAMP;
                uprintf("Continuous sampling mode (databarf) enabled");  prn_nl();
#endif
                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(eeprom_sys_data_store())                         //if(EEPROMProgram((uint32_t*) &sys_data, 0x400, (sizeof(sys_data) + 3) & ~3))
                {
                    prn_nl(); prn_nl();
                    uprintf("Error storing system data in EEPROM.");  prn_nl();
                }
                else
                {
                    prn_nl(); prn_nl();
                    uprintf("\r\n\r\nSystem data stored. (910) -- Press enter to bring up main menu");  prn_nl();
                }
                return;

        }  // end of switch statement

    }
}

#endif // USE_CONFIG_DATA_MENU >= 1

void print_all_metadata(void)
{
    time_t  current_time;

    current_time = read_hib_rtcc();

    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  || BOARD_MSC == 2
    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 BOARD_MSC == 3
    uprintf("\r\nEnter MSC3 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  || BOARD_MSC == 2 || BOARD_MSC == 3
    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 Package Fabrication notes [%s]: ", sys_data.package_fab_note);   // was board now package fab
    if( getUserInput(buff, MAX_PACKAGE_FABNOTE-1) )       // board fabricaton notes
    {
        strcpy(sys_data.package_fab_note, buff);
        uprintf("\r\nBoard Fab notes: %s\r\n", sys_data.package_fab_note);
    }

    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 sensor_SN[MAX_SENSOR_SN];  8
#if BOARD_MPHOX >= 1  || BOARD_MSC == 2 | BOARD_MFET >= 2 | BOARD_MSC == 3
    uprintf("\r\nEnter Sensor/Durafet Serial # [%s]: ", sys_data.sensor_SN);
#endif
#if BOARD_NANOFET >= 1
    uprintf("\r\nEnter Sensor Serial # [%s]: ", sys_data.sensor_SN);
#endif
    if( getUserInput(buff, MAX_SENSOR_SN) )       // was MAX_SENSOR_SN-1)
    {
        strcpy(sys_data.sensor_SN, buff);
        sys_data.sensor_SN[MAX_SENSOR_SN-1] = 0;
        uprintf("\r\nSensor Serial #: %s\r\n", sys_data.sensor_SN);
    }

    // new 20 Sep 2023
    uprintf("\r\nEnter ISFET Serial # [%s]: ", sys_data.isfet_SN);
    if( getUserInput(buff, MAX_ISFET_SN) )       //
    {
        strcpy(sys_data.isfet_SN, buff);
        sys_data.isfet_SN[MAX_ISFET_SN-1] = 0;
        uprintf("\r\nISFET Serial #: %s\r\n", sys_data.isfet_SN);
    }

    // new 20 Sep 2023
    uprintf("\r\nEnter ISE Serial # [%s]: ", sys_data.ise_SN);
    if( getUserInput(buff, MAX_ISE_SN) )       //
    {
        strcpy(sys_data.ise_SN, buff);
        sys_data.ise_SN[MAX_ISE_SN-1] = 0;
        uprintf("\r\nISE Serial #: %s\r\n", sys_data.ise_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  || BOARD_MSC == 2
    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 Pump1 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);
    }
    //char pump_SN[MAX_PUMP_SN];
    uprintf("\r\nEnter Pump2 Serial #  [%s]: ", sys_data.pump2_SN);
    if( getUserInput(buff, MAX_PUMP_SN-1) )       //
    {
        strcpy(sys_data.pump2_SN, buff);
        uprintf("\r\nPump Serial #: %s\r\n", sys_data.pump2_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)
{
    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;

    prn_nl();

    if(sys_data.data_cfg[CFG_SAMPLE_NUM] > 0)       { indx += sprintf((char*)&prnBuf[indx], " SampNum\t");     }
    if(sys_data.data_cfg[CFG_TIMESTAMP] == TYPE_US_DATETIME)
    {
        if(sys_data.data_cfg[CFG_TIMESTAMP] > 0)         { indx += sprintf((char*)&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((char*)&prnBuf[indx], "Epoch millisec\t");   }   //if(sys_data.data_cfg[CFG_TIMESTAMP] > 0)         { indx += sprintf((char*)&prnBuf[indx], "     Epoch milliseconds \t");   }
    }


//--- board sensors

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

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

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

//---

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


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



//---- External Instruments

    //if(sys_data.data_cfg[CFG_UART3_INST] > 0)           { indx += sprintf((char*)&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_UART3_INST] == INST_OPTODE)   { indx += sprintf((char*)&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_UART3_INST] == INST_OCR504)   { indx += sprintf((char*)&prnBuf[indx], "OCR_PN  \tChan_1 \tChan_2 \tChan_3 \tChan_4 \t");   }
    if(sys_data.data_cfg[CFG_UART3_INST] == INST_NANOFET)  { indx += sprintf((char*)&prnBuf[indx], " SampNum\tMM/DD/YYYY HH:MM:SS\tVbiasPos\t TC_cont\tHumidity\t  Vtherm\tVthrmStd\t TC_Dfet\t    Vrse\tVrse_std\t      Vk\t  Vk_std\t      Ik \t      Ib\t");   }
    if(sys_data.data_cfg[CFG_UART3_INST] == INST_PICOPH)   { indx += sprintf((char*)&prnBuf[indx], "MEA  \tChan \tSensors \tErrors \tdphi \t0 \t0 \t0 \tTC_samp \tTC_case \tsigInt \tambLight \tPres \tHum \tTO_res \t0 \t0 \tpH \t0 \t0 \t0 \t ");   }



    //if(sys_data.data_cfg[CFG_UART4_INST] != INST_CTD_NOTDEFD)  // if(sys_data.data_cfg[CFG_UART4_INST] > 0)
    //{                                             //01234567
    if((sys_data.data_cfg[CFG_UART4_INST]) == INST_SBE37_MICROCAT)      { indx += sprintf((char*)&prnBuf[indx], "TC_MCat\tCond\tPres\tpSal\tDate_MC\tTime_MC\t");   } // bug fix 19May2022 swapped pSal/Press"TC_MCat\tCond\tpSal\tPres\tDate_MC\tTime_MC\t");   }//if(ctd.type == 1)        // microCAT SBE37
    if((sys_data.data_cfg[CFG_UART4_INST]) == INST_AANDERAA_5860)       { indx += sprintf((char*)&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((char*)&prnBuf[indx], "OCR_PN  \tChan_1 \tChan_2 \tChan_3 \tChan_4 \t");   }

    if(sys_data.pump_seq_type == 2)                 { indx += sprintf((char*)&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((const char*)prnBuf, strlen((const char*)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, f_size(&fileObject));
        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((char*)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) )
    {
        strcpy(sys_data.deploy_note, noteBuf);
        byteCnt = strlen(sys_data.deploy_note);
        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
 *
 * returns: 0 for success,  1 if error writing file
 */

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, force writeFlg to zero
    {
        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", StringFromFresult(fresult)); prn_nl();
            //return 1;
            retVal = 1;
            writeFlg = 0;
        }

        // Seek to the end, to append our file
        fresult = f_lseek(&fileObject, f_size(&fileObject));
        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)   {               prn_nl();  prn_nl();  }
    if(writeFlg == 1)   sd_fprintf(&fileObject, "//++************** Deployment Settings ***************\r\n");
    if(printFlg == 1)   {               uprintf("//++************** Deployment Settings ***************");  prn_nl(); }

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


    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", sys_data.sampling_period); prn_nl();  }

    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");  prn_nl();   }
    }
    else
    {
        if(writeFlg == 1) sd_fprintf(&fileObject, "// Samples hour align:\tNo\r\n");
        if(printFlg == 1) {               uprintf("// Samples hour align:\tNo");  prn_nl();  }
    }

    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", sys_data.Vrsi_sps, sys_data.Vrsi_trials); prn_nl(); }

    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", sys_data.Vrse_sps, sys_data.Vrse_trials); prn_nl(); }

    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", sys_data.Vtherm_sps, sys_data.Vtherm_trials); prn_nl(); }

    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", sys_data.Ik_sps, sys_data.Ik_trials); prn_nl(); }

    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", sys_data.Vk_sps, sys_data.Vk_trials); prn_nl(); }

    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", sys_data.Ib_sps, sys_data.Ib_trials); prn_nl(); }

    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", sys_data.Vb_sps, sys_data.Vb_trials); prn_nl(); }

    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", sys_data.Vbias_sps, sys_data.Vbias_trials); prn_nl(); }




    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);  prn_nl(); }
    }

    //APFTODO, FINISH the prn_nl and make sure to audit the 'automatic' line substition

    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");  prn_nl();  }

        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");  prn_nl();  }

        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(printFlg == 1)                 uprintf("// Hey there, add pump sequencer metadata for new seq_type=%u\t%u\r\n", sys_data.pump_seq_type);


        if(writeFlg == 1) sd_fprintf(&fileObject, "// Pump seq type:   \t2PUMP_BEAMSV2\r\n");
        if(printFlg == 1) {               uprintf("// Pump seq type:   \t2PUMP_BEAMSV2");  prn_nl();  }

        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_PUMP_SELFCAL))
    {
        //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(printFlg == 1)                 uprintf("// Hey there, add pump sequencer metadata for new seq_type=%u\t%u\r\n", sys_data.pump_seq_type);


        if(writeFlg == 1) sd_fprintf(&fileObject, "// Pump seq type:   \t2PUMP_SELFCAL\r\n");
        if(printFlg == 1) {               uprintf("// Pump seq type:   \t2PUMP_SELFCAL");  prn_nl();  }

        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.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.dura_vin_min_volt);  // Low battery voltage:\t%.1f\r\n"
    if(printFlg == 1)                 uprintf("// Low battery voltage:\t%.1f\r\n", sys_data.dura_vin_min_volt);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// ISUS Vin Min voltage:\t%.1f\r\n", sys_data.isus_vin_min_volt);
    if(printFlg == 1)                 uprintf("// ISUS Vin Min voltage:\t%.1f\r\n", sys_data.isus_vin_min_volt);

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

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

    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);
    }

    //-- Cal Data, new 20Sep2023
    if(writeFlg == 1) sd_fprintf(&fileObject, "// Cal filename  \t%s\r\n", sys_data.cal_filename);
    if(printFlg == 1)                 uprintf("// Cal filename  \t%s\r\n", sys_data.cal_filename);

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


    if(writeFlg == 1) sd_fprintf(&fileObject, "// k2_C0         \t%e\r\n", sys_data.K2_Cal[0]);
    if(printFlg == 1)                 uprintf("// k2_C0         \t%e\r\n", sys_data.K2_Cal[0]);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// k2_C1         \t%e\r\n", sys_data.K2_Cal[1]);
    if(printFlg == 1)                 uprintf("// k2_C1         \t%e\r\n", sys_data.K2_Cal[1]);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// k2_C2         \t%e\r\n", sys_data.K2_Cal[2]);
    if(printFlg == 1)                 uprintf("// k2_C2         \t%e\r\n", sys_data.K2_Cal[2]);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// k2_C3         \t%e\r\n", sys_data.K2_Cal[3]);
    if(printFlg == 1)                 uprintf("// k2_C3         \t%e\r\n", sys_data.K2_Cal[3]);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// fP_0          \t%e\r\n", sys_data.fP_Cal[0]);
    if(printFlg == 1)                 uprintf("// fP_0          \t%e\r\n", sys_data.fP_Cal[0]);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// fP_1          \t%e\r\n", sys_data.fP_Cal[1]);
    if(printFlg == 1)                 uprintf("// fP_1          \t%e\r\n", sys_data.fP_Cal[1]);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// fP_2          \t%e\r\n", sys_data.fP_Cal[2]);
    if(printFlg == 1)                 uprintf("// fP_2          \t%e\r\n", sys_data.fP_Cal[2]);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// fP_3          \t%e\r\n", sys_data.fP_Cal[3]);
    if(printFlg == 1)                 uprintf("// fP_3          \t%e\r\n", sys_data.fP_Cal[3]);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// fP_4          \t%e\r\n", sys_data.fP_Cal[4]);
    if(printFlg == 1)                 uprintf("// fP_4          \t%e\r\n", sys_data.fP_Cal[4]);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// fP_5          \t%e\r\n", sys_data.fP_Cal[5]);
    if(printFlg == 1)                 uprintf("// fP_5          \t%e\r\n", sys_data.fP_Cal[5]);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// fP_6          \t%e\r\n", sys_data.fP_Cal[6]);
    if(printFlg == 1)                 uprintf("// fP_6          \t%e\r\n", sys_data.fP_Cal[6]);

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

    if(writeFlg == 1) sd_fprintf(&fileObject, "// k0_HCl        \t%e\r\n", sys_data.k0_HCL);
    if(printFlg == 1)                 uprintf("// k0_HCl        \t%e\r\n", sys_data.k0_HCL);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// k0_SW         \t%e\r\n", sys_data.k0_SW);
    if(printFlg == 1)                 uprintf("// k0_SW         \t%e\r\n", sys_data.k0_SW);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// k0std_SW      \t%e\r\n", sys_data.k0std_SW);
    if(printFlg == 1)                 uprintf("// k0std_SW      \t%e\r\n", sys_data.k0std_SW);

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

    //-- Cal File end

    if(writeFlg == 1)   sd_fprintf(&fileObject, "// Version Info: \t%s\r\n", versionStr(0));
    if(printFlg == 1)                   uprintf("// Version Info: \t%s\r\n", versionStr(0));


    // 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_MSC == 2 || 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, "// Sensor SN:     \t%s\r\n", sys_data.sensor_SN);
    if(printFlg == 1)                 uprintf("// Sensor SN:     \t%s\r\n", sys_data.sensor_SN);

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

    if(writeFlg == 1) sd_fprintf(&fileObject, "// ISE SN:        \t%s\r\n", sys_data.ise_SN);
    if(printFlg == 1)                 uprintf("// ISE SN:        \t%s\r\n", sys_data.ise_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, "// Pump1 SN:      \t%s\r\n", sys_data.pump_SN);
    if(printFlg == 1)                 uprintf("// Pump1 SN:      \t%s\r\n", sys_data.pump_SN);
    if(writeFlg == 1) sd_fprintf(&fileObject, "// Pump2 SN:      \t%s\r\n", sys_data.pump2_SN);
    if(printFlg == 1)                 uprintf("// Pump2 SN:      \t%s\r\n", sys_data.pump2_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.package_fab_note);
    if(printFlg == 1)                 uprintf("// Fab Note:      \t%s\r\n", sys_data.package_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);

    // write app config state  new 21 June 2022
    if(writeFlg == 1) sd_fprintf(&fileObject, "// MicroSD Logging:  \t%u\r\n", sys_data.app_cfg[APPCFG_MICROSD_ENABLE]);
    if(printFlg == 1)                 uprintf("// MicroSD Logging:  \t%u\r\n", sys_data.app_cfg[APPCFG_MICROSD_ENABLE]);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// Uart Echo:     \t%u\r\n", sys_data.app_cfg[APPCFG_DEPLOY_UARTECHO]);
    if(printFlg == 1)                 uprintf("// Uart Echo:     \t%u\r\n", sys_data.app_cfg[APPCFG_DEPLOY_UARTECHO]);

    if(writeFlg == 1) sd_fprintf(&fileObject, "// App Exec:      \t%u\r\n", sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI]);
    if(printFlg == 1)                 uprintf("// App Exec:      \t%u\r\n", sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI]);

    // 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, f_size(&fileObject));
        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_samp_data_structure(void)
{
    prn_nl();
    uprintf("// ------ sys_samp FRAM volatile data structure, size = %u ---- ", sizeof(struct systemSamplingData)); prn_nl();
    uprintf("// initNumBeg:      %08x    ", sys_samp.initNumBeg); prn_nl();
    uprintf("// state:           %u    0=IDLE,1=START,2=DEPLOYED,3=COMMAND", sys_samp.state); prn_nl();
    uprintf("// nextWakeUp:      %u    ", sys_samp.nextWakeUp); prn_nl();
    uprintf("// next_gdata_fptr: %u    ", sys_samp.next_gdata_fptr); prn_nl();
    uprintf("// current_sample:  %u    ", sys_samp.current_sample); prn_nl();
    uprintf("// AD24_std:        %8.6f    ", sys_samp.AD24_std); prn_nl();
    uprintf("// sensor_sal:      %8.4f    ", sys_samp.sensor_sal); prn_nl();
    uprintf("// spare1:          %8.4f    ", sys_samp.spare1); prn_nl();
    uprintf("// spare2:          %8.4f    ", sys_samp.spare2); prn_nl();
    uprintf("// spare3:          %8.4f    ", sys_samp.spare3); prn_nl();
    uprintf("// spare4:          %8.4f    ", sys_samp.spare4); prn_nl();
    uprintf("// pump_seq_state:  %u    ", sys_samp.pump_seq_state); prn_nl();
    uprintf("// pump1_cnt:       %u    ", sys_samp.pump1_cnt); prn_nl();
    uprintf("// pump2_cnt:       %u    ", sys_samp.pump2_cnt); prn_nl();
    uprintf("// start_pump_cntdown: %u    ", sys_samp.start_pump_cntdown); prn_nl();
    uprintf("// initNumEmd:      %08x    ", sys_samp.initNumEnd); prn_nl();
    prn_nl();


}

void print_sys_data_structure(void)
{
    prn_nl();
    uprintf("// ------ sys_data EEPROM structure, size = %u ---- ", sizeof(struct systemData)); prn_nl();
    uprintf("// firmware version: %s", sys_data.firmware_version);  prn_nl(); // new 10Oct2022
    uprintf("// sampling_period: %u", sys_data.sampling_period); prn_nl();
    uprintf("// chksum:          %u", sys_data.chksum); prn_nl();
    uprintf("// averaging_interval: %u", sys_data.averaging_interval); prn_nl();
    uprintf("// pump1_ontime: %u", sys_data.pump1_ontime); prn_nl();
    uprintf("// dura_vin_min_volt: %.2f", sys_data.dura_vin_min_volt); prn_nl();
    uprintf("// isus_vin_min_volt: %.2f", sys_data.isus_vin_min_volt); prn_nl();
    prn_nl();
    uprintf("// TCOffset: %.6f", sys_data.TCOffset); prn_nl();
    uprintf("// k0ext: %.6f", sys_data.k0ext); prn_nl();
    uprintf("// k0int: %.6f", sys_data.k0int); prn_nl();
    uprintf("// k2ext: %.6f", sys_data.k2ext); prn_nl();
    uprintf("// k2int: %.6f", sys_data.k2int); prn_nl();
    uprintf("// quadTherm_c0: %.11lf", sys_data.quadTherm_c0); prn_nl();
    uprintf("// quadTherm_c2: %.11lf", sys_data.quadTherm_c1); prn_nl();
    uprintf("// quadTherm_c3: %.11lf", sys_data.quadTherm_c2); prn_nl();
    uprintf("// quadTherm_c4: %.11lf", sys_data.quadTherm_c3); prn_nl();
    uprintf("// shTherm_A: %.11lf", sys_data.shTherm_A);  prn_nl();               // steinhart-hart coefficient A
    uprintf("// shTherm_B: %.11lf", sys_data.shTherm_B); prn_nl();                // steinhart-hart coefficient C
    uprintf("// shTherm_C: %.11lf", sys_data.shTherm_C);  prn_nl();               // steinhart-hart coefficient B
    uprintf("// default_sal: %.6f", sys_data.default_sal); prn_nl();
    uprintf("// sensor_sal: %.6f", sys_samp.sensor_sal); prn_nl();

    uprintf("//"); prn_nl();
    wait_consoleTx();

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

    uprintf("//");  prn_nl();
    wait_consoleTx();

    uprintf("// output: %u", sys_data.output); prn_nl();
    uprintf("// test_mode: %u", sys_data.test_mode); prn_nl();
    uprintf("// fast_mode: %u", sys_data.fast_mode); prn_nl();

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

    uprintf("// baud_rate: %u", sys_data.baud_rate); prn_nl();
    uprintf("//"); prn_nl();
    wait_consoleTx();

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

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

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

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

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

    wait_consoleTx();

    uprintf("// Cal filename: %s", sys_data.cal_filename); prn_nl();
    uprintf("// PT_Cal_date,%s", sys_data.PT_Cal_date); prn_nl();

    uprintf("// k2_C0,%e", sys_data.K2_Cal[0]); prn_nl();
    uprintf("// k2_C1,%e", sys_data.K2_Cal[1]); prn_nl();
    uprintf("// k2_C2,%e", sys_data.K2_Cal[2]); prn_nl();
    uprintf("// k2_C3,%e", sys_data.K2_Cal[3]); prn_nl();

    wait_consoleTx();

    uprintf("// fP_0,%e", sys_data.fP_Cal[0]); prn_nl();
    uprintf("// fP_1,%e", sys_data.fP_Cal[1]); prn_nl();
    uprintf("// fP_2,%e", sys_data.fP_Cal[2]); prn_nl();
    uprintf("// fP_3,%e", sys_data.fP_Cal[3]); prn_nl();
    uprintf("// fP_4,%e", sys_data.fP_Cal[4]); prn_nl();
    uprintf("// fP_5,%e", sys_data.fP_Cal[5]); prn_nl();
    uprintf("// fP_6,%e", sys_data.fP_Cal[6]); prn_nl();

    wait_consoleTx();

    uprintf("// k0_Cal_date,%s", sys_data.k0_Cal_date); prn_nl();
    uprintf("// k0_HCl,%e", sys_data.k0_HCL); prn_nl();
    uprintf("// k0_SW,%e", sys_data.k0_SW); prn_nl();
    uprintf("// k0std_SW,%e", sys_data.k0std_SW); prn_nl();
    uprintf("// service_date,%s", sys_data.service_date); prn_nl();

    wait_consoleTx();

    uprintf("// fileName: %s", sys_data.fileName); prn_nl();
    uprintf("// user: %s", sys_data.user); prn_nl();
    uprintf("// board_SN: %s", sys_data.board_SN); prn_nl();
    uprintf("// mcap_SN: %s", sys_data.mcap_SN); prn_nl();
    uprintf("// sensor_SN: %s", sys_data.sensor_SN); prn_nl();
    uprintf("// isfet_SN: %s", sys_data.isfet_SN); prn_nl();
    uprintf("// ise_SN: %s", sys_data.ise_SN); prn_nl();
    uprintf("// package_name: %s", sys_data.package_name); prn_nl();
    uprintf("// optode_SN: %s", sys_data.optode_SN); prn_nl();
    uprintf("// ctd_SN: %s", sys_data.ctd_SN); prn_nl();
    uprintf("// pump1_SN: %s", sys_data.pump_SN); prn_nl();
    uprintf("// pump2_SN: %s", sys_data.pump2_SN); prn_nl();
    uprintf("// deploy_note: %s", sys_data.deploy_note); prn_nl();
    uprintf("// package_fab_note: %s", sys_data.package_fab_note); prn_nl();
    uprintf("//"); prn_nl();

    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);


}

// THOM: 15 Dec 2025, A Bug exists when using the raw edit, the user MUST enter a value or it is zerod
uint8_t edit_uc(uint8_t *uint_data, uint8_t negLim, uint8_t posLim)
{
#ifdef OLDCODE
    uint32_t temp = 0;

    edit_uint(&temp, negLim, posLim);
    //edit_uint(uint_data, negLim, posLim);

    if(temp != *uint_data)
    //if(*uint_data)      //if the value was non-zero
    {
        *uint_data = (uint8_t)temp;
    }

    uprintf(" DBG: %u ", *uint_data);

    //return temp;
    return(*uint_data);
#endif

    unsigned int temp;
    char buff[24];

    temp = (unsigned int)*uint_data;
    if(getUserInput(buff, 20))
    {
        if(sscanf(buff, "%u", &temp) == 1)
        {
             *uint_data = (uint8_t)temp;
        }
    }
    return((uint8_t)temp);

}

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

    //temp = 0;       //THOM - shouldnt this be temp = *uint_data?
    temp = *uint_data;
    if(getUserInput(buff, 20))
    {
        if(sscanf(buff, "%u", &temp) == 1)
        {
             *uint_data = temp;

        }
    }
    return(temp);
}
#if 0
float edit_expfloat(float *float_data, float negLim, float posLim)
{
    float temp;
    char buff[24];

    //temp = 0.0;
    temp = *float_data;
    if(getUserInput(buff, 20))
    {
        if(sscanf(buff, "%e", &temp) == 1)
        {
             *float_data = temp;
             //return(temp);
        }
    }
    return(temp);
}
#endif
float edit_float(float *float_data, float negLim, float posLim)
{
    float temp;
    char buff[24];

    //temp = 0.0f;
    temp = *float_data;
    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;
    temp = *double_data;
    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;

    //microsd_logging();
    old = sys_data.app_cfg[APPCFG_MICROSD_ENABLE];
    if(sys_data.app_cfg[APPCFG_MICROSD_ENABLE] == 1)
    {
        prn_nl(); prn_nl();
        response = yesOrNoMenuChoice("Enable 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;
        }
        eeprom_sys_data_store();
    }
    else
    {
        prn_nl(); prn_nl();
        response = yesOrNoMenuChoice("Enable 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;
        }
        eeprom_sys_data_store();
    }

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

    if((old == 0) && (sys_data.app_cfg[APPCFG_MICROSD_ENABLE] == 1))
    {
        // init the filesystem
        if( uSD_present() )
        {
            prn_nl();
            uprintf("MicroSD card is Initialized...."); prn_nl();
            init_uSDCard();     //defd in microsd.c
            microSD_flg = 1;
        }
        else
        {
            prn_nl();
            uprintf("Error: MicroSD card is not detected"); prn_nl();
            microSD_flg = 0;
        }
    }

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


    // console echo enable/disable
    if(sys_data.app_cfg[APPCFG_DEPLOY_UARTECHO] == 1)
    {
        prn_nl(); prn_nl();
        response = yesOrNoMenuChoice("Enable 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;
        }
        eeprom_sys_data_store();
    }
    else
    {
        prn_nl(); prn_nl();
        response = yesOrNoMenuChoice("Enable 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;
        }
        eeprom_sys_data_store();
    }

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

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

    while(1)
    {
        uprintf("EXEC_DEPLOY is 0"); prn_nl();
        uprintf("EXEC_EDDY_COVARIANCE is 1"); prn_nl();
        uprintf("EXEC_FASTSAMP is 2"); prn_nl(); prn_nl();


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

        prn_nl();

        if(sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] > EXEC_MAXDEFD)
        {
            uprintf("\r\nEntry out of bounds, %u   Try again\r\n", sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI]);
            sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] = EXEC_DEFAULT;
            uprintf("app_cfg[APPCFG_EXEC_SWITCHERONI] [%u]: ", sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI]);
        }
        else
        {
            if(sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI] == EXEC_FASTSAMP)  // New 31 Oct 2023
            {
                sys_data.sampling_period = 2;       // if sampling_period = 0, then v5 does not RTC Wake properly
            }
            prn_nl(); prn_nl();
            break;
        }

    }

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

    //FLOATMODE is used for MSC3 application of pHFET-SOS  22 Aug 2024
    old = sys_data.app_cfg[APPCFG_FLOATMODE];
    if(sys_data.app_cfg[APPCFG_FLOATMODE] == 1)
    {
        prn_nl(); prn_nl();
        response = yesOrNoMenuChoice("Enable Argo Profiling Float Mode? (Y/N) [Y]? ", YES);
        if(response == YES)
        {
            sys_data.app_cfg[APPCFG_FLOATMODE] = 1;
        }
        else
        {
            sys_data.app_cfg[APPCFG_FLOATMODE] = 0;
        }

#if BOARD_MSC == 3
        apf_mosos_config();      // setup phfetsos config parms for float mode
#endif // #if BOARD_MSC == 3
        eeprom_sys_data_store();
    }
    else
    {
        prn_nl(); prn_nl();
        response = yesOrNoMenuChoice("Enable Argo Profiling Float Mode? (Y/N) [N]? ", NO);
        if(response == YES)
        {
            sys_data.app_cfg[APPCFG_FLOATMODE] = 1;
        }
        else
        {
            sys_data.app_cfg[APPCFG_FLOATMODE] = 0;
        }
#if BOARD_MSC == 3
        apf_mosos_config();      // setup phfetsos config parms for float mode
#endif // #if BOARD_MSC == 3
        eeprom_sys_data_store();
    }

    if(sys_data.app_cfg[APPCFG_FLOATMODE] == 1)
    {
        uprintf("Argo Profiling Float Mode Enabled"); prn_nl(); prn_nl();
    }
    else
    {
        uprintf("Argo Profiling Float Mode Disabled"); prn_nl(); prn_nl();
    }



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

    //FLOATMODE is used for MSC3 application of pHFET-SOS  22 Aug 2024
    old = sys_data.app_cfg[APPCFG_SER_LINETERM_MODE];
    if(sys_data.app_cfg[APPCFG_SER_LINETERM_MODE] == 1)
    {
        prn_nl(); prn_nl();
        response = yesOrNoMenuChoice("Enable cr (not cr-lf) newline mode? (Y/N) [Y]? ", YES);
        if(response == YES)
        {
            sys_data.app_cfg[APPCFG_SER_LINETERM_MODE] = 1;   //cr
        }
        else
        {
            sys_data.app_cfg[APPCFG_SER_LINETERM_MODE] = 0;   //cr-lf
        }
        eeprom_sys_data_store();
    }
    else
    {
        prn_nl(); prn_nl();
        response = yesOrNoMenuChoice("Enable cr (not cr-lf) newline mode? (Y/N) [N]? ", NO);
        if(response == YES)
        {
            sys_data.app_cfg[APPCFG_SER_LINETERM_MODE] = 1;
        }
        else
        {
            sys_data.app_cfg[APPCFG_SER_LINETERM_MODE] = 0;
        }
#if BOARD_MSC == 3
        apf_mosos_config();      // setup phfetsos config parms for float mode
#endif // #if BOARD_MSC == 3
        eeprom_sys_data_store();
    }

    if(sys_data.app_cfg[APPCFG_SER_LINETERM_MODE] == 1)
    {
        uprintf("cr newline mode"); prn_nl(); prn_nl();
    }
    else
    {
        uprintf("cr-lf newline mode"); prn_nl(); prn_nl();
    }
}


#if BOARD_MSC == 3
/*
 * setup mosos config parms for float mode
 * Note: this was early code and not tested.   Removed setting of APPCFG_SER_LINETERM_MODE 14 May 2025
 */
void apf_mosos_config(void)      // setup phfetsos config parms for float mode
{
    if(sys_data.app_cfg[APPCFG_FLOATMODE] == 1)
    {
        //sys_data.newline_mode = 1;
        //TODO config the commandline hibernate timeout to NEVER  THOM TODO 22 Aug 2024
        //sys_data.app_cfg[APPCFG_SER_LINETERM_MODE] = 1;  //cr   Commented out 14 May 2025
    }
    else
    {
        //sys_data.newline_mode = 0;
        //TODO config the commandline hibernate timeout to default (30sec)
        //sys_data.app_cfg[APPCFG_SER_LINETERM_MODE] = 0;  //cr-lf  Commented out 14 May 2025
    }
}
#endif // #if BOARD_MSC == 3

#if USE_CONFIGURATION_MENU >= 1
void copy_edit_sys_data_structure(void)
{
    uint32_t indx;
    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);
        cmd_period_get(); prn_nl();

        //uprintf("sampling_average [%u] sec: ", sys_data.chksum);  //APFTODO, commented out 19 Apr 2025
        //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("averaging_interval=%u", sys_data.averaging_interval);  prn_nl(); prn_nl();

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

#if BOARD_MSC == 3
        uprintf("dura_vin_min_volt [%.1f]: ", sys_data.dura_vin_min_volt);
        edit_float(&sys_data.dura_vin_min_volt, 5.5, 18.0);
        apf_vinmin_dura_get(); prn_nl();

        uprintf("isus_vin_min_volt [%.1f]: ", sys_data.isus_vin_min_volt);
        edit_float(&sys_data.isus_vin_min_volt, 5.5, 18.0);
        apf_vinmin_isus_get(); prn_nl();
#endif // BOARD_MSC == 3

        prn_nl(); prn_nl();
        response = yesOrNoMenuChoice("Re-visit? (Y/N) [N]? ", NO);
        if(response == NO)
            {
            prn_nl();
            break;
            }
    }
    //----
    while(1)
    {
        prn_nl();
        //uprintf("Second batch of 13 sys_data fields:"); prn_nl(); prn_nl();

        response = yesOrNoMenuChoice("Second batch of 13 sys_data fields for pH? (Y/N) [Y]? ", YES);
        if(response == NO)
            break;

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

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

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

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

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

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

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

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

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

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

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

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

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

        prn_nl(); prn_nl();
        response = yesOrNoMenuChoice("Re-visit? (Y/N) [N]? ", NO);
        if(response == NO)
            break;
    }
    //----
    while(1)
    {


        //uprintf("\r\nThird batch of 20 sys_data fields:\r\n\r\n");
        prn_nl();

        response = yesOrNoMenuChoice("Third batch of 20 sys_data fields for 24bit ADC? (Y/N) [Y]? ", YES);
        if(response == NO)
            break;

        prn_nl(); prn_nl();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        uprintf("Vb_trials=%u", sys_data.Vb_trials);
        edit_uint(&sys_data.Vb_trials, 0, 80);
        uprintf("Vb_trials=%u", sys_data.Vb_trials); prn_nl(); prn_nl();

        uprintf("Vbias_sps=%u", sys_data.Vbias_sps);
        edit_uint(&sys_data.Vbias_sps, 0, 80);
        uprintf("Vbias_sps=%u", sys_data.Vbias_sps); prn_nl(); prn_nl();

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

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

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

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

        prn_nl();

        response = yesOrNoMenuChoice("Fourth batch of 7 sys_data fields for modes and pump? (Y/N) [Y]? ", YES);
        if(response == NO)
            break;

        prn_nl(); prn_nl();

        uprintf("output [%u]: ", sys_data.output);
        {
            uint32_t temp;
            edit_uint(&temp, 0, 5);
            sys_data.output = (output_mode)temp;
        }

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

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

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

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

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

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

        prn_nl(); prn_nl();
        response = yesOrNoMenuChoice("Re-visit? (Y/N) [N]? ", NO);
        if(response == NO)
            break;
    }
    //----

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

        prn_nl();

        response = yesOrNoMenuChoice("Fifth batch of 32 sys_data fields for sample config? (Y/N) [Y]? ", YES);
        if(response == NO)
            break;

        prn_nl(); prn_nl();

        // 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_uc(&sys_data.data_cfg[CFG_SAMPLE_NUM], 0, 5);
        uprintf("sys_data.data_cfg[CFG_SAMPLE_NUM]=%u", sys_data.data_cfg[CFG_SAMPLE_NUM]); prn_nl(); prn_nl();

        uprintf("sys_data.data_cfg[CFG_TIMESTAMP] [%u]: ", sys_data.data_cfg[CFG_TIMESTAMP]);
        edit_uc(&sys_data.data_cfg[CFG_TIMESTAMP], 0, 5);
        uprintf("sys_data.data_cfg[CFG_TIMESTAMP]=%u", sys_data.data_cfg[CFG_TIMESTAMP]); prn_nl(); prn_nl();

        uprintf("sys_data.data_cfg[CFG_V_THERMISTOR] [%u]: ", sys_data.data_cfg[CFG_V_THERMISTOR]);
        edit_uc(&sys_data.data_cfg[CFG_V_THERMISTOR], 0, 5);
        uprintf("sys_data.data_cfg[CFG_V_THERMISTOR]=%u", sys_data.data_cfg[CFG_V_THERMISTOR]); prn_nl(); prn_nl();

        if(sys_data.data_cfg[CFG_V_THERMISTOR] == 0)
        {
            sys_data.data_cfg[CFG_V_THERMISTOR_STD] = 0;
        }
        else
        {
            uprintf("sys_data.data_cfg[CFG_V_THERMISTOR_STD] [%u]: ", sys_data.data_cfg[CFG_V_THERMISTOR_STD]);
            edit_uc(&sys_data.data_cfg[CFG_V_THERMISTOR_STD], 0, 5);
        }
        uprintf("sys_data.data_cfg[CFG_V_THERMISTOR_STD]=%u", sys_data.data_cfg[CFG_V_THERMISTOR_STD]); prn_nl(); prn_nl();

        uprintf("sys_data.data_cfg[CFG_CALC_TEMP] [%u]: ", sys_data.data_cfg[CFG_CALC_TEMP]);
        edit_uc(&sys_data.data_cfg[CFG_CALC_TEMP], 0, 5);
        uprintf("sys_data.data_cfg[CFG_CALC_TEMP]=%u", sys_data.data_cfg[CFG_CALC_TEMP]); prn_nl(); prn_nl();

        uprintf("sys_data.data_cfg[CFG_VRSI] [%u]: ", sys_data.data_cfg[CFG_VRSI]);
        edit_uc(&sys_data.data_cfg[CFG_VRSI], 0, 5);
        uprintf("sys_data.data_cfg[CFG_VRSI]=%u", sys_data.data_cfg[CFG_VRSI]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_VRSI_STD] [%u]: ", sys_data.data_cfg[CFG_VRSI_STD]);
        edit_uc(&sys_data.data_cfg[CFG_VRSI_STD], 0, 5);
        uprintf("sys_data.data_cfg[CFG_VRSI_STD]=%u", sys_data.data_cfg[CFG_VRSI_STD]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_CALC_PH_VRSI] [%u]: ", sys_data.data_cfg[CFG_CALC_PH_VRSI]);
        edit_uc(&sys_data.data_cfg[CFG_CALC_PH_VRSI], 0, 5);
        uprintf("sys_data.data_cfg[CFG_CALC_PH_VRSI]=%u", sys_data.data_cfg[CFG_CALC_PH_VRSI]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_VRSE] [%u]: ", sys_data.data_cfg[CFG_VRSE]);
        edit_uc(&sys_data.data_cfg[CFG_VRSE], 0, 5);
        uprintf("sys_data.data_cfg[CFG_VRSE]=%u", sys_data.data_cfg[CFG_VRSE]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_VRSE_STD] [%u]: ", sys_data.data_cfg[CFG_VRSE_STD]);
        edit_uc(&sys_data.data_cfg[CFG_VRSE_STD], 0, 5);
        uprintf("sys_data.data_cfg[CFG_VRSE_STD]=%u", sys_data.data_cfg[CFG_VRSE_STD]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_CALC_PH_VRSE] [%u]: ", sys_data.data_cfg[CFG_CALC_PH_VRSE]);
        edit_uc(&sys_data.data_cfg[CFG_CALC_PH_VRSE], 0, 5);
        uprintf("sys_data.data_cfg[CFG_CALC_PH_VRSE]=%u", sys_data.data_cfg[CFG_CALC_PH_VRSE]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_VRSI_BIASED] [%u]: ", sys_data.data_cfg[CFG_VRSI_BIASED]);
        edit_uc(&sys_data.data_cfg[CFG_VRSI_BIASED], 0, 5);
        uprintf("sys_data.data_cfg[CFG_VRSI_BIASED]=%u", sys_data.data_cfg[CFG_VRSI_BIASED]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_VRSI_BIASED_STD] [%u]: ", sys_data.data_cfg[CFG_VRSI_BIASED_STD]);
        edit_uc(&sys_data.data_cfg[CFG_VRSI_BIASED_STD], 0, 5);
        uprintf("sys_data.data_cfg[CFG_VRSI_BIASED_STD]=%u", sys_data.data_cfg[CFG_VRSI_BIASED_STD]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_VRSE_BIASED] [%u]: ", sys_data.data_cfg[CFG_VRSE_BIASED]);
        edit_uc(&sys_data.data_cfg[CFG_VRSE_BIASED], 0, 5);
        uprintf("sys_data.data_cfg[CFG_VRSE_BIASED]=%u", sys_data.data_cfg[CFG_VRSE_BIASED]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_VRSE_BIASED_STD] [%u]: ", sys_data.data_cfg[CFG_VRSE_BIASED_STD]);
        edit_uc(&sys_data.data_cfg[CFG_VRSE_BIASED_STD], 0, 5);
        uprintf("sys_data.data_cfg[CFG_VRSE_BIASED_STD]=%u", sys_data.data_cfg[CFG_VRSE_BIASED_STD]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_V_COUNTER_ELECT] [%u]: ", sys_data.data_cfg[CFG_V_COUNTER_ELECT]);
        edit_uc(&sys_data.data_cfg[CFG_V_COUNTER_ELECT], 0, 5);
        uprintf("sys_data.data_cfg[CFG_V_COUNTER_ELECT]=%u", sys_data.data_cfg[CFG_V_COUNTER_ELECT]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD] [%u]: ", sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD]);
        edit_uc(&sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD], 0, 5);
        uprintf("sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD]=%u", sys_data.data_cfg[CFG_V_COUNTER_ELECT_STD]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_I_COUNTER] [%u]: ", sys_data.data_cfg[CFG_I_COUNTER]);
        edit_uc(&sys_data.data_cfg[CFG_I_COUNTER], 0, 5);
        uprintf("sys_data.data_cfg[CFG_I_COUNTER]=%u", sys_data.data_cfg[CFG_I_COUNTER]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_I_SUBSTRATE] [%u]: ", sys_data.data_cfg[CFG_I_SUBSTRATE]);
        edit_uc(&sys_data.data_cfg[CFG_I_SUBSTRATE], 0, 5);
        uprintf("sys_data.data_cfg[CFG_I_SUBSTRATE]=%u", sys_data.data_cfg[CFG_I_SUBSTRATE]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_VIN_BAT_VOLT] [%u]: ", sys_data.data_cfg[CFG_VIN_BAT_VOLT]);
        edit_uc(&sys_data.data_cfg[CFG_VIN_BAT_VOLT], 0, 5);
        uprintf("sys_data.data_cfg[CFG_VIN_BAT_VOLT]=%u", sys_data.data_cfg[CFG_VIN_BAT_VOLT]); prn_nl(); prn_nl();



        uprintf("sys_data.data_cfg[CFG_BIAS_BAT_POS] [%u]: ", sys_data.data_cfg[CFG_BIAS_BAT_POS]);
        edit_uc(&sys_data.data_cfg[CFG_BIAS_BAT_POS], 0, 5);
        uprintf("sys_data.data_cfg[CFG_BIAS_BAT_POS]=%u", sys_data.data_cfg[CFG_BIAS_BAT_POS]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_BIAS_BAT_NEG] [%u]: ", sys_data.data_cfg[CFG_BIAS_BAT_NEG]);
        edit_uc(&sys_data.data_cfg[CFG_BIAS_BAT_NEG], 0, 5);
        uprintf("sys_data.data_cfg[CFG_BIAS_BAT_NEG]=%u", sys_data.data_cfg[CFG_BIAS_BAT_NEG]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_BRD_TEMP] [%u]: ", sys_data.data_cfg[CFG_BRD_TEMP]);
        edit_uc(&sys_data.data_cfg[CFG_BRD_TEMP], 0, 5);
        uprintf("sys_data.data_cfg[CFG_BRD_TEMP]=%u", sys_data.data_cfg[CFG_BRD_TEMP]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_BRD_HUMIDITY] [%u]: ", sys_data.data_cfg[CFG_BRD_HUMIDITY]);
        edit_uc(&sys_data.data_cfg[CFG_BRD_HUMIDITY], 0, 5);
        uprintf("sys_data.data_cfg[CFG_BRD_HUMIDITY]=%u", sys_data.data_cfg[CFG_BRD_HUMIDITY]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_UART3_INST] [%u]: ", sys_data.data_cfg[CFG_UART3_INST]);
        edit_uc(&sys_data.data_cfg[CFG_UART3_INST], 0, 5);
        uprintf("sys_data.data_cfg[CFG_UART3_INST]=%u", sys_data.data_cfg[CFG_UART3_INST]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_UART4_INST] [%u]: ", sys_data.data_cfg[CFG_UART4_INST]);
        edit_uc(&sys_data.data_cfg[CFG_UART4_INST], 0, 5);
        uprintf("sys_data.data_cfg[CFG_UART4_INST]=%u", sys_data.data_cfg[CFG_UART4_INST]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_SPARE1] [%u]: ", sys_data.data_cfg[CFG_SPARE1]);
        edit_uc(&sys_data.data_cfg[CFG_SPARE1], 0, 5);
        uprintf("sys_data.data_cfg[CFG_SPARE1]=%u", sys_data.data_cfg[CFG_SPARE1]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_SPARE2] [%u]: ", sys_data.data_cfg[CFG_SPARE2]);
        edit_uc(&sys_data.data_cfg[CFG_SPARE2], 0, 5);
        uprintf("sys_data.data_cfg[CFG_SPARE2]=%u", sys_data.data_cfg[CFG_SPARE2]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_SPARE3] [%u]: ", sys_data.data_cfg[CFG_SPARE3]);
        edit_uc(&sys_data.data_cfg[CFG_SPARE3], 0, 5);
        uprintf("sys_data.data_cfg[CFG_SPARE3]=%u", sys_data.data_cfg[CFG_SPARE3]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_SPARE4] [%u]: ", sys_data.data_cfg[CFG_SPARE4]);
        edit_uc(&sys_data.data_cfg[CFG_SPARE4], 0, 5);
        uprintf("sys_data.data_cfg[CFG_SPARE4]=%u", sys_data.data_cfg[CFG_SPARE4]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_SPARE5] [%u]: ", sys_data.data_cfg[CFG_SPARE5]);
        edit_uc(&sys_data.data_cfg[CFG_SPARE5], 0, 5);
        uprintf("sys_data.data_cfg[CFG_SPARE5]=%u", sys_data.data_cfg[CFG_SPARE5]); prn_nl(); prn_nl();


        uprintf("sys_data.data_cfg[CFG_SPARE6] [%u]: ", sys_data.data_cfg[CFG_SPARE6]);
        edit_uc(&sys_data.data_cfg[CFG_SPARE6], 0, 5);
        uprintf("sys_data.data_cfg[CFG_SPARE6]=%u", sys_data.data_cfg[CFG_SPARE6]); prn_nl(); prn_nl();

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

        response = yesOrNoMenuChoice("Sixth batch of 8 sys_data fields? (Y/N) [Y]? ", YES);
        if(response == NO)
            break;

        prn_nl(); prn_nl();


        // app cfg   MAX_NUMOF_APP_CONFIG_FIELDS
        uprintf("app_cfg[APPCFG_SAMPLING_DIAG] [%u]: ", sys_data.app_cfg[APPCFG_SAMPLING_DIAG]);
        edit_uc(&sys_data.app_cfg[APPCFG_SAMPLING_DIAG], 0, 1);
        uprintf("app_cfg[APPCFG_SAMPLING_DIAG]=%u", sys_data.app_cfg[APPCFG_SAMPLING_DIAG]); prn_nl(); prn_nl();

        uprintf("app_cfg[APPCFG_TEMPC_SH_ALG] [%u]: ", sys_data.app_cfg[APPCFG_TEMPC_SH_ALG]);
        edit_uc(&sys_data.app_cfg[APPCFG_TEMPC_SH_ALG], 0, 1);
        uprintf("app_cfg[APPCFG_TEMPC_SH_ALG]=%u", sys_data.app_cfg[APPCFG_TEMPC_SH_ALG]); prn_nl(); prn_nl();


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


        uprintf("app_cfg[APPCFG_MENU_LEVEL] [%u]: ", sys_data.app_cfg[APPCFG_MENU_LEVEL]);
        edit_uc(&sys_data.app_cfg[APPCFG_MENU_LEVEL], 0, 255);
        uprintf("app_cfg[APPCFG_MENU_LEVEL]=%u", sys_data.app_cfg[APPCFG_MENU_LEVEL]); prn_nl(); prn_nl();


        uprintf("app_cfg[APPCFG_DEPLOY_UARTECHO] [%u]: ", sys_data.app_cfg[APPCFG_DEPLOY_UARTECHO]);
        edit_uc(&sys_data.app_cfg[APPCFG_DEPLOY_UARTECHO], 0, 1);
        uprintf("app_cfg[APPCFG_DEPLOY_UARTECHO]=%u", sys_data.app_cfg[APPCFG_DEPLOY_UARTECHO]); prn_nl(); prn_nl();

        uprintf("app_cfg[APPCFG_EXEC_SWITCHERONI] [%u]: ", sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI]);
        edit_uc(&sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI], 0, 5);
        uprintf("app_cfg[APPCFG_EXEC_SWITCHERONI]=%u", sys_data.app_cfg[APPCFG_EXEC_SWITCHERONI]); prn_nl(); prn_nl();


        //sys_data.app_cfg[APPCFG_FLOATMODE] = 0;  // float mode off
        //sys_data.app_cfg[APPCFG_SER_LINETERM_MODE] = 0;  // cr-lf
        //sys_data.app_cfg[APPCFG_FILE_LINETERM_MODE] = 2;

        uprintf("app_cfg[APPCFG_FLOATMODE] [%u]: ", sys_data.app_cfg[APPCFG_FLOATMODE]);
        edit_uc(&sys_data.app_cfg[APPCFG_FLOATMODE], 0, 5);
        uprintf("app_cfg[APPCFG_FLOATMODE]=%u", sys_data.app_cfg[APPCFG_FLOATMODE]); prn_nl(); prn_nl();

        uprintf("app_cfg[APPCFG_SER_LINETERM_MODE] [%u]: ", sys_data.app_cfg[APPCFG_SER_LINETERM_MODE]);
        edit_uc(&sys_data.app_cfg[APPCFG_SER_LINETERM_MODE], 0, 5);
        uprintf("app_cfg[APPCFG_SER_LINETERM_MODE]=%u", sys_data.app_cfg[APPCFG_SER_LINETERM_MODE]); prn_nl(); prn_nl();

        uprintf("app_cfg[APPCFG_FILE_LINETERM_MODE] [%u]: ", sys_data.app_cfg[APPCFG_FILE_LINETERM_MODE]);
        edit_uc(&sys_data.app_cfg[APPCFG_FILE_LINETERM_MODE], 0, 5);
        uprintf("app_cfg[APPCFG_FILE_LINETERM_MODE]=%u", sys_data.app_cfg[APPCFG_FILE_LINETERM_MODE]); prn_nl(); prn_nl();

        // No edit for spare appcfg
        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);

        prn_nl(); prn_nl();
        response = yesOrNoMenuChoice("Re-visit? (Y/N) [N]? ", NO);
        if(response == NO)
            break;
    }
    //----

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

        response = yesOrNoMenuChoice("Seventh batch of 14 sys_data fields? (Y/N) [Y]? ", YES);
        if(response == NO)
            break;

        prn_nl(); prn_nl();


        {
            uint32_t temp;

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

            sys_data.GMT = (temp) ? (true) : (false);
        }


        {
            uint32_t temp;

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

            sys_data.sample_aligned = (temp) ? (true) : (false);
        }


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


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


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

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

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

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

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


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

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

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

#ifdef NOCODE
        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);
#endif

        prn_nl(); prn_nl();
        response = yesOrNoMenuChoice("Re-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");

        prn_nl();

        response = yesOrNoMenuChoice("Eighth batch of 7 sys_data pump sequencer fields? (Y/N) [Y]? ", YES);
        if(response == NO)
            break;

        prn_nl(); prn_nl();

        //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);
        uprintf("pump_seq_type=%u", sys_data.pump_seq_type); prn_nl(); prn_nl();

        //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);
        uprintf("sampleCnt_duty_on=%u", sys_data.sampleCnt_duty_on); prn_nl(); prn_nl();

        //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);
        uprintf("sampleCnt_duty_off=%u", sys_data.sampleCnt_duty_off); prn_nl(); prn_nl();

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

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

        //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);
        uprintf("pump1_ontime=%u", sys_data.pump1_ontime); prn_nl(); prn_nl();

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

        prn_nl(); prn_nl();
        response = yesOrNoMenuChoice("Re-visit? (Y/N) [N]? ", NO);
        if(response == NO)
            break;

    }




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

        response = yesOrNoMenuChoice("Nineth batch of 11 sys_data fields? (Y/N) [Y]? ", YES);
        if(response == NO)
            break;

        prn_nl(); prn_nl();

        uprintf("Filename [%s]: ", sys_data.fileName);
        edit_string(&sys_data.fileName[0], MAX_FILENAME_SIZE);
        uprintf("Filename=%s", sys_data.fileName); prn_nl(); prn_nl();

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

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

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

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

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

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

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

        uprintf("pump2_SN [%s]: ", sys_data.pump2_SN);
        edit_string(&sys_data.pump2_SN[0], MAX_PUMP_SN);
        uprintf("pump2_SN=%s", sys_data.pump2_SN); prn_nl(); prn_nl();

        uprintf("package_fab_note [%s]: ", sys_data.package_fab_note);
        edit_string(&sys_data.package_fab_note[0], MAX_BOARD_FABNOTE);
        uprintf("package_fab_note=%s", sys_data.package_fab_note); prn_nl(); prn_nl();

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

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

        prn_nl();
        uprintf("If the old firmware version is corrupt or shifted, please re-run QA routine or defaults command"); prn_nl(); prn_nl();

        prn_nl(); prn_nl();
        response = yesOrNoMenuChoice("Re-visit? (Y/N) [N]? ", NO);
        if(response == NO)
            break;
    }

    while(1)
    {
        //uprintf("\r\nTenth batch, Cal data, sys_data fields:\r\n\r\n");
        prn_nl();

        response = yesOrNoMenuChoice("Tenth batch, Cal data, sys_data fields? (Y/N) [Y]? ", YES);
        if(response == NO)
            break;

        prn_nl(); prn_nl();

        uprintf("cal_filename [%s]: ", sys_data.cal_filename);
        edit_string(&sys_data.cal_filename[0], MAX_CAL_FILENAME);
        uprintf("cal_filename=%s", sys_data.cal_filename); prn_nl(); prn_nl();

        uprintf("sensor_SN [%s]: ", sys_data.sensor_SN);
        edit_string(&sys_data.sensor_SN[0], MAX_SENSOR_SN);
        uprintf("sensor_SN=%s", sys_data.sensor_SN); prn_nl(); prn_nl();

        uprintf("isfet_SN [%s]: ", sys_data.isfet_SN);
        edit_string(&sys_data.isfet_SN[0], MAX_ISFET_SN);
        uprintf("isfet_SN=%s", sys_data.isfet_SN); prn_nl(); prn_nl();

        uprintf("ise_SN [%s]: ", sys_data.ise_SN);
        edit_string(&sys_data.ise_SN[0], MAX_ISE_SN);
        uprintf("ise_SN=%s", sys_data.ise_SN); prn_nl(); prn_nl();

        uprintf("PT_Cal_date [%s]: ", sys_data.PT_Cal_date);
        edit_string(&sys_data.PT_Cal_date[0], MAX_K0_CAL_DATE);
        uprintf("PT_Cal_date=%s", sys_data.PT_Cal_date); prn_nl(); prn_nl();

        for(indx=0; indx<MAX_NUMOF_K2_CAL_FIELDS; indx++)
        {
            uprintf("Enter K2_C%u  [%e]: ", indx, sys_data.K2_Cal[indx]);
            edit_float(&sys_data.K2_Cal[indx], -500, 500);
            uprintf("K2_C%u=%e", indx, sys_data.K2_Cal[indx]); prn_nl(); prn_nl();
        }

        for(indx=0; indx<MAX_NUMOF_FP_CAL_FIELDS; indx++)
        {
            uprintf("Enter Fp_%u  [%e]: ", indx, sys_data.fP_Cal[indx]);
            edit_float(&sys_data.fP_Cal[indx], -500, 500);
            uprintf("Fp_%u=%e", indx, sys_data.fP_Cal[indx]); prn_nl(); prn_nl();
        }

        uprintf("Enter k0_HCL  [%e]: ", sys_data.k0_HCL);
        edit_float(&sys_data.k0_HCL, -500, 500);
        uprintf("k0_HCL=%e", sys_data.k0_HCL); prn_nl(); prn_nl();

        uprintf("Enter k0_SW  [%e]: ", sys_data.k0_SW);
        edit_float(&sys_data.k0_SW, -500, 500);
        uprintf("k0_SW=%e", sys_data.k0_SW); prn_nl(); prn_nl();

        uprintf("Enter k0std_SW  [%e]: ", sys_data.k0std_SW);
        edit_float(&sys_data.k0std_SW, -500, 500);
        uprintf("k0std_SW=%e", sys_data.k0std_SW); prn_nl(); prn_nl();

        uprintf("k0_Cal_date [%s]: ", sys_data.k0_Cal_date);
        edit_string(&sys_data.k0_Cal_date[0], MAX_K0_CAL_DATE);
        uprintf("k0_Cal_date=%s", sys_data.k0_Cal_date); prn_nl(); prn_nl();

        uprintf("service_date [%s]: ", sys_data.service_date);
        edit_string(&sys_data.service_date[0], MAX_SERVICE_DATE);
        uprintf("service_date=%s", sys_data.service_date); prn_nl(); prn_nl();

        prn_nl(); prn_nl();
        response = yesOrNoMenuChoice("Re-visit? (Y/N) [N]? ", NO);
        if(response == NO)
            break;
    }



    prn_nl();
    uprintf("EEPROM sys_data copy/edit is complete");
    prn_nl(); prn_nl();

    //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();

    response = yesOrNoMenuChoice("Save changes to EEPROM? (Y/N) [N]? ", NO);
    if(response == YES)
    {
        eeprom_sys_data_store();
    }



}

#endif // 0
