// ClockSettingDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CollectionConditions.h"
#include "ClockSettingDlg.h"
#include "afxdialogex.h"
#include "clogger_api.h"
#include <wchar.h>


// ClockSettingDlg dialog

IMPLEMENT_DYNAMIC(ClockSettingDlg, CDialogEx)

ClockSettingDlg::ClockSettingDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_CLOCKSETTING, pParent)
{

}

ClockSettingDlg::~ClockSettingDlg()
{
}

void ClockSettingDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO_CLOCKTYPE, m_combo_clocktype);
	DDX_Control(pDX, IDC_COMBO_DELAYTIME, m_combo_delaytime);
	DDX_Control(pDX, IDC_COMBO_SAMPLINGCLOCKUNIT, m_combo_samplingclock_unit);
	DDX_Control(pDX, IDC_COMBO_SAMPLINGTIMES, m_combo_sampling_times);
	DDX_Control(pDX, IDC_COMBO_STARTLEVEL_EDGE, m_combo_startlevel_edge);
	DDX_Control(pDX, IDC_COMBO_STARTTRIGGERTYPE, m_combo_starttrigger_type);
	DDX_Control(pDX, IDC_COMBO_STOPLEVEL_EDGE, m_combo_stoplevel_edge);
	DDX_Control(pDX, IDC_COMBO_STOPTRIGGERTYPE, m_combo_stoptrigger_type);
	DDX_Control(pDX, IDC_EDIT_CLOCKEXTERNAL, m_edit_clock_external);
	DDX_Control(pDX, IDC_EDIT_DELEYTIME, m_edit_deleytime);
	DDX_Control(pDX, IDC_EDIT_REPEATTIMES, m_edit_repeattimes);
	DDX_Control(pDX, IDC_EDIT_SAMPLINGCLOCK, m_edit_samplingclock);
	DDX_Control(pDX, IDC_EDIT_SAMPLINGTIMES, m_edit_sampling_times);
	DDX_Control(pDX, IDC_EDIT_SCANCLOCK, m_edit_scanclock);
	DDX_Control(pDX, IDC_EDIT_STARTLEVEL_BORDERVALUE, m_edit_startlevel_bordervalue);
	DDX_Control(pDX, IDC_EDIT_STARTLEVEL_CHANNEL, m_edit_startlevel_channel);
	DDX_Control(pDX, IDC_EDIT_STARTRANGE_CHANNEL, m_edit_startrange_channel);
	DDX_Control(pDX, IDC_EDIT_STARTRANGE_LOWER, m_edit_startrange_lower);
	DDX_Control(pDX, IDC_EDIT_STARTRANGE_STATRTIMES, m_edit_startrange_statrtimes);
	DDX_Control(pDX, IDC_EDIT_STARTRANGE_UPPER, m_edit_startrange_upper);
	DDX_Control(pDX, IDC_EDIT_STARTTIME_TIME, m_edit_starttime_time);
	DDX_Control(pDX, IDC_EDIT_STARTTIME_HOUR, m_edit_starttime_hour);
	DDX_Control(pDX, IDC_EDIT_STARTTIME_MINUTE, m_edit_starttime_minute);
	DDX_Control(pDX, IDC_EDIT_STARTTIME_SECOND, m_edit_starttime_second);
	DDX_Control(pDX, IDC_EDIT_STOPLEVEL_BORDERVALUE, m_edit_stoplevel_bordervalue);
	DDX_Control(pDX, IDC_EDIT_STOPLEVEL_CHANNEL, m_edit_stoplevel_channel);
	DDX_Control(pDX, IDC_EDIT_STOPRANGE_CHANNEL, m_edit_stoprange_channel);
	DDX_Control(pDX, IDC_EDIT_STOPRANGE_LOWER, m_edit_stoprange_lower);
	DDX_Control(pDX, IDC_EDIT_STOPRANGE_STATRTIMES, m_edit_stoprange_statrtimes);
	DDX_Control(pDX, IDC_EDIT_STOPRANGE_UPPER, m_edit_stoprange_upper);
	DDX_Control(pDX, IDC_EDIT_STOPTIME_TIME, m_edit_stoptime_time);
	DDX_Control(pDX, IDC_EDIT_STOPTIME_HOUR, m_edit_stoptime_hour);
	DDX_Control(pDX, IDC_EDIT_STOPTIME_MINUTE, m_edit_stoptime_minute);
	DDX_Control(pDX, IDC_EDIT_STOPTIME_SECOND, m_edit_stoptime_second);
}

BEGIN_MESSAGE_MAP(ClockSettingDlg, CDialogEx)
	ON_BN_CLICKED(IDOK, &ClockSettingDlg::OnBnClickedOk)
	ON_CBN_SELCHANGE(IDC_COMBO_CLOCKTYPE, &ClockSettingDlg::OnCbnSelchangeComboClocktype)
	ON_CBN_SELCHANGE(IDC_COMBO_STARTTRIGGERTYPE, &ClockSettingDlg::OnCbnSelchangeComboStarttriggertype)
	ON_CBN_SELCHANGE(IDC_COMBO_STOPTRIGGERTYPE, &ClockSettingDlg::OnCbnSelchangeComboStoptriggertype)
	ON_CBN_SELCHANGE(IDC_COMBO_SAMPLINGTIMES, &ClockSettingDlg::OnCbnSelchangeComboSamplingtimes)
	ON_CBN_SELCHANGE(IDC_COMBO_DELAYTIME, &ClockSettingDlg::OnCbnSelchangeComboDelaytime)
