<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using WasatchNET;

namespace WinFormDemo
{
    /// <summary>
    /// Encapsulates the mapping and updates of the TreeView on the main GUI.
    /// </summary>
    ///
    /// <remarks>
    /// It would be nice to use an enumeration instead of strings as the key 
    /// field, to reduce bugs introduced by typos and the like. It was for
    /// that reason that the enumeration WasatchNET.Opcodes was created.
    ///
    /// However, a significant number of settings aren't associated with a
    /// unique Opcode, but rather come from parsed ModelConfig, 
    /// FPGACompilationOptions etc. Maybe we'll make those into their own
    /// classes someday and we can add a little rigor here, but for now you
    /// get strings :-/
    /// </remarks>
    public class Settings
    {
        Dictionary<string, Tuple<TreeNode, string>> treeNodes = new Dictionary<string, Tuple<TreeNode, string>>();
        TreeView tv;
        Logger logger = Logger.getInstance();

        public delegate T MyDelegate<T>();
        AutoResetEvent autoResetEvent = new AutoResetEvent(true);

        public Settings(TreeView treeView)
        {
            tv = treeView;
            stubAll();
        }

        void stubAll()
        {
            // note that while TreeView nodes CAN be sorted, they currently AREN'T,
            // so insertion order is physical display order

            ////////////////////////////////////////////////////////////////////
            // EEPROM
            ////////////////////////////////////////////////////////////////////

            stub("serialNumber",                "EEPROM/Page 0/Serial Number");
            stub("model",                       "EEPROM/Page 0/Model");
            stub("baudRate",                    "EEPROM/Page 0/Baud Rate");
            stub("hasCooling",                  "EEPROM/Page 0/Features/Cooling");
            stub("hasBattery",                  "EEPROM/Page 0/Features/Battery");
            stub("hasLaser",                    "EEPROM/Page 0/Features/Laser");
            stub("excitationNM",                "EEPROM/Page 0/Excitation (nm)");
            stub("slitSizeUM",                  "EEPROM/Page 0/Slit Size (µm)");
            stub("startupIntegrationTimeMS",    "EEPROM/Page 0/Startup/Integration Time (ms)");
            stub("startupTemperatureDegC",      "EEPROM/Page 0/Startup/Temperature (°C)");
            stub("startupTriggerScheme",        "EEPROM/Page 0/Startup/Trigger Scheme");
            stub("detectorGain",                "EEPROM/Page 0/Detector Gain/value (InGaAs even pixels)");
            stub("detectorGainOdd",             "EEPROM/Page 0/Detector Gain/odd pixels (InGaAs only)");
            stub("detectorOffset",              "EEPROM/Page 0/Detector Offset/value (InGaAs even pixels)");
            stub("detectorOffsetOdd",           "EEPROM/Page 0/Detector Offset/odd pixels (InGaAs only)");

            for (int i = 0; i < 4; i++)
                stub("wavecalCoeff" + i,        "EEPROM/Page 1/Wavelength Calibration/Coeff" + i);
            for (int i = 0; i < 3; i++)
                stub("degCToDACCoeff" + i,      "EEPROM/Page 1/Detector TEC Calibration (°C->DAC)/Coeff" + i);
            stub("detectorTempMax",             "EEPROM/Page 1/Detector Temperature (°C)/Max");
            stub("detectorTempMin",             "EEPROM/Page 1/Detector Temperature (°C)/Min");
            for (int i = 0; i < 3; i++)
                stub("adcToDegCCoeff" + i,      "EEPROM/Page 1/Thermistor/Calibration (ADC->°C)/Coeff" + i);
            stub("thermistorResistanceAt298K",  "EEPROM/Page 1/Thermistor/Ω@298K");
            stub("thermistorBeta",              "EEPROM/Page 1/Thermistor/β");
            stub("calibrationDate",             "EEPROM/Page 1/Calibration/Date");
            stub("calibrationBy",               "EEPROM/Page 1/Calibration/By");
                                                
            stub("detector",                    "EEPROM/Page 2/Detector");
            stub("activePixelsHoriz",           "EEPROM/Page 2/Active Pixels/Horizontal");
            stub("activePixelsVert",            "EEPROM/Page 2/Active Pixels/Vertical");
            stub("minIntegrationTimeMS",        "EEPROM/Page 2/Integration Time (ms)/Min");
            stub("maxIntegrationTimeMS",        "EEPROM/Page 2/Integration Time (ms)/Max");
            stub("actualHoriz",                 "EEPROM/Page 2/Actual Pixels Horizontal");
            stub("ROIHorizStart",               "EEPROM/Page 2/ROI Horizontal/Start");
            stub("ROIHorizEnd",                 "EEPROM/Page 2/ROI Horizontal/End");
            for (int i = 1; i < 4; i++)
            {
                stub(String.Format("ROIVertRegion{0}Start", i), String.Format("EEPROM/Page 2/ROI Vertical Region {0}/Start", i));
                stub(String.Format("ROIVertRegion{0}End",   i), String.Format("EEPROM/Page 2/ROI Vertical Region {0}/End",   i));
            }
            for (int i = 0; i < 5; i++)
                stub("linearityCoeff" + i,      "EEPROM/Page 2/Linearity/Coeff" + i);

            stub("maxLaserPowerMW",             "EEPROM/Page 3/Laser Power (mW)/Max");
            stub("minLaserPowerMW",             "EEPROM/Page 3/Laser Power (mW)/Min");
            for (int i = 0; i < 3; i++)
                stub("laserPowerCoeff" + i,     "EEPROM/Page 3/Laser Power Calibration (% -> mW)/Coeff" + i);

            stub("userText",                    "EEPROM/Page 4/User Text");

            for (int i = 0; i < 15; i++)
                stub("badPixels" + i,           "EEPROM/Page 5/Bad Pixels/Index " + i);

            ////////////////////////////////////////////////////////////////////
            // FPGA Compilation Options
            ////////////////////////////////////////////////////////////////////

            stub("fpgaDataHeader",                "FPGA Compilation Options/Data Header");
            stub("fpgaHasCFSelect",               "FPGA Compilation Options/Has CF Select");
            stub("fpgaLaserType",                 "FPGA Compilation Options/Laser Type");
            stub("fpgaLaserControl",              "FPGA Compilation Options/Laser Control");
            stub("fpgaHasAreaScan",               "FPGA Compilation Options/Has Area Scan");
            stub("fpgaHasActualIntegTime",        "FPGA Compilation Options/Has Actual Integration Time");
            stub("fpgaHasHorizBinning",           "FPGA Compilation Options/Has Horiz Binning");
            stub("fpgaIntegrationTimeResolution", "FPGA Compilation Options/Integ Time Resolution");

            ////////////////////////////////////////////////////////////////////
            // Miscellaneous
            ////////////////////////////////////////////////////////////////////

            stub("featureBoardType",            "Features/Board Type");
            stub("featureDesc",                 "Features/Description");

            ////////////////////////////////////////////////////////////////////
            // Firmware Versions
            ////////////////////////////////////////////////////////////////////

            stub("firmwareRev",                 "Firmware/Microcontroller");
            stub("fpgaRev",                     "Firmware/FPGA");

            ////////////////////////////////////////////////////////////////////
            // Spectrometer State
            ////////////////////////////////////////////////////////////////////

            stub("integrationTimeMS",           "Spectrometer State/Acquisition/Integration Time (ms)");
            stub("actualIntegrationTimeUS",     "Spectrometer State/Acquisition/Integration/Actual (µs)");
            stub("frame",                       "Spectrometer State/Acquisition/Frame");
                                                
            stub("detectorTemperatureDegC",     "Spectrometer State/Detector/TEC/Temperature/°C");
            stub("detectorTemperatureRaw",      "Spectrometer State/Detector/TEC/Temperature/raw");
            stub("detectorTECEnabled",          "Spectrometer State/Detector/TEC/Enabled");
            stub("detectorTECSetpointDegC",     "Spectrometer State/Detector/TEC/Setpoint/°C");
            stub("detectorTECSetpointraw",      "Spectrometer State/Detector/TEC/Setpoint/raw");
            stub("detectorSensingThresholdEnabled","Spectrometer State/Detector/Sensing/Enabled");
            stub("detectorSensingThreshold",    "Spectrometer State/Detector/Sensing/Threshold");
            stub("horizBinning",                "Spectrometer State/Detector/Horizontal Binning/Mode");
                                                
            stub("laserEnabled",                "Spectrometer State/Laser/Enabled");
            stub("laserTemperatureDegC",        "Spectrometer State/Laser/TEC/Temperature (°C)");
            stub("laserTemperatureRaw",         "Spectrometer State/Laser/TEC/Temperature (raw)");
            stub("laserTemperatureSetpointRaw", "Spectrometer State/Laser/TEC/Setpoint (raw)"); 
            stub("laserModEnabled",             "Spectrometer State/Laser/Modulation/Enabled");
            stub("laserModDuration",            "Spectrometer State/Laser/Modulation/Duration (µs)");
            stub("laserModPeriod",              "Spectrometer State/Laser/Modulation/Period (µs)");
            stub("laserModPulseDelay",          "Spectrometer State/Laser/Modulation/Pulse Delay (µs)");
            stub("laserModPulseWidth",          "Spectrometer State/Laser/Modulation/Pulse Width (µs)");
        stub("laserModLinkedToIntegrationTime", "Spectrometer State/Laser/Modulation/Linked to Integration Time");
            stub("laserRampingEnabled",         "Spectrometer State/Laser/Ramping Enabled");
            stub("laserInterlock",              "Spectrometer State/Laser/Interlock");

            stub("adcSelection",                "Spectrometer State/Selected ADC");<commit_msg>demo-only (detectorTECSetpointRaw typo)<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using WasatchNET;

namespace WinFormDemo
{
    /// <summary>
    /// Encapsulates the mapping and updates of the TreeView on the main GUI.
    /// </summary>
    ///
    /// <remarks>
    /// It would be nice to use an enumeration instead of strings as the key 
    /// field, to reduce bugs introduced by typos and the like. It was for
    /// that reason that the enumeration WasatchNET.Opcodes was created.
    ///
    /// However, a significant number of settings aren't associated with a
    /// unique Opcode, but rather come from parsed ModelConfig, 
    /// FPGACompilationOptions etc. Maybe we'll make those into their own
    /// classes someday and we can add a little rigor here, but for now you
    /// get strings :-/
    /// </remarks>
    public class Settings
    {
        Dictionary<string, Tuple<TreeNode, string>> treeNodes = new Dictionary<string, Tuple<TreeNode, string>>();
        TreeView tv;
        Logger logger = Logger.getInstance();

        public delegate T MyDelegate<T>();
        AutoResetEvent autoResetEvent = new AutoResetEvent(true);

        public Settings(TreeView treeView)
        {
            tv = treeView;
            stubAll();
        }

        void stubAll()
        {
            // note that while TreeView nodes CAN be sorted, they currently AREN'T,
            // so insertion order is physical display order

            ////////////////////////////////////////////////////////////////////
            // EEPROM
            ////////////////////////////////////////////////////////////////////

            stub("serialNumber",                "EEPROM/Page 0/Serial Number");
            stub("model",                       "EEPROM/Page 0/Model");
            stub("baudRate",                    "EEPROM/Page 0/Baud Rate");
            stub("hasCooling",                  "EEPROM/Page 0/Features/Cooling");
            stub("hasBattery",                  "EEPROM/Page 0/Features/Battery");
            stub("hasLaser",                    "EEPROM/Page 0/Features/Laser");
            stub("excitationNM",                "EEPROM/Page 0/Excitation (nm)");
            stub("slitSizeUM",                  "EEPROM/Page 0/Slit Size (µm)");
            stub("startupIntegrationTimeMS",    "EEPROM/Page 0/Startup/Integration Time (ms)");
            stub("startupTemperatureDegC",      "EEPROM/Page 0/Startup/Temperature (°C)");
            stub("startupTriggerScheme",        "EEPROM/Page 0/Startup/Trigger Scheme");
            stub("detectorGain",                "EEPROM/Page 0/Detector Gain/value (InGaAs even pixels)");
            stub("detectorGainOdd",             "EEPROM/Page 0/Detector Gain/odd pixels (InGaAs only)");
            stub("detectorOffset",              "EEPROM/Page 0/Detector Offset/value (InGaAs even pixels)");
            stub("detectorOffsetOdd",           "EEPROM/Page 0/Detector Offset/odd pixels (InGaAs only)");

            for (int i = 0; i < 4; i++)
                stub("wavecalCoeff" + i,        "EEPROM/Page 1/Wavelength Calibration/Coeff" + i);
            for (int i = 0; i < 3; i++)
                stub("degCToDACCoeff" + i,      "EEPROM/Page 1/Detector TEC Calibration (°C->DAC)/Coeff" + i);
            stub("detectorTempMax",             "EEPROM/Page 1/Detector Temperature (°C)/Max");
            stub("detectorTempMin",             "EEPROM/Page 1/Detector Temperature (°C)/Min");
            for (int i = 0; i < 3; i++)
                stub("adcToDegCCoeff" + i,      "EEPROM/Page 1/Thermistor/Calibration (ADC->°C)/Coeff" + i);
            stub("thermistorResistanceAt298K",  "EEPROM/Page 1/Thermistor/Ω@298K");
            stub("thermistorBeta",              "EEPROM/Page 1/Thermistor/β");
            stub("calibrationDate",             "EEPROM/Page 1/Calibration/Date");
            stub("calibrationBy",               "EEPROM/Page 1/Calibration/By");
                                                
            stub("detector",                    "EEPROM/Page 2/Detector");
            stub("activePixelsHoriz",           "EEPROM/Page 2/Active Pixels/Horizontal");
            stub("activePixelsVert",            "EEPROM/Page 2/Active Pixels/Vertical");
            stub("minIntegrationTimeMS",        "EEPROM/Page 2/Integration Time (ms)/Min");
            stub("maxIntegrationTimeMS",        "EEPROM/Page 2/Integration Time (ms)/Max");
            stub("actualHoriz",                 "EEPROM/Page 2/Actual Pixels Horizontal");
            stub("ROIHorizStart",               "EEPROM/Page 2/ROI Horizontal/Start");
            stub("ROIHorizEnd",                 "EEPROM/Page 2/ROI Horizontal/End");
            for (int i = 1; i < 4; i++)
            {
                stub(String.Format("ROIVertRegion{0}Start", i), String.Format("EEPROM/Page 2/ROI Vertical Region {0}/Start", i));
                stub(String.Format("ROIVertRegion{0}End",   i), String.Format("EEPROM/Page 2/ROI Vertical Region {0}/End",   i));
            }
            for (int i = 0; i < 5; i++)
                stub("linearityCoeff" + i,      "EEPROM/Page 2/Linearity/Coeff" + i);

            stub("maxLaserPowerMW",             "EEPROM/Page 3/Laser Power (mW)/Max");
            stub("minLaserPowerMW",             "EEPROM/Page 3/Laser Power (mW)/Min");
            for (int i = 0; i < 3; i++)
                stub("laserPowerCoeff" + i,     "EEPROM/Page 3/Laser Power Calibration (% -> mW)/Coeff" + i);

            stub("userText",                    "EEPROM/Page 4/User Text");

            for (int i = 0; i < 15; i++)
                stub("badPixels" + i,           "EEPROM/Page 5/Bad Pixels/Index " + i);

            ////////////////////////////////////////////////////////////////////
            // FPGA Compilation Options
            ////////////////////////////////////////////////////////////////////

            stub("fpgaDataHeader",                "FPGA Compilation Options/Data Header");
            stub("fpgaHasCFSelect",               "FPGA Compilation Options/Has CF Select");
            stub("fpgaLaserType",                 "FPGA Compilation Options/Laser Type");
            stub("fpgaLaserControl",              "FPGA Compilation Options/Laser Control");
            stub("fpgaHasAreaScan",               "FPGA Compilation Options/Has Area Scan");
            stub("fpgaHasActualIntegTime",        "FPGA Compilation Options/Has Actual Integration Time");
            stub("fpgaHasHorizBinning",           "FPGA Compilation Options/Has Horiz Binning");
            stub("fpgaIntegrationTimeResolution", "FPGA Compilation Options/Integ Time Resolution");

            ////////////////////////////////////////////////////////////////////
            // Miscellaneous
            ////////////////////////////////////////////////////////////////////

            stub("featureBoardType",            "Features/Board Type");
            stub("featureDesc",                 "Features/Description");

            ////////////////////////////////////////////////////////////////////
            // Firmware Versions
            ////////////////////////////////////////////////////////////////////

            stub("firmwareRev",                 "Firmware/Microcontroller");
            stub("fpgaRev",                     "Firmware/FPGA");

            ////////////////////////////////////////////////////////////////////
            // Spectrometer State
            ////////////////////////////////////////////////////////////////////

            stub("integrationTimeMS",           "Spectrometer State/Acquisition/Integration Time (ms)");
            stub("actualIntegrationTimeUS",     "Spectrometer State/Acquisition/Integration/Actual (µs)");
            stub("frame",                       "Spectrometer State/Acquisition/Frame");
                                                
            stub("detectorTemperatureDegC",     "Spectrometer State/Detector/TEC/Temperature/°C");
            stub("detectorTemperatureRaw",      "Spectrometer State/Detector/TEC/Temperature/raw");
            stub("detectorTECEnabled",          "Spectrometer State/Detector/TEC/Enabled");
            stub("detectorTECSetpointDegC",     "Spectrometer State/Detector/TEC/Setpoint/°C");
            stub("detectorTECSetpointRaw",      "Spectrometer State/Detector/TEC/Setpoint/raw");
            stub("detectorSensingThresholdEnabled","Spectrometer State/Detector/Sensing/Enabled");
            stub("detectorSensingThreshold",    "Spectrometer State/Detector/Sensing/Threshold");
            stub("horizBinning",                "Spectrometer State/Detector/Horizontal Binning/Mode");
                                                
            stub("laserEnabled",                "Spectrometer State/Laser/Enabled");
            stub("laserTemperatureDegC",        "Spectrometer State/Laser/TEC/Temperature (°C)");
            stub("laserTemperatureRaw",         "Spectrometer State/Laser/TEC/Temperature (raw)");
            stub("laserTemperatureSetpointRaw", "Spectrometer State/Laser/TEC/Setpoint (raw)"); 
            stub("laserModEnabled",             "Spectrometer State/Laser/Modulation/Enabled");
            stub("laserModDuration",            "Spectrometer State/Laser/Modulation/Duration (µs)");
            stub("laserModPeriod",              "Spectrometer State/Laser/Modulation/Period (µs)");
            stub("laserModPulseDelay",          "Spectrometer State/Laser/Modulation/Pulse Delay (µs)");
            stub("laserModPulseWidth",          "Spectrometer State/Laser/Modulation/Pulse Width (µs)");
        stub("laserModLinkedToIntegrationTime", "Spectrometer State/Laser/Modulation/Linked to Integration Time");
            stub("laserRampingEnabled",         "Spectrometer State/Laser/Ramping Enabled");
            stub("laserInterlock",              "Spectrometer State/Laser/Interlock");

            stub("adcSelection",                "Spectrometer State/Selected ADC");
{'fraction_non_alphanumeric': 0.17839046199701938, 'fraction_numerical': 0.006458022851465474, 'mean_word_length': 1.5245798846250314, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4771624', 'n_tokens_mistral': 5499, 'n_tokens_neox': 5216, 'n_words': 1115}