Header
Product Comparison: USB I2C | USB SPI | USB GPIO
  • My Account
  • Shopping Cart
  • Products
  • My Account
  • About
  • Products
  • PC-I2C/SPI/GPIO Adapters
  • Main Page
  • Classes
  • Files
  • File List
  • File Members

D:/_sources/u2c_12/ControlPanel/SpiBar.cpp

Go to the documentation of this file.
00001 // Copyright (C)2006 Diolan ( http://www.diolan.com )
00002 //
00003 // This program is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU General Public License
00005 // as published by the Free Software Foundation
00006 //
00007 // This program is distributed in the hope that it will be useful,
00008 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010 // GNU General Public License for more details.
00011 
00012 
00013 #include "stdafx.h"
00014 #include "controlpanel.h"
00015 #include "SpiBar.h"
00016 #include ".\spibar.h"
00017 
00018 
00019 #ifdef _DEBUG
00020 #define new DEBUG_NEW
00021 #undef THIS_FILE
00022 static char THIS_FILE[] = __FILE__;
00023 #endif
00024 
00026 // CSpiBar dialog
00027 
00028 
00029 CSpiBar::CSpiBar()
00030         : CDialogBar()
00031         ,m_bEnableControls(false)
00032 {
00033         //{{AFX_DATA_INIT(CSpiBar)
00034         m_Length = 0;
00035         m_strData = _T("");
00036         //}}AFX_DATA_INIT
00037 }
00038 
00039 
00040 void CSpiBar::DoDataExchange(CDataExchange* pDX)
00041 {
00042         //{{AFX_DATA_MAP(CSpiBar)
00043         DDX_Text(pDX, IDC_SPI_LENGTH, m_Length);
00044         DDX_Text(pDX, IDC_SPI_DATA, m_strData);
00045         //}}AFX_DATA_MAP
00046 }
00047 
00048 
00049 BOOL CSpiBar::Create(CWnd* pParentWnd)
00050 {
00051         if (!CDialogBar::Create(pParentWnd, IDD, CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY |
00052                 CBRS_GRIPPER, IDD))
00053         {
00054                 TRACE("CDialogBar::Create failed in CSpiBar::Create");
00055                 return FALSE;
00056         }
00057         SetWindowText("SPI Bar");
00058 
00059 
00060         UpdateData(FALSE);
00061         return TRUE;
00062 }
00063 
00064 BEGIN_MESSAGE_MAP(CSpiBar, CDialogBar)
00065         //{{AFX_MSG_MAP(CSpiBar)
00066         //}}AFX_MSG_MAP
00067         ON_UPDATE_COMMAND_UI(IDC_SPI_READ_WRITE, OnUpdateButton)
00068         ON_UPDATE_COMMAND_UI(IDC_SPI_WRITE, OnUpdateButton)
00069         ON_UPDATE_COMMAND_UI(IDC_SPI_READ, OnUpdateButton)
00070 END_MESSAGE_MAP()
00071 
00073 // CSpiBar message handlers
00074 
00075 void CSpiBar::EnableControls(bool bEnable)
00076 {
00077         m_bEnableControls = bEnable;
00078         if(bEnable)
00079         {
00080                 GetDlgItem(IDC_SPI_LENGTH)->EnableWindow(TRUE);
00081                 GetDlgItem(IDC_SPI_DATA)->EnableWindow(TRUE);
00082         }
00083         else
00084         {
00085                 GetDlgItem(IDC_SPI_LENGTH)->EnableWindow(FALSE);
00086                 GetDlgItem(IDC_SPI_DATA)->EnableWindow(FALSE);
00087         }
00088 
00089 }
00090 
00091 void CSpiBar::OnUpdateButton (CCmdUI* pCmdUI)
00092 {
00093         if(m_bEnableControls)
00094                 pCmdUI->Enable(TRUE);
00095         else
00096                 pCmdUI->Enable(FALSE);
00097 }
00098 
00099 bool CSpiBar::GetLength(unsigned short* pLength)
00100 {
00101         UpdateData(TRUE);
00102         if ((m_Length <= 0) || (m_Length > 256))
00103         {
00104                 MessageBox("Bad value has been used as length.\nPlease provide value in range from 1 to 256");
00105                 GetDlgItem(IDC_SPI_LENGTH)->SetFocus();
00106                 return false;
00107         }
00108         *pLength = (unsigned short)m_Length;
00109         return true;
00110 }
00111 
00112 bool CSpiBar::GetOutData(BYTE* pBuffer, unsigned short Length)
00113 {
00114         UpdateData(TRUE);
00115         USHORT i = 0;
00116         char *endp;
00117         CString strItem;
00118         unsigned int value;
00119         for (strItem = m_strData.SpanExcluding(" "); strItem.GetLength() && (i < Length); strItem =m_strData.SpanExcluding(" "))
00120         {
00121                 value = strtoul(strItem.GetBuffer(0), &endp, 16);
00122                 if ((*endp) || (value > 0xFF))
00123                 {
00124                         MessageBox("Bad value has been used as data");
00125                         GetDlgItem(IDC_SPI_DATA)->SetFocus();
00126                         return false;
00127                 }
00128                 pBuffer[i++] = (BYTE)value;
00129                 m_strData = m_strData.Mid(strItem.GetLength());
00130                 m_strData.TrimLeft();
00131         }
00132         if (strItem.GetLength() || (i != Length))
00133         {
00134                 MessageBox("Data length mismatch");
00135                 GetDlgItem(IDC_SPI_DATA)->SetFocus();
00136                 return false;
00137         }
00138         return true;
00139 }
00140 
00141 
00142 
  • Products
  • PC-I2C/SPI/GPIO Adapters
  • Comparison
  • PC-I2C/SPI/GPIO Adapter DLN-1
  • USB-I2C/SPI/GPIO Adapter DLN-2
  • Multiprotocol Master DLN-4M
  • Multiprotocol Slave DLN-4S
  • Downloads
  • Software
  • Documentation
  • SW Tools & Examples
  • Development Boards
  • Open Source Projects
  • Discontinued Products
  • API Documentation
  • Downloads
  • SW Tools and Examples
footer top footer bottom
© Copyright Diolan 2006-2012