END_MESSAGE_MAP()

//----------------------------------------
// Data transfer
//----------------------------------------
void ClockSettingDlg::clock_data(
	PCLOCK_SETTING clock_setting
){
	m_clock_setting = clock_setting;
}


// ClockSettingDlg message handlers

//================================================================================
// Initialization setting
//================================================================================
BOOL ClockSettingDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	CString		text_temp;			// For temporary text storage

	//----------------------------------------
	// Create the combobox for clock type
	//----------------------------------------
	m_combo_clocktype.AddString(_T("Internal clock"));
	m_combo_clocktype.AddString(_T("External clock(Falling edge)"));
	m_combo_clocktype.AddString(_T("External clock(Rising edge)"));
	//----------------------------------------
	// Update the selection of clock type combobox
	//----------------------------------------
	m_combo_clocktype.SetCurSel(m_clock_setting->clock_type);
	this->OnCbnSelchangeComboClocktype();
	//----------------------------------------
	// Update the sampling clock period (frequency) display
	//----------------------------------------
	text_temp.Format(_T("%f"), m_clock_setting->sampling_clock);
	m_edit_samplingclock.SetWindowTextW(text_temp);
	//----------------------------------------
	// Update the external clock update interval display
	//----------------------------------------
	text_temp.Format(_T("%f"), m_clock_setting->external_clock);
	m_edit_clock_external.SetWindowTextW(text_temp);
	//----------------------------------------
	// Create the combobox for sampling clock unit
	//----------------------------------------
	m_combo_samplingclock_unit.AddString(_T("usec"));
	m_combo_samplingclock_unit.AddString(_T("msec"));
	m_combo_samplingclock_unit.AddString(_T("sec"));
	m_combo_samplingclock_unit.AddString(_T("Hz"));
	m_combo_samplingclock_unit.AddString(_T("kHz"));
	m_combo_samplingclock_unit.AddString(_T("MHz"));
	//----------------------------------------
	// Update the selection of sampling clock unit combobox
	//----------------------------------------
	m_combo_samplingclock_unit.SetCurSel(m_clock_setting->sampling_clock_unit);
	//----------------------------------------
	// Create the combobox for sampling condition
	//----------------------------------------
	m_combo_sampling_times.AddString(_T("Infinite"));
	m_combo_sampling_times.AddString(_T("Finite"));
	//----------------------------------------
	// Update the selection of sampling condition combobox
	//----------------------------------------
	if(m_clock_setting->sampling_times == 0){
		m_combo_sampling_times.SetCurSel(0);
	}else{
		m_combo_sampling_times.SetCurSel(1);
	}
	//----------------------------------------
	// Perform the processing when the value of the sampling condition combobox is changed
	//----------------------------------------
	this->OnCbnSelchangeComboSamplingtimes();
	//----------------------------------------
	// Update the sampling times display
	//----------------------------------------
	text_temp.Format(_T("%lu"), m_clock_setting->sampling_times);
	m_edit_sampling_times.SetWindowTextW(text_temp);
	//----------------------------------------
	// Update scan clock display
	//----------------------------------------
	text_temp.Format(_T("%f"), m_clock_setting->scan_clock);
	m_edit_scanclock.SetWindowTextW(text_temp);
	//----------------------------------------
	// Update repeat times display
	//----------------------------------------
	text_temp.Format(_T("%lu"), m_clock_setting->repeat_times);
	m_edit_repeattimes.SetWindowTextW(text_temp);
	//----------------------------------------
	// Create the combobox for delay condition
	//----------------------------------------
	m_combo_delaytime.AddString(_T("Disable"));
	m_combo_delaytime.AddString(_T("Enable"));
	//----------------------------------------
	// Update the selection of delay condition combobox
	//----------------------------------------
	if(m_clock_setting->delay_time == 0){
		m_combo_delaytime.SetCurSel(LOGGER_PARAM_DISABLE);
	}else{
		m_combo_delaytime.SetCurSel(LOGGER_PARAM_ENABLE);
	}
	//----------------------------------------
	// Perform the processing when the value of the delay condition combobox is changed
	//----------------------------------------
	this->OnCbnSelchangeComboDelaytime();
	//----------------------------------------
	// Update delay times display
	//----------------------------------------
	text_temp.Format(_T("%lu"), m_clock_setting->delay_time);
	m_edit_deleytime.SetWindowTextW(text_temp);
	//----------------------------------------
	// Create the combobox for start condition
	//----------------------------------------
	m_combo_starttrigger_type.AddString(_T("None"));
	m_combo_starttrigger_type.AddString(_T("External trigger rising edge"));
	m_combo_starttrigger_type.AddString(_T("External trigger falling edge"));
	m_combo_starttrigger_type.AddString(_T("Level comparison"));
	m_combo_starttrigger_type.AddString(_T("In Range"));
	m_combo_starttrigger_type.AddString(_T("Out Range"));
	m_combo_starttrigger_type.AddString(_T("Time (Time(sec))"));
	m_combo_starttrigger_type.AddString(_T("Time (Moment)"));
	//----------------------------------------
	// Update the selection of start condition combobox
	//----------------------------------------
	m_combo_starttrigger_type.SetCurSel(m_clock_setting->start_trigger_type);
	//----------------------------------------
	// Perform the processing when the value of the start condition combobox is changed
	//----------------------------------------
	this->OnCbnSelchangeComboStarttriggertype();
	//----------------------------------------
	// Start condition -> Level comparison -> Update channel number display
	//----------------------------------------
	text_temp.Format(_T("%u"), m_clock_setting->start_level_sequence_no);
	m_edit_startlevel_channel.SetWindowTextW(text_temp);
	//----------------------------------------
	// Start condition -> Level comparison -> Update comparison value display
	//----------------------------------------
	text_temp.Format(_T("%f"), m_clock_setting->start_level_border_value);
	m_edit_startlevel_bordervalue.SetWindowTextW(text_temp);
	//----------------------------------------
	// Start condition -> Level comparison -> Create the comparison direction combobox
	//----------------------------------------
	m_combo_startlevel_edge.AddString(_T("Rising edge"));
	m_combo_startlevel_edge.AddString(_T("Falling edge"));
	m_combo_startlevel_edge.AddString(_T("Both edges"));
	//----------------------------------------
	// Start condition -> Level comparison -> Update the selection of comparison direction combobox
	//----------------------------------------
	m_combo_startlevel_edge.SetCurSel(m_clock_setting->start_level_trigger_edge);
	//----------------------------------------
	// Start condition -> In range/out range comparison -> Update channel number display
	//----------------------------------------
	text_temp.Format(_T("%u"), m_clock_setting->start_range_sequence_no);
	m_edit_startrange_channel.SetWindowTextW(text_temp);
	//----------------------------------------
	// Start condition -> In range/out range comparison -> Update lower limit value display
	//----------------------------------------
	text_temp.Format(_T("%f"), m_clock_setting->start_range_lower_border_value);
	m_edit_startrange_lower.SetWindowTextW(text_temp);
	//----------------------------------------
	// Start condition -> In range/out range comparison -> Update upper limit value display
	//----------------------------------------
	text_temp.Format(_T("%f"), m_clock_setting->start_range_upper_border_value);
	m_edit_startrange_upper.SetWindowTextW(text_temp);
	//----------------------------------------
	// Start condition -> In range/out range comparison -> Update state times display
	//----------------------------------------
	text_temp.Format(_T("%lu"), m_clock_setting->start_range_state_times);
	m_edit_startrange_statrtimes.SetWindowTextW(text_temp);
	//----------------------------------------
	// Start condition -> Time/Moment -> Update Time display
	//----------------------------------------
	text_temp.Format(_T("%lu"), m_clock_setting->start_time_time);
	m_edit_starttime_time.SetWindowTextW(text_temp);
	//----------------------------------------
	// Start condition -> Time/Moment -> Update Moment(H) display
	//----------------------------------------
	text_temp.Format(_T("%lu"), m_clock_setting->start_time_hour);
	m_edit_starttime_hour.SetWindowTextW(text_temp);
	//----------------------------------------
	// Start condition -> Time/Moment -> Update Moment(M) display
	//----------------------------------------
	text_temp.Format(_T("%lu"), m_clock_setting->start_time_minute);
	m_edit_starttime_minute.SetWindowTextW(text_temp);
	//----------------------------------------
	// Start condition -> Time/Moment -> Update Moment(S) display
	//----------------------------------------
	text_temp.Format(_T("%lu"), m_clock_setting->start_time_second);
	m_edit_starttime_second.SetWindowTextW(text_temp);
	//----------------------------------------
	// Create the stop condition combobox
	//----------------------------------------
	m_combo_stoptrigger_type.AddString(_T("None"));
	m_combo_stoptrigger_type.AddString(_T("External trigger rising edge"));
	m_combo_stoptrigger_type.AddString(_T("External trigger falling edge"));
	m_combo_stoptrigger_type.AddString(_T("Level comparison"));
	m_combo_stoptrigger_type.AddString(_T("In Range"));
	m_combo_stoptrigger_type.AddString(_T("Out Range"));
	m_combo_stoptrigger_type.AddString(_T("Time (Time(sec))"));
	m_combo_stoptrigger_type.AddString(_T("Time (Moment)"));
	//----------------------------------------
	// Update the selection of stop condition combobox
	//----------------------------------------
	m_combo_stoptrigger_type.SetCurSel(m_clock_setting->stop_trigger_type);
	//----------------------------------------
	// Perform the processing when the value of the stop condition combobox is changed
	//----------------------------------------
	this->OnCbnSelchangeComboStoptriggertype();
	//----------------------------------------
	// Stop condition -> Level comparison -> Update channel number display
	//----------------------------------------
	text_temp.Format(_T("%u"), m_clock_setting->stop_level_sequence_no);
	m_edit_stoplevel_channel.SetWindowTextW(text_temp);
	//----------------------------------------
	// Stop condition -> Level comparison -> Update comparison value display
	//----------------------------------------
	text_temp.Format(_T("%f"), m_clock_setting->stop_level_border_value);
	m_edit_stoplevel_bordervalue.SetWindowTextW(text_temp);
	//----------------------------------------
	// Stop condition -> Level comparison -> Create the comparison direction combobox
	//----------------------------------------
	m_combo_stoplevel_edge.AddString(_T("Rising edge"));
	m_combo_stoplevel_edge.AddString(_T("Falling edge"));
	m_combo_stoplevel_edge.AddString(_T("Both edges"));
	//----------------------------------------
	// Stop condition -> Level comparison -> Update the selection of comparison direction combobox
	//----------------------------------------
	m_combo_stoplevel_edge.SetCurSel(m_clock_setting->stop_level_trigger_edge);
	//----------------------------------------
	// Stop condition -> In range/out range comparison -> Update channel number display
	//----------------------------------------
	text_temp.Format(_T("%d"), m_clock_setting->stop_range_sequence_no);
	m_edit_stoprange_channel.SetWindowTextW(text_temp);
	//----------------------------------------
	// Stop condition -> In range/out range comparison -> Update lower limit value display
	//----------------------------------------
	text_temp.Format(_T("%f"), m_clock_setting->stop_range_lower_border_value);
	m_edit_stoprange_lower.SetWindowTextW(text_temp);
	//----------------------------------------
	// Stop condition -> In range/out range comparison -> Update upper limit value display
	//----------------------------------------
	text_temp.Format(_T("%f"), m_clock_setting->stop_range_upper_border_value);
	m_edit_stoprange_upper.SetWindowTextW(text_temp);
	//----------------------------------------
	// Stop conditions -> In range/out range comparison -> Update state times display
	//----------------------------------------
	text_temp.Format(_T("%lu"), m_clock_setting->stop_range_state_times);
	m_edit_stoprange_statrtimes.SetWindowTextW(text_temp);
	//----------------------------------------
	// Stop conditions -> Time/Moment -> Update Time display
	//----------------------------------------
	text_temp.Format(_T("%lu"), m_clock_setting->stop_time_time);
	m_edit_stoptime_time.SetWindowTextW(text_temp);
	//----------------------------------------
	// Stop conditions -> Time/Moment -> Update Moment(H) display
	//----------------------------------------
	text_temp.Format(_T("%lu"), m_clock_setting->stop_time_hour);
	m_edit_stoptime_hour.SetWindowTextW(text_temp);
	//----------------------------------------
	// Stop conditions -> Time/Moment -> Update Moment(M) display
	//----------------------------------------
	text_temp.Format(_T("%lu"), m_clock_setting->stop_time_minute);
	m_edit_stoptime_minute.SetWindowTextW(text_temp);
	//----------------------------------------
	// Stop conditions -> Time/Moment -> Update Moment(S) display
	//----------------------------------------
	text_temp.Format(_T("%lu"), m_clock_setting->stop_time_second);
	m_edit_stoptime_second.SetWindowTextW(text_temp);
	return TRUE;  // return TRUE unless you set the focus to a control
}

