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/I2cLowLevelBar.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 "I2cLowLevelBar.h"
00016 
00017 #ifdef _DEBUG
00018 #define new DEBUG_NEW
00019 #undef THIS_FILE
00020 static char THIS_FILE[] = __FILE__;
00021 #endif
00022 
00024 // CI2cLowLevelBar dialog
00025 
00026 
00027 CI2cLowLevelBar::CI2cLowLevelBar()
00028         : CDialogBar()
00029 {
00030         //{{AFX_DATA_INIT(CI2cLowLevelBar)
00031         m_strWriteByteData = _T("");
00032         m_bWriteByteAck = FALSE;
00033         m_bReadByteAck = FALSE;
00034         m_nReadAckState = -1;
00035         m_nPutAckState = -1;
00036         //}}AFX_DATA_INIT
00037 }
00038 
00039 
00040 void CI2cLowLevelBar::DoDataExchange(CDataExchange* pDX)
00041 {
00042         //{{AFX_DATA_MAP(CI2cLowLevelBar)
00043         DDX_Control(pDX, IDC_WRITE_BYTE_DATA, m_ctrlWriteByteData);
00044         DDX_CBString(pDX, IDC_WRITE_BYTE_DATA, m_strWriteByteData);
00045         DDX_Check(pDX, IDC_I2C_WRITE_ACK, m_bWriteByteAck);
00046         DDX_Check(pDX, IDC_I2C_READ_ACK, m_bReadByteAck);
00047         DDX_CBIndex(pDX, IDC_I2C_READ_ACK_STATE, m_nReadAckState);
00048         DDX_CBIndex(pDX, IDC_I2C_PUT_ACK_STATE, m_nPutAckState);
00049         //}}AFX_DATA_MAP
00050 }
00051 
00052 
00053 BEGIN_MESSAGE_MAP(CI2cLowLevelBar, CDialogBar)
00054         //{{AFX_MSG_MAP(CI2cLowLevelBar)
00055         ON_BN_CLICKED(IDC_I2C_READ_ACK, OnI2cReadAck)
00056         //}}AFX_MSG_MAP
00057         ON_UPDATE_COMMAND_UI(IDC_I2C_START, OnUpdateButtons)
00058         ON_UPDATE_COMMAND_UI(IDC_I2C_REPEATED_START, OnUpdateButtons)
00059         ON_UPDATE_COMMAND_UI(IDC_I2C_STOP, OnUpdateButtons)
00060         ON_UPDATE_COMMAND_UI(IDC_I2C_WRITE_BYTE, OnUpdateButtons)
00061         ON_UPDATE_COMMAND_UI(IDC_READ_BYTE, OnUpdateButtons)
00062         ON_UPDATE_COMMAND_UI(IDC_I2C_GET_ACK, OnUpdateButtons)
00063         ON_UPDATE_COMMAND_UI(IDC_I2C_PUT_ACK, OnUpdateButtons)
00064 END_MESSAGE_MAP()
00065 
00066 BOOL CI2cLowLevelBar::Create(CWnd* pParentWnd)
00067 {
00068         if (!CDialogBar::Create(pParentWnd, IDD, CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY |
00069                 CBRS_GRIPPER, IDD))
00070         {
00071                 TRACE("CDialogBar::Create failed in CI2cLowLevelBar::Create");
00072                 return FALSE;
00073         }
00074         SetWindowText("I2c low level commands bar");
00075         m_bReadByteAck = TRUE;
00076         m_bWriteByteAck = TRUE;
00077         m_nPutAckState = 0;
00078         m_nReadAckState = 0;
00079         UpdateData(FALSE);
00080         return TRUE;
00081 }
00082 
00083 void CI2cLowLevelBar::SaveWriteByteInHistory()
00084 {
00085         UpdateData(TRUE);
00086         int CurIndex;
00087         if (CB_ERR != (CurIndex = m_ctrlWriteByteData.FindStringExact(-1, m_strWriteByteData)))
00088                 m_ctrlWriteByteData.DeleteString(CurIndex);
00089         m_ctrlWriteByteData.InsertString(0, m_strWriteByteData);
00090         UpdateData(FALSE);
00091 }
00092 
00093 BOOL CI2cLowLevelBar::GetWriteByteData(BYTE *pData)
00094 {
00095         UpdateData(TRUE);
00096         char *endp;
00097         m_strWriteByteData.TrimLeft();
00098         int Data = strtol(m_strWriteByteData, &endp, 16);
00099         if ((*endp) || m_strWriteByteData.IsEmpty() || (Data < 0) || (Data > 0xFF))
00100         {
00101                 MessageBox("Bad value has been used as data.\nPlease provide value in range from 0 to FF");
00102                 GetDlgItem(IDC_WRITE_BYTE_DATA)->SetFocus();
00103                 return FALSE;
00104         }
00105         *pData = (BYTE)Data;
00106         SaveWriteByteInHistory();
00107         return TRUE;
00108 }
00109 
00110 BOOL CI2cLowLevelBar::IsWriteByteAckNeeded()
00111 {
00112         UpdateData(TRUE);
00113         return m_bWriteByteAck;
00114 }
00115 
00116 
00117 BOOL CI2cLowLevelBar::IsReadByteAckNeeded(BOOL *bAckState)
00118 {
00119         UpdateData(TRUE);
00120         if (!m_bReadByteAck)
00121                 return FALSE;
00122         if (m_nReadAckState == 0)
00123                 *bAckState = TRUE;
00124         else
00125                 *bAckState = FALSE;
00126         return TRUE;
00127 }
00128 
00129 BOOL CI2cLowLevelBar::GetPutAckState()
00130 {
00131         UpdateData(TRUE);
00132         if (m_nPutAckState == 0)
00133                 return TRUE;
00134         else 
00135                 return FALSE;
00136 }
00137 
00138 void CI2cLowLevelBar::EnableControls(bool bEnable)
00139 {
00140         m_bEnableControls = bEnable;
00141         if(bEnable)
00142         {
00143                 GetDlgItem(IDC_WRITE_BYTE_DATA)->EnableWindow(TRUE);
00144                 GetDlgItem(IDC_I2C_WRITE_ACK)->EnableWindow(TRUE);
00145                 GetDlgItem(IDC_I2C_READ_ACK)->EnableWindow(TRUE);
00146                 GetDlgItem(IDC_I2C_READ_ACK_STATE)->EnableWindow(TRUE);
00147                 GetDlgItem(IDC_I2C_PUT_ACK_STATE)->EnableWindow(TRUE);
00148         }
00149         else
00150         {
00151                 GetDlgItem(IDC_WRITE_BYTE_DATA)->EnableWindow(FALSE);
00152                 GetDlgItem(IDC_I2C_WRITE_ACK)->EnableWindow(FALSE);
00153                 GetDlgItem(IDC_I2C_READ_ACK)->EnableWindow(FALSE);
00154                 GetDlgItem(IDC_I2C_READ_ACK_STATE)->EnableWindow(FALSE);
00155                 GetDlgItem(IDC_I2C_PUT_ACK_STATE)->EnableWindow(FALSE);
00156         }
00157 }
00158 
00159 
00160 void CI2cLowLevelBar::OnI2cReadAck() 
00161 {
00162         UpdateData(TRUE);
00163         if (m_bReadByteAck)
00164                 GetDlgItem(IDC_I2C_READ_ACK_STATE)->EnableWindow(TRUE);
00165         else
00166                 GetDlgItem(IDC_I2C_READ_ACK_STATE)->EnableWindow(FALSE);
00167 }
00168 
00169 
00170 void CI2cLowLevelBar::OnUpdateButtons (CCmdUI* pCmdUI)
00171 {
00172         if(m_bEnableControls)
00173                 pCmdUI->Enable(TRUE);
00174         else
00175                 pCmdUI->Enable(FALSE);
00176 }
00177 
  • 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