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/ControlPanelView.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 "ControlPanelView.h"
00016 #include "MainFrm.h"
00017 //#include "../CommonDialogs/DeviceChoiceDlg.h"
00018 #include "ControlPanelDoc.h"
00019 
00020 #ifdef _DEBUG
00021 #define new DEBUG_NEW
00022 #undef THIS_FILE
00023 static char THIS_FILE[] = __FILE__;
00024 #endif
00025 
00027 // CControlPanelView
00028 
00029 IMPLEMENT_DYNCREATE(CControlPanelView, CListView)
00030 
00031 
00032 
00033 CControlPanelView::CControlPanelView()
00034 : m_indent(0), m_bAutoscroll(true), m_bControlsEnabled(false)
00035 {
00036 }
00037 
00038 CControlPanelView::~CControlPanelView()
00039 {
00040 }
00041 
00042 
00043 BEGIN_MESSAGE_MAP(CControlPanelView, CListView)
00044         //{{AFX_MSG_MAP(CControlPanelView)
00045         ON_WM_SIZE()
00046         ON_COMMAND(ID_CLEAR_LOG, OnClearLog)
00047         ON_COMMAND(ID_AUTOSCROLL, OnAutoscroll)
00048         ON_UPDATE_COMMAND_UI(ID_AUTOSCROLL, OnUpdateAutoscroll)
00049         ON_UPDATE_COMMAND_UI(ID_OPTIONS_I2C_FREQUENCY, OnUpdateI2cFrequency)
00050         //}}AFX_MSG_MAP
00051 END_MESSAGE_MAP()
00052 
00053 
00054 
00055 
00056 
00057 CString CControlPanelView::U2cResult2Str(U2C_RESULT res)
00058 {
00059         switch (res)
00060         {
00061         case U2C_SUCCESS: return "U2C_SUCCESS";
00062         case U2C_BAD_PARAMETER: return "U2C_BAD_PARAMETER";
00063         case U2C_HARDWARE_NOT_FOUND: return "U2C_HARDWARE_NOT_FOUND";
00064         case U2C_SLAVE_DEVICE_NOT_FOUND: return "U2C_SLAVE_DEVICE_NOT_FOUND";
00065         case U2C_TRANSACTION_FAILED: return "U2C_TRANSACTION_FAILED";
00066         case U2C_SLAVE_OPENNING_FOR_WRITE_FAILED: return "U2C_SLAVE_OPENNING_FOR_WRITE_FAILED";
00067         case U2C_SLAVE_OPENNING_FOR_READ_FAILED: return "U2C_SLAVE_OPENNING_FOR_READ_FAILED";
00068         case U2C_SENDING_MEMORY_ADDRESS_FAILED: return "U2C_SENDING_MEMORY_ADDRESS_FAILED";
00069         case U2C_SENDING_DATA_FAILED: return "U2C_SENDING_DATA_FAILED";
00070         case U2C_NOT_IMPLEMENTED: return "U2C_NOT_IMPLEMENTED";
00071         case U2C_NO_ACK: return "U2C_NO_ACK";
00072         case U2C_DEVICE_BUSY: return "U2C_DEVICE_BUSY";
00073         case U2C_MEMORY_ERROR: return "U2C_MEMORY_ERROR";
00074         case U2C_UNKNOWN_ERROR: return "U2C_UNKNOWN_ERROR";
00075         case U2C_I2C_CLOCK_SYNCH_TIMEOUT: return "U2C_I2C_CLOCK_SYNCH_TIMEOUT";
00076         default: return "Unknown return code";
00077         }
00078 }
00079 
00080 
00082 // CControlPanelView drawing
00083 
00084 /*
00085 void CControlPanelView::OnDraw(CDC* pDC)
00086 {
00087         CDocument* pDoc = GetDocument();
00088         // TODO: add draw code here
00089 }
00090 */
00092 // CControlPanelView diagnostics
00093 
00094 #ifdef _DEBUG
00095 void CControlPanelView::AssertValid() const
00096 {
00097         CListView::AssertValid();
00098 }
00099 
00100 void CControlPanelView::Dump(CDumpContext& dc) const
00101 {
00102         CListView::Dump(dc);
00103 }
00104 #endif //_DEBUG
00105 
00107 // CControlPanelView message handlers
00108 
00109 void CControlPanelView::OnInitialUpdate() 
00110 {
00111         CListView::OnInitialUpdate();
00112         EnableControls(false);
00113         GetListCtrl().InsertColumn(0, "");
00114         CFont font;
00115         if (font.CreateStockObject(SYSTEM_FIXED_FONT))
00116                 SetFont(&font);
00117 
00118 
00119         GetListCtrl().SetExtendedStyle(GetListCtrl().GetExtendedStyle() | LVS_EX_FULLROWSELECT);
00120         CControlPanelDoc *pDoc = (CControlPanelDoc*)GetDocument();
00121         ASSERT_VALID(pDoc);
00122         pDoc->InitView(this);
00123         pDoc->OpenDevice();
00124 }
00125 
00126 
00127 //      void UpdateWindow();
00128 //      void SetRedraw(BOOL bRedraw = TRUE);
00129 //      BOOL GetUpdateRect(LPRECT lpRect, BOOL bErase = FALSE);
00130 //      int GetUpdateRgn(CRgn* pRgn, BOOL bErase = FALSE);
00131 //      void Invalidate(BOOL bErase = TRUE);
00132 //      void InvalidateRect(LPCRECT lpRect, BOOL bErase = TRUE);
00133 //      void InvalidateRgn(CRgn* pRgn, BOOL bErase = TRUE);
00134 //      void ValidateRect(LPCRECT lpRect);
00135 //      void ValidateRgn(CRgn* pRgn);
00136 //      BOOL ShowWindow(int nCmdShow);
00137 //      BOOL IsWindowVisible() const;
00138 //      void ShowOwnedPopups(BOOL bShow = TRUE);
00139 //
00140 
00141 void CControlPanelView::PrintLine(CString str)
00142 {
00143         for(int i = 0; i < m_indent; i++)
00144                 str = "       " + str;
00145         GetListCtrl().InsertItem(GetListCtrl().GetItemCount(), str);
00146 
00147         if (m_bAutoscroll)
00148         {
00149                 int nItemCount = GetListCtrl().GetItemCount();
00150                 GetListCtrl().EnsureVisible(nItemCount - 1, FALSE);
00151         }
00152 //      SetFocus();
00153 //      GetListCtrl().Update();
00154 
00155 }
00156 
00157 void CControlPanelView::PrintHexBuffer(const BYTE *pBuffer, int Length)
00158 {
00159         CString curLine;
00160         for (int i = 0; i < Length; i++)
00161         {
00162                 CString curByte;
00163                 curByte.Format("%02X ", pBuffer[i]);
00164                 curLine += curByte;
00165                 if (i % 16 == 15)
00166                 {
00167                         PrintLine(curLine);
00168                         curLine = "";
00169                 }
00170         }
00171         if (curLine.GetLength() != 0)
00172                 PrintLine(curLine);
00173                 
00174 }
00175 
00176 
00177 void CControlPanelView::PrintTransaction(const U2C_TRANSACTION &Transaction, bool bPrintBuffer)
00178 {
00179         CString temp_str;
00180         temp_str.Format("Slave device address - 0x%X", Transaction.nSlaveDeviceAddress);
00181         PrintLine(temp_str);
00182         temp_str.Format("Memory address length - %d", Transaction.nMemoryAddressLength);
00183         PrintLine(temp_str);
00184         if (Transaction.nMemoryAddressLength != 0)
00185         {
00186                 temp_str.Format("Memory address - 0x%X", Transaction.nMemoryAddress);
00187                 PrintLine(temp_str);
00188         }
00189         temp_str.Format("Length - %d", Transaction.nBufferLength);
00190         PrintLine(temp_str);
00191         if (bPrintBuffer)
00192         {
00193                 PrintLine("Data:");
00194                 m_indent++;
00195                 PrintHexBuffer(Transaction.Buffer, Transaction.nBufferLength);
00196                 m_indent--;
00197         }
00198 }
00199 
00200 
00201 
00202 CMainFrame* CControlPanelView::GetMainFrame()
00203 {
00204         CMainFrame* pFrame = (CMainFrame*)GetParentFrame();
00205         ASSERT_VALID(pFrame);
00206         return pFrame;
00207 }
00208 
00209 
00210 
00211 
00212 void CControlPanelView::EnableControls(bool bEnable)
00213 {
00214         GetMainFrame()->EnableControls(bEnable);
00215         m_bControlsEnabled = bEnable;
00216 }
00217 
00218 
00219 
00220 BOOL CControlPanelView::PreCreateWindow(CREATESTRUCT& cs) 
00221 {
00222         cs.style |= LVS_REPORT | LVS_NOCOLUMNHEADER | LVS_SHOWSELALWAYS;        
00223         return CListView::PreCreateWindow(cs);
00224 }
00225 
00226 void CControlPanelView::OnSize(UINT nType, int cx, int cy) 
00227 {
00228         CListView::OnSize(nType, cx, cy);
00229         
00230         GetListCtrl().SetColumnWidth(0,cx);     
00231         
00232 }
00233 
00234 
00235 void CControlPanelView::PrintError(CString strFunName, U2C_RESULT ErrorCode)
00236 {
00237         PrintLine(strFunName + " failed. Return value = " + U2cResult2Str(ErrorCode));
00238 }
00239 
00240 
00241 
00242 void CControlPanelView::OnClearLog() 
00243 {
00244         GetListCtrl().DeleteAllItems();
00245 }
00246 
00247 void CControlPanelView::OnAutoscroll() 
00248 {
00249         if (m_bAutoscroll)
00250                 m_bAutoscroll = FALSE;
00251         else
00252                 m_bAutoscroll = TRUE;
00253         
00254 }
00255 
00256 void CControlPanelView::OnUpdateAutoscroll(CCmdUI* pCmdUI) 
00257 {
00258         pCmdUI->SetCheck(m_bAutoscroll);
00259 }
00260 
00261 void CControlPanelView::OnUpdateI2cFrequency(CCmdUI* pCmdUI)
00262 {
00263         if (m_bControlsEnabled)
00264                 pCmdUI->Enable(TRUE);
00265         else
00266                 pCmdUI->Enable(FALSE);
00267 }
00268 
00269 BOOL CControlPanelView::OnScroll(UINT nScrollCode, UINT nPos, BOOL bDoScroll) 
00270 {
00271         // TODO: Add your specialized code here and/or call the base class
00272         
00273         return CListView::OnScroll(nScrollCode, nPos, bDoScroll);
00274 }
  • 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