//================================================================================
// It is the process when the Apply button is clicked
// Confirm the settings
//================================================================================
void ClockSettingDlg::OnBnClickedOk()
{
	CLOCK_SETTING	pre_clock_setting;	// For temporary parameters storage
	TCHAR			text_temp[256];		// For temporary text storage

	//----------------------------------------
	// Get the clock type from the combobox
	//----------------------------------------
	pre_clock_setting.clock_type = m_combo_clocktype.GetCurSel();
	//----------------------------------------
	// Get the unit of the sampling clock period from the combobox
	//----------------------------------------
	pre_clock_setting.sampling_clock_unit = m_combo_samplingclock_unit.GetCurSel();
	//----------------------------------------
	// Get the sampling clock period from the textbox
	//----------------------------------------
	m_edit_samplingclock.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.sampling_clock = (double)_ttof(text_temp);
	//----------------------------------------
	// Get external clock update interval from textbox
	//----------------------------------------
	m_edit_clock_external.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.external_clock = (double)_ttof(text_temp);
	//----------------------------------------
	// Get sampling conditions from the combobox
	//----------------------------------------
	if(m_combo_sampling_times.GetCurSel() == 0){
		//----------------------------------------
		// Set to 0 for infinite
		//----------------------------------------
		pre_clock_setting.sampling_times = 0;
	}else{
		//----------------------------------------
		// If finite, get the sampling times from the textbox
		//----------------------------------------
		m_edit_sampling_times.GetWindowText(text_temp, _countof(text_temp));
		pre_clock_setting.sampling_times = wcstoul(text_temp, NULL, 10);
	}
	//----------------------------------------
	// Get conversion speed from the textbox
	//----------------------------------------
	m_edit_scanclock.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.scan_clock = (float)_ttof(text_temp);
	//----------------------------------------
	// Get the repeat times from the textbox
	//----------------------------------------
	m_edit_repeattimes.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.repeat_times = wcstoul(text_temp, NULL, 10);
	//----------------------------------------
	// Get delay condition from combobox
	//----------------------------------------
	if(m_combo_delaytime.GetCurSel() == LOGGER_PARAM_DISABLE){
		//----------------------------------------
		// Set to 0 if disabled
		//----------------------------------------
		pre_clock_setting.delay_time = 0;
	}
	else{
		//----------------------------------------
		// If enabled, get the delay times from the textbox
		//----------------------------------------
		m_edit_deleytime.GetWindowText(text_temp, _countof(text_temp));
		pre_clock_setting.delay_time = wcstoul(text_temp, NULL, 10);
	}
	//----------------------------------------
	// Get start condition from combobox
	//----------------------------------------
	pre_clock_setting.start_trigger_type = m_combo_starttrigger_type.GetCurSel();
	//----------------------------------------
	// Get Start condition - Level comparison - Channel number from the textbox
	//----------------------------------------
	m_edit_startlevel_channel.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.start_level_sequence_no = (unsigned short)_ttoi(text_temp);
	//----------------------------------------
	// Get Start condition - Level comparison - Comparison value from the textbox
	//----------------------------------------
	m_edit_startlevel_bordervalue.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.start_level_border_value = (float)_ttof(text_temp);
	//----------------------------------------
	// Get Start condition - Level comparison - Comparison direction from the textbox
	//----------------------------------------
	pre_clock_setting.start_level_trigger_edge = m_combo_startlevel_edge.GetCurSel();
	//----------------------------------------
	// Get Start condition - In range/out range comparison - Channel number from textbox
	//----------------------------------------
	m_edit_startrange_channel.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.start_range_sequence_no = (unsigned short)_ttoi(text_temp);
	//----------------------------------------
	// Get Start condition - In range/out range comparison - Upper limit from textbox
	//----------------------------------------
	m_edit_startrange_upper.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.start_range_upper_border_value = (float)_ttof(text_temp);
	//----------------------------------------
	// Get Start condition - In range/out range comparison - Lower limit from textbox
	//----------------------------------------
	m_edit_startrange_lower.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.start_range_lower_border_value = (float)_ttof(text_temp);
	//----------------------------------------
	// Get Start condition - In range/out range comparison - State times from textbox
	//----------------------------------------
	m_edit_startrange_statrtimes.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.start_range_state_times = wcstoul(text_temp, NULL, 10);
	//----------------------------------------
	// Get Start condition - Time/Moment - Time from textbox
	//----------------------------------------
	m_edit_starttime_time.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.start_time_time = wcstoul(text_temp, NULL, 10);
	//----------------------------------------
	// Get Start condition - Time/Moment - Moment(H) from textbox
	//----------------------------------------
	m_edit_starttime_hour.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.start_time_hour = wcstoul(text_temp, NULL, 10);
	//----------------------------------------
	// Get Start condition - Time/Moment - Moment(M) from textbox
	//----------------------------------------
	m_edit_starttime_minute.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.start_time_minute = wcstoul(text_temp, NULL, 10);
	//----------------------------------------
	// Get Start condition - Time/Moment - Moment(S) from textbox
	//----------------------------------------
	m_edit_starttime_second.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.start_time_second = wcstoul(text_temp, NULL, 10);
	//----------------------------------------
	// Get the stop condition from the combobox
	//----------------------------------------
	pre_clock_setting.stop_trigger_type = m_combo_stoptrigger_type.GetCurSel();
	//----------------------------------------
	// Get Stop condition - Level comparison - Channel number from textbox
	//----------------------------------------
	m_edit_stoplevel_channel.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.stop_level_sequence_no = (unsigned short)_ttoi(text_temp);
	//----------------------------------------
	// Get Stop condition - Level comparison - Comparison value from textbox
	//----------------------------------------
	m_edit_stoplevel_bordervalue.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.stop_level_border_value = (float)_ttof(text_temp);
	//----------------------------------------
	// Get Stop condition - Level comparison - Comparison direction from textbox
	//----------------------------------------
	pre_clock_setting.stop_level_trigger_edge = m_combo_stoplevel_edge.GetCurSel();
	//----------------------------------------
	// Get Stop condition - In range/out range comparison - Channel number from textbox
	//----------------------------------------
	m_edit_stoprange_channel.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.stop_range_sequence_no = (unsigned short)_ttoi(text_temp);
	//----------------------------------------
	// Get Stop condition - In range/out range comparison - Upper limit from textbox
	//----------------------------------------
	m_edit_stoprange_upper.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.stop_range_upper_border_value = (float)_ttof(text_temp);
	//----------------------------------------
	// Get Stop condition - In range/out range comparison - Lower limit from textbox
	//----------------------------------------
	m_edit_stoprange_lower.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.stop_range_lower_border_value = (float)_ttof(text_temp);
	//----------------------------------------
	// Get Stop condition - In range/out range comparison - State times from textbox
	//----------------------------------------
	m_edit_stoprange_statrtimes.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.stop_range_state_times = wcstoul(text_temp, NULL, 10);
	//----------------------------------------
	// Get Stop condition - Time/Moment - Time from textbox
	//----------------------------------------
	m_edit_stoptime_time.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.stop_time_time = wcstoul(text_temp, NULL, 10);
	//----------------------------------------
	// Get Stop condition - Time/Moment - Moment(H) from textbox
	//----------------------------------------
	m_edit_stoptime_hour.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.stop_time_hour = wcstoul(text_temp, NULL, 10);
	//----------------------------------------
	// Get Stop condition - Time/Moment - Moment(M) from textbox
	//----------------------------------------
	m_edit_stoptime_minute.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.stop_time_minute = wcstoul(text_temp, NULL, 10);
	//----------------------------------------
	// Get Stop condition - Time/Moment - Moment(S) from textbox
	//----------------------------------------
	m_edit_stoptime_second.GetWindowText(text_temp, _countof(text_temp));
	pre_clock_setting.stop_time_second = wcstoul(text_temp, NULL, 10);
	//----------------------------------------
	// Copy from temporary storage to member variable
	//----------------------------------------
	memcpy_s(m_clock_setting, sizeof(CLOCK_SETTING), &pre_clock_setting, sizeof(CLOCK_SETTING));
	CDialogEx::OnOK();
	return;
}

