|
@@ -54,11 +54,25 @@ COLORREF HexColor2RGB(std::string strHexColor)
|
|
|
|
|
|
return RGB(r, g, b);
|
|
|
}
|
|
|
+
|
|
|
+std::string RGBColor2Hex(DWORD dwRGB)
|
|
|
+{
|
|
|
+ DWORD r = GetRValue(dwRGB);
|
|
|
+ DWORD g = GetGValue(dwRGB);
|
|
|
+ DWORD b = GetBValue(dwRGB);
|
|
|
+
|
|
|
+ TCHAR szHex[8] = {0};
|
|
|
+ _stprintf_s(szHex, _T("%02X%02X%02X"), r, g, b);
|
|
|
+
|
|
|
+ return std::string(szHex);
|
|
|
+}
|
|
|
+
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
// CResourceViewBar
|
|
|
-
|
|
|
+KeyInfo* CPropertiesWnd::m_pKeyInfo = NULL;
|
|
|
CPropertiesWnd::CPropertiesWnd()
|
|
|
{
|
|
|
+ m_dwThreadId = 0;
|
|
|
}
|
|
|
|
|
|
CPropertiesWnd::~CPropertiesWnd()
|
|
@@ -182,9 +196,8 @@ void CPropertiesWnd::OnSignalBtnClick(UINT uId) //
|
|
|
CString text;
|
|
|
pWnd->GetWindowText(text);
|
|
|
KeyInfo *pKey = m_map_key.find(id)->second;
|
|
|
- // 发送红外信号;
|
|
|
- //SendInfraedSignal(pKey);
|
|
|
- LearnInfraedSignal(pKey);
|
|
|
+ // 发送红外信号或学习;
|
|
|
+ Global::g_bLearn ? LearnInfraedSignal(uId, pKey) : SendInfraedSignal(pKey);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -264,13 +277,23 @@ void CPropertiesWnd::LoadKeyInfo(std::vector<KeyInfo> &vtKeyInfo, TString path)
|
|
|
{
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
// 获取属性;
|
|
|
- m_nCols = _tstoi(pXmlRoot->Attribute("cols") ? pXmlRoot->Attribute("cols") : "3");
|
|
|
- m_nRowSpacing = _tstoi(pXmlRoot->Attribute("rowSpacing") ? pXmlRoot->Attribute("rowSpacing") : "5");
|
|
|
- m_nColSpacing = _tstoi(pXmlRoot->Attribute("colSpacing") ? pXmlRoot->Attribute("colSpacing") : "5");
|
|
|
- m_nTopMargin = _tstoi(pXmlRoot->Attribute("topMargin") ? pXmlRoot->Attribute("topMargin") : "8");
|
|
|
- m_nLeftMargin = _tstoi(pXmlRoot->Attribute("leftMargin") ? pXmlRoot->Attribute("leftMargin") : "8");
|
|
|
- int nWidth = _tstoi(pXmlRoot->Attribute("with") ? pXmlRoot->Attribute("with") : "58");
|
|
|
- int nHeight = _tstoi(pXmlRoot->Attribute("height") ? pXmlRoot->Attribute("height") : "25");
|
|
|
+ m_curKeyLayout.cols = pXmlRoot->Attribute("cols") ? pXmlRoot->Attribute("cols") : "3";
|
|
|
+ m_curKeyLayout.with = pXmlRoot->Attribute("with") ? pXmlRoot->Attribute("with") : "58";
|
|
|
+ m_curKeyLayout.height = pXmlRoot->Attribute("height") ? pXmlRoot->Attribute("height") : "25";
|
|
|
+ m_curKeyLayout.rowSpacing = pXmlRoot->Attribute("rowSpacing") ? pXmlRoot->Attribute("rowSpacing") : "5";
|
|
|
+ m_curKeyLayout.colSpacing = pXmlRoot->Attribute("colSpacing") ? pXmlRoot->Attribute("colSpacing") : "5";
|
|
|
+ m_curKeyLayout.leftMargin = pXmlRoot->Attribute("leftMargin") ? pXmlRoot->Attribute("leftMargin") : "8";
|
|
|
+ m_curKeyLayout.topMargin = pXmlRoot->Attribute("topMargin") ? pXmlRoot->Attribute("topMargin") : "8";
|
|
|
+ m_curKeyLayout.ver = pXmlRoot->Attribute("ver") ? pXmlRoot->Attribute("ver") : "1.0.0.1";
|
|
|
+ m_curKeyLayout.desc = pXmlRoot->Attribute("desc") ? pXmlRoot->Attribute("desc") : "key info";
|
|
|
+
|
|
|
+ m_nCols = _tstoi(m_curKeyLayout.cols.c_str());
|
|
|
+ m_nRowSpacing = _tstoi(m_curKeyLayout.rowSpacing.c_str());
|
|
|
+ m_nColSpacing = _tstoi(m_curKeyLayout.colSpacing.c_str());
|
|
|
+ m_nTopMargin = _tstoi(m_curKeyLayout.topMargin.c_str());
|
|
|
+ m_nLeftMargin = _tstoi(m_curKeyLayout.leftMargin.c_str());
|
|
|
+ int nWidth = _tstoi(m_curKeyLayout.with.c_str());
|
|
|
+ int nHeight = _tstoi(m_curKeyLayout.height.c_str());
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
// 子项;
|
|
@@ -414,16 +437,59 @@ void CPropertiesWnd::SaveKeyInfo(std::vector<KeyInfo> &vtKeyInfo, TString path)
|
|
|
pXmlRoot = doc.NewElement("KeyList");
|
|
|
if ( pXmlRoot )
|
|
|
{
|
|
|
- pXmlRoot->SetAttribute(_T("cols"), _T("4"));
|
|
|
- pXmlRoot->SetAttribute(_T("with"), _T("60"));
|
|
|
- pXmlRoot->SetAttribute(_T("height"), _T("25"));
|
|
|
- pXmlRoot->SetAttribute(_T("rowSpacing"), _T("5"));
|
|
|
- pXmlRoot->SetAttribute(_T("colSpacing"), _T("3"));
|
|
|
- pXmlRoot->SetAttribute(_T("leftMargin"), _T("8"));
|
|
|
- pXmlRoot->SetAttribute(_T("topMargin"), _T("8"));
|
|
|
- pXmlRoot->SetAttribute(_T("ver"), _T("1.0.0.1"));
|
|
|
- pXmlRoot->SetAttribute(_T("desc"), _T("key info"));
|
|
|
+ pXmlRoot->SetAttribute(_T("cols"), m_curKeyLayout.cols.c_str());
|
|
|
+ pXmlRoot->SetAttribute(_T("with"), m_curKeyLayout.with.c_str());
|
|
|
+ pXmlRoot->SetAttribute(_T("height"), m_curKeyLayout.height.c_str());
|
|
|
+ pXmlRoot->SetAttribute(_T("rowSpacing"), m_curKeyLayout.rowSpacing.c_str());
|
|
|
+ pXmlRoot->SetAttribute(_T("colSpacing"), m_curKeyLayout.colSpacing.c_str());
|
|
|
+ pXmlRoot->SetAttribute(_T("leftMargin"), m_curKeyLayout.leftMargin.c_str());
|
|
|
+ pXmlRoot->SetAttribute(_T("topMargin"), m_curKeyLayout.topMargin.c_str());
|
|
|
+ pXmlRoot->SetAttribute(_T("ver"), m_curKeyLayout.ver.c_str());
|
|
|
+ pXmlRoot->SetAttribute(_T("desc"), m_curKeyLayout.desc.c_str());
|
|
|
doc.InsertEndChild(pXmlRoot);
|
|
|
+
|
|
|
+ for (std::vector<KeyInfo>::iterator it = m_vtKeyInfo.begin(); it != m_vtKeyInfo.end(); it++ )
|
|
|
+ {
|
|
|
+ tinyxml2::XMLElement* pXmlElent = doc.NewElement("ITEM");
|
|
|
+ if ( pXmlElent )
|
|
|
+ {
|
|
|
+ pXmlElent->SetAttribute(_T("color"), RGBColor2Hex(it->color).c_str());
|
|
|
+ // 赋值各元素节点;
|
|
|
+ tinyxml2::XMLElement *pUse = doc.NewElement("USE");
|
|
|
+ pUse->SetText(1);
|
|
|
+ pXmlElent->InsertEndChild(pUse);
|
|
|
+
|
|
|
+ tinyxml2::XMLElement *pName = doc.NewElement("NAME");
|
|
|
+ pName->SetText(it->strName.c_str());
|
|
|
+ pXmlElent->InsertEndChild(pName);
|
|
|
+
|
|
|
+ tinyxml2::XMLElement *pDesc = doc.NewElement("DESC");
|
|
|
+ pDesc->SetText(it->strDesc.c_str());
|
|
|
+ pXmlElent->InsertEndChild(pDesc);
|
|
|
+
|
|
|
+ tinyxml2::XMLElement *pType = doc.NewElement("TYPE");
|
|
|
+ pType->SetText(it->strType.c_str());
|
|
|
+ pXmlElent->InsertEndChild(pType);
|
|
|
+
|
|
|
+ tinyxml2::XMLElement *pValue = doc.NewElement("VALUE");
|
|
|
+ pValue->SetText(it->strValue.c_str());
|
|
|
+ pXmlElent->InsertEndChild(pValue);
|
|
|
+
|
|
|
+ tinyxml2::XMLElement *pValue2 = doc.NewElement("VALUE2");
|
|
|
+ pValue2->SetText(it->strValue2.c_str());
|
|
|
+ pXmlElent->InsertEndChild(pValue2);
|
|
|
+
|
|
|
+ tinyxml2::XMLElement *pValue3 = doc.NewElement("VALUE3");
|
|
|
+ pValue3->SetText(it->strValue3.c_str());
|
|
|
+ pXmlElent->InsertEndChild(pValue3);
|
|
|
+
|
|
|
+ tinyxml2::XMLElement *pValue4 = doc.NewElement("VALUE4");
|
|
|
+ pValue4->SetText(it->strValue4.c_str());
|
|
|
+ pXmlElent->InsertEndChild(pValue4);
|
|
|
+
|
|
|
+ pXmlRoot->InsertEndChild(pXmlElent);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
doc.SaveFile(path.c_str());
|
|
@@ -686,8 +752,9 @@ bool CPropertiesWnd::SendInfraedSignal(const KeyInfo *pKey)
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-void CPropertiesWnd::LearnInfraedSignal(KeyInfo *pKey)
|
|
|
+void CPropertiesWnd::LearnInfraedSignal(UINT uId, KeyInfo *pKey)
|
|
|
{
|
|
|
+ m_pKeyInfo = pKey;
|
|
|
CMainFrame *pMainWnd = (CMainFrame*)AfxGetApp()->m_pMainWnd;
|
|
|
if ( !pMainWnd )
|
|
|
return;
|
|
@@ -715,8 +782,7 @@ void CPropertiesWnd::LearnInfraedSignal(KeyInfo *pKey)
|
|
|
// 发送学习红外信号;
|
|
|
if ( pMainWnd->m_SerialTW.WriteSync(szSendData, dwSendLen) )
|
|
|
{
|
|
|
- memset(szSendData, 0, MAX_SENDDATA);
|
|
|
- pMainWnd->m_SerialTW.ReadSync(szSendData, MAX_SENDDATA);
|
|
|
+ // 自动化的红外不返回,如果没有收到任务红外,会等待10多秒后自动结束学习状态;
|
|
|
TRACE("发送单信号成功\n");
|
|
|
}
|
|
|
else
|
|
@@ -724,21 +790,71 @@ void CPropertiesWnd::LearnInfraedSignal(KeyInfo *pKey)
|
|
|
TRACE("发送单信号失败\n");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if (m_dwThreadId)
|
|
|
+ {
|
|
|
+ PostThreadMessage(m_dwThreadId, 10, uId, 0);
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
-#if 1
|
|
|
- // 要另起线程后台读取,否则UI会卡住,体验不好;
|
|
|
- Sleep(1500);
|
|
|
- // 等待学习的红外信号发出;
|
|
|
- DWORD dwRealRead = 0;
|
|
|
- memset(szSendData, 0, MAX_SENDDATA);
|
|
|
- if ( dwRealRead = pMainWnd->m_SerialTW.ReadSync(szSendData, MAX_SENDDATA) )
|
|
|
+DWORD WINAPI CPropertiesWnd::ThreadLearn(LPVOID lpParam)
|
|
|
+{
|
|
|
+ CPropertiesWnd* pthis = (CPropertiesWnd*)lpParam;
|
|
|
+ CMainFrame* pMainWnd = (CMainFrame*)AfxGetApp()->m_pMainWnd;
|
|
|
+ if (!pthis || !pMainWnd)
|
|
|
+ return 0;
|
|
|
+
|
|
|
+ DWORD dwSendLen = 0;
|
|
|
+ byte szSendData[MAX_SENDDATA] = { 0 };
|
|
|
+ while (Global::g_bLearn)
|
|
|
{
|
|
|
- if ( Global::g_nVersion == 1 )
|
|
|
- pKey->strValue =(TCHAR*)szSendData;
|
|
|
- else if ( Global::g_nVersion == 2 )
|
|
|
- pKey->strValue2 = utils::BytesToHexString(szSendData, dwRealRead, ' ');
|
|
|
+ MSG msg;
|
|
|
+ if (GetMessage(&msg, NULL, 0, 0))
|
|
|
+ {
|
|
|
+ if (msg.message == 10)
|
|
|
+ {
|
|
|
+ DWORD dwTickCount = ::GetTickCount64();
|
|
|
+ while (GetTickCount64() - dwTickCount < 60000)
|
|
|
+ {
|
|
|
+ // 等待学习的红外信号发出;
|
|
|
+ DWORD dwRealRead = 0;
|
|
|
+ memset((char*)szSendData, 0, MAX_SENDDATA);
|
|
|
+ if (dwRealRead = pMainWnd->m_SerialTW.ReadSync(szSendData, MAX_SENDDATA))
|
|
|
+ {
|
|
|
+ if (m_pKeyInfo)
|
|
|
+ {
|
|
|
+ if (Global::g_nVersion == 1)
|
|
|
+ m_pKeyInfo->strValue = (TCHAR*)szSendData;
|
|
|
+ else if (Global::g_nVersion == 2)
|
|
|
+ {
|
|
|
+ std::string val = utils::BytesToHexString(szSendData, dwRealRead, ' ');
|
|
|
+ //if (_tcsncmp("fd fd 30 03 88 99 aa 34 ff ff ff ff ff ff ff ff", val.c_str(), 16))
|
|
|
+ if ( _tcsncmp("FD FD 30 03 88 99 AA 34 FF FF FF FF FF FF FF FF", val.c_str(), 16) )
|
|
|
+ {
|
|
|
+ m_pKeyInfo->strValue2 = val;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ m_pKeyInfo->pbtnInfo->pBTN->SetFaceColor(RGB(255, 255, 255), TRUE);
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ Sleep(200);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-#endif
|
|
|
+
|
|
|
+ OutputDebugString(_T("线程结束"));
|
|
|
+ pthis->m_dwThreadId = 0;
|
|
|
+
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
// 如果CDockablePane无控件,改变大小时背景会刷新失败;
|
|
@@ -770,3 +886,23 @@ void CPropertiesWnd::OnDestroy()
|
|
|
// TODO: 在此处添加消息处理程序代码
|
|
|
ClearAllBTNInfo();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+BOOL CPropertiesWnd::PreTranslateMessage(MSG* pMsg)
|
|
|
+{
|
|
|
+ // TODO: 在此添加专用代码和/或调用基类
|
|
|
+ if (pMsg->message == WM_KEYDOWN)
|
|
|
+ {
|
|
|
+ if (pMsg->wParam == VK_F5)
|
|
|
+ {
|
|
|
+ Global::g_bLearn = !Global::g_bLearn;
|
|
|
+ if (m_dwThreadId == 0 && Global::g_bLearn)
|
|
|
+ {
|
|
|
+ CreateThread(NULL, 0, ThreadLearn, this, 0, &m_dwThreadId);
|
|
|
+ }
|
|
|
+ MessageBox(Global::g_bLearn ? _T("开启学习红外") : _T("关闭红外学习"), _T("提示"), MB_OK);
|
|
|
+ return TRUE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return CDockablePane::PreTranslateMessage(pMsg);
|
|
|
+}
|