// DepthSensorDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Dashboard.h"
#include "DepthSensorDlg.h"
#include "DashboardRecipient.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define DEPTH_TIMER 1
#define DEPTH_TIMER_ELAPSE 2000

/////////////////////////////////////////////////////////////////////////////
// CDepthSensorDlg dialog


CDepthSensorDlg::CDepthSensorDlg(CWnd* pParent /*=NULL*/)
	: CTestDlg(CDepthSensorDlg::IDD, pParent, IDC_DEPTH_STATUS)
{
	//{{AFX_DATA_INIT(CDepthSensorDlg)
	m_depthIndicator = 0.0f;
	m_pressureIndicator = 0.0f;
	m_temperatureIndicator = 0.0f;
	m_pressureIndicator2 = 0.0f;
	//}}AFX_DATA_INIT
}


void CDepthSensorDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDepthSensorDlg)
	DDX_Control(pDX, IDC_DEPTH, m_depth);
	DDX_OCFloat(pDX, IDC_DEPTH_INDICATOR, DISPID(7), m_depthIndicator);
	DDX_Control(pDX, IDC_PRESSURE, m_pressure);
	DDX_OCFloat(pDX, IDC_PRESSURE_INDICATOR, DISPID(7), m_pressureIndicator);
	DDX_Control(pDX, IDC_TEMPERATURE, m_temperature);
	DDX_OCFloat(pDX, IDC_TEMPERATURE_INDICATOR, DISPID(7), m_temperatureIndicator);
	DDX_OCFloat(pDX, IDC_PRESSURE_INDICATOR2, DISPID(7), m_pressureIndicator2);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDepthSensorDlg, CTestDlg)
	//{{AFX_MSG_MAP(CDepthSensorDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDepthSensorDlg message handlers

void CDepthSensorDlg::initSubClassDlg()
{
	SetTimer(DEPTH_TIMER,DEPTH_TIMER_ELAPSE,0);
}

void CDepthSensorDlg::requestUpdate()
{
	Assert(m_recipient);
	m_recipient->requestData(MMAgentRequest::Start,
		ModemMessage::tMMDepthSensor,1);

}

void CDepthSensorDlg::stopRequests()
{
	Assert(m_recipient);
	m_recipient->requestData(MMAgentRequest::Stop,
		ModemMessage::tMMDepthSensor,-1);

	resetDialog();
}

void CDepthSensorDlg::resetDialog()
{ 
	UpdateData(TRUE);
	m_depthIndicator = 0.0f;
	m_pressureIndicator = 0.0f;
	m_pressureIndicator2 = 0.0f;
	m_temperatureIndicator = 0.0f;
	UpdateData(FALSE);
}

void CDepthSensorDlg::setDepthSensor(double depth, double temperature,
									 double pressure)
{
	receiveData();
	UpdateData(TRUE);
	m_depth.SetValue(COleVariant(depth));
	m_temperature.SetValue(COleVariant(temperature));
	m_pressure.SetValue(COleVariant(pressure));
	m_depthIndicator = depth;
	m_temperatureIndicator = temperature;
	m_pressureIndicator = pressure;
	m_pressureIndicator2 = pressure / 14.5038; // convert to bars
	UpdateData(FALSE);
}
