|
通过一个简单的界面可以很快的定位自己需要的芯片这是用户最需要的功能,几千几万的芯片要想通过一个个的翻那是不现实的。我们的芯片选择功能可以很方便的通过芯片名,型号,芯片类型等快速过滤,精准定位,这个功能是怎么实现的呢,这节我们将分步实现该功能。
虽然实现这个功能不是很难,但是处于用户考虑,这样的功能是编程器必须具有的,可以提供用户使用体验。要实现这个功能主要考虑一种是知道芯片型号的情况,这个可以直接输入就可以快速定位;另一种是不知道芯片型号,但是知道厂家的情况,这个可以直接通过芯片类型和厂家可以快速定位;当然芯片厂家,型号都不知道的话只能一个个试试看了(对于8脚的存储类芯片我们还是会提供自动测试功能,尝试通过软件的方法自动查找)。
芯片的查找功能和我们的芯片库的结构息息相关,这个要是你还没熟悉的话最好看看前一节的内容。看视该功能简单,但是实际实现的代码量却不简单,这里只能简要点滴,方便大家找到看代码的方向。
1、直接输入关键字
这里主要通过处理cbn_editchange的消息实现。
下面就是处理函数:
- void CProgDeviceSelect::OnEditchangeCOMBOSeachDevice()
- {
- // TODO: Add your control notification handler code here
- UpdateData(true);
- DeviceList();
- }
复制代码 我们这里为了方便代码公用,采用DeviceList()实现:
- void CProgDeviceSelect::DeviceList()
- {
- int DeviceCount,lcount;
- BOOL bFind = false;
- CString DeviceManuName,DeviceName,temp;
- m_cManuList.ResetContent();
- m_cDeviceList.ResetContent();
- DeviceCount = parent->m_arDeviceList.GetSize();
- if (TypeSwitch == 0)
- {
- for (int n=0;n<DeviceCount;n++)
- {
- DeviceName = parent->m_arDeviceList.GetAt(n).DeviceName;
- if (DeviceName.Find(m_sSeachDevice) != -1)
- {
- bFind = false;
- DeviceManuName = parent->m_arDeviceList.GetAt(n).DeviceManuName;
- lcount= m_cManuList.GetCount();
- if (lcount == 0)
- {
- m_cManuList.AddString(DeviceManuName);
- bFind = true;
- }
- for(int i=0; i < lcount ; i++)
- {
- m_cManuList.GetText(i, temp);
- if (DeviceManuName == temp)
- {
- bFind = true;
- break;
- }
- }
- if (!bFind)
- m_cManuList.AddString(DeviceManuName);
- m_cDeviceList.AddString(DeviceName);
- }
- }
- }
- else
- {
- for (int n=0;n<DeviceCount;n++)
- {
- DeviceName = parent->m_arDeviceList.GetAt(n).DeviceName;
- if (DeviceName.Find(m_sSeachDevice) != -1 && TypeSwitch == parent->m_arDeviceList.GetAt(n).DeviceType)
- {
- bFind = false;
- DeviceManuName = parent->m_arDeviceList.GetAt(n).DeviceManuName;
- lcount= m_cManuList.GetCount();
- if (lcount == 0)
- {
- m_cManuList.AddString(DeviceManuName);
- bFind = true;
- }
- for(int i=0; i < lcount ; i++)
- {
- m_cManuList.GetText(i, temp);
- if (DeviceManuName == temp)
- {
- bFind = true;
- break;
- }
- }
- if (!bFind)
- m_cManuList.AddString(DeviceManuName);
- m_cDeviceList.AddString(DeviceName);
- }
- }
- }
- }
复制代码 2、通过芯片类型快速过滤
该部分主要是处理radio的点击事件,每个radio都需要个相应的处理函数实现。这里我们只列举一个做例子,其他的请看源代码。
这里我们就拿eprom型号做例:
在该点击事件中加入自己的处理代码:
- void CProgDeviceSelect::OnRadioEprom()
- {
- // TODO: Add your control notification handler code here
- CString temp;
- for (int i=0; i<parent->m_arTypeList.GetSize(); i++)
- {
- temp = parent->m_arTypeList.GetAt(i).TypeName;
- if( temp == "EPROM")
- {
- TypeSwitch = parent->m_arTypeList.GetAt(i).TypeVal;
- break;
-
- }
- }
- DeviceList();
- }
复制代码 通过设置typeswitch的值实现过滤,然后调用devicelist()函数。
3、通过厂家、类型等条件配合搜索
这里就体现了代码重用的好处了,多搜索条件时代码量非常复杂,通过设置参数,调用同一个函数实现,也方便了代码维护与阅读。具体怎么实现的呢?
就是没有实现代码,直接通过上面的功能配合就可以实现了。
4、其他有好功能
为了使用鼠标方便,还需要处理列表框中的点击事件,厂商列表框和芯片列表框都要做单独处理。
实现代码如下:
- void CProgDeviceSelect::OnSelchangeManuList()
- {
- // TODO: Add your control notification handler code here
- int DeviceCount;
- CString DeviceManuName,DeviceName;
- m_cManuList.GetText(m_cManuList.GetCurSel(),DeviceManuName);
- m_cDeviceList.ResetContent();
- DeviceCount = parent->m_arDeviceList.GetSize();
- for (int n=0;n<DeviceCount;n++)
- {
- if(DeviceManuName == parent->m_arDeviceList.GetAt(n).DeviceManuName)
- {
- DeviceName = parent->m_arDeviceList.GetAt(n).DeviceName;
- m_cDeviceList.AddString(DeviceName);
- }
- }
-
- }
复制代码 当然处理这些还不够,还需要实时显示当前选择的芯片信息,方便用户确认。
同时也要统计下当前厂商数和芯片支持量以及芯片厂商的图标等,这些看视简单的功能都需要很大的代码量,但是用户体验会很不错。
- void CProgDeviceSelect::SetDeviceInfo(int iDeviceSel)
- {
- CString temp;
- m_cDeviceList.GetText(m_cDeviceList.GetCurSel(),temp);
- for (int i=0; i<parent->m_arDeviceList.GetSize(); i++)
- {
- if(temp == parent->m_arDeviceList.GetAt(i).DeviceName)
- {
- m_iDeviceIndex = iDeviceSel = i;
-
- }
- }
- m_sDeviceName = parent->m_arDeviceList.GetAt(iDeviceSel).DeviceName;
- m_sDeviceNote = parent->m_arDeviceList.GetAt(iDeviceSel).DeviceNote;
- m_sDeviceDatasheet = parent->m_arDeviceList.GetAt(iDeviceSel).Datasheet;
- for (i=0; i<parent->m_arAdapterList.GetSize(); i++)
- {
- if (parent->m_arDeviceList.GetAt(iDeviceSel).DeviceAdapter == parent->m_arAdapterList.GetAt(i).TypeVal)
- m_sDeviceAdapter = parent->m_arAdapterList.GetAt(i).TypeName;
- }
- for (i=0; i<parent->m_arPackageList.GetSize(); i++)
- {
- if (parent->m_arDeviceList.GetAt(iDeviceSel).DevicePackage == parent->m_arPackageList.GetAt(i).TypeVal)
- m_sDevicePackage = parent->m_arPackageList.GetAt(i).TypeName;
- }
- for (i=0; i<parent->m_arTypeList.GetSize(); i++)
- {
- if (parent->m_arDeviceList.GetAt(iDeviceSel).DeviceType == parent->m_arTypeList.GetAt(i).TypeVal)
- m_sDeviceType = parent->m_arTypeList.GetAt(i).TypeName;
- }
- for (i=0; i<parent->m_arSizeList.GetSize(); i++)
- {
- if (parent->m_arDeviceList.GetAt(iDeviceSel).DeviceSize == parent->m_arSizeList.GetAt(i).TypeVal)
- m_sDeviceSize = parent->m_arSizeList.GetAt(i).TypeName;
- }
- for (i=0; i<parent->m_arVCCList.GetSize(); i++)
- {
- if (parent->m_arDeviceList.GetAt(iDeviceSel).DeviceVCC == parent->m_arVCCList.GetAt(i).TypeVal)
- m_sDeviceVCC = parent->m_arVCCList.GetAt(i).TypeName;
- }
- for (i=0; i<parent->m_arVPPList.GetSize(); i++)
- {
- if (parent->m_arDeviceList.GetAt(iDeviceSel).DeviceVPP == parent->m_arVPPList.GetAt(i).TypeVal)
- m_sDeviceVPP = parent->m_arVPPList.GetAt(i).TypeName;
- }
- temp.Format("%04x",parent->m_arDeviceList.GetAt(iDeviceSel).DeviceManuID);
- m_sDeviceManuCode = temp+"h";
- temp.Format("%04x",parent->m_arDeviceList.GetAt(iDeviceSel).DeviceID);
- m_sDeviceCode = temp+"h";
- temp.Format("%08x",parent->m_arDeviceList.GetAt(iDeviceSel).DeviceCheckCRC);
- m_sDeviceCheckCRC = temp+"h";
- /* temp.Format("%d",parent->m_arDeviceList.GetAt(iDeviceSel).DeviceSize/1024);
- m_sDeviceSize = temp+"k";
- temp.Format("%.2f",parent->m_arDeviceList.GetAt(iDeviceSel).DeviceVCC);
- m_sDeviceVCC = temp+"V";
- temp.Format("%.2f",parent->m_arDeviceList.GetAt(iDeviceSel).DeviceVPP);
- m_sDeviceVPP = temp+"V";
- */
- HBITMAP bmp =(HBITMAP) ::LoadImage(AfxGetInstanceHandle(),
- parent->m_sAppPath+"brand\\"+parent->m_arDeviceList.GetAt(iDeviceSel).DeviceManuICO/*或者相对路径*/,
- IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE);
- m_cDeviceManuICO.SetBitmap(bmp);
- HBITMAP bmp1 =(HBITMAP) ::LoadImage(AfxGetInstanceHandle(),
- parent->m_sAppPath+"brand\\ic\\"+parent->m_arDeviceList.GetAt(iDeviceSel).DeviceICICO/*或者相对路径*/,
- IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE);
- m_cDeviceICICO.SetBitmap(bmp1);
- UpdateData(false);
- }
复制代码 今天的篇幅很大,本来该分几节来讲解的,避免大家查找,只能慢慢品味了。
|
|