1433 lines
43 KiB
C++
1433 lines
43 KiB
C++
// HSI_Illumination.cpp : 定义 DLL 的初始化例程。
|
|
//
|
|
#include "stdafx.h"
|
|
#include "SevenOcean\CMMIO_SERIAL.h"
|
|
#include "HSI.h"
|
|
#include "HSI_Sevenocean_EF3.h"
|
|
#include "HSI_Motion.h"
|
|
#include "HSI_Illumination.h"
|
|
#include "hidsdi.h"
|
|
#include <setupapi.h>
|
|
#include <dbt.h>
|
|
#include <math.h>
|
|
#include <atltime.h>
|
|
#include <sys/timeb.h>
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
//===========================================================================
|
|
HSI_Illumination *g_pHSI_Illumination = nullptr;
|
|
const double PERCENT_PRECISION = 0.000001;
|
|
//const int SO7II_SECTOR_ORDER[8] = { 5, 4, 3, 2, 1, 8, 7, 6 };
|
|
int SO7II_SECTOR_ORDER[8] = {5, 4, 3, 2, 1, 8, 7, 6};
|
|
|
|
PSP_DEVICE_INTERFACE_DETAIL_DATA m_detailData;
|
|
HIDP_CAPS m_Capabilities;
|
|
|
|
//===========================================================================
|
|
HSI_Illumination::HSI_Illumination()
|
|
{
|
|
TRACE0("HSI_Illumination Constructor!\n");
|
|
hWnd = NULL;
|
|
bOfflineOnly = false;
|
|
for (int i = 0; i < 64;i++)
|
|
{
|
|
m_cSendData[i] = 0;
|
|
}
|
|
m_bRS232AOpened = FALSE;
|
|
m_bRS232BOpened = FALSE;
|
|
m_iBuadRate = 2400;
|
|
m_iSleepTime = 50;
|
|
m_iSo7DoubleSurface = 0;
|
|
m_iMinRings = 0;
|
|
m_iMaxRings = 0;
|
|
m_iMinSectors = 0;
|
|
m_iMaxSectors = 0;
|
|
m_iIlluminationType = 0;
|
|
m_iSelectedIndex = 0;
|
|
|
|
m_cSendData[0] = 2;
|
|
m_cSendData[1] = 2;
|
|
|
|
m_detailData = NULL;
|
|
m_DeviceHandle = NULL;
|
|
m_VendorID = 0x0483;
|
|
m_ProductID = 0x5710;
|
|
//m_cSendData[2] = 2;
|
|
//m_cSendData[3] = 48;
|
|
//m_cSendData[4] = 4;
|
|
//m_cSendData[6] = 4;
|
|
}
|
|
//===========================================================================
|
|
HSI_Illumination::~HSI_Illumination()
|
|
{
|
|
TRACE0("HSI_Illumination Destructor!\n");
|
|
}
|
|
//===========================================================================
|
|
HSI_STATUS HSI_Illumination::IsSupported(UINT &Types)
|
|
{
|
|
auto rStatus = HSI_STATUS_NORMAL;
|
|
Types = 1;
|
|
return rStatus;
|
|
}
|
|
//===========================================================================
|
|
HSI_STATUS HSI_Illumination::Startup(HWND _hWnd, bool _bOfflineOnly)
|
|
{
|
|
auto rStatus = HSI_STATUS_NORMAL;
|
|
hWnd = _hWnd;
|
|
bOfflineOnly = _bOfflineOnly;
|
|
if (!bOfflineOnly)
|
|
{
|
|
DebugLog("Startup -> in");
|
|
if (!g_pHSI_Motion)
|
|
{
|
|
return HSI_STATUS_FAILED;
|
|
}
|
|
if (g_pHSI_Motion->m_isUseAport == 1)
|
|
{
|
|
DebugLog("Startup -> A");
|
|
m_SO7_SerialA.SetPort(g_pHSI_Motion->m_portAnum, m_iBuadRate);
|
|
if (m_SO7_SerialA.Open())
|
|
{
|
|
DebugLog("Startup -> A success");
|
|
m_bRS232AOpened = TRUE;
|
|
}
|
|
else
|
|
{
|
|
char messageAlarm[100] = "";
|
|
m_bRS232AOpened = false;
|
|
sEvenProp.Init();
|
|
sEvenProp.EventType = HSI_EVENT_ERROR;
|
|
sEvenProp.EventID = HSI_EVENT_MOTION;
|
|
sEvenProp.EventResponse = HSI_EVENT_RESPONSE_OK;
|
|
_itoa_s(g_pHSI_Motion->m_portAnum, messageAlarm, 30, 10);
|
|
strcat_s(messageAlarm, 100, "号端口MCU串口控制器打开失败");
|
|
strcpy_s(sEvenProp.EventData, HSI_MaxStringLength, messageAlarm);
|
|
EventCallback(sEvenProp);
|
|
rStatus = HSI_STATUS_FAILED;
|
|
}
|
|
}
|
|
if (g_pHSI_Motion->m_isUseBport == 1)
|
|
{
|
|
DebugLog("Startup -> B");
|
|
m_SO7_SerialB.SetPort(g_pHSI_Motion->m_portBnum, m_iBuadRate);
|
|
if (m_SO7_SerialB.Open())
|
|
{
|
|
DebugLog("Startup -> B success");
|
|
m_bRS232BOpened = TRUE;
|
|
}
|
|
else
|
|
{
|
|
char messageAlarm[100] = "";
|
|
m_bRS232BOpened = false;
|
|
sEvenProp.Init();
|
|
sEvenProp.EventType = HSI_EVENT_ERROR;
|
|
sEvenProp.EventID = HSI_EVENT_MOTION;
|
|
sEvenProp.EventResponse = HSI_EVENT_RESPONSE_OK;
|
|
_itoa_s(g_pHSI_Motion->m_portBnum, messageAlarm, 30, 10);
|
|
strcat_s(messageAlarm, 100, "号端口MCU串口控制器打开失败");
|
|
strcpy_s(sEvenProp.EventData, HSI_MaxStringLength, messageAlarm);
|
|
EventCallback(sEvenProp);
|
|
rStatus = HSI_STATUS_FAILED;
|
|
}
|
|
}
|
|
if (g_pHSI_Motion->m_IsUseTwentySixLight == 2)
|
|
{
|
|
DebugLog("Startup -> 26");
|
|
if (FindTheHID() == false)
|
|
{
|
|
m_bSTM32UsbFlag = false;
|
|
sEvenProp.Init();
|
|
sEvenProp.EventType = HSI_EVENT_ERROR;
|
|
sEvenProp.EventID = HSI_EVENT_MOTION;
|
|
sEvenProp.EventResponse = HSI_EVENT_RESPONSE_OK;
|
|
strcpy_s(sEvenProp.EventData, HSI_MaxStringLength, "STM32 USB模式打开失败");
|
|
EventCallback(sEvenProp);
|
|
rStatus = HSI_STATUS_FAILED;
|
|
}
|
|
DebugLog("Startup -> 26 success");
|
|
}
|
|
}
|
|
return rStatus;
|
|
}
|
|
//===========================================================================
|
|
HSI_STATUS HSI_Illumination::GetLampCount(int &nLamps)
|
|
{
|
|
auto rStatus = HSI_STATUS_NORMAL;
|
|
nLamps = 3;
|
|
return rStatus;
|
|
}
|
|
//===========================================================================
|
|
HSI_STATUS HSI_Illumination::GetLampInfo(int& _LampInfo, int& _NumLamps, int(*_LampsType)[HSI_ILLUMINATION_MAX_BULB_TYPE],
|
|
int *NumRings, int *NumSectors, int* _Color, double *_Angle, bool &bCanBeCalibrated)
|
|
{
|
|
auto rStatus = HSI_STATUS_NORMAL;
|
|
|
|
UNREFERENCED_PARAMETER(NumRings);
|
|
UNREFERENCED_PARAMETER(NumSectors);
|
|
UNREFERENCED_PARAMETER(_Color);
|
|
UNREFERENCED_PARAMETER(_Angle);
|
|
UNREFERENCED_PARAMETER(bCanBeCalibrated);
|
|
|
|
m_iMinRings = 1;
|
|
m_iMaxRings = 6;
|
|
m_iMinSectors = 1;
|
|
m_iMaxSectors = 8;
|
|
_LampInfo = m_iIlluminationType;
|
|
_NumLamps = 0;
|
|
_LampsType[_NumLamps][0] = HSI_ILLUMINATION_LAMP_COAXIAL;
|
|
NumRings[_NumLamps] = 1;
|
|
NumSectors[_NumLamps] = 1;
|
|
_NumLamps++;
|
|
_LampsType[_NumLamps][0] = HSI_ILLUMINATION_LAMP_SURFACE;
|
|
NumRings[_NumLamps] = m_iMaxRings - m_iMinRings + 1;
|
|
NumSectors[_NumLamps] = m_iMaxSectors - m_iMinSectors + 1;
|
|
_NumLamps++;
|
|
_LampsType[_NumLamps][0] = HSI_ILLUMINATION_LAMP_PROFILE;
|
|
NumRings[_NumLamps] = 1;
|
|
NumSectors[_NumLamps] = 1;
|
|
_NumLamps++;
|
|
_LampsType[_NumLamps][0] = HSI_ILLUMINATION_LAMP_PROFILE_OUTER;
|
|
NumRings[_NumLamps] = 1;
|
|
NumSectors[_NumLamps] = 1;
|
|
_NumLamps++;
|
|
|
|
return rStatus;
|
|
}
|
|
//===========================================================================
|
|
HSI_STATUS HSI_Illumination::GetLampState(int nLamp, bool *bBulbStates, double *Intensities, int &Color, double &Angle)
|
|
{
|
|
auto rStatus = HSI_STATUS_NORMAL;
|
|
UNREFERENCED_PARAMETER(nLamp);
|
|
UNREFERENCED_PARAMETER(bBulbStates);
|
|
UNREFERENCED_PARAMETER(Intensities);
|
|
UNREFERENCED_PARAMETER(Color);
|
|
UNREFERENCED_PARAMETER(Angle);
|
|
rStatus = HSI_STATUS_NOT_SUPPORTED;
|
|
|
|
return rStatus;
|
|
}
|
|
//===========================================================================
|
|
HSI_STATUS HSI_Illumination::SetLampState(int nLamp, bool *bBulbStates, double *Intensities, int Color, double Angle, bool bWait)
|
|
{
|
|
auto rStatus = HSI_STATUS_NORMAL;
|
|
UNREFERENCED_PARAMETER(nLamp);
|
|
UNREFERENCED_PARAMETER(bBulbStates);
|
|
UNREFERENCED_PARAMETER(Intensities);
|
|
UNREFERENCED_PARAMETER(Color);
|
|
UNREFERENCED_PARAMETER(Angle);
|
|
UNREFERENCED_PARAMETER(bWait);
|
|
rStatus = HSI_STATUS_NOT_SUPPORTED;
|
|
|
|
return rStatus;
|
|
}
|
|
//===========================================================================
|
|
//设置控制的光源板的序号
|
|
HSI_STATUS HSI_Illumination::SetSelectedIndex(int index)
|
|
{
|
|
auto rStatus = HSI_STATUS_NORMAL;
|
|
if (!g_pHSI_Motion)
|
|
{
|
|
return HSI_STATUS_FAILED;
|
|
}
|
|
if (g_pHSI_Motion->m_IsUseTwentySixLight == 2 && index == 0)
|
|
return rStatus;
|
|
if (g_pHSI_Motion->m_IsUseEF3 == 0)
|
|
{
|
|
if (index + 1 > g_pHSI_Motion->m_bISUseMoreLights)
|
|
{
|
|
return HSI_STATUS_FAILED;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (index > g_pHSI_Motion->m_bISUseMoreLights)
|
|
{
|
|
return HSI_STATUS_FAILED;
|
|
}
|
|
}
|
|
m_iSelectedIndex = index;
|
|
return rStatus;
|
|
}
|
|
//===========================================================================
|
|
HSI_STATUS HSI_Illumination::GetLampStateAll(int _LampInfo, int _NumLamps, int(*_LampsType)[HSI_ILLUMINATION_MAX_BULB_TYPE], int(*bBulbStates)[HSI_ILLUMINATION_MAX_BULBS], double(*Intensities)[HSI_ILLUMINATION_MAX_BULBS])
|
|
{
|
|
auto rStatus = HSI_STATUS_NORMAL;
|
|
UNREFERENCED_PARAMETER(_LampInfo);
|
|
UNREFERENCED_PARAMETER(_NumLamps);
|
|
UNREFERENCED_PARAMETER(_LampsType);
|
|
UNREFERENCED_PARAMETER(bBulbStates);
|
|
UNREFERENCED_PARAMETER(Intensities);
|
|
rStatus = HSI_STATUS_NOT_SUPPORTED;
|
|
|
|
return rStatus;
|
|
}
|
|
//===========================================================================
|
|
HSI_STATUS HSI_Illumination::SetLampStateAll(int _LampInfo, int _NumLamps, int(*_LampsType)[HSI_ILLUMINATION_MAX_BULB_TYPE], int(*bBulbStates)[HSI_ILLUMINATION_MAX_BULBS], double(*Intensities)[HSI_ILLUMINATION_MAX_BULBS], bool bWait)
|
|
{
|
|
auto rStatus = HSI_STATUS_NORMAL;
|
|
UNREFERENCED_PARAMETER(_LampInfo);
|
|
if (!g_pHSI_Motion)
|
|
{
|
|
return HSI_STATUS_FAILED;
|
|
}
|
|
DebugLog("SetLampStateAll -> in");
|
|
m_iIlluminationType = HSI_ILLUMINATION_INFO_SO7_II;
|
|
if (m_iIlluminationType == HSI_ILLUMINATION_INFO_SO7_II)
|
|
{
|
|
m_iMinRings = 3;
|
|
m_iMaxRings = 6;
|
|
m_iMinSectors = 1;
|
|
m_iMaxSectors = 8;
|
|
SetLampState_So7II(_NumLamps, _LampsType, bBulbStates, Intensities, bWait);
|
|
}
|
|
if (g_pHSI_Motion->m_IsUseSixRingEightArea == 1)
|
|
{
|
|
//更改六环八区扇形区域显示的位置
|
|
m_iIlluminationType = HSI_ILLUMINATION_INFO_SO7_III;
|
|
for (size_t i = 0; i < 8; i++)
|
|
{
|
|
SO7II_SECTOR_ORDER[i] = g_pHSI_Motion->m_SixEightSubArea[i];
|
|
}
|
|
}
|
|
if (m_iIlluminationType == HSI_ILLUMINATION_INFO_SO7_III)
|
|
{
|
|
m_iMinRings = 1;
|
|
m_iMaxRings = 6;
|
|
m_iMinSectors = 1;
|
|
m_iMaxSectors = 8;
|
|
SetLampState_So7III(_NumLamps, _LampsType, bBulbStates, Intensities, bWait);
|
|
}
|
|
if (m_iIlluminationType == HSI_ILLUMINATION_INFO_SO7)
|
|
{
|
|
m_iMinRings = 1;
|
|
m_iMaxRings = 2;
|
|
m_iMinSectors = 1;
|
|
m_iMaxSectors = 8;
|
|
SetLampState_So7I(_NumLamps, _LampsType, bBulbStates, Intensities, bWait);
|
|
}
|
|
if (g_pHSI_Motion->m_IsUseSixRingEightArea == 2)
|
|
{
|
|
m_iMinRings = 1;
|
|
m_iMaxRings = 2;
|
|
m_iMinSectors = 1;
|
|
m_iMaxSectors = 8;
|
|
SetLampState_So7IIII(_NumLamps, _LampsType, bBulbStates, Intensities, bWait);
|
|
}
|
|
return rStatus;
|
|
}
|
|
//===========================================================================
|
|
BOOL HSI_Illumination::SetLampState_So7I(int _NumLamps, int(*_LampsType)[HSI_ILLUMINATION_MAX_BULB_TYPE], int(*bBulbStates)[HSI_ILLUMINATION_MAX_BULBS], double(*Intensities)[HSI_ILLUMINATION_MAX_BULBS], bool bWait)
|
|
{
|
|
BOOL rStatus(TRUE);
|
|
UNREFERENCED_PARAMETER(bWait);
|
|
UNREFERENCED_PARAMETER(bBulbStates);
|
|
int iOffsetIndex(0);
|
|
short LampValue(0);
|
|
short LampMaxValue(255);
|
|
short LampMinValue(1);
|
|
for (int i = 0; i < _NumLamps; i++)
|
|
{
|
|
switch (_LampsType[i][0])
|
|
{
|
|
case HSI_ILLUMINATION_LAMP_COAXIAL://3
|
|
{
|
|
break;
|
|
}
|
|
case HSI_ILLUMINATION_LAMP_SURFACE:
|
|
{
|
|
double dMaxValue(-999.9), dTmpValue(0.0);
|
|
if (bBulbStates[HSI_ILLUMINATION_LAMP_SURFACE][0] == HSI_ILLUMINATION_BULB_STATE_TURN_ON)
|
|
{
|
|
LampValue = LampMinValue + static_cast<short>((LampMaxValue - LampMinValue)*Intensities[HSI_ILLUMINATION_LAMP_SURFACE][0]);
|
|
}
|
|
else
|
|
{
|
|
LampValue = LampMinValue;
|
|
}
|
|
switch (_LampsType[i][1])
|
|
{
|
|
case HSI_ILLUMINATION_LAMP_CONTROL_BY_WHOLE_LAMP:
|
|
{
|
|
break;
|
|
}
|
|
case HSI_ILLUMINATION_LAMP_CONTROL_BY_RINGS:
|
|
{
|
|
dMaxValue = -999.9;
|
|
dTmpValue = 0.0;
|
|
for (int iRing = m_iMinRings; iRing <= m_iMaxRings; iRing++)
|
|
{
|
|
if (bBulbStates[HSI_ILLUMINATION_LAMP_SURFACE][iRing*HSI_ILLUMINATION_MAX_SECTORS] == HSI_ILLUMINATION_BULB_STATE_TURN_ON)
|
|
{
|
|
dTmpValue = Intensities[HSI_ILLUMINATION_LAMP_SURFACE][iRing*HSI_ILLUMINATION_MAX_SECTORS];
|
|
if (dTmpValue > dMaxValue)
|
|
{
|
|
dMaxValue = dTmpValue;
|
|
}
|
|
if (dTmpValue > PERCENT_PRECISION)
|
|
{
|
|
iOffsetIndex = iRing - m_iMinRings;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dTmpValue = 0.0;
|
|
if (dTmpValue > dMaxValue)
|
|
{
|
|
dMaxValue = dTmpValue;
|
|
}
|
|
}
|
|
}
|
|
LampValue = LampMinValue + static_cast<short>((LampMaxValue - LampMinValue)*dMaxValue);
|
|
break;
|
|
}
|
|
case HSI_ILLUMINATION_LAMP_CONTROL_BY_OCTANTS:
|
|
{
|
|
break;
|
|
}
|
|
case HSI_ILLUMINATION_LAMP_CONTROL_BY_SEGMENTS:
|
|
{
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
case HSI_ILLUMINATION_LAMP_PROFILE:
|
|
{
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return rStatus;
|
|
}
|
|
//===========================================================================
|
|
BOOL HSI_Illumination::SetLampState_So7II(int _NumLamps, int(*_LampsType)[HSI_ILLUMINATION_MAX_BULB_TYPE], int(*bBulbStates)[HSI_ILLUMINATION_MAX_BULBS], double(*Intensities)[HSI_ILLUMINATION_MAX_BULBS], bool bWait)
|
|
{
|
|
DebugLog("SetLampState_So7II -> in");
|
|
UNREFERENCED_PARAMETER(_NumLamps);
|
|
UNREFERENCED_PARAMETER(bBulbStates);
|
|
UNREFERENCED_PARAMETER(bWait);
|
|
BOOL rStatus(TRUE);
|
|
BYTE LampMaxValue(0xFF);
|
|
BYTE LampMinValue(0x01);
|
|
BYTE cSendDataA[9] = { 0xA1, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xB1 };
|
|
BYTE cSendDataB[9] = { 0xA1, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xB1 };
|
|
int ampTimes = 1120;
|
|
|
|
switch (_LampsType[1][1])
|
|
{
|
|
case HSI_ILLUMINATION_LAMP_CONTROL_BY_WHOLE_LAMP:
|
|
{
|
|
int index = 2;
|
|
short int tempIntensity = 0;
|
|
tempIntensity = (short int)(Intensities[0][0] * ampTimes);
|
|
m_cSendData[index++] = (tempIntensity >> 8);
|
|
m_cSendData[index++] = (tempIntensity & 0x00ff);
|
|
tempIntensity = (short int)(Intensities[2][0] * ampTimes);
|
|
m_cSendData[index++] = (tempIntensity >> 8);
|
|
m_cSendData[index++] = (tempIntensity & 0x00ff);
|
|
tempIntensity = (short int)(Intensities[3][0] * ampTimes);
|
|
m_cSendData[index++] = (tempIntensity >> 8);
|
|
m_cSendData[index++] = (tempIntensity & 0x00ff);
|
|
tempIntensity = (short int)(Intensities[1][0] * ampTimes);
|
|
m_cSendData[index++] = (tempIntensity >> 8);
|
|
m_cSendData[index++] = (tempIntensity & 0x00ff);
|
|
g_pHSI_Motion->Send_Command(m_iSelectedIndex, (const char*)m_cSendData, 64);
|
|
Sleep(5);
|
|
break;
|
|
}
|
|
case HSI_ILLUMINATION_LAMP_CONTROL_BY_RINGS:
|
|
{
|
|
//EF3自带光源的数据发送 环形区域可控制EF3的8路 其他区域只能控制部分
|
|
int index = 2;
|
|
short int tempIntensity = 0;
|
|
tempIntensity = (short int)(Intensities[0][0] * ampTimes);
|
|
m_cSendData[index++] = (tempIntensity >> 8);
|
|
m_cSendData[index++] = (tempIntensity & 0x00ff);
|
|
tempIntensity = (short int)(Intensities[2][0] * ampTimes);
|
|
m_cSendData[index++] = (tempIntensity >> 8);
|
|
m_cSendData[index++] = (tempIntensity & 0x00ff);
|
|
tempIntensity = (short int)(Intensities[3][0] * ampTimes);
|
|
m_cSendData[index++] = (tempIntensity >> 8);
|
|
m_cSendData[index++] = (tempIntensity & 0x00ff);
|
|
for (int i = 96; i > 16;)
|
|
{
|
|
tempIntensity = (short int)(Intensities[1][i] * ampTimes);
|
|
m_cSendData[index++] = (tempIntensity >> 8);
|
|
m_cSendData[index++] = (tempIntensity & 0x00ff);
|
|
i -= 16;
|
|
}
|
|
g_pHSI_Motion->Send_Command(m_iSelectedIndex, (const char*)m_cSendData, 64);
|
|
Sleep(5);
|
|
break;
|
|
}
|
|
case HSI_ILLUMINATION_LAMP_CONTROL_BY_OCTANTS:
|
|
{
|
|
int index = 2;
|
|
short int tempIntensity = 0;
|
|
tempIntensity = (short int)(Intensities[0][0] * ampTimes);
|
|
m_cSendData[index++] = (tempIntensity >> 8);
|
|
m_cSendData[index++] = (tempIntensity & 0x00ff);
|
|
tempIntensity = (short int)(Intensities[2][0] * ampTimes);
|
|
m_cSendData[index++] = (tempIntensity >> 8);
|
|
m_cSendData[index++] = (tempIntensity & 0x00ff);
|
|
tempIntensity = (short int)(Intensities[3][0] * ampTimes);
|
|
m_cSendData[index++] = (tempIntensity >> 8);
|
|
m_cSendData[index++] = (tempIntensity & 0x00ff);
|
|
g_pHSI_Motion->Send_Command(m_iSelectedIndex, (const char*)m_cSendData, 64);
|
|
Sleep(5);
|
|
break;
|
|
}
|
|
case HSI_ILLUMINATION_LAMP_CONTROL_BY_SEGMENTS:
|
|
{
|
|
int index = 2;
|
|
short int tempIntensity = 0;
|
|
tempIntensity = (short int)(Intensities[0][0] * ampTimes);
|
|
m_cSendData[index++] = (tempIntensity >> 8);
|
|
m_cSendData[index++] = (tempIntensity & 0x00ff);
|
|
tempIntensity = (short int)(Intensities[2][0] * ampTimes);
|
|
m_cSendData[index++] = (tempIntensity >> 8);
|
|
m_cSendData[index++] = (tempIntensity & 0x00ff);
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
for (int j = 0; j < 8; j++)
|
|
{
|
|
tempIntensity = (short int)(Intensities[1][(i + 1)*HSI_ILLUMINATION_MAX_SECTORS + (j + 1)] * ampTimes);
|
|
m_cSendData[index++] = (tempIntensity >> 8);
|
|
m_cSendData[index++] = (tempIntensity & 0x00ff);
|
|
if (index >= 64)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
g_pHSI_Motion->Send_Command(m_iSelectedIndex, (const char*)m_cSendData, 64);
|
|
Sleep(5);
|
|
if (g_pHSI_Motion->m_IsUseTwentySixLight == 1 || g_pHSI_Motion->m_IsUseTwentySixLight == 2)
|
|
{
|
|
//二十六路/八路光源板的数据发送
|
|
DebugLog("UseTwentySixLight -> in");
|
|
int index = 7;
|
|
short int tempIntensity = 0;
|
|
for (int i = 1; i < 5; i++)
|
|
{
|
|
for (int j = 0; j < 8; j++)
|
|
{
|
|
//共26盏灯,到[2, 66]
|
|
if (i == 4 && j >= 2)
|
|
{
|
|
break;
|
|
}
|
|
if (i == 4)
|
|
{
|
|
if ((i * 16 + 1) + j == 65)
|
|
{
|
|
Intensities[1][64] = Intensities[0][0];
|
|
}
|
|
else if ((i * 16 + 1) + j == 66)
|
|
{
|
|
Intensities[1][64] = Intensities[2][0];
|
|
}
|
|
}
|
|
tempIntensity = (short int)(Intensities[1][(i * 16 + 1) + j] * ampTimes);
|
|
if (tempIntensity > 1120)
|
|
{
|
|
tempIntensity = 1120;
|
|
}
|
|
if (tempIntensity < 0)
|
|
{
|
|
tempIntensity = 0;
|
|
}
|
|
m_cSendData[index++] = (tempIntensity >> 8);
|
|
m_cSendData[index++] = (tempIntensity & 0x00ff);
|
|
}
|
|
}
|
|
if (g_pHSI_Motion->m_IsUseTwentySixLight == 1)
|
|
{
|
|
if (g_pHSI_Motion->m_bISUseMoreLights > 0)
|
|
{
|
|
if (g_pHSI_Motion->m_bConnected)
|
|
{
|
|
g_pHSI_Motion->m_selectedIndex = m_iSelectedIndex - 1;
|
|
}
|
|
else
|
|
{
|
|
g_pHSI_Motion->m_selectedIndex = m_iSelectedIndex;
|
|
}
|
|
for (size_t i = 0; i < 64; i++)
|
|
{
|
|
g_pHSI_Motion->lightdata[i] = m_cSendData[i];
|
|
}
|
|
if (g_pHSI_Motion->m_Led8MotionFlag[g_pHSI_Motion->m_selectedIndex])
|
|
{
|
|
g_pHSI_Motion->lightdata[0] = 0x02;
|
|
g_pHSI_Motion->lightdata[1] = 0x02;
|
|
g_pHSI_Motion->lightdata[2] = 0x02;
|
|
g_pHSI_Motion->lightdata[6] = 0x04;
|
|
g_pHSI_Motion->LightSend++;
|
|
Sleep(10);
|
|
}
|
|
else
|
|
{
|
|
g_pHSI_Motion->lightdata[0] = 0x02;
|
|
g_pHSI_Motion->lightdata[1] = 0x02;
|
|
g_pHSI_Motion->lightdata[2] = 0x02;
|
|
g_pHSI_Motion->lightdata[3] = 0x36;
|
|
g_pHSI_Motion->lightdata[4] = 0x04;
|
|
g_pHSI_Motion->LightSend++;
|
|
Sleep(10);
|
|
}
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
m_cSendData[0] = 0x02;
|
|
m_cSendData[1] = 0x02;
|
|
m_cSendData[2] = 0x02;
|
|
m_cSendData[3] = 0x36;
|
|
m_cSendData[4] = 0x04;
|
|
DebugLog("UseTwentySixLight -> in 2");
|
|
HidD_SetOutputReport(m_WriteHandle, m_cSendData, m_Capabilities.OutputReportByteLength);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
return rStatus;
|
|
}
|
|
//===========================================================================
|
|
BOOL HSI_Illumination::SetLampState_So7III(int _NumLamps, int(*_LampsType)[HSI_ILLUMINATION_MAX_BULB_TYPE], int(*bBulbStates)[HSI_ILLUMINATION_MAX_BULBS], double(*Intensities)[HSI_ILLUMINATION_MAX_BULBS], bool bWait)
|
|
{
|
|
//六环八区灯
|
|
DebugLog("SetLampState_So7III -> in");
|
|
BOOL rStatus(TRUE);
|
|
int iOffsetIndex(0);
|
|
short LampValue(0);
|
|
short LampMaxValue(0X1388);
|
|
short LampMinValue(0X0001);
|
|
BYTE cSendDataA[23] = {0x02,0x02,0x08,0XAA, 0X00, 0X01, 0X00, 0X01, 0X00, 0X01, 0X00, 0X01, 0X00, 0X01, 0X00, 0X01, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0XBB };
|
|
for (int i = 0; i < _NumLamps; i++)
|
|
{
|
|
switch (_LampsType[i][0])
|
|
{
|
|
case HSI_ILLUMINATION_LAMP_COAXIAL://3
|
|
{
|
|
if (bBulbStates[HSI_ILLUMINATION_LAMP_COAXIAL][0] == HSI_ILLUMINATION_BULB_STATE_TURN_ON)
|
|
{
|
|
LampValue = LampMinValue + static_cast<short>((LampMaxValue - LampMinValue)*Intensities[HSI_ILLUMINATION_LAMP_COAXIAL][0]);
|
|
}
|
|
else
|
|
{
|
|
LampValue = LampMinValue;
|
|
}
|
|
break;
|
|
}
|
|
case HSI_ILLUMINATION_LAMP_SURFACE:
|
|
{
|
|
double dMaxValue(-999.9), dTmpValue(0.0);
|
|
BYTE bTmpVal(0);
|
|
int iShift(0);
|
|
switch (_LampsType[i][1])
|
|
{
|
|
case HSI_ILLUMINATION_LAMP_CONTROL_BY_WHOLE_LAMP:
|
|
{
|
|
if (bBulbStates[HSI_ILLUMINATION_LAMP_SURFACE][0] == HSI_ILLUMINATION_BULB_STATE_TURN_ON)
|
|
{
|
|
LampValue = LampMinValue + static_cast<short>((LampMaxValue - LampMinValue)*Intensities[HSI_ILLUMINATION_LAMP_SURFACE][0]);
|
|
}
|
|
else
|
|
{
|
|
LampValue = LampMinValue;
|
|
}
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
iOffsetIndex = 4 + i * 2;
|
|
cSendDataA[iOffsetIndex] = (LampValue >> 8) & 0x00ff;
|
|
cSendDataA[iOffsetIndex + 1] = LampValue & 0x00ff;
|
|
}
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
iOffsetIndex = 16 + i;
|
|
cSendDataA[iOffsetIndex] = 0xff;
|
|
}
|
|
break;
|
|
}
|
|
case HSI_ILLUMINATION_LAMP_CONTROL_BY_RINGS:
|
|
{
|
|
dMaxValue = -999.9;
|
|
dTmpValue = 0.0;
|
|
for (int iRing = m_iMinRings; iRing <= m_iMaxRings; iRing++)
|
|
{
|
|
if (bBulbStates[HSI_ILLUMINATION_LAMP_SURFACE][iRing*HSI_ILLUMINATION_MAX_SECTORS] == HSI_ILLUMINATION_BULB_STATE_TURN_ON)
|
|
{
|
|
dTmpValue = Intensities[HSI_ILLUMINATION_LAMP_SURFACE][iRing*HSI_ILLUMINATION_MAX_SECTORS];
|
|
if (dTmpValue > PERCENT_PRECISION)
|
|
{
|
|
LampValue = LampMinValue + static_cast<short>((LampMaxValue - LampMinValue)*dTmpValue);
|
|
iOffsetIndex = (iRing - m_iMinRings) * 2 + 4;
|
|
cSendDataA[iOffsetIndex] = (LampValue >> 8) & 0x00ff;
|
|
cSendDataA[iOffsetIndex + 1] = LampValue & 0x00ff;
|
|
|
|
iOffsetIndex = 16 + (m_iMaxRings - iRing);
|
|
cSendDataA[iOffsetIndex] = 0xff;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dTmpValue = 0.0;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
case HSI_ILLUMINATION_LAMP_CONTROL_BY_OCTANTS:
|
|
{
|
|
dMaxValue = -999.9;
|
|
dTmpValue = 0.0;
|
|
bTmpVal = 0;
|
|
iShift = 0;
|
|
int iSector1;
|
|
for (int iSector = m_iMinSectors; iSector <= m_iMaxSectors; iSector++)
|
|
{
|
|
iSector1 = SO7II_SECTOR_ORDER[iSector - m_iMinSectors];
|
|
//dTmpValue=Intensities[HSI_ILLUMINATION_LAMP_SURFACE][iSector];
|
|
if (bBulbStates[HSI_ILLUMINATION_LAMP_SURFACE][iSector1] == HSI_ILLUMINATION_BULB_STATE_TURN_ON)
|
|
{
|
|
dTmpValue = Intensities[HSI_ILLUMINATION_LAMP_SURFACE][iSector1];
|
|
if (dTmpValue > dMaxValue)
|
|
{
|
|
dMaxValue = dTmpValue;
|
|
}
|
|
if (dTmpValue > PERCENT_PRECISION)
|
|
{
|
|
for (int iRing = m_iMinRings; iRing <= m_iMaxRings; iRing++)
|
|
{
|
|
iOffsetIndex = 16 + (m_iMaxRings - iRing);
|
|
bTmpVal = 1;
|
|
iShift = (m_iMaxSectors - iSector);
|
|
bTmpVal = bTmpVal << iShift;
|
|
cSendDataA[iOffsetIndex] = cSendDataA[iOffsetIndex] | bTmpVal;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dTmpValue = 0.0;
|
|
if (dTmpValue > dMaxValue)
|
|
{
|
|
dMaxValue = dTmpValue;
|
|
}
|
|
}
|
|
}
|
|
LampValue = LampMinValue + static_cast<short>((LampMaxValue - LampMinValue)*dMaxValue);
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
iOffsetIndex = 4 + i * 2;
|
|
cSendDataA[iOffsetIndex] = (LampValue >> 8) & 0x00ff;
|
|
cSendDataA[iOffsetIndex + 1] = LampValue & 0x00ff;
|
|
}
|
|
break;
|
|
}
|
|
case HSI_ILLUMINATION_LAMP_CONTROL_BY_SEGMENTS:
|
|
{
|
|
double dAMaxValue[6] = { -999.9, -999.9, -999.9, -999.9, -999.9, -999.9 };
|
|
dTmpValue = 0.0;
|
|
bTmpVal = 0;
|
|
iShift = 0;
|
|
int iSector1;
|
|
for (int iSector = m_iMinSectors; iSector <= m_iMaxSectors; iSector++)
|
|
{
|
|
iSector1 = SO7II_SECTOR_ORDER[iSector - m_iMinSectors];
|
|
for (int iRing = m_iMinRings; iRing <= m_iMaxRings; iRing++)
|
|
{
|
|
if (bBulbStates[HSI_ILLUMINATION_LAMP_SURFACE][iRing*HSI_ILLUMINATION_MAX_SECTORS + iSector1] == HSI_ILLUMINATION_BULB_STATE_TURN_ON)
|
|
{
|
|
dTmpValue = Intensities[HSI_ILLUMINATION_LAMP_SURFACE][iRing*HSI_ILLUMINATION_MAX_SECTORS + iSector1];
|
|
if (dTmpValue > dAMaxValue[iRing - m_iMinRings])
|
|
{
|
|
dAMaxValue[iRing - m_iMinRings] = dTmpValue;
|
|
}
|
|
if (dTmpValue > PERCENT_PRECISION)
|
|
{
|
|
iOffsetIndex = 16 + (m_iMaxRings - iRing);
|
|
bTmpVal = 1;
|
|
iShift = (m_iMaxSectors - iSector);
|
|
bTmpVal = bTmpVal << iShift;
|
|
cSendDataA[iOffsetIndex] = cSendDataA[iOffsetIndex] | bTmpVal;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dTmpValue = 0.0;
|
|
if (dTmpValue > dAMaxValue[iRing - m_iMinRings])
|
|
{
|
|
dAMaxValue[iRing - m_iMinRings] = dTmpValue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
LampValue = LampMinValue + static_cast<short>((LampMaxValue - LampMinValue)*dAMaxValue[i]);
|
|
iOffsetIndex = 4 + i * 2;
|
|
cSendDataA[iOffsetIndex] = (LampValue >> 8) & 0x00ff;
|
|
cSendDataA[iOffsetIndex + 1] = LampValue & 0x00ff;
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
case HSI_ILLUMINATION_LAMP_PROFILE://2
|
|
{
|
|
if (bBulbStates[HSI_ILLUMINATION_LAMP_PROFILE][0] == HSI_ILLUMINATION_BULB_STATE_TURN_ON)
|
|
{
|
|
LampValue = LampMinValue + static_cast<short>((LampMaxValue - LampMinValue)*Intensities[HSI_ILLUMINATION_LAMP_PROFILE][0]);
|
|
}
|
|
else
|
|
{
|
|
LampValue = LampMinValue;
|
|
}
|
|
break;
|
|
}
|
|
case HSI_ILLUMINATION_LAMP_PROFILE_OUTER://1
|
|
{
|
|
if (bBulbStates[HSI_ILLUMINATION_LAMP_PROFILE_OUTER][0] == HSI_ILLUMINATION_BULB_STATE_TURN_ON)
|
|
{
|
|
LampValue = LampMinValue + static_cast<short>((LampMaxValue - LampMinValue)*Intensities[HSI_ILLUMINATION_LAMP_PROFILE_OUTER][0]);
|
|
}
|
|
else
|
|
{
|
|
LampValue = LampMinValue;
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
//CString strlog("");
|
|
//for (int i = 0; i < 23;i++)
|
|
//{
|
|
// strlog += (CString((const char*)cSendDataA[i]) + " ");
|
|
//}
|
|
//DebugLog("SetLampState_So7III -> " + strlog);
|
|
DWORD iSendDataLength = 23;
|
|
if (g_pHSI_Motion->m_bConnected)
|
|
{
|
|
if (m_iSelectedIndex == 0)
|
|
{
|
|
DebugLog("6_8_EF3");
|
|
g_pHSI_Motion->Send_Command(m_iSelectedIndex, (const char*)cSendDataA, 64);
|
|
Sleep(10);
|
|
}
|
|
else
|
|
{
|
|
DebugLog("6_8_other");
|
|
g_pHSI_Motion->m_selectedIndex = m_iSelectedIndex - 1;
|
|
if (g_pHSI_Motion->m_bISUseMoreLights > 0)
|
|
{
|
|
for (size_t i = 0; i < 64; i++)
|
|
{
|
|
g_pHSI_Motion->lightdata[i] = cSendDataA[i];
|
|
}
|
|
g_pHSI_Motion->LightSend++;
|
|
Sleep(10);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
g_pHSI_Motion->m_selectedIndex = m_iSelectedIndex;
|
|
if (g_pHSI_Motion->m_bISUseMoreLights > 0)
|
|
{
|
|
for (size_t i = 0; i < 64; i++)
|
|
{
|
|
g_pHSI_Motion->lightdata[i] = cSendDataA[i];
|
|
}
|
|
g_pHSI_Motion->LightSend++;
|
|
Sleep(10);
|
|
}
|
|
}
|
|
return rStatus;
|
|
}
|
|
//===========================================================================
|
|
BOOL HSI_Illumination::SetLampState_So7IIII(int _NumLamps, int(*_LampsType)[HSI_ILLUMINATION_MAX_BULB_TYPE], int(*bBulbStates)[HSI_ILLUMINATION_MAX_BULBS], double(*Intensities)[HSI_ILLUMINATION_MAX_BULBS], bool bWait)
|
|
{
|
|
//两环八区灯
|
|
DebugLog("SetLampState_So7IIII -> in");
|
|
BOOL rStatus(TRUE);
|
|
int iOffsetIndex(0);
|
|
short LampValue(0);
|
|
short LampMaxValue(255);
|
|
short LampMinValue(1);
|
|
BYTE cSendDataA[9] = { 0xA1, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xB1 };
|
|
UNREFERENCED_PARAMETER(bWait);
|
|
for (int i = 0; i < _NumLamps; i++)
|
|
{
|
|
switch (_LampsType[i][0])
|
|
{
|
|
case HSI_ILLUMINATION_LAMP_COAXIAL://3
|
|
{
|
|
if (bBulbStates[HSI_ILLUMINATION_LAMP_COAXIAL][0] == HSI_ILLUMINATION_BULB_STATE_TURN_ON)
|
|
{
|
|
LampValue = LampMinValue + static_cast<short>((LampMaxValue - LampMinValue)*Intensities[HSI_ILLUMINATION_LAMP_COAXIAL][0]);
|
|
}
|
|
else
|
|
{
|
|
LampValue = LampMinValue;
|
|
}
|
|
cSendDataA[4] = static_cast<char>(LampValue);
|
|
break;
|
|
}
|
|
case HSI_ILLUMINATION_LAMP_SURFACE:
|
|
{
|
|
double dMaxValue(-999.9), dTmpValue(0.0);
|
|
BYTE bTmpVal(0);
|
|
int iShift(0);
|
|
if (bBulbStates[HSI_ILLUMINATION_LAMP_SURFACE][0] == HSI_ILLUMINATION_BULB_STATE_TURN_ON)
|
|
{
|
|
LampValue = LampMinValue + static_cast<short>((LampMaxValue - LampMinValue)*Intensities[HSI_ILLUMINATION_LAMP_SURFACE][0]);
|
|
}
|
|
else
|
|
{
|
|
LampValue = LampMinValue;
|
|
}
|
|
cSendDataA[2] = static_cast<char>(LampValue);
|
|
switch (_LampsType[i][1])
|
|
{
|
|
case HSI_ILLUMINATION_LAMP_CONTROL_BY_WHOLE_LAMP:
|
|
{
|
|
if (bBulbStates[HSI_ILLUMINATION_LAMP_SURFACE][0] == HSI_ILLUMINATION_BULB_STATE_TURN_ON)
|
|
{
|
|
LampValue = LampMinValue + static_cast<short>((LampMaxValue - LampMinValue)*Intensities[HSI_ILLUMINATION_LAMP_SURFACE][0]);
|
|
}
|
|
else
|
|
{
|
|
LampValue = LampMinValue;
|
|
}
|
|
if (m_iSo7DoubleSurface == 0)
|
|
{
|
|
cSendDataA[6] = (BYTE)0xff;
|
|
cSendDataA[7] = (BYTE)0xff;
|
|
cSendDataA[3] = static_cast<char>(LampValue);
|
|
}
|
|
break;
|
|
}
|
|
case HSI_ILLUMINATION_LAMP_CONTROL_BY_RINGS:
|
|
{
|
|
dMaxValue = -999.9;
|
|
dTmpValue = 0.0;
|
|
for (int iRing = m_iMinRings; iRing <= m_iMaxRings; iRing++)
|
|
{
|
|
if (bBulbStates[HSI_ILLUMINATION_LAMP_SURFACE][iRing*HSI_ILLUMINATION_MAX_SECTORS] == HSI_ILLUMINATION_BULB_STATE_TURN_ON)
|
|
{
|
|
dTmpValue = Intensities[HSI_ILLUMINATION_LAMP_SURFACE][iRing*HSI_ILLUMINATION_MAX_SECTORS];
|
|
if (dTmpValue > dMaxValue)
|
|
{
|
|
dMaxValue = dTmpValue;
|
|
}
|
|
if (dTmpValue > PERCENT_PRECISION)
|
|
{
|
|
iOffsetIndex = iRing - m_iMinRings;
|
|
if (iOffsetIndex<2)
|
|
{
|
|
cSendDataA[7 - iOffsetIndex] = (BYTE)0xff;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dTmpValue = 0.0;
|
|
if (dTmpValue > dMaxValue)
|
|
{
|
|
dMaxValue = dTmpValue;
|
|
}
|
|
}
|
|
}
|
|
LampValue = LampMinValue + static_cast<short>((LampMaxValue - LampMinValue)*dMaxValue);
|
|
cSendDataA[3] = static_cast<char>(LampValue);
|
|
break;
|
|
}
|
|
case HSI_ILLUMINATION_LAMP_CONTROL_BY_OCTANTS:
|
|
{
|
|
dMaxValue = -999.9;
|
|
dTmpValue = 0.0;
|
|
bTmpVal = 0;
|
|
iShift = 0;
|
|
cSendDataA[6] = 0;
|
|
cSendDataA[7] = 0;
|
|
for (int iSector = m_iMinSectors; iSector <= m_iMaxSectors; iSector++)
|
|
{
|
|
if (bBulbStates[HSI_ILLUMINATION_LAMP_SURFACE][iSector] == HSI_ILLUMINATION_BULB_STATE_TURN_ON)
|
|
{
|
|
dTmpValue = Intensities[HSI_ILLUMINATION_LAMP_SURFACE][iSector];
|
|
if (dTmpValue > dMaxValue)
|
|
{
|
|
dMaxValue = dTmpValue;
|
|
}
|
|
if (dTmpValue > PERCENT_PRECISION)
|
|
{
|
|
for (int iRing = m_iMinRings; iRing <= m_iMaxRings; iRing++)
|
|
{
|
|
iOffsetIndex = iRing - m_iMinRings;
|
|
bTmpVal = 1;
|
|
iShift = (m_iMaxSectors - iSector);
|
|
bTmpVal = bTmpVal << iShift;
|
|
if (iOffsetIndex < 2)
|
|
cSendDataA[7 - iOffsetIndex] = cSendDataA[7 - iOffsetIndex] | bTmpVal;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dTmpValue = 0.0;
|
|
if (dTmpValue > dMaxValue)
|
|
{
|
|
dMaxValue = dTmpValue;
|
|
}
|
|
}
|
|
}
|
|
LampValue = LampMinValue + static_cast<short>((LampMaxValue - LampMinValue)*dMaxValue);
|
|
cSendDataA[3] = static_cast<char>(LampValue);
|
|
break;
|
|
}
|
|
case HSI_ILLUMINATION_LAMP_CONTROL_BY_SEGMENTS:
|
|
{
|
|
dMaxValue = -999.9;
|
|
dTmpValue = 0.0;
|
|
bTmpVal = 0;
|
|
iShift = 0;
|
|
cSendDataA[6] = 0;
|
|
cSendDataA[7] = 0;
|
|
for (int iSector = m_iMinSectors; iSector <= m_iMaxSectors; iSector++)
|
|
{
|
|
for (int iRing = m_iMinRings; iRing <= m_iMaxRings; iRing++)
|
|
{
|
|
if (bBulbStates[HSI_ILLUMINATION_LAMP_SURFACE][iRing*HSI_ILLUMINATION_MAX_SECTORS + iSector] == HSI_ILLUMINATION_BULB_STATE_TURN_ON)
|
|
{
|
|
dTmpValue = Intensities[HSI_ILLUMINATION_LAMP_SURFACE][iRing*HSI_ILLUMINATION_MAX_SECTORS + iSector];
|
|
if (dTmpValue > dMaxValue)
|
|
{
|
|
dMaxValue = dTmpValue;
|
|
}
|
|
if (dTmpValue > PERCENT_PRECISION)
|
|
{
|
|
iOffsetIndex = (iRing - m_iMinRings);
|
|
bTmpVal = 1;
|
|
iShift = (m_iMaxSectors - iSector);
|
|
bTmpVal = bTmpVal << iShift;
|
|
|
|
if (iOffsetIndex < 2)
|
|
cSendDataA[7 - iOffsetIndex] = cSendDataA[7 - iOffsetIndex] | bTmpVal;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dTmpValue = 0.0;
|
|
if (dTmpValue > dMaxValue)
|
|
{
|
|
dMaxValue = dTmpValue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
LampValue = LampMinValue + static_cast<short>((LampMaxValue - LampMinValue)*dMaxValue);
|
|
cSendDataA[3] = static_cast<char>(LampValue);
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
case HSI_ILLUMINATION_LAMP_PROFILE:
|
|
{
|
|
if (bBulbStates[HSI_ILLUMINATION_LAMP_PROFILE][0] == HSI_ILLUMINATION_BULB_STATE_TURN_ON)
|
|
{
|
|
LampValue = LampMinValue + static_cast<short>((LampMaxValue - LampMinValue)*Intensities[HSI_ILLUMINATION_LAMP_PROFILE][0]);
|
|
}
|
|
else
|
|
{
|
|
LampValue = LampMinValue;
|
|
}
|
|
iOffsetIndex = 2 * 2 - 1;
|
|
cSendDataA[1] = static_cast<char>(LampValue);
|
|
break;
|
|
}
|
|
case HSI_ILLUMINATION_LAMP_PROFILE_OUTER:
|
|
{
|
|
if (bBulbStates[HSI_ILLUMINATION_LAMP_PROFILE_OUTER][0] == HSI_ILLUMINATION_BULB_STATE_TURN_ON)
|
|
{
|
|
LampValue = LampMinValue + static_cast<short>((LampMaxValue - LampMinValue)*Intensities[HSI_ILLUMINATION_LAMP_PROFILE_OUTER][0]);
|
|
}
|
|
else
|
|
{
|
|
LampValue = LampMinValue;
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
CString ss = "";
|
|
ss = (CString)cSendDataA;
|
|
DebugLog(ss);
|
|
DWORD sendDataLength = 9;
|
|
if (m_bRS232AOpened)
|
|
{
|
|
_SendA_Command((const char*)cSendDataA, sendDataLength);
|
|
}
|
|
DebugLog("SetLampState_So7IIII -> out");
|
|
return rStatus;
|
|
}
|
|
//===========================================================================
|
|
BOOL HSI_Illumination::_SendA_Command(const char* _SendData, DWORD _SendDataLength)
|
|
{
|
|
BOOL rStatus(FALSE);
|
|
if (m_bRS232AOpened)
|
|
{
|
|
DWORD iWriteByte(0);
|
|
iWriteByte = m_SO7_SerialA.Send(_SendData, _SendDataLength);
|
|
}
|
|
return rStatus;
|
|
};
|
|
//===========================================================================
|
|
BOOL HSI_Illumination::So7LightII_set_light_off()
|
|
{
|
|
for (size_t i = 2; i < 64; i++)
|
|
{
|
|
m_cSendData[i] = 0;
|
|
}
|
|
if (g_pHSI_Motion)
|
|
{
|
|
if (g_pHSI_Motion->m_bConnected)
|
|
{
|
|
//EF3 关闭灯光
|
|
m_cSendData[0] = 2;
|
|
m_cSendData[1] = 2;
|
|
g_pHSI_Motion->Send_Command(0, (const char*)m_cSendData, 64);
|
|
}
|
|
if (g_pHSI_Motion->m_IsUseTwentySixLight == 2)
|
|
{
|
|
//二十六路关闭灯光 HID通信
|
|
m_cSendData[0] = 0x02;
|
|
m_cSendData[1] = 0x02;
|
|
m_cSendData[2] = 0x02;
|
|
m_cSendData[3] = 0x36;
|
|
m_cSendData[4] = 0x04;
|
|
DebugLog("UseTwentySixLight -> in 2");
|
|
HidD_SetOutputReport(m_WriteHandle, m_cSendData, m_Capabilities.OutputReportByteLength);
|
|
}
|
|
if (g_pHSI_Motion->m_bISUseMoreLights > 0)
|
|
{
|
|
for (size_t i = 0; i < g_pHSI_Motion->m_bISUseMoreLights; i++)
|
|
{
|
|
if (g_pHSI_Motion->m_Led8MotionFlag[i])
|
|
{
|
|
//8路光源板关闭灯光
|
|
for (size_t j = 0; j < 64; j++)
|
|
{
|
|
g_pHSI_Motion->lightdata[j] = m_cSendData[j];
|
|
}
|
|
g_pHSI_Motion->lightdata[0] = 0x02;
|
|
g_pHSI_Motion->lightdata[1] = 0x02;
|
|
g_pHSI_Motion->lightdata[2] = 0x02;
|
|
g_pHSI_Motion->lightdata[6] = 0x04;
|
|
g_pHSI_Motion->m_selectedIndex = i;
|
|
g_pHSI_Motion->LightSend++;
|
|
Sleep(10);
|
|
}
|
|
else
|
|
{
|
|
//26路光源板关闭灯光
|
|
for (size_t i = 5; i < 64; i++)
|
|
{
|
|
g_pHSI_Motion->lightdata[i] = m_cSendData[i];
|
|
}
|
|
g_pHSI_Motion->lightdata[0] = 0x02;
|
|
g_pHSI_Motion->lightdata[1] = 0x02;
|
|
g_pHSI_Motion->lightdata[2] = 0x02;
|
|
g_pHSI_Motion->lightdata[3] = 0x36;
|
|
g_pHSI_Motion->lightdata[4] = 0x04;
|
|
|
|
g_pHSI_Motion->LightSend++;
|
|
Sleep(5);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Sleep(10);
|
|
return TRUE;
|
|
}
|
|
//===========================================================================
|
|
BOOL HSI_Illumination::So7LightIII_set_light_off()
|
|
{
|
|
//六环八区关灯
|
|
BYTE cSendDataA[24] = { 0X02, 0X02, 0X08, 0XAA, 0X00, 0X01, 0X00, 0X01, 0X00, 0X01, 0X00, 0X01, 0X00, 0X01, 0X00, 0X01, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0XBB };
|
|
DWORD iSendDataLength = 24;
|
|
if (g_pHSI_Motion && (g_pHSI_Motion->m_IsUseSixRingEightArea == 1))
|
|
{
|
|
if (g_pHSI_Motion->m_bConnected)
|
|
{
|
|
g_pHSI_Motion->Send_Command(0, (const char*)cSendDataA, 64);
|
|
Sleep(5);
|
|
}
|
|
if (g_pHSI_Motion->m_bISUseMoreLights > 0)
|
|
{
|
|
for (size_t i = 0; i < g_pHSI_Motion->m_bISUseMoreLights; i++)
|
|
{
|
|
g_pHSI_Motion->m_selectedIndex = i;
|
|
for (size_t i = 0; i < 64; i++)
|
|
{
|
|
g_pHSI_Motion->lightdata[i] = cSendDataA[i];
|
|
}
|
|
g_pHSI_Motion->LightSend++;
|
|
Sleep(5);
|
|
}
|
|
}
|
|
}
|
|
BYTE cSendDataB[9] = { 0xA1, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xB1 };
|
|
iSendDataLength = 9;
|
|
if (m_bRS232AOpened)
|
|
{
|
|
_SendA_Command((const char*)cSendDataB, iSendDataLength);
|
|
}
|
|
return TRUE;
|
|
}
|
|
//===========================================================================
|
|
HSI_STATUS HSI_Illumination::Shutdown()
|
|
{
|
|
auto rStatus = HSI_STATUS_NORMAL;
|
|
m_iIlluminationType = HSI_ILLUMINATION_INFO_SO7_III;
|
|
if (m_iIlluminationType == HSI_ILLUMINATION_INFO_SO7_III)
|
|
{
|
|
So7LightIII_set_light_off();
|
|
}
|
|
m_iIlluminationType = HSI_ILLUMINATION_INFO_SO7_II;
|
|
if (m_iIlluminationType == HSI_ILLUMINATION_INFO_SO7_II)
|
|
{
|
|
So7LightII_set_light_off();
|
|
}
|
|
return rStatus;
|
|
}
|
|
//===========================================================================
|
|
VOID HSI_Illumination::EventCallback(sHSIEventProperties& sEventProp)
|
|
{
|
|
if (g_pHSI_Sevenocean_EF3)
|
|
{
|
|
g_pHSI_Sevenocean_EF3->EventCallback(sEventProp);
|
|
}
|
|
}
|
|
|
|
void HSI_Illumination::CreateDirectorySO(CString directoryLog)
|
|
{
|
|
// 文件夹不存在
|
|
if (FALSE == PathFileExists(directoryLog))
|
|
{
|
|
//循环创建日志文件夹
|
|
int nCout = directoryLog.Replace('\\', '/');
|
|
int findOff = 0;
|
|
for (int i = 1; i<nCout; i++)
|
|
{
|
|
findOff = directoryLog.Find('/', findOff + 1);
|
|
if (i == 1)
|
|
{
|
|
findOff = directoryLog.Find('/', findOff + 1);
|
|
}
|
|
CString floderPath = directoryLog.Mid(0, findOff);
|
|
CreateDirectory(floderPath, NULL);
|
|
}
|
|
}
|
|
}
|
|
|
|
void HSI_Illumination::DebugLog(CString strlog)
|
|
{
|
|
if (!g_pHSI_Motion->m_LogIsOpen[1])
|
|
return;
|
|
CString strPath = ".\\Log\\";
|
|
CreateDirectorySO(strPath);
|
|
|
|
CString csLogFileFullName = strPath + "\\Light.log";
|
|
|
|
if (true)
|
|
{
|
|
CStdioFile outFile;
|
|
if (outFile.Open(csLogFileFullName,
|
|
CFile::modeCreate | CFile::modeNoTruncate | CFile::modeWrite))
|
|
{
|
|
|
|
CTime _cTime = CTime::GetCurrentTime();
|
|
CString csTime = _cTime.Format("[%m/%d %H:%M:%S");
|
|
struct _timeb timebuffer;
|
|
_ftime64_s(&timebuffer);
|
|
//CString milTime("");
|
|
//milTime.Format("%s", timebuffer.millitm);
|
|
char ch[20] = { 0 };
|
|
_itoa_s(timebuffer.millitm,ch,10);
|
|
CString strTime = csTime + CString(ch);
|
|
|
|
outFile.SeekToEnd();//先定位到文件尾部
|
|
outFile.WriteString(strTime + strlog);
|
|
outFile.WriteString((LPCTSTR)"\n");
|
|
}
|
|
else
|
|
{
|
|
//DoNothing();
|
|
}
|
|
outFile.Close();
|
|
}
|
|
}
|
|
//===========================================================================
|
|
void HSI_Illumination::TestSELight(bool flag)
|
|
{
|
|
BYTE cSendDataA[23] = { 0x02, 0x02, 0x08, 0XAA, 0X00, 0X01, 0X00, 0X01, 0X00, 0X01, 0X00, 0X01, 0X00, 0X01, 0X00, 0X01, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0XBB };
|
|
BYTE cSendDataB[23] = { 0x02, 0x02, 0x08, 0XAA, 0X02, 0XFF, 0X02, 0XFF, 0X02, 0XFF, 0X02, 0XFF, 0X02, 0XFF, 0X02, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XBB };
|
|
if (g_pHSI_Motion && g_pHSI_Motion->m_bConnected && flag)
|
|
{
|
|
g_pHSI_Motion->Send_Command(0, (const char*)cSendDataB, 64);
|
|
Sleep(10);
|
|
}
|
|
else
|
|
{
|
|
g_pHSI_Motion->Send_Command(0, (const char*)cSendDataA, 64);
|
|
Sleep(10);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
//========================光源控制器USB控制==================================
|
|
//26路 HID通信
|
|
//===========================================================================
|
|
bool HSI_Illumination::FindTheHID()
|
|
{
|
|
HIDD_ATTRIBUTES Attributes;
|
|
SP_DEVICE_INTERFACE_DATA devInfoData;
|
|
bool LastDevice = FALSE;
|
|
int MemberIndex = 0;
|
|
LONG Result;
|
|
CString UsageDescription;
|
|
HidD_GetHidGuid(&m_HidGuid);
|
|
m_hDevInfo = SetupDiGetClassDevs(&m_HidGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
|
|
devInfoData.cbSize = sizeof(devInfoData);
|
|
MemberIndex = 0;
|
|
LastDevice = FALSE;
|
|
do
|
|
{
|
|
Result = SetupDiEnumDeviceInterfaces(m_hDevInfo, 0, &m_HidGuid, MemberIndex, &devInfoData);
|
|
if (Result != 0)
|
|
{
|
|
Result = SetupDiGetDeviceInterfaceDetail(m_hDevInfo, &devInfoData, NULL, 0, &m_Length, NULL);
|
|
m_detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(m_Length);
|
|
m_detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
|
|
Result = SetupDiGetDeviceInterfaceDetail(m_hDevInfo, &devInfoData, m_detailData, m_Length, &m_Required, NULL);
|
|
m_DeviceHandle = CreateFile(m_detailData->DevicePath, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, (LPSECURITY_ATTRIBUTES)NULL, OPEN_EXISTING, 0, NULL);
|
|
Attributes.Size = sizeof(Attributes);
|
|
Result = HidD_GetAttributes(m_DeviceHandle, &Attributes);
|
|
m_MyDeviceDetected = FALSE;
|
|
if (Attributes.VendorID == m_VendorID)
|
|
{
|
|
if (Attributes.ProductID == m_ProductID)
|
|
{
|
|
m_MyDeviceDetected = TRUE;
|
|
m_MyDevicePathName = m_detailData->DevicePath;
|
|
RegisterForDeviceNotifications();
|
|
GetDeviceCapabilities();
|
|
m_bSTM32UsbFlag = true;
|
|
m_WriteHandle = CreateFile(m_detailData->DevicePath, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, (LPSECURITY_ATTRIBUTES)NULL, OPEN_EXISTING, 0, NULL);
|
|
PrepareForOverlappedTransfer();
|
|
}
|
|
else
|
|
{
|
|
m_bSTM32UsbFlag = false;
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
m_bSTM32UsbFlag = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
LastDevice = TRUE;
|
|
m_bSTM32UsbFlag = false;
|
|
}
|
|
MemberIndex = MemberIndex + 1;
|
|
|
|
} while ((LastDevice == FALSE) && (m_MyDeviceDetected == FALSE));
|
|
return m_bSTM32UsbFlag;
|
|
}
|
|
//===========================================================================
|
|
void HSI_Illumination::CloseHandles()
|
|
{
|
|
if (m_DeviceHandle != INVALID_HANDLE_VALUE)
|
|
{
|
|
CloseHandle(m_DeviceHandle);
|
|
}
|
|
if (m_ReadHandle != INVALID_HANDLE_VALUE)
|
|
{
|
|
CloseHandle(m_ReadHandle);
|
|
}
|
|
if (m_WriteHandle != INVALID_HANDLE_VALUE)
|
|
{
|
|
CloseHandle(m_WriteHandle);
|
|
}
|
|
}
|
|
//===========================================================================
|
|
void HSI_Illumination::RegisterForDeviceNotifications()
|
|
{
|
|
DEV_BROADCAST_DEVICEINTERFACE DevBroadcastDeviceInterface;
|
|
HDEVNOTIFY DeviceNotificationHandle;
|
|
DevBroadcastDeviceInterface.dbcc_size = sizeof(DevBroadcastDeviceInterface);
|
|
DevBroadcastDeviceInterface.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
|
|
DevBroadcastDeviceInterface.dbcc_classguid = m_HidGuid;
|
|
DeviceNotificationHandle = RegisterDeviceNotification(hWnd, &DevBroadcastDeviceInterface, DEVICE_NOTIFY_WINDOW_HANDLE);
|
|
}
|
|
//===========================================================================
|
|
void HSI_Illumination::GetDeviceCapabilities()
|
|
{
|
|
PHIDP_PREPARSED_DATA PreparsedData;
|
|
HidD_GetPreparsedData(m_DeviceHandle, &PreparsedData);
|
|
HidP_GetCaps(PreparsedData, &m_Capabilities);
|
|
HidD_FreePreparsedData(PreparsedData);
|
|
}
|
|
//===========================================================================
|
|
void HSI_Illumination::PrepareForOverlappedTransfer()
|
|
{
|
|
m_ReadHandle = CreateFile(m_detailData->DevicePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, (LPSECURITY_ATTRIBUTES)NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
|
if (m_hEventObject == 0)
|
|
{
|
|
m_hEventObject = CreateEvent(NULL, TRUE, TRUE, _T(""));
|
|
m_HIDOverlapped.hEvent = m_hEventObject;
|
|
m_HIDOverlapped.Offset = 0;
|
|
m_HIDOverlapped.OffsetHigh = 0;
|
|
}
|
|
} |