//================================================================================
// It is the process when the value of clock type combobox is changed
// Check the setting value and enable/disable the sampling clock period and the external clock update interval
//================================================================================
void ClockSettingDlg::OnCbnSelchangeComboClocktype()
{
	//----------------------------------------
	// Get the clock type from the combobox
	//----------------------------------------
	int select_clocktype = m_combo_clocktype.GetCurSel();
	//----------------------------------------
	// For internal clock
	//----------------------------------------
	if(select_clocktype == LOGGER_PARAM_CLOCK_INTERNAL){
		//----------------------------------------
		// Enable sampling clock period
		//----------------------------------------
		m_edit_samplingclock.EnableWindow(TRUE);
		m_combo_samplingclock_unit.EnableWindow(TRUE);
		//----------------------------------------
		// Disable external clock update interval
		//----------------------------------------
		m_edit_clock_external.EnableWindow(FALSE);
	//----------------------------------------
	// For external clock
	//----------------------------------------
	}else{
		//----------------------------------------
		// Disable the sampling clock period
		//----------------------------------------
		m_edit_samplingclock.EnableWindow(FALSE);
		m_combo_samplingclock_unit.EnableWindow(FALSE);
		//----------------------------------------
		// Enable external clock update interval
		//----------------------------------------
		m_edit_clock_external.EnableWindow(TRUE);
	}
	return;
}

