#include "stdafx.h" #include ".\dppslowthreshold.h" //-------------------------------------------------------------------------------------- //@doc CDppSlowThreshold // //@module DppSlowThreshold.cpp | Threshold Control Functions // //This class has the software functionality for Threshold //controls. // // Copyright (c)2004 Amptek, All Rights Reserved // //@devnote The Threshold Control Functions run independantly //from the clsDPPConfig class. Anytime a function is called that updates a //value, the corresponding clsDPPConfig variable must updated as well. // //@devnote Version: v20040629_1613 // //@head3 CDppSlowThreshold Members | //@index | CDppSlowThreshold // //-------------------------------------------------------------------------------------- CDppSlowThreshold::CDppSlowThreshold(void) { } CDppSlowThreshold::~CDppSlowThreshold(void) { } //@bfield SlowChThreshold | Byte | Slow channel threshold, Events with amplitude lower not added to spectrum UCHAR CDppSlowThreshold::GetSlowChThreshold() { return mSlowChThreshold; } void CDppSlowThreshold::SetSlowChThreshold(UCHAR SlowChThresholdVal) { mSlowChThreshold = SlowChThresholdVal; } //@mfunc Threshold Control Setup and Initialization. //@parm Slow Threshold UpDown Control //@parm Slow Threshold label //@parm Slow Threshold label void CDppSlowThreshold::Thresholds_Setup(CSpinButtonCtrl *udThresholdObj, CEdit *lblThresholdObj, CEdit *lblThresholdChannelsObj) { udThreshold = udThresholdObj; lblThreshold = lblThresholdObj; lblThresholdChannels = lblThresholdChannelsObj; GainChannels = 1024; //udThreshold.ToolTipText = "Shaped threshold" udThreshold->SetRange32(0,250); // set control min,max //udThreshold.Wrap = True //udThreshold.Enabled = True //lblSlowThreshold.Caption = "Slow Threshold" //lblThreshold.Caption = "lblThreshold" //lblThreshold.ToolTipText = "Slow Channel Threshold excludes events that should not be added to the stored spectrum" //udThreshold.Value = 4 // default threhold=4 udThreshold->SetPos(4); // default fast threshold=100 // udFThreshold.Value = 100 DPPThreshold(4); } //@mfunc Set Slow Threshold UpDown control and slow threshold value //from a slow threshold value string //@parm slow threshold value string //@devnote Used by clsDPPFile.SetDPPControlsFromStr, must set //clsDPPConfig.SlowChThreshold variable after running. void CDppSlowThreshold::SetGain(long GainVal) { if (GainVal > 8192) { GainChannels = 8192; } else if (GainVal < 256) { GainChannels = 256; } else { GainChannels = GainVal; } } //@mfunc Set Slow Threshold UpDown control and slow threshold value //from a slow threshold value string //@parm slow threshold value string //@devnote Used by clsDPPFile.SetDPPControlsFromStr, must set //clsDPPConfig.SlowChThreshold variable after running. void CDppSlowThreshold::SetSlowChThresholdFromStr(CString strSlowThresh) { udThreshold->SetPos(atoi(strSlowThresh)); } //@mfunc Set Slow Threshold UpDown control and slow threshold value //from a slow threshold value //@parm slow threshold value //@devnote Used by clsDPPFile.SetDPPControlsFromVal, must set //clsDPPConfig.SlowChThreshold variable after running. void CDppSlowThreshold::SetSlowChThresholdFromVal(int intSlowThresh) { udThreshold->SetPos(intSlowThresh); //udThreshold.Value = intSlowThresh } //@mfunc Set Slow threshold value from a Slow threshold value string //@parm Slow threshold value string //@devnote Must set clsDPPConfig.SlowChThreshold variable after running, //does not update the controls, used for direct //initialization of the clsDPPConfig class. void CDppSlowThreshold::SetSlowChThresholdConfigFromStr(CString strSlowThresh) { mSlowChThreshold = atoi(strSlowThresh); } //@mfunc Slow Threshold Selection Control function. // //@comm This sub is used with the udFThreshold control change event. // //@ex Calling DPPFThreshold from a control | // //Private Sub udFThreshold_Change() // clsThreshold.DPPFThreshold // dlgDPPCONFIG.SlowChThreshold = clsThreshold.SlowChThreshold //} void CDppSlowThreshold::DPPThreshold(int SpinPos) { //mSlowChThreshold = udThreshold->GetPos(); mSlowChThreshold = SpinPos; lblThreshold->SetWindowText(GetSlowThreshPcntStr()); lblThresholdChannels->SetWindowText(GetSlowThreshChStr()); } //@mfunc Get Slow Threshold display text string from current Slow Threshold. CString CDppSlowThreshold::GetSlowThreshPcntStr() { CString cstrSlowThresh; cstrSlowThresh = GetSlowChThresStrFromVal(mSlowChThreshold); return cstrSlowThresh; } //@mfunc Get Slow Threshold display text string from Slow Threshold value. //@parm Slow Threshold value //@rdesc Slow Threshold display text string CString CDppSlowThreshold::GetSlowChThresStrFromVal(UCHAR byteSlowThres) { CString cstrSlowThresh; cstrSlowThresh.Format("%.2f%% FS",((byteSlowThres * 100.0 * 4.0 / 4096 * 100) / 100)); return cstrSlowThresh; } //@mfunc Slow Threshold Selection Control function. // //@comm This sub is used with the udFThreshold control change event. // //@ex Calling DPPFThreshold from a control | // //Private Sub udFThreshold_Change() // clsThreshold.DPPFThreshold // dlgDPPCONFIG.SlowChThreshold = clsThreshold.SlowChThreshold //} void CDppSlowThreshold::txtSlowThreshold_Click() { CString cstrSlowThresh; double dblSlowThresh; double FSReal; int FSCFG; // get value, cast to double, convert to real percent lblThreshold->GetWindowText(cstrSlowThresh); dblSlowThresh = atof(cstrSlowThresh); FSReal = dblSlowThresh / 100.0; if (FSReal < 0.0) { FSReal = 0.0; } else if (FSReal > 0.2441) { FSReal = 0.2441; // max is 24.41 percent } // convert FSReal to FSCFG to get closest actual setting FSCFG = (int)((FSReal * 4.0 * 256.0) + 0.5); //%FS CFG = %FS Real * 4 * 256; // xtra check if (FSCFG > 250) { FSCFG = 250; } //%FS 0-24.41%, 0-250 if (FSCFG < 0) { FSCFG = 0; } //%FS 0-24.41%, 0-250 // set controls to value, textbox, ud, (when added,) channels textbox mSlowChThreshold = FSCFG; udThreshold->SetPos(FSCFG); lblThreshold->SetWindowText(GetSlowThreshPcntStr()); lblThresholdChannels->SetWindowText(GetSlowThreshChStr()); } UCHAR CDppSlowThreshold::GetSlowThresholdSettingFromPercent(double dblSlowThresh) { double FSReal; int FSCFG; FSReal = dblSlowThresh / 100.0; if (FSReal < 0.0) { FSReal = 0.0; } else if (FSReal > 0.2441) { FSReal = 0.2441; // max is 24.41 percent } // convert FSReal to FSCFG to get closest actual setting FSCFG = (int)((FSReal * 4.0 * 256.0) + 0.5); //%FS CFG = %FS Real * 4 * 256; // xtra check if (FSCFG > 250) { FSCFG = 250; } //%FS 0-24.41%, 0-250 if (FSCFG < 0) { FSCFG = 0; } //%FS 0-24.41%, 0-250 return FSCFG; } //@mfunc Slow Threshold Selection Control function. // //@comm This sub is used with the udFThreshold control change event. // //@ex Calling DPPFThreshold from a control | // //Private Sub udFThreshold_Change() // clsThreshold.DPPFThreshold // dlgDPPCONFIG.SlowChThreshold = clsThreshold.SlowChThreshold //} void CDppSlowThreshold::txtSlowThresholdChannels_Click() { CString cstrSlowThresh; double dblSlowThresh; double FSReal; int FSCFG; // get value, cast to double, convert to real percent lblThresholdChannels->GetWindowText(cstrSlowThresh); dblSlowThresh = atof(cstrSlowThresh); FSReal = dblSlowThresh / (double)GainChannels; if (FSReal < 0.0) { FSReal = 0.0; } else if (FSReal > 0.2441) { FSReal = 0.2441; // max is 24.41 percent } // convert FSReal to FSCFG to get closest actual setting FSCFG = (int)((FSReal * 4.0 * 256.0) + 0.5); //%FS CFG = %FS Real * 4 * 256; // xtra check if (FSCFG > 250) { FSCFG = 250; } //%FS 0-24.41%, 0-250 if (FSCFG < 0) { FSCFG = 0; } //%FS 0-24.41%, 0-250 // set controls to value, textbox, ud, (when added,) channels textbox mSlowChThreshold = FSCFG; udThreshold->SetPos(FSCFG); lblThreshold->SetWindowText(GetSlowThreshPcntStr()); if (!(cstrSlowThresh == GetSlowThreshChStr())) { lblThresholdChannels->SetWindowText(GetSlowThreshChStr()); } } //@mfunc Set Slow Threshold from channels value. // //@comm This sub is used with auto threshold scaling. // UCHAR CDppSlowThreshold::GetSlowThresholdSettingFromChannels(double dblSlowThreshChannels) { double FSReal; int FSCFG; // get value, cast to double, convert to real percent FSReal = dblSlowThreshChannels / (double)GainChannels; if (FSReal < 0.0) { FSReal = 0.0; } else if (FSReal > 0.2441) { FSReal = 0.2441; // max is 24.41 percent } // convert FSReal to FSCFG to get closest actual setting FSCFG = (int)((FSReal * 4.0 * 256.0) + 0.5); //%FS CFG = %FS Real * 4 * 256; // xtra check if (FSCFG > 250) { FSCFG = 250; } //%FS 0-24.41%, 0-250 if (FSCFG < 0) { FSCFG = 0; } //%FS 0-24.41%, 0-250 // set controls to value, textbox, ud, (when added,) channels textbox mSlowChThreshold = FSCFG; return mSlowChThreshold; } //@mfunc Get Slow Threshold display text string from Slow Threshold value. //@parm Slow Threshold value //@rdesc Slow Threshold display text string CString CDppSlowThreshold::GetSlowThreshChStr() { long lngSlowThresh; CString cstrSlowThresh; lngSlowThresh = (long)(((double)mSlowChThreshold * (double)GainChannels / 1024.0) + 0.5); cstrSlowThresh.Format("%d",lngSlowThresh); return cstrSlowThresh; } //@mfunc Get Slow Threshold display text string from Slow Threshold value. //@parm Slow Threshold value //@rdesc Slow Threshold display text string CString CDppSlowThreshold::GetSlowThreshChStrFromVal(UCHAR byteSlowThres) { long lngSlowThresh; CString cstrSlowThresh; lngSlowThresh = (long)(((double)byteSlowThres * (double)GainChannels / 1024.0) + 0.5); cstrSlowThresh.Format("%d",lngSlowThresh); return cstrSlowThresh; } //@mfunc Set Slow Threshold UpDown control and slow threshold value //from a slow threshold value string //@devnote Used by clsDPPFile.SetDPPControlsFromStr, must set //clsDPPConfig.SlowChThreshold variable after running. void CDppSlowThreshold::UpdateSlowThresChDisplay() { lblThresholdChannels->SetWindowText(GetSlowThreshChStr()); }