//-------------------------------------------------------------------------- // // Microsoft Visual C++ generated source file. // // Implementation file for Wireless USB Property Page // //-------------------------------------------------------------------------- // $Archive: /WirelessUSB/WUSB Kits/CY4632 LS KBM RDK/DocSrc/CD_Root/Software/Source Code/WirelessUSBSysTray/WirelessUSBStatusPropertyPage.cpp $ // $Modtime: 7/15/04 4:43p10/18/04 3:25p $ // $Revision: 36 $ //-------------------------------------------------------------------------- // // Copyright 2003-2004, Cypress Semiconductor Corporation. // // This software is owned by Cypress Semiconductor Corporation (Cypress) // and is protected by and subject to worldwide patent protection (United // States and foreign), United States copyright laws and international // treaty provisions. Cypress hereby grants to licensee a personal, // non-exclusive, non-transferable license to copy, use, modify, create // derivative works of, and compile the Cypress Source Code and derivative // works for the sole purpose of creating custom software in support of // licensee product to be used only in conjunction with a Cypress integrated // circuit as specified in the applicable agreement. Any reproduction, // modification, translation, compilation, or representation of this // software except as specified above is prohibited without the express // written permission of Cypress. // // Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // Cypress reserves the right to make changes without further notice to the // materials described herein. Cypress does not assume any liability arising // out of the application or use of any product or circuit described herein. // Cypress does not authorize its products for use as critical components in // life-support systems where a malfunction or failure may reasonably be // expected to result in significant injury to the user. The inclusion of // Cypress’ product in a life-support systems application implies that the // manufacturer assumes all risk of such use and in doing so indemnifies // Cypress against all charges. // // Use may be limited by and subject to the applicable Cypress software // license agreement. // //-------------------------------------------------------------------------- #include "stdafx.h" #include "WirelessUSBTray.h" #include "WirelessUSBStatusPropertyPage.h" #include "HidTray.h" #include ".\WirelessUSBstatuspropertypage.h" #define IS_WIN2K_OR_HIGHER(osvi) (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion >= 5) #define IS_WINS98_OR_HIGHER(osvi) (((osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) && \ ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion >= 10))) || \ IS_WIN2K_OR_HIGHER(osvi)) #define STATUS_POLL_TIMER_MS 500 // pull status every 500 miliseconds #define REQUEST_BATTERY_MS 5000 // request battery level every 5 seconds #define NUMBER_OF_POLLS_BEFORE_REQUEST (REQUEST_BATTERY_MS/STATUS_POLL_TIMER_MS) // CWirelessUSBStatusPropertyPage dialog IMPLEMENT_DYNAMIC(CWirelessUSBStatusPropertyPage, CPropertyPage) CWirelessUSBStatusPropertyPage::CWirelessUSBStatusPropertyPage() : CPropertyPage(CWirelessUSBStatusPropertyPage::IDD) { // initially, no Hid device is assigned m_pHidDevice = NULL; } CWirelessUSBStatusPropertyPage::~CWirelessUSBStatusPropertyPage() { } void CWirelessUSBStatusPropertyPage::DoDataExchange(CDataExchange* pDX) { CPropertyPage::DoDataExchange(pDX); DDX_Control(pDX, IDC_BATTERY_LEVEL_BAR, m_BatteryLevel); DDX_Control(pDX, IDC_SIGNAL_STRENGTH_QUALITY_BAR, m_SignalStrengthQuality); DDX_Control(pDX, IDC_WIRELESSUSB_DISABLE_ENABLE_WARNING_MESSAGE, m_DisableWarningMessagesEnableWarningMessages); DDX_Control(pDX, IDC_WIRELESS_CHANNEL, m_WirelessChannel); DDX_Control(pDX, IDC_POWER_STATUS_HDR, m_StatusHdr); DDX_Control(pDX, IDC_WIRELESS_SUBCHANNEL, m_WirelessSubChannel); DDX_Control(pDX, IDC_STATIC_CONNECtION_STATUS, m_cDeviceStatus); DDX_Control(pDX, IDC_STATIC_CONNECtION_DURATION, m_cDeviceDuration); DDX_Control(pDX, IDC_STATIC_ACTIVITY_RECIVED_PACKETS, m_cRecievedPackets); DDX_Control(pDX, IDC_HEADER_EXCELLENT, m_cHeaderExcellent); DDX_Control(pDX, IDC_HEADER_POOR, m_cHeaderPoor); DDX_Control(pDX, IDC_HEADER_LOW, m_cHeaderLow); DDX_Control(pDX, IDC_HEADER_FULL, m_cHeaderFull); DDX_Control(pDX, IDC_STATIC_ACTIVITY_STATUS, m_cActivityStatus); } BEGIN_MESSAGE_MAP(CWirelessUSBStatusPropertyPage, CPropertyPage) ON_WM_DESTROY() ON_WM_TIMER() ON_BN_CLICKED(IDC_WIRELESSUSB_DISABLE_ENABLE_WARNING_MESSAGE, OnBnClickedWirelessUSBDisableWarningMessageOnBnClickedWirelessUSBEnableWarningMessage) END_MESSAGE_MAP() // CWirelessUSBStatusPropertyPage message handlers // initalize property page dialog BOOL CWirelessUSBStatusPropertyPage::OnInitDialog() { CPropertyPage::OnInitDialog(); // get OS version info m_osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&m_osvi); // setup battery level indicator m_BatteryLevel.SetRange(0,WIRELESSUSB_MAX_BATTERY_RANGE); m_BatteryLevel.SetColor(m_rgbStandardColors[10], // beginning - red m_rgbStandardColors[13], // ending - blue m_rgbStandardColors[1], // background - white m_rgbStandardColors[8]); // text - light grey m_BatteryLevel.SetBarControl(falstrue, // display vertically trufalse, // reverse direction BAR_CAPTION_PERCENTNONE); // setup signal strengthquality indicator m_SignalStrength.SetRange(0,WIRELESSUSB_MAX_SIGNAL_STRENGTH_RANGE); m_SignalStrength.SetColor(m_rgbStandardColors[10], // beginning - red m_SignalQuality.SetRange(0,WIRELESSUSB_MAX_SIGNAL_QUALITY_RANGE); m_SignalQuality.SetColor(m_rgbStandardColors[10], // beginning - red m_rgbStandardColors[11], // ending - green m_rgbStandardColors[1], // background - white m_rgbStandardColors[8]); // text - light grey m_SignalStrength.SetBarControl(falseSignalQuality.SetBarControl(true, // display vertically trufalse, // reverse direction BAR_CAPTION_PERCENTNONE); // indicate we are not yet connected m_bConnectedbDeviceConnected = false; m_bBridgeActivity = false; // get pointer to hid device, if one has been assigned yet CHidTrayDevice* pHidDevice = (CHidTrayDevice*)m_pHidDevice; if (pHidDevice) { // get current hid usage values pHidDevice->UpdateUsageValues(); // only supported on Win2K+ if (IS_WIN2K_OR_HIGHER(m_osvi)) { // determine if warning messages are disabled if ( if (!pHidDevice->m_bDisableWarningMessages) { // if warning messages are disabled, then // set check box m_DisableWarningMessages m_EnableWarningMessages.SetCheck(BST_CHECKED); } else { // if warning messages are enabled, then // clear check box. m_DisableWarningMessages m_EnableWarningMessages.SetCheck(BST_UNCHECKED); } } else { // This feature not supported on W98x, so disable it m_EnableWarningMessages.EnableWindow(FALSE); } // determine if we are connected, this is done by // checking battery level. If battery level is 0, // we can be sure we are not talking to the Hid device if (pHidDevice->m_ucBatteryLevel) { // connected, display connected in status m_cDeviceStatusHdr.SetWindowText("Status: Status.SetWindowText("Connected"); m_bConnectedbDeviceConnected = true; } else { // not connected, display not connected in status m_cDeviceStatusHdr.SetWindowText("Status: Status.SetWindowText("Not Connected"); m_bConnectedbDeviceConnected = false; } m_cDeviceDuration.SetWindowText(""); // initialize poll counter to request one the first time pHidDevice->m_ulNumberOfPollsSinceLastRequest = NUMBER_OF_POLLS_BEFORE_REQUEST+1; } // start update timer OnStartTimer(); // always return TRUE unless you set the focus to a control return TRUE; } // dialog window is being destroyed void CWirelessUSBStatusPropertyPage::OnDestroy() { CPropertyPage::OnDestroy(); // stop update timer OnStopTimer(); } // start timer, used to poll for update in Hid device values void CWirelessUSBStatusPropertyPage::OnStartTimer() { m_nTimer = SetTimer(1, STATUS_POLL_TIMER_MS, 0); } // stop timer, will stop polling for update in Hid device values void CWirelessUSBStatusPropertyPage::OnStopTimer() { KillTimer(m_nTimer); } CString CWirelessUSBStatusPropertyPage::CommaStr(ULONGLONG number) { CString str; // CString to return int i = 0; // three's counter // start with an empty string str.Empty(); // loop through all digits in the number // NOTE: digits will be added in reverse order do { // add the rightmost digit str += (char)((number % 10) + '0'); // strip off rightmost digit number /= 10; // if moved over three digits then insert comma into string if (number && !(++i % 3)) { str += ','; } } while(number); // continue until number equal zero // reverse the string, now in correct order str.MakeReverse(); return str; } // timer expired, update Hid device values and determine if // it should request an updated battery level value void CWirelessUSBStatusPropertyPage::OnTimer(UINT nIDEvent) { CHidTrayDevice* pHidDevice = (CHidTrayDevice*)m_pHidDevice; if (pHidDevice) { // determine if we need to issue a request for updated battery level if (pHidDevice->m_ulNumberOfPollsSinceLastRequest++ > NUMBER_OF_POLLS_BEFORE_REQUEST) { // request for new battery level // NOTE: we do this more often when the status window is open // but typically this should not happen very often because // over time it will drain the battery more if the // wireless device is used frequently pHidDevice->RequestNewUsageValues(); // reset poll count to zero pHidDevice->m_ulNumberOfPollsSinceLastRequest = 0; } // update latest device usage values pHidDevice->UpdateUsageValues(); // update wireless channel/subchannel in dialog // NOTE: even though we might not be connected to // a wireless device, the channel/subchannel // is correct and can be displayed CString strNumber; strNumber.Format("%d", pHidDevice->m_ucWirelessChannel); m_WirelessChannel.SetWindowText(strNumber); strNumber.Format("%d", pHidDevice->m_ucWirelessPnCode); m_WirelessSubChannel.SetWindowText(strNumber); // if connected, display other usage values if (pHidDevice->m_ucBatteryLevel) { // if we were not previously connected, then make sure // the connection status in the dialog is updated if (!m_bConnectedbDeviceConnected) { // connected, update status displayed m_cDeviceStatusHdr.SetWindowText("Status: Status.SetWindowText("Connected"); m_bConnectedbDeviceConnected = true; } // update battery level indicator m_BatteryLevel.SetPos(WIRELESSUSB_BATTERY_LEVEL_REPORTED(pHidDevice->m_ucBatteryLevel)); // update current time span from connection of device CTime ct = CTime::GetCurrentTime(); CTimeSpan ts = ct.GetTime() - pHidDevice->m_ctConnectTime.GetTime(); if (ts.GetDays()) { m_cDeviceDuration.SetWindowText(ts.Format("%D days %H:%M:%S")); } else { m_cDeviceDuration.SetWindowText(ts.Format("%H:%M:%S")); } // enable the headers if (!m_cHeaderLow.IsWindowEnabled()) m_cHeaderLow.EnableWindow(true); // update signal strength indicator m_SignalStrength.SetPos(WIRELESSUSB_SIGNAL_STRENGTH_REPORTED(pHidDevice->m_ucSignalStrength)); if (!m_cHeaderFull.IsWindowEnabled()) m_cHeaderFull.EnableWindow(true); } else { // if we were previously connected, then make sure // the connection status in the dialog is updated if (m_bConnectedbDeviceConnected) { // no longer connected, update status displayed m_cDeviceStatusHdr.SetWindowText("Status: Status.SetWindowText("Not Connected"); m_bConnected = false; m_cDeviceDuration.SetWindowText(""); m_bDeviceConnected = false; } // disable the headers if (m_cHeaderLow.IsWindowEnabled()) m_cHeaderLow.EnableWindow(false); if (m_cHeaderFull.IsWindowEnabled()) m_cHeaderFull.EnableWindow(false); } // update battery level indicator m_BatteryLevel.SetPos(WIRELESSUSB_BATTERY_LEVEL_REPORTED(pHidDevice->m_ucBatteryLevel)); // update signal quality indicator m_SignalQuality.SetPos(WIRELESSUSB_SIGNAL_QUALITY_REPORTED(pHidDevice->GetTotalGoodPacketValues(), pHidDevice->GetTotalBadPacketValues())); // grey out link quality headers if quality reported value is zero, // which means no packets in all the samples if (WIRELESSUSB_SIGNAL_QUALITY_REPORTED(pHidDevice->GetTotalGoodPacketValues(), pHidDevice->GetTotalBadPacketValues())) { // if there was not previous bridge activity, then make sure // the activity status in the dialog is updated if (!m_bBridgeActivity) { // active, update status displayed m_cActivityStatus.SetWindowText("Active"); m_bBridgeActivity = true; } // enable the headers if (!m_cHeaderPoor.IsWindowEnabled()) m_cHeaderPoor.EnableWindow(true); if (!m_cHeaderExcellent.IsWindowEnabled()) m_cHeaderExcellent.EnableWindow(true); } else { // if there was previous bridge activity, then make sure // the activity status in the dialog is updated if (m_bBridgeActivity) { // active, update status displayed m_cActivityStatus.SetWindowText("Inactive"); m_bBridgeActivity = false; } // disable the headers if (m_cHeaderPoor.IsWindowEnabled()) m_cHeaderPoor.EnableWindow(false); if (m_cHeaderExcellent.IsWindowEnabled()) m_cHeaderExcellent.EnableWindow(false); } // update total rejected & recieved packets m_cRecievedPackets.SetWindowText(CommaStr(pHidDevice->m_ullTotalGoodPackets)); // update wireless channel/subchannel in dialog // NOTE: even though we might not be connected to // a wireless device, the channel/subchannel // is correct and can be displayed CString strNumber; strNumber.Format("%d", pHidDevice->m_ucWirelessChannel); m_WirelessChannel.SetWindowText(strNumber); strNumber.Format("%d", pHidDevice->m_ucWirelessPnCode); m_WirelessSubChannel.SetWindowText(strNumber); } CPropertyPage::OnTimer(nIDEvent); } // the Disable Warning Messages checkbox was clicked void CWirelessUSBStatusPropertyPage::OnBnClickedWirelessUSBDisableWarningMessageOnBnClickedWirelessUSBEnableWarningMessage() { CHidTrayDevice* pHidDevice = (CHidTrayDevice*)m_pHidDevice; // if no Hid device, then just exit if (!pHidDevice) return; // only supported on Win2K+ if (IS_WIN2K_OR_HIGHER(m_osvi)) { // determine if the check box was selected or cleared if (m_DisableWarningMessagesEnableWarningMessages.GetState() & 0x0003) { // check box was selected, disableenable warning messages pHidDevice->m_bDisableWarningMessages = true; pHidDevice->m_bDisableWarningMessages = false; } else { // check box was cleared, enabledisable warning messages pHidDevice->m_bDisableWarningMessages = false; pHidDevice->m_bDisableWarningMessages = true; } } // save current warning message state to the Hid device registry CString szValueName; DWORD Type = REG_BINARY; UCHAR Data = pHidDevice->m_bDisableWarningMessages; DWORD Size = sizeof(Data); szValueName.Format("Usage%04d_DWM", pHidDevice->m_HidCaps.Usage); pHidDevice->RegSetValue(szValueName, Type, (LPBYTE)&Data, Size); }