void KinectClient::ThreadDataReceive(ThreadParam *param)
{
	INT nRecvLen;
	SeverBuffer bMessage;
	while (!param->bStopThread)
	{
		nRecvLen = recv(*(param->sClient), (CHAR*)&bMessage, sizeof(bMessage), 0);
		switch (bMessage.nType)
		{
		case (CALIBRATION_STOP_MESSAGE) :
		{

			StopCalibration(param);
			break;
		}
		case (TIMING_MESSAGE) :
		{
			TimingProc(param, bMessage.bData);
			break;
		}
		case (HALT_MESSAGE) :
		{
			param->bStopThread = TRUE;
			break;

		}
		default:
		{

			break;
		}
		}
	}
}
HIDCalibrateDialog::~HIDCalibrateDialog()
{
	delete layout;

	disconnect(ui.okButton, SIGNAL(clicked()), this, SLOT(OkButtonClicked()));
	disconnect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(CancelButtonClicked()));
	disconnect(ui.startButton, SIGNAL(clicked()), this, SLOT(StartButtonClicked()));
	disconnect(ui.stopButton, SIGNAL(clicked()), this, SLOT(StopButtonClicked()));
	disconnect(m_USBHIDDev, SIGNAL(CalibrateThreadStarted(QString)), this, SLOT(CalibrationStarted(QString)));
	disconnect(m_USBHIDDev, SIGNAL(CalibrateThreadStopped(QString)), this, SLOT(CalibrationStopped(QString)));
	disconnect(m_USBHIDDev, SIGNAL(CaptureThreadButtonTriggered(unsigned char,unsigned char)), this, SLOT(HIDButtonPressed(unsigned char,unsigned char)));

	StopCalibration();
	if(m_bSuccesfullyInitialized)
	{
		m_USBHIDDev->StopCaptureThread(true);
	}
	delete renderArea;
}
void HIDCalibrateDialog::HIDButtonPressed(unsigned char cButtonValue,unsigned char cChangedByteValue)
{
	Q_UNUSED(cButtonValue);
	if (cChangedByteValue & 1)//Left HID Button pressed;
	{
		StartCalibration();
	}
	else if (cChangedByteValue & 2)//Right HID Button pressed;
	{
		if (!m_bCalibrationActive)
		{
			this->reject();
		}
		else
		{
			StopCalibration();
		}
	}
}
void HIDCalibrateDialog::StopButtonClicked()
{
	StopCalibration();
}