请选择 进入手机版 | 继续访问电脑版

DIY编程器网

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 3391|回复: 0

[UUProg] uuprog开发教程: 选择芯片功能的实现

[复制链接]
发表于 2014-12-2 06:53:37 | 显示全部楼层 |阅读模式
       通过一个简单的界面可以很快的定位自己需要的芯片这是用户最需要的功能,几千几万的芯片要想通过一个个的翻那是不现实的。我们的芯片选择功能可以很方便的通过芯片名,型号,芯片类型等快速过滤,精准定位,这个功能是怎么实现的呢,这节我们将分步实现该功能。
QQ图片20141130105550.jpg
       虽然实现这个功能不是很难,但是处于用户考虑,这样的功能是编程器必须具有的,可以提供用户使用体验。要实现这个功能主要考虑一种是知道芯片型号的情况,这个可以直接输入就可以快速定位;另一种是不知道芯片型号,但是知道厂家的情况,这个可以直接通过芯片类型和厂家可以快速定位;当然芯片厂家,型号都不知道的话只能一个个试试看了(对于8脚的存储类芯片我们还是会提供自动测试功能,尝试通过软件的方法自动查找)。
芯片的查找功能和我们的芯片库的结构息息相关,这个要是你还没熟悉的话最好看看前一节的内容。看视该功能简单,但是实际实现的代码量却不简单,这里只能简要点滴,方便大家找到看代码的方向。
QQ图片20141202060234.jpg
1、直接输入关键字
这里主要通过处理cbn_editchange的消息实现。
QQ图片20141202061434.jpg
下面就是处理函数:
  1. void CProgDeviceSelect::OnEditchangeCOMBOSeachDevice()
  2. {
  3.         // TODO: Add your control notification handler code here
  4.         UpdateData(true);
  5.         DeviceList();
  6. }
复制代码
我们这里为了方便代码公用,采用DeviceList()实现:
  1. void CProgDeviceSelect::DeviceList()
  2. {
  3.         int DeviceCount,lcount;
  4.         BOOL bFind = false;
  5.         CString DeviceManuName,DeviceName,temp;

  6.         m_cManuList.ResetContent();
  7.         m_cDeviceList.ResetContent();
  8.         DeviceCount = parent->m_arDeviceList.GetSize();
  9.         if (TypeSwitch == 0)
  10.         {
  11.                 for (int n=0;n<DeviceCount;n++)
  12.                 {
  13.                         DeviceName = parent->m_arDeviceList.GetAt(n).DeviceName;
  14.                         if (DeviceName.Find(m_sSeachDevice) != -1)
  15.                         {
  16.                                 bFind = false;
  17.                                 DeviceManuName = parent->m_arDeviceList.GetAt(n).DeviceManuName;
  18.                                 lcount= m_cManuList.GetCount();
  19.                                 if (lcount == 0)
  20.                                 {
  21.                                         m_cManuList.AddString(DeviceManuName);
  22.                                         bFind = true;
  23.                                 }
  24.                                 for(int   i=0;   i   < lcount ;   i++)
  25.                                 {
  26.                                         m_cManuList.GetText(i,   temp);
  27.                                         if (DeviceManuName == temp)
  28.                                         {
  29.                                                 bFind = true;
  30.                                                 break;
  31.                                         }
  32.                                 }
  33.                                 if (!bFind)
  34.                                         m_cManuList.AddString(DeviceManuName);
  35.                                 m_cDeviceList.AddString(DeviceName);
  36.                         }
  37.                 }
  38.         }
  39.         else
  40.         {
  41.                 for (int n=0;n<DeviceCount;n++)
  42.                 {
  43.                         DeviceName = parent->m_arDeviceList.GetAt(n).DeviceName;
  44.                         if (DeviceName.Find(m_sSeachDevice) != -1 && TypeSwitch == parent->m_arDeviceList.GetAt(n).DeviceType)
  45.                         {
  46.                                 bFind = false;
  47.                                 DeviceManuName = parent->m_arDeviceList.GetAt(n).DeviceManuName;
  48.                                 lcount= m_cManuList.GetCount();
  49.                                 if (lcount == 0)
  50.                                 {
  51.                                         m_cManuList.AddString(DeviceManuName);
  52.                                         bFind = true;
  53.                                 }
  54.                                 for(int   i=0;   i   < lcount ;   i++)
  55.                                 {
  56.                                         m_cManuList.GetText(i,   temp);
  57.                                         if (DeviceManuName == temp)
  58.                                         {
  59.                                                 bFind = true;
  60.                                                 break;
  61.                                         }
  62.                                 }
  63.                                 if (!bFind)
  64.                                         m_cManuList.AddString(DeviceManuName);
  65.                                 m_cDeviceList.AddString(DeviceName);
  66.                         }
  67.                 }
  68.         }

  69. }
