Garmin Fleet Management Controller  2.19.0
CSpeedLimitAlertsDlg.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * CSpeedLimitAlertsDlg.cpp
5 *
6 * Copyright 2008-2011 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 #include "stdafx.h"
11 #include "CSpeedLimitAlertsDlg.h"
12 
13 IMPLEMENT_DYNAMIC( CSpeedLimitAlertsDlg, CDialog )
14 
15 BEGIN_MESSAGE_MAP( CSpeedLimitAlertsDlg, CDialog )
16  ON_BN_CLICKED( IDC_SPEED_LIMIT_SEND, OnBnClickedSend )
17  ON_CBN_SELCHANGE(IDC_SPEED_LIMIT_CBO_MODE, OnCbnSelchangeSpeedLimitCboMode)
18  ON_MESSAGE( WM_EVENT( EVENT_FMI_SPEED_LIMIT_SET_RESULT ), OnEventSpeedLimitSetResultFromClient )
19 END_MESSAGE_MAP()
20 
21 //----------------------------------------------------------------------
25 //----------------------------------------------------------------------
26 CSpeedLimitAlertsDlg::CSpeedLimitAlertsDlg
27  (
28  CWnd * aParent,
29  FmiApplicationLayer & aCom
30  )
31  : CDialog( IDD_SPEED_ALERTS, aParent )
32  , mCom( aCom )
33  , mMode( 0 )
34  , mTimeOver( 10 )
35  , mTimeUnder( 10 )
36  , mAlertUser( TRUE )
37  , mThreshold( 0.0 )
38 {
39 }
40 
41 //----------------------------------------------------------------------
43 //----------------------------------------------------------------------
45 {
46 }
47 
48 //----------------------------------------------------------------------
51 //----------------------------------------------------------------------
53  (
54  CDataExchange * aDataExchange
55  )
56 {
57  CDialog::DoDataExchange( aDataExchange );
58 
59  // Bind to needed edit boxes
60  DDX_Text( aDataExchange, IDC_SPEED_LIMIT_EDIT_TIME_OVER, mTimeOver );
61  DDX_Text( aDataExchange, IDC_SPEED_LIMIT_EDIT_TIME_UNDER, mTimeUnder );
62  DDX_Text( aDataExchange, IDC_SPEED_LIMIT_EDIT_THRESHOLD, mThreshold );
63 
64  // make sure time over and under values fits into one byte
65  DDV_MinMaxInt( aDataExchange, mTimeOver, 0x0, 0xff );
66  DDV_MinMaxInt( aDataExchange, mTimeUnder, 0x0, 0xff );
67 
68  // DDX will round to nearest integer, make sure to update the fields
69  CString text;
70  CEdit* pEdit;
71  text.Format( _T("%d"), mTimeOver );
72  pEdit = (CEdit *)GetDlgItem( IDC_SPEED_LIMIT_EDIT_TIME_OVER );
73  pEdit->SetWindowText( text );
74 
75  text.Format( _T("%d"), mTimeUnder );
76  pEdit = (CEdit *)GetDlgItem( IDC_SPEED_LIMIT_EDIT_TIME_UNDER );
77  pEdit->SetWindowText( text );
78 
79  // Resolve Mode
80  // Note: Mode is enumerated with speed_limit_alert_mode_type
81  mMode = (uint8)
82  ( (CComboBox *)GetDlgItem( IDC_SPEED_LIMIT_CBO_MODE ) )->GetCurSel();
83 
84  // Resolve AlertUser
85  mAlertUser = !(boolean)
86  ( (CComboBox *)GetDlgItem( IDC_SPEED_LIMIT_CBO_ALERT_USER ) )->GetCurSel();
87 }
88 
89 //----------------------------------------------------------------------
92 //----------------------------------------------------------------------
94  (
95  bool aValue
96  )
97 {
98  GetDlgItem( IDC_SPEED_LIMIT_EDIT_TIME_OVER )->EnableWindow( aValue );
99  GetDlgItem( IDC_SPEED_LIMIT_EDIT_TIME_UNDER )->EnableWindow( aValue );
100  GetDlgItem( IDC_SPEED_LIMIT_CBO_ALERT_USER )->EnableWindow( aValue );
101  GetDlgItem( IDC_SPEED_LIMIT_EDIT_THRESHOLD )->EnableWindow( aValue );
102 }
103 
104 //----------------------------------------------------------------------
107 //----------------------------------------------------------------------
109 {
110  UpdateData();
111 
114 }
115 
116 //----------------------------------------------------------------------
119 //----------------------------------------------------------------------
121 {
122  UpdateData();
123  switch( mMode )
124  {
126  EnableFields( TRUE );
127  break;
129  EnableFields( FALSE );
130  break;
132  EnableFields( TRUE );
133  break;
134  default:
135  break;
136  }
137 }
138 
139 //----------------------------------------------------------------------
144 //----------------------------------------------------------------------
146  (
147  WPARAM aResultCode,
148  LPARAM
149  )
150 {
151  SetResult( static_cast<uint8>( aResultCode ) );
152 
153  return 0;
154 }
155 
156 //----------------------------------------------------------------------
160 //----------------------------------------------------------------------
162 {
163  CDialog::OnInitDialog();
164 
165  ( (CComboBox *)GetDlgItem( IDC_SPEED_LIMIT_CBO_MODE ) )->SetCurSel( 0 );
166  ( (CComboBox *)GetDlgItem( IDC_SPEED_LIMIT_CBO_ALERT_USER ) )->SetCurSel( 0 );
167 
168  return TRUE;
169 }
170 
171 //----------------------------------------------------------------------
175 //----------------------------------------------------------------------
177  (
178  uint8 aResultCode
179  )
180 {
181  CString resultCodeText;
182  switch( aResultCode )
183  {
185  resultCodeText.Format( _T("Success") );
186  break;
188  resultCodeText.Format( _T("Error") );
189  break;
191  resultCodeText.Format( _T("Unsupported") );
192  break;
193  default:
194  resultCodeText.Format( _T("Unknown") );
195  break;
196  }
197 
198  CString text;
199  CEdit * pEdit;
200  text.Format( _T("%d - %s"), aResultCode, resultCodeText );
201  pEdit = (CEdit *)GetDlgItem( IDC_SPEED_LIMIT_EDIT_RESULT );
202  pEdit->SetWindowText( text );
203 }
uint8 mTimeOver
Value of the time over edit box.
uint8 mMode
Selection of the mode combo box.
#define IDC_SPEED_LIMIT_SEND
Definition: resource.h:404
void EnableFields(bool aValue)
Enable/Disable dialog fields.
void SetResult(uint8 aResultCode)
Set REsult text on the dialog.
#define IDC_SPEED_LIMIT_EDIT_TIME_OVER
Definition: resource.h:398
boolean mAlertUser
Selection value of the alert user combo box.
float mThreshold
Value of the threshold edit box.
afx_msg void OnCbnSelchangeSpeedLimitCboMode()
Selection changed handler for the Mode combo box.
Dialog allowing the user to change speed limit alerts settings.
#define IDC_SPEED_LIMIT_EDIT_THRESHOLD
Definition: resource.h:400
#define IDC_SPEED_LIMIT_EDIT_RESULT
Definition: resource.h:402
#define FALSE
Definition: garmin_types.h:46
#define IDD_SPEED_ALERTS
Definition: resource.h:49
virtual ~CSpeedLimitAlertsDlg()
Destructor.
unsigned char boolean
8-bit value representing FALSE (0) or TRUE (nonzero)
Definition: garmin_types.h:52
#define TRUE
Definition: garmin_types.h:45
#define IDC_SPEED_LIMIT_CBO_MODE
Definition: resource.h:397
void sendSetSpeedLimitAlerts(uint8 aMode, uint8 aTimeOver, uint8 aTimeUnder, boolean aAlertUser, float aThreshold)
Set FMI speed limit alerts.
afx_msg void OnBnClickedSend()
Click handler for the Send button.
afx_msg LRESULT OnEventSpeedLimitSetResultFromClient(WPARAM aResultCode, LPARAM)
Handler for the receipt event from Com.
Serial communication controller for Garmin and FMI packets.
FmiApplicationLayer & mCom
Reference to the FMI communication controller that this dialog uses.
BOOL OnInitDialog()
Initialize the dialog.
#define IDC_SPEED_LIMIT_EDIT_TIME_UNDER
Definition: resource.h:399
#define IDC_SPEED_LIMIT_CBO_ALERT_USER
Definition: resource.h:401
virtual void DoDataExchange(CDataExchange *aDataExchange)
Perform dialog data exchange and validation.
unsigned char uint8
8-bit unsigned integer
Definition: garmin_types.h:62
uint8 mTimeUnder
Value of the time under edit box.
#define WM_EVENT(_event)
Translation from an application event to the corresponding Windows message.