//================================================================================
// It is the process when the value of start condition combobox is changed
// Check the setting value and enable/disable the level comparison and the in range/out range comparison
//================================================================================
void ClockSettingDlg::OnCbnSelchangeComboStarttriggertype()
{
	//----------------------------------------
	// Get start condition from combobox
	//----------------------------------------
	int select_trigger_type = m_combo_starttrigger_type.GetCurSel();
	//----------------------------------------
	// For level comparison
	//----------------------------------------
	if(select_trigger_type == LOGGER_PARAM_TRIGGER_LEVEL){
		//----------------------------------------
		// Enable level comparison
		//----------------------------------------
		m_edit_startlevel_channel.EnableWindow(TRUE);
		m_edit_startlevel_bordervalue.EnableWindow(TRUE);
		m_combo_startlevel_edge.EnableWindow(TRUE);
		//----------------------------------------
		// Disable in range/out range comparison
		//----------------------------------------
		m_edit_startrange_channel.EnableWindow(FALSE);
		m_edit_startrange_lower.EnableWindow(FALSE);
		m_edit_startrange_upper.EnableWindow(FALSE);
		m_edit_startrange_statrtimes.EnableWindow(FALSE);
		//----------------------------------------
		// Disable Time
		//----------------------------------------
		m_edit_starttime_time.EnableWindow(FALSE);
		//----------------------------------------
		// Disable Moment
		//----------------------------------------
		m_edit_starttime_hour.EnableWindow(FALSE);
		m_edit_starttime_minute.EnableWindow(FALSE);
		m_edit_starttime_second.EnableWindow(FALSE);
	//----------------------------------------
	// For in range/out range comparison
	//----------------------------------------
	}else if((select_trigger_type == LOGGER_PARAM_TRIGGER_INRANGE) || (select_trigger_type == LOGGER_PARAM_TRIGGER_OUTRANGE)){
		//----------------------------------------
		// Disable level comparison
		//----------------------------------------
		m_edit_startlevel_channel.EnableWindow(FALSE);
		m_edit_startlevel_bordervalue.EnableWindow(FALSE);
		m_combo_startlevel_edge.EnableWindow(FALSE);
		//----------------------------------------
		// Enable in range/out range comparison
		//----------------------------------------
		m_edit_startrange_channel.EnableWindow(TRUE);
		m_edit_startrange_lower.EnableWindow(TRUE);
		m_edit_startrange_upper.EnableWindow(TRUE);
		m_edit_startrange_statrtimes.EnableWindow(TRUE);\
		//----------------------------------------
		// Disable Time
		//----------------------------------------
		m_edit_starttime_time.EnableWindow(FALSE);
		//----------------------------------------
		// Disable Moment
		//----------------------------------------
		m_edit_starttime_hour.EnableWindow(FALSE);
		m_edit_starttime_minute.EnableWindow(FALSE);
		m_edit_starttime_second.EnableWindow(FALSE);
	//----------------------------------------
	// For Time (Time(sec))
	//----------------------------------------
	}else if(select_trigger_type == LOGGER_PARAM_TRIGGER_ELAPSED_TIME){
		//----------------------------------------
		// Disable level comparison
		//----------------------------------------
		m_edit_startlevel_channel.EnableWindow(FALSE);
		m_edit_startlevel_bordervalue.EnableWindow(FALSE);
		m_combo_startlevel_edge.EnableWindow(FALSE);
		//----------------------------------------
		// Disable in range/out range comparison
		//----------------------------------------
		m_edit_startrange_channel.EnableWindow(FALSE);
		m_edit_startrange_lower.EnableWindow(FALSE);
		m_edit_startrange_upper.EnableWindow(FALSE);
		m_edit_startrange_statrtimes.EnableWindow(FALSE);
		//----------------------------------------
		// Enable Time
		//----------------------------------------
		m_edit_starttime_time.EnableWindow(TRUE);
		//----------------------------------------
		// Disable Moment
		//----------------------------------------
		m_edit_starttime_hour.EnableWindow(FALSE);
		m_edit_starttime_minute.EnableWindow(FALSE);
		m_edit_starttime_second.EnableWindow(FALSE);
	//----------------------------------------
	// For Time (Moment)
	//----------------------------------------
	}else if(select_trigger_type == LOGGER_PARAM_TRIGGER_CURRENT_TIME){
		//----------------------------------------
		// Disable level comparison
		//----------------------------------------
		m_edit_startlevel_channel.EnableWindow(FALSE);
		m_edit_startlevel_bordervalue.EnableWindow(FALSE);
		m_combo_startlevel_edge.EnableWindow(FALSE);
		//----------------------------------------
		// Disable in range/out range comparison
		//----------------------------------------
		m_edit_startrange_channel.EnableWindow(FALSE);
		m_edit_startrange_lower.EnableWindow(FALSE);
		m_edit_startrange_upper.EnableWindow(FALSE);
		m_edit_startrange_statrtimes.EnableWindow(FALSE);
		//----------------------------------------
		// Disable Time
		//----------------------------------------
		m_edit_starttime_time.EnableWindow(FALSE);
		//----------------------------------------
		// Enable Moment
		//----------------------------------------
		m_edit_starttime_hour.EnableWindow(TRUE);
		m_edit_starttime_minute.EnableWindow(TRUE);
		m_edit_starttime_second.EnableWindow(TRUE);
	//----------------------------------------
	// Other than level, range comparison, Time, Moment
	//----------------------------------------
	}else{
		//----------------------------------------
		// Disable level comparison
		//----------------------------------------
		m_edit_startlevel_channel.EnableWindow(FALSE);
		m_edit_startlevel_bordervalue.EnableWindow(FALSE);
		m_combo_startlevel_edge.EnableWindow(FALSE);
		//----------------------------------------
		// Disable in range/out range comparison
		//----------------------------------------
		m_edit_startrange_channel.EnableWindow(FALSE);
		m_edit_startrange_lower.EnableWindow(FALSE);
		m_edit_startrange_upper.EnableWindow(FALSE);
		m_edit_startrange_statrtimes.EnableWindow(FALSE);
		//----------------------------------------
		// Disable Time
		//----------------------------------------
		m_edit_starttime_time.EnableWindow(FALSE);
		//----------------------------------------
		// Disable Moment
		//----------------------------------------
		m_edit_starttime_hour.EnableWindow(FALSE);
		m_edit_starttime_minute.EnableWindow(FALSE);
		m_edit_starttime_second.EnableWindow(FALSE);
	}
	return;
}