复制代码
2、通过芯片类型快速过滤
该部分主要是处理radio的点击事件,每个radio都需要个相应的处理函数实现。这里我们只列举一个做例子,其他的请看源代码。
这里我们就拿eprom型号做例:
QQ图片20141202062811.jpg
在该点击事件中加入自己的处理代码:
  1. void CProgDeviceSelect::OnRadioEprom()
  2. {
  3.         // TODO: Add your control notification handler code here
  4.         CString temp;
  5.         for (int i=0; i<parent->m_arTypeList.GetSize(); i++)
  6.         {
  7.                 temp = parent->m_arTypeList.GetAt(i).TypeName;
  8.                 if( temp == "EPROM")
  9.                 {
  10.                         TypeSwitch = parent->m_arTypeList.GetAt(i).TypeVal;
  11.                         break;
  12.                        
  13.                 }
  14.         }
  15.         DeviceList();
  16. }

复制代码
通过设置typeswitch的值实现过滤,然后调用devicelist()函数。
3、通过厂家、类型等条件配合搜索
这里就体现了代码重用的好处了,多搜索条件时代码量非常复杂,通过设置参数,调用同一个函数实现,也方便了代码维护与阅读。具体怎么实现的呢?
就是没有实现代码,直接通过上面的功能配合就可以实现了。
4、其他有好功能
为了使用鼠标方便,还需要处理列表框中的点击事件,厂商列表框和芯片列表框都要做单独处理。
QQ图片20141202064213.jpg
实现代码如下:
  1. void CProgDeviceSelect::OnSelchangeManuList()
  2. {
  3.         // TODO: Add your control notification handler code here
  4.         int DeviceCount;
  5.         CString DeviceManuName,DeviceName;

  6.         m_cManuList.GetText(m_cManuList.GetCurSel(),DeviceManuName);
  7.         m_cDeviceList.ResetContent();
  8.         DeviceCount = parent->m_arDeviceList.GetSize();
  9.         for (int n=0;n<DeviceCount;n++)
  10.         {
  11.         if(DeviceManuName == parent->m_arDeviceList.GetAt(n).DeviceManuName)
  12.         {
  13.         DeviceName = parent->m_arDeviceList.GetAt(n).DeviceName;
  14.         m_cDeviceList.AddString(DeviceName);
  15.         }
  16.         }
  17.        
  18. }
