Difference Analysis Generated by HtmlDiff on 10/26/2004 1:35 PM  

Base file: C:\CY4632_RDK_1_21\Software\Source Code\WirelessUSBSysTray\HidTray.h

Modified file: C:\CY4632_RDK_1_3\Software\Source Code\WirelessUSBSysTray\HidTray.h

//--------------------------------------------------------------------------
//
// Include file which defines the HidTrayDevice and HidTrayManager
// classes used in MainFrame.cpp, along with commonly used defines
//
//--------------------------------------------------------------------------
// $Archive: /WirelessUSB/WUSB Kits/CY4632 LS KBM RDK/DocSrc/CD_Root/Software/Source Code/WirelessUSBSysTray/HidTray.h $
// $Modtime: 7/15/04 4:43p10/18/04 3:26p $
// $Revision: 57 $
//--------------------------------------------------------------------------
//
// 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.
//
//--------------------------------------------------------------------------
#ifndef _HIDTRAY_H_
#define _HIDTRAY_H_

#include "..\CSystemTrayMFC\CySysTray.h"
#include "..\CUSBHidAPI\HidAPI.h"
#include "WirelessUSBStatusPropertyPage.h"

#define WM_SYSTEM_TRAY_ICON_NOTIFY                  WM_APP+1

// 
// the following definitions are defined in the
// CY4632 Bridge Firmware User’s Guide section 3.6.2
//

// wirelessUSB usage page and usage values
#define WIRELESSUSB_USAGEPAGE                       0xFF01
#define WIRELESSUSB_USAGE_KEYBOARD                  0x0001
#define WIRELESSUSB_USAGE_MOUSE                     0x0002

// wirelessUSB usage ID values
#define WIRELESSUSB_USAGEID_BATTERYLEVEL            0x20
#define WIRELESSUSB_USAGEID_WIRELESSCHANNEL         0x21
#define WIRELESSUSB_USAGEID_WIRELESSPNCODE          0x22
#define WIRELESSUSB_USAGEID_SIGNALSTRENGTHBAD_PACKETS               0x23
#define WIRELESSUSB_USAGEID_DUTYLOAD    GOOD_PACKETS            0x24

// battery level definitions
#define WIRELESSUSB_BATTERY_LEVEL_MULTIPLIER        25
#define WIRELESSUSB_MIN_BATTERY_LEVEL               1
#define WIRELESSUSB_MAX_BATTERY_LEVEL               10(10*WIRELESSUSB_BATTERY_LEVEL_MULTIPLIER)
#define WIRELESSUSB_MAX_BATTERY_LEVEL_HIGH          8(8*WIRELESSUSB_BATTERY_LEVEL_MULTIPLIER)
#define WIRELESSUSB_MAX_BATTERY_LEVEL_CRITICAL      3(3*WIRELESSUSB_BATTERY_LEVEL_MULTIPLIER)
#define WIRELESSUSB_MAX_BATTERY_RANGE               100
#define WIRELESSUSB_BATTERY_LEVEL_REPORTED(_x_) ((((WIRELESSUSB_MAX_BATTERY_RANGE*10000)/WIRELESSUSB_MAX_BATTERY_LEVEL)*(_x_ > WIRELESSUSB_MAX_BATTERY_LEVEL ? WIRELESSUSB_MAX_BATTERY_LEVEL : _x_))/10000)MAX_ADJUST       1
#define WIRELESSUSB_BATTERY_LEVEL_REPORTED(_x_)     ((((WIRELESSUSB_MAX_BATTERY_RANGE*10000)/WIRELESSUSB_MAX_BATTERY_LEVEL)*(_x_ > WIRELESSUSB_MAX_BATTERY_LEVEL ? WIRELESSUSB_MAX_BATTERY_LEVEL : _x_))/10000) // return percent

// signal strengthquality definitions
#define WIRELESSUSB_MIN_MAX_SIGNAL_STRENGTH             1QUALITY_SAMPLES        10
#define WIRELESSUSB_MAX_SIGNAL_STRENGTH             31QUALITY_RANGE     100
#define WIRELESSUSB_MAX_SIGNAL_STRENGTH_QUALITY_HIGH        25  (WIRELESSUSB_MAX_SIGNAL_QUALITY_RANGE * 0.80) // 80 percent
#define WIRELESSUSB_MAX_SIGNAL_STRENGTH_QUALITY_CRITICAL    6   (WIRELESSUSB_MAX_SIGNAL_QUALITY_RANGE * 0.30) // 30 percent
#define WIRELESSUSB_MAX_SIGNAL_STRENGTH_RANGE       100QUALITY_CC_ADJ       (0.10)
#define WIRELESSUSB_SIGNAL_STRENGTH_FILTER          8QUALITY_REPORTED(_good_, _bad_)    ((_good_+_bad_) ? (WIRELESSUSB_MAX_SIGNAL_QUALITY_RANGE - (((_bad_*2)*WIRELESSUSB_MAX_SIGNAL_QUALITY_RANGE)/(_good_+_bad_))):0) // return percent
#define WIRELESSUSB_SIGNAL_STRENGTH_ADJUST          5
#define WIRELESSUSB_SIGNAL_STRENGTH_REPORTED(_x_)   ((((WIRELESSUSB_MAX_SIGNAL_STRENGTH_RANGE*10000)/WIRELESSUSB_MAX_SIGNAL_STRENGTH)*((_x_* 2) > WIRELESSUSB_MAX_SIGNAL_STRENGTH ? WIRELESSUSB_MAX_SIGNAL_STRENGTH : (_x_ * 2)))/10000)+1

