//*****************************************
//******** PC Configurator V1.00 **********
//*** (C) - 2001 B.Bowling/A. Grippo ******
//** All derivatives from this software ***
//**  are required to keep this header ****
//** **************************************

static char *rcsId() { return "$Id$"; }

#include "stdafx.h"
#include "megatune.h"
#include "msDatabase.h"
#include "veconst.h"
#include "Dsetcomm.h"

#ifdef _DEBUG
#  define new DEBUG_NEW
#  undef THIS_FILE
   static char THIS_FILE[] = __FILE__;
#endif

extern msDatabase mdb;

//------------------------------------------------------------------------------
// Dsetcomm dialog

Dsetcomm::Dsetcomm(CWnd *pParent /*=NULL*/ )
 : CDialog(Dsetcomm::IDD, pParent)
{
   //{{AFX_DATA_INIT(Dsetcomm)
   // NOTE: the ClassWizard will add member initialization here
   //}}AFX_DATA_INIT
}

//------------------------------------------------------------------------------

void Dsetcomm::DoDataExchange(CDataExchange *pDX)
{
   CDialog::DoDataExchange(pDX);
   //{{AFX_DATA_MAP(Dsetcomm)
	DDX_Control(pDX, IDC_TEST_STATUS, m_Status);
      DDX_Control(pDX, IDC_TIMERINTERVAL, m_timerInterval);
      DDX_Control(pDX, IDC_SELECTCOMM, m_selserial);
	//}}AFX_DATA_MAP
}

//------------------------------------------------------------------------------

BEGIN_MESSAGE_MAP(Dsetcomm, CDialog)
   //{{AFX_MSG_MAP(Dsetcomm)
      ON_BN_CLICKED(IDC_TESTCOMM, OnTestcomm)
      ON_CBN_SELCHANGE(IDC_SELECTCOMM,   OnSelchangeSelectcomm)
      ON_EN_KILLFOCUS(IDC_TIMERINTERVAL, OnSelchangeSelectcomm)
   //}}AFX_MSG_MAP
END_MESSAGE_MAP()

//------------------------------------------------------------------------------
// Dsetcomm message handlers

void Dsetcomm::OnTestcomm()
{
   unsigned char runtimevars[Rget];
   if (!mdb.getRuntime(runtimevars))
      m_Status.SetWindowText("No response!");
   else
      m_Status.SetWindowText("Success!");
}

//------------------------------------------------------------------------------

void Dsetcomm::OnSelchangeSelectcomm()
{
   m_Status.SetWindowText("Untested.");

   mdb.commPortNumber = m_selserial.GetCurSel() + 1;

   CString hhh;
   LPTSTR  pp;
   int     ti;
   m_timerInterval.GetWindowText(hhh);
   pp = hhh.GetBuffer(10); sscanf(pp, "%d", &ti); hhh.ReleaseBuffer();
   mdb.timerInterval = ti;

   mdb.writeConfig();

   UpdateData(false);
}

//------------------------------------------------------------------------------

BOOL Dsetcomm::OnInitDialog()
{
   CDialog::OnInitDialog();

   m_Status.SetWindowText("Untested.");

   m_selserial.AddString("COM1");
   m_selserial.AddString("COM2");
   m_selserial.AddString("COM3");
   m_selserial.AddString("COM4");
   m_selserial.SetCurSel(mdb.commPortNumber - 1);

   char cbuf[100];
   sprintf(cbuf, "%d", mdb.timerInterval);
   m_timerInterval.SetWindowText(cbuf);
   return TRUE;
}

//------------------------------------------------------------------------------

