home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / RealTime Graphics ActiveX / DATA.3 / Examples / CPP / PID / PIDView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-17  |  3.5 KB  |  145 lines

  1. // PIDView.cpp : implementation of the CPIDView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "PID.h"
  6.  
  7. #include "PIDDoc.h"
  8. #include "PIDView.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CPIDView
  18.  
  19. IMPLEMENT_DYNCREATE(CPIDView, CFormView)
  20.  
  21. BEGIN_MESSAGE_MAP(CPIDView, CFormView)
  22.     //{{AFX_MSG_MAP(CPIDView)
  23.         // NOTE - the ClassWizard will add and remove mapping macros here.
  24.         //    DO NOT EDIT what you see in these blocks of generated code!
  25.     //}}AFX_MSG_MAP
  26.     // Standard printing commands
  27.     ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
  28.     ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
  29.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
  30. END_MESSAGE_MAP()
  31.  
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CPIDView construction/destruction
  34.  
  35. CPIDView::CPIDView()
  36.     : CFormView(CPIDView::IDD)
  37. {
  38.     //{{AFX_DATA_INIT(CPIDView)
  39.         // NOTE: the ClassWizard will add member initialization here
  40.     //}}AFX_DATA_INIT
  41.     // TODO: add construction code here
  42.  
  43. }
  44.  
  45. CPIDView::~CPIDView()
  46. {
  47. }
  48.  
  49. void CPIDView::DoDataExchange(CDataExchange* pDX)
  50. {
  51.     CFormView::DoDataExchange(pDX);
  52.     //{{AFX_DATA_MAP(CPIDView)
  53.     DDX_Control(pDX, IDC_RTPIDXCTRL1, m_PIDControl);
  54.     DDX_Control(pDX, IDC_SCROLLXCTRL1, m_ScrollGraph);
  55.     //}}AFX_DATA_MAP
  56. }
  57.  
  58. BOOL CPIDView::PreCreateWindow(CREATESTRUCT& cs)
  59. {
  60.     // TODO: Modify the Window class or styles here by modifying
  61.     //  the CREATESTRUCT cs
  62.  
  63.     return CFormView::PreCreateWindow(cs);
  64. }
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CPIDView printing
  68.  
  69. BOOL CPIDView::OnPreparePrinting(CPrintInfo* pInfo)
  70. {
  71.     // default preparation
  72.     return DoPreparePrinting(pInfo);
  73. }
  74.  
  75. void CPIDView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  76. {
  77.     // TODO: add extra initialization before printing
  78. }
  79.  
  80. void CPIDView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  81. {
  82.     // TODO: add cleanup after printing
  83. }
  84.  
  85. void CPIDView::OnPrint(CDC* pDC, CPrintInfo*)
  86. {
  87.     // TODO: add code to print the controls
  88. }
  89.  
  90. /////////////////////////////////////////////////////////////////////////////
  91. // CPIDView diagnostics
  92.  
  93. #ifdef _DEBUG
  94. void CPIDView::AssertValid() const
  95. {
  96.     CFormView::AssertValid();
  97. }
  98.  
  99. void CPIDView::Dump(CDumpContext& dc) const
  100. {
  101.     CFormView::Dump(dc);
  102. }
  103.  
  104. CPIDDoc* CPIDView::GetDocument() // non-debug version is inline
  105. {
  106.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPIDDoc)));
  107.     return (CPIDDoc*)m_pDocument;
  108. }
  109. #endif //_DEBUG
  110.  
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CPIDView message handlers
  113.  
  114. BEGIN_EVENTSINK_MAP(CPIDView, CFormView)
  115.     //{{AFX_EVENTSINK_MAP(CPIDView)
  116.     ON_EVENT(CPIDView, IDC_RTPIDXCTRL1, 1 /* OnInternalTimer */, OnOnInternalTimerRtpidxctrl1, VTS_NONE)
  117.     //}}AFX_EVENTSINK_MAP
  118. END_EVENTSINK_MAP()
  119.  
  120. void CPIDView::OnOnInternalTimerRtpidxctrl1() 
  121. { double rValues[3];
  122.  
  123.   rMeasured += (rOutput / 20);
  124.   rOutput = m_PIDControl.CalcPID(rMeasured);
  125.   
  126.   m_PIDControl.UpdatePIDBargraph(rMeasured, rSetpoint, rOutput);
  127.  
  128.   rValues[0] = rSetpoint;
  129.   rValues[1] = rMeasured;
  130.   rValues[2] = rOutput;
  131.   m_ScrollGraph.UpdateDynData(0,rValues);
  132. }
  133.  
  134. void CPIDView::OnInitialUpdate() 
  135. {
  136.     CFormView::OnInitialUpdate();
  137.     
  138.     rMeasured = 32;
  139.     rOutput = 0.0;
  140.     rSetpoint = 68;
  141.  
  142.     m_PIDControl.SetPIDSetpoint(rSetpoint);
  143.     m_PIDControl.SetEnableInternalTimer(TRUE);
  144. }
  145.