复制代码
当然处理这些还不够,还需要实时显示当前选择的芯片信息,方便用户确认。
QQ图片20141202064622.jpg
同时也要统计下当前厂商数和芯片支持量以及芯片厂商的图标等,这些看视简单的功能都需要很大的代码量,但是用户体验会很不错。
  1. void CProgDeviceSelect::SetDeviceInfo(int iDeviceSel)
  2. {
  3.         CString temp;

  4.         m_cDeviceList.GetText(m_cDeviceList.GetCurSel(),temp);
  5.         for (int i=0; i<parent->m_arDeviceList.GetSize(); i++)
  6.         {
  7.                 if(temp == parent->m_arDeviceList.GetAt(i).DeviceName)
  8.                 {
  9.                         m_iDeviceIndex = iDeviceSel = i;
  10.                        
  11.                 }
  12.         }
  13.         m_sDeviceName = parent->m_arDeviceList.GetAt(iDeviceSel).DeviceName;
  14.         m_sDeviceNote = parent->m_arDeviceList.GetAt(iDeviceSel).DeviceNote;
  15.         m_sDeviceDatasheet = parent->m_arDeviceList.GetAt(iDeviceSel).Datasheet;
  16.         for (i=0; i<parent->m_arAdapterList.GetSize(); i++)
  17.         {
  18.                 if (parent->m_arDeviceList.GetAt(iDeviceSel).DeviceAdapter == parent->m_arAdapterList.GetAt(i).TypeVal)
  19.                 m_sDeviceAdapter = parent->m_arAdapterList.GetAt(i).TypeName;
  20.         }
  21.         for (i=0; i<parent->m_arPackageList.GetSize(); i++)
  22.         {
  23.                 if (parent->m_arDeviceList.GetAt(iDeviceSel).DevicePackage == parent->m_arPackageList.GetAt(i).TypeVal)
  24.                 m_sDevicePackage = parent->m_arPackageList.GetAt(i).TypeName;
  25.         }
  26.         for (i=0; i<parent->m_arTypeList.GetSize(); i++)
  27.         {
  28.                 if (parent->m_arDeviceList.GetAt(iDeviceSel).DeviceType == parent->m_arTypeList.GetAt(i).TypeVal)
  29.                 m_sDeviceType = parent->m_arTypeList.GetAt(i).TypeName;
  30.         }

  31.         for (i=0; i<parent->m_arSizeList.GetSize(); i++)
  32.         {
  33.                 if (parent->m_arDeviceList.GetAt(iDeviceSel).DeviceSize == parent->m_arSizeList.GetAt(i).TypeVal)
  34.                 m_sDeviceSize = parent->m_arSizeList.GetAt(i).TypeName;
  35.         }
  36.         for (i=0; i<parent->m_arVCCList.GetSize(); i++)
  37.         {
  38.                 if (parent->m_arDeviceList.GetAt(iDeviceSel).DeviceVCC == parent->m_arVCCList.GetAt(i).TypeVal)
  39.                 m_sDeviceVCC = parent->m_arVCCList.GetAt(i).TypeName;
  40.         }
  41.         for (i=0; i<parent->m_arVPPList.GetSize(); i++)
  42.         {
  43.                 if (parent->m_arDeviceList.GetAt(iDeviceSel).DeviceVPP == parent->m_arVPPList.GetAt(i).TypeVal)
  44.                 m_sDeviceVPP = parent->m_arVPPList.GetAt(i).TypeName;
  45.         }

  46.         temp.Format("%04x",parent->m_arDeviceList.GetAt(iDeviceSel).DeviceManuID);
  47.         m_sDeviceManuCode = temp+"h";
  48.         temp.Format("%04x",parent->m_arDeviceList.GetAt(iDeviceSel).DeviceID);
  49.         m_sDeviceCode = temp+"h";
  50.         temp.Format("%08x",parent->m_arDeviceList.GetAt(iDeviceSel).DeviceCheckCRC);
  51.         m_sDeviceCheckCRC = temp+"h";
  52. /*        temp.Format("%d",parent->m_arDeviceList.GetAt(iDeviceSel).DeviceSize/1024);
  53.         m_sDeviceSize = temp+"k";
  54.         temp.Format("%.2f",parent->m_arDeviceList.GetAt(iDeviceSel).DeviceVCC);
  55.         m_sDeviceVCC = temp+"V";
  56.         temp.Format("%.2f",parent->m_arDeviceList.GetAt(iDeviceSel).DeviceVPP);
  57.         m_sDeviceVPP = temp+"V";
  58. */
  59. HBITMAP bmp =(HBITMAP) ::LoadImage(AfxGetInstanceHandle(),
  60.                                                                    parent->m_sAppPath+"brand\\"+parent->m_arDeviceList.GetAt(iDeviceSel).DeviceManuICO/*或者相对路径*/,
  61.                                                                    IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE);

  62. m_cDeviceManuICO.SetBitmap(bmp);
  63. HBITMAP bmp1 =(HBITMAP) ::LoadImage(AfxGetInstanceHandle(),
  64.                                                                    parent->m_sAppPath+"brand\\ic\\"+parent->m_arDeviceList.GetAt(iDeviceSel).DeviceICICO/*或者相对路径*/,
  65.                                                                    IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE);

  66. m_cDeviceICICO.SetBitmap(bmp1);
  67.         UpdateData(false);
  68. }
复制代码
今天的篇幅很大,本来该分几节来讲解的,避免大家查找,只能慢慢品味了。


您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|文字版|手机版|DIY编程器网 ( 桂ICP备14005565号-1 )

GMT+8, 2024-4-16 22:13 , 耗时 0.126108 秒, 26 个查询请求 , Gzip 开启.

各位嘉宾言论仅代表个人观点,非属DIY编程器网立场。

桂公网安备 45031202000115号

DIY编程器群(超员):41210778 DIY编程器

DIY编程器群1(满员):3044634 DIY编程器1

diy编程器群2:551025008 diy编程器群2

QQ:28000622;Email:libyoufer@sina.com

本站由桂林市临桂区技兴电子商务经营部独家赞助。旨在技术交流,请自觉遵守国家法律法规,一旦发现将做封号删号处理。

快速回复 返回顶部 返回列表