//================================================================================
// It is the process when the value of stop condition combobox is changed
// Check the setting value and enable/disable the level comparison and the in range/out range comparison
//================================================================================
void ClockSettingDlg::OnCbnSelchangeComboStoptriggertype()
{
	//----------------------------------------
	// Get the stop condition from the combobox
	//----------------------------------------
	int select_trigger_type = m_combo_stoptrigger_type.GetCurSel();
	//----------------------------------------
	// For level comparison
	//----------------------------------------
	if(select_trigger_type == LOGGER_PARAM_TRIGGER_LEVEL){
		//----------------------------------------
		// Enable level comparison
		//----------------------------------------
		m_edit_stoplevel_channel.EnableWindow(TRUE);
		m_edit_stoplevel_bordervalue.EnableWindow(TRUE);
		m_combo_stoplevel_edge.EnableWindow(TRUE);
		//----------------------------------------
		// Disable in range/out range comparison
		//----------------------------------------
		m_edit_stoprange_channel.EnableWindow(FALSE);
		m_edit_stoprange_lower.EnableWindow(FALSE);
		m_edit_stoprange_upper.EnableWindow(FALSE);
		m_edit_stoprange_statrtimes.EnableWindow(FALSE);
		//----------------------------------------
		// Disable Time
		//----------------------------------------
		m_edit_stoptime_time.EnableWindow(FALSE);
		//----------------------------------------
		// Disable Moment
		//----------------------------------------
		m_edit_stoptime_hour.EnableWindow(FALSE);
		m_edit_stoptime_minute.EnableWindow(FALSE);
		m_edit_stoptime_second.EnableWindow(FALSE);
	//----------------------------------------
	// For in range/out range comparison
	//----------------------------------------
	}else if((select_trigger_type == LOGGER_PARAM_TRIGGER_INRANGE) || (select_trigger_type == LOGGER_PARAM_TRIGGER_OUTRANGE)){
		//----------------------------------------
		// Disable level comparison
		//----------------------------------------
		m_edit_stoplevel_channel.EnableWindow(FALSE);
		m_edit_stoplevel_bordervalue.EnableWindow(FALSE);
		m_combo_stoplevel_edge.EnableWindow(FALSE);
		//----------------------------------------
		// Enable in range/out range comparison
		//----------------------------------------
		m_edit_stoprange_channel.EnableWindow(TRUE);
		m_edit_stoprange_lower.EnableWindow(TRUE);
		m_edit_stoprange_upper.EnableWindow(TRUE);
		m_edit_stoprange_statrtimes.EnableWindow(TRUE);
		//----------------------------------------
		// Disable Time
		//----------------------------------------
		m_edit_stoptime_time.EnableWindow(FALSE);
		//----------------------------------------
		// Disable Moment
		//----------------------------------------
		m_edit_stoptime_hour.EnableWindow(FALSE);
		m_edit_stoptime_minute.EnableWindow(FALSE);
		m_edit_stoptime_second.EnableWindow(FALSE);
	//----------------------------------------
	// For Time (Time(sec))
	//----------------------------------------
	}else if(select_trigger_type == LOGGER_PARAM_TRIGGER_ELAPSED_TIME){
		//----------------------------------------
		// Disable level comparison
		//----------------------------------------
		m_edit_stoplevel_channel.EnableWindow(FALSE);
		m_edit_stoplevel_bordervalue.EnableWindow(FALSE);
		m_combo_stoplevel_edge.EnableWindow(FALSE);
		//----------------------------------------
		// Disable in range/out range comparison
		//----------------------------------------
		m_edit_stoprange_channel.EnableWindow(FALSE);
		m_edit_stoprange_lower.EnableWindow(FALSE);
		m_edit_stoprange_upper.EnableWindow(FALSE);
		m_edit_stoprange_statrtimes.EnableWindow(FALSE);
		//----------------------------------------
		// Enable Time
		//----------------------------------------
		m_edit_stoptime_time.EnableWindow(TRUE);
		//----------------------------------------
		// Disable Moment
		//----------------------------------------
		m_edit_stoptime_hour.EnableWindow(FALSE);
		m_edit_stoptime_minute.EnableWindow(FALSE);
		m_edit_stoptime_second.EnableWindow(FALSE);
	//----------------------------------------
	// For Time (Moment)
	//----------------------------------------
	}else if(select_trigger_type == LOGGER_PARAM_TRIGGER_CURRENT_TIME){
		//----------------------------------------
		// Disable level comparison
		//----------------------------------------
		m_edit_stoplevel_channel.EnableWindow(FALSE);
		m_edit_stoplevel_bordervalue.EnableWindow(FALSE);
		m_combo_stoplevel_edge.EnableWindow(FALSE);
		//----------------------------------------
		// Disable in range/out range comparison
		//----------------------------------------
		m_edit_stoprange_channel.EnableWindow(FALSE);
		m_edit_stoprange_lower.EnableWindow(FALSE);
		m_edit_stoprange_upper.EnableWindow(FALSE);
		m_edit_stoprange_statrtimes.EnableWindow(FALSE);
		//----------------------------------------
		// Disable Time
		//----------------------------------------
		m_edit_stoptime_time.EnableWindow(FALSE);
		//----------------------------------------
		// Enable Moment
		//----------------------------------------
		m_edit_stoptime_hour.EnableWindow(TRUE);
		m_edit_stoptime_minute.EnableWindow(TRUE);
		m_edit_stoptime_second.EnableWindow(TRUE);
	//----------------------------------------
	// Other than level, range comparison, Time, Moment
	//----------------------------------------
	}else{
		//----------------------------------------
		// Disable level comparison
		//----------------------------------------
		m_edit_stoplevel_channel.EnableWindow(FALSE);
		m_edit_stoplevel_bordervalue.EnableWindow(FALSE);
		m_combo_stoplevel_edge.EnableWindow(FALSE);
		//----------------------------------------
		// Disable in range/out range comparison
		//----------------------------------------
		m_edit_stoprange_channel.EnableWindow(FALSE);
		m_edit_stoprange_lower.EnableWindow(FALSE);
		m_edit_stoprange_upper.EnableWindow(FALSE);
		m_edit_stoprange_statrtimes.EnableWindow(FALSE);
		//----------------------------------------
		// Disable Time
		//----------------------------------------
		m_edit_stoptime_time.EnableWindow(FALSE);
		//----------------------------------------
		// Disable Moment
		//----------------------------------------
		m_edit_stoptime_hour.EnableWindow(FALSE);
		m_edit_stoptime_minute.EnableWindow(FALSE);
		m_edit_stoptime_second.EnableWindow(FALSE);
	}
	return;
}

