// DeviceInfoDlg.cpp : t@C
//

#include "stdafx.h"
#include "MultiChannelWave.h"
#include "DeviceInfoDlg.h"
#include "afxdialogex.h"


// DeviceInfoDlg _CAO

IMPLEMENT_DYNAMIC(DeviceInfoDlg, CDialogEx)

DeviceInfoDlg::DeviceInfoDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_DEVICESETTING, pParent)
{
}

DeviceInfoDlg::~DeviceInfoDlg()
{
}

void DeviceInfoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT_FREQUENCY,		m_edit_frequency);
	DDX_Control(pDX, IDC_EDIT_STARTOSCILLATION,	m_edit_start_oscillation);
	DDX_Control(pDX, IDC_EDIT_STOPOSCILLATION,	m_edit_stop_oscillation);
	DDX_Control(pDX, IDC_COMBO_CHANNELNUM,		m_combo_channelnum);
	DDX_Control(pDX, IDC_COMBO_FREQUENCY_UNIT,	m_combo_frequencyunit);
	DDX_Control(pDX, IDC_COMBO_OSCILLATIONTYPE,	m_combo_oscillationtype);
}

BEGIN_MESSAGE_MAP(DeviceInfoDlg, CDialogEx)
	ON_BN_CLICKED(IDOK, &DeviceInfoDlg::OnBnClickedOk)
	ON_BN_CLICKED(IDCANCEL, &DeviceInfoDlg::OnBnClickedCancel)
END_MESSAGE_MAP()

//----------------------------------------
// f[^̎󂯓n
//----------------------------------------
void DeviceInfoDlg::devinfo_data(unsigned short* aochannels, float* frequency, short* frequencyunit, unsigned short* oscillationtype, unsigned short* oscillationstart, float* oscillationstop) {
	m_aochannels			= aochannels;
	m_frequency				= frequency;
	m_frequencyunit_value	= frequencyunit;
	m_oscillation_type		= oscillationtype;
	m_oscillation_start		= oscillationstart;
	m_oscillation_stop		= oscillationstop;
}

//----------------------------------------
// \
// l݂͌̐ݒl
//----------------------------------------
BOOL DeviceInfoDlg::OnInitDialog() {
	CDialogEx::OnInitDialog();
	CString		text_temp;			// eLXgꎞi[p

	//----------------------------------------
	// g̏\XV
	//----------------------------------------
	text_temp.Format(_T("%.4f"), *m_frequency);
	m_edit_frequency.SetWindowText(text_temp);
	//----------------------------------------
	// Ug̏\XV
	//----------------------------------------
	text_temp.Format(_T("%d"), *m_oscillation_start);
	m_edit_start_oscillation.SetWindowText(text_temp);
	//----------------------------------------
	// U~gorU~Ԃ̏\XV
	//----------------------------------------
	text_temp.Format(_T("%.4f"), *m_oscillation_stop);
	m_edit_stop_oscillation.SetWindowText(text_temp);
	//----------------------------------------
	// `lR{{bNX̍쐬
	//----------------------------------------
	for (int i = 0; i < CWAVEFORMGENERATOR_CHANNELS; i++) {
		text_temp.Format(_T("%d"), i + 1);
		m_combo_channelnum.AddString(text_temp);
	}
	//----------------------------------------
	// `lR{{bNX̑IύX
	//----------------------------------------
	m_combo_channelnum.SetCurSel(*m_aochannels - 1);
	//----------------------------------------
	// gPʃR{{bNX̍쐬
	//----------------------------------------
	m_combo_frequencyunit.AddString(_T("Hz"));
	m_combo_frequencyunit.AddString(_T("kHz"));
	m_combo_frequencyunit.AddString(_T("sec"));
	m_combo_frequencyunit.AddString(_T("msec"));
	//----------------------------------------
	// gPʃR{{bNX̑IύX
	//----------------------------------------
	m_combo_frequencyunit.SetCurSel(*m_frequencyunit_value);
	//----------------------------------------
	// U^CvR{{bNX̍쐬
	//----------------------------------------
	m_combo_oscillationtype.AddString(_T("Ȃ"));
	m_combo_oscillationtype.AddString(_T("I[go[Xg"));
	m_combo_oscillationtype.AddString(_T("gKo[Xgiオj"));
	m_combo_oscillationtype.AddString(_T("gKo[Xgij"));
	//----------------------------------------
	// U^CvR{{bNX̑IύX
	//----------------------------------------
	m_combo_oscillationtype.SetCurSel(*m_oscillation_type);
	return TRUE;
}


//================================================================================
// OK{^NbNۂ̏ɂȂ܂
// ݒl̊mF
//================================================================================
void DeviceInfoDlg::OnBnClickedOk()
{
	CString			text_temp;				// eLXgꎞi[p
	float			pre_frequency;			// g
	unsigned short	pre_oscillation_start;	// U
	float			pre_oscillation_stop;	// ~
	unsigned short	pre_channel_num;		// `l
	unsigned short	pre_frequency_unit;		// gP
	unsigned short	pre_oscillation_type;	// U^Cv

	//----------------------------------------
	// R{{bNX`l擾
	// `l1n܂̂+1
	//----------------------------------------
	pre_channel_num			= m_combo_channelnum.GetCurSel() + 1;
	//----------------------------------------
	// eLXg{bNXg擾
	//----------------------------------------
	m_edit_frequency.GetWindowText(text_temp);
	pre_frequency			= (float)_ttof(text_temp);
	//----------------------------------------
	// R{{bNXgPʂ擾
	//----------------------------------------
	pre_frequency_unit		= m_combo_frequencyunit.GetCurSel();
	//----------------------------------------
	// R{{bNXg^Cv擾
	//----------------------------------------
	pre_oscillation_type	= m_combo_oscillationtype.GetCurSel();
	//----------------------------------------
	// eLXg{bNX甭U擾
	//----------------------------------------
	m_edit_start_oscillation.GetWindowText(text_temp);
	pre_oscillation_start	= (unsigned short)_ttoi(text_temp);
	//----------------------------------------
	// eLXg{bNX~擾
	//----------------------------------------
	m_edit_stop_oscillation.GetWindowText(text_temp);
	pre_oscillation_stop	= (float)_ttof(text_temp);
	//----------------------------------------
	// q_CAOŐݒ肵lCɓn
	// CŐݒs
	//----------------------------------------
	*m_aochannels			= pre_channel_num;
	*m_frequency			= pre_frequency;
	*m_frequencyunit_value	= pre_frequency_unit;
	*m_oscillation_type		= pre_oscillation_type;
	*m_oscillation_start	= pre_oscillation_start;
	*m_oscillation_stop		= pre_oscillation_stop;
	CDialogEx::OnOK();
}

//================================================================================
// LZ{^NbNۂ̏ɂȂ܂
// ݒl̔j
//================================================================================
void DeviceInfoDlg::OnBnClickedCancel()
{
	CDialogEx::OnCancel();
}