// wireless channel definitions
#define WIRELESSUSB_MIN_WIRELESS_CHANNEL            0
#define WIRELESSUSB_MAX_WIRELESS_CHANNEL            255

// wireless pn code definitions
#define WIRELESSUSB_MIN_WIRELESS_PNCODE             0
#define WIRELESSUSB_MAX_WIRELESS_PNCODE             255

#define WIRELESSUSB_MAX_STRING_LENGTH               126


class CHidTrayDevice : public CHidDevice
{
public:
    CHidTrayDevice(void);
    ~CHidTrayDevice(void);

public:
    bool RequestNewUsageValues();
    bool UpdateUsageValues();
    bool UpdateDeviceInfo(CCySysTray* pSysTray);

    ULONG GetUsageIDValue(USHORT usUsageID);
    void  SetUsageIDValue(USHORT usUsageID, ULONG ulValue);

    void AddGoodPacketValue(unsigned short goodValue);
    void AddBadPacketValue(unsigned short badValue);

    ULONG GetGoodPacketValue(int index);
    void SetGoodPacketValue(int index, ULONG value);
    ULONG GetBadPacketValue(int index);
    void SetBadPacketValue(int index, ULONG value);

    ULONG GetTotalGoodPacketValues();
    ULONG GetTotalBadPacketValues();

    void ChannelChangeAdjustment(void);

    // NOTE: overriding to add System Tray validation
    bool VerifyHidDevice(void); 

public:
    CHAR m_szProductString[WIRELESSUSB_MAX_STRING_LENGTH];
    CHAR m_szSerialNumberString[WIRELESSUSB_MAX_STRING_LENGTH];

    UCHAR m_ucBatteryLevel;     // UsageID 0x20
    UCHAR m_ucWirelessChannel;  // UsageID 0x21
    UCHAR m_ucWirelessPnCode;   // UsageID 0x22
    UCHAR m_ucSignalStrength;CWordArray m_wBadPackets;      // UsageID 0x23
    UCHAR m_ucDutyLoad; CWordArray  m_wGoodPackets;     // UsageID 0x24

    UCHAR m_ucPrevBatteryLevel;

    UCHAR m_ucPrevSignalStrengthWirelessChannel;

    ULONGLONG m_ullTotalBadPackets;
    ULONGLONG m_ullTotalGoodPackets;

    CTime m_ctConnectTime;

    bool m_bCriticalBatteryLevelWarning;
    bool m_bCriticalSignalStrengthWarning;
    bool m_bCriticalSignalQualityWarning;
    bool m_bDisableWarningMessages;

    ULONG m_ulNumberOfPollsSinceLastRequest;

    CWirelessUSBStatusPropertyPage m_DeviceStatusPropertyPage;
};

class CHidTrayManager : public CHidManager
{
public:
    CHidTrayManager(void);
    ~CHidTrayManager(void);

protected:
    CHidDevice* NewHidDevice(PCHAR pDevicePath); // overriding to support new CHidTrayDevice
    void DeleteHidDevice(CHidDevice *pHidDevice); // overriding to remove CHidTrayDevice
};

class CHidCallback
{
public:
    virtual bool Execute(CHidTrayDevice *pHidDevice, UINT uHidCode) const =0;
};


template <class cHidInstance>
class THidCallback : public CHidCallback // Inheriting
{
public:
    THidCallback() // constructor
    {
        // zeroing the function pointer, later we check to make 
        // sure the callback function is defined
        pHidFunction = 0;
    }

    // defining callback function
    typedef void (cHidInstance::*tHidFunction)(CHidTrayDevice *pHidDevice, UINT uHidCode);
    
    // executes the callback function
    virtual bool Execute(CHidTrayDevice *pHidDevice, UINT uHidCode) const 
    {
        // if the callback function is undefined, it crash the application
        if (pHidFunction)
        {
            // execute callback funtion
            (cHidInst->*pHidFunction)(pHidDevice, uHidCode);

            // return success
            return true;
        }

        // return failure due to undefined fuction
        return false;
    }

    // setup (or change) the callback function
    void SetCallback (cHidInstance *cHidInstancePointer, 
                        tHidFunction pHidFunctionPointer)
    {
        cHidInst     = cHidInstancePointer;
        pHidFunction    = pHidFunctionPointer;
    }

private:
    cHidInstance  *cHidInst;
    tHidFunction  pHidFunction;
};

#endif // #ifndef _HIDTRAY_H_