//================================================================================
// It is the process when the value of sampling condition combobox is changed
// Check the setting value and enable/disable the sampling times
//================================================================================
void ClockSettingDlg::OnCbnSelchangeComboSamplingtimes()
{
	//----------------------------------------
	// Get sampling conditions from the combobox
	//----------------------------------------
	int sampling_times = m_combo_sampling_times.GetCurSel();
	//----------------------------------------
	// For infinite
	//----------------------------------------
	if(sampling_times == 0){
		//----------------------------------------
		// Disable sampling times
		//----------------------------------------
		m_edit_sampling_times.EnableWindow(FALSE);
	//----------------------------------------
	// For finite
	//----------------------------------------
	}else{
		//----------------------------------------
		// Enable sampling times
		//----------------------------------------
		m_edit_sampling_times.EnableWindow(TRUE);
	}
	return;
}

//================================================================================
// It is the process when the value of delay condition combobox is changed
// Check the setting value and enable/disable the delay times
//================================================================================
void ClockSettingDlg::OnCbnSelchangeComboDelaytime()
{
	//----------------------------------------
	// Get delay condition from combobox
	//----------------------------------------
	int delay_time = m_combo_delaytime.GetCurSel();

	//----------------------------------------
	// For disable
	//----------------------------------------
	if(delay_time == LOGGER_PARAM_DISABLE){
		//----------------------------------------
		// Disable delay times
		//----------------------------------------
		m_edit_deleytime.EnableWindow(FALSE);
	//----------------------------------------
	// For enable
	//----------------------------------------
	}else{
		//----------------------------------------
		// Enable delay times
		//----------------------------------------
		m_edit_deleytime.EnableWindow(TRUE);
	}
	return;
}
