// -------------------------------------------------------------------------- // ========================================================================== // File: TDIDevCaps.CPP // Authors: BCB_Code_Generator v1.62, // Darren Dwyer (source code, documentation, demos, website), // Hugh Edwards (documentation, icons, website), // Brian Austin (some source code, documentation) // Description: This file contains the code for the TDIDevCaps Component // // "TDx_Input_Library v1.62" // (c) 2002 BCB-Tools.com Pty. Ltd., Sydney, Australia. // All Rights Reserved. // // Refer to the 'Licence.Txt' file for licencing & copyright information. // ========================================================================== // -------------------------------------------------------------------------- // #includes ... // -------------------------------------------------------------------------- #include #pragma hdrstop // -------------------------------------------------------------------------- #include "TDIDevCaps.H" // -------------------------------------------------------------------------- #pragma link "TDx_Library_Defns" #pragma link "TDx_Library_Functions" #pragma link "TDx_Input_Library_Defns" #pragma link "TDx_Input_Library_Functions" // -------------------------------------------------------------------------- // Object Registration... // -------------------------------------------------------------------------- #if (__BORLANDC__ >= 0x0530) // BCB Version 3+ #pragma package(smart_init) #endif // -------------------------------------------------------------------------- static inline void ValidCtrCheck(TDIDevCaps*) { new TDIDevCaps(NULL); } // -------------------------------------------------------------------------- namespace Tdidevcaps { #if (__BORLANDC__ >= 0x0530) // BCB Version 3+ void __fastcall PACKAGE Register() #else void __fastcall Register() #endif { TComponentClass classes[1] = {__classid(TDIDevCaps)}; RegisterComponents("TDx_Input", classes, 0); } } // -------------------------------------------------------------------------- // Constructor: TDIDevCaps::TDIDevCaps() // Description: The default constructor for the TDIDevCaps object. // -------------------------------------------------------------------------- __fastcall TDIDevCaps::TDIDevCaps(TComponent* Owner) : TComponent(Owner) { Clear(); fFlags_Strings=NULL; } // -------------------------------------------------------------------------- // Destructor: TDIDevCaps::~TDIDevCaps() // Description: The destructor for the TDIDevCaps object. // -------------------------------------------------------------------------- __fastcall TDIDevCaps::~TDIDevCaps() { if (fFlags_Strings!=NULL) delete fFlags_Strings; } // -------------------------------------------------------------------------- // Property: Axes // Description: The Axes property defines the number of axes available on the // device. // // Any part of a device that is capable of returning a range of // values is regarded to be an axis. // -------------------------------------------------------------------------- dword __fastcall TDIDevCaps::FGetAxes() { return fDIDEVCAPS.dwAxes; } // -------------------------------------------------------------------------- void __fastcall TDIDevCaps::FSetAxes( dword pAxes ) { fDIDEVCAPS.dwAxes = pAxes; } // -------------------------------------------------------------------------- // Property: Buttons // Description: The Buttons property defines the number of buttons available // on the device. // // Any part of a device that is basically boolean is regarded to // be a button. // -------------------------------------------------------------------------- dword __fastcall TDIDevCaps::FGetButtons() { return fDIDEVCAPS.dwButtons; } // -------------------------------------------------------------------------- void __fastcall TDIDevCaps::FSetButtons( dword pButtons ) { fDIDEVCAPS.dwButtons = pButtons; } // -------------------------------------------------------------------------- // Property: DevType // Description: The DevType property defines the device type specification // flags. // The described effect applies when the flag is set. // // The device type defines a device as one of four basic types, // those being keyboard, mouse, joystick and unknown. // The four basic types have subtypes that further specify the // device type. All devices can also be defined as using HID // (Human Interface Device) protocol. // // Basic types are defined in the least significant byte, // subtypes in the next byte and further definitions such as HID // are contained in the high order word. // -------------------------------------------------------------------------- dword __fastcall TDIDevCaps::FGetDevType() { return fDIDEVCAPS.dwDevType; } // -------------------------------------------------------------------------- void __fastcall TDIDevCaps::FSetDevType( dword pDevType ) { fDIDEVCAPS.dwDevType = pDevType; } // -------------------------------------------------------------------------- // Property: ErrorValue // Description: The ErrorValue property contains the last error value // returned from a call to a TDIDevCaps method or fget/fset. eg. // DI_OK or DDERR_SURFACELOST or TDX_ERROR // -------------------------------------------------------------------------- HRESULT __fastcall TDIDevCaps::FGetErrorValue() { return fErrorValue; } // -------------------------------------------------------------------------- void __fastcall TDIDevCaps::FSetErrorValue( HRESULT pErrorValue ) { fErrorValue = pErrorValue; } // -------------------------------------------------------------------------- // Property: FFDriverVersion // Description: The FFDriverVersion property defines the version number of // the force feedback device driver. // // There is no standard format for revisions, except that newer // revisions will have a larger value. // -------------------------------------------------------------------------- dword __fastcall TDIDevCaps::FGetFFDriverVersion() { return fDIDEVCAPS.dwFFDriverVersion; } // -------------------------------------------------------------------------- void __fastcall TDIDevCaps::FSetFFDriverVersion( dword pFFDriverVersion ) { fDIDEVCAPS.dwFFDriverVersion = pFFDriverVersion; } // -------------------------------------------------------------------------- // Property: FFMinTimeResolution // Description: The FFMinTimeResolution property defines the minimum amount // of time, in microseconds, that the device can resolve. // // Any times assigned by the application, for force feedback // effects, will be rounded to the nearest increment that is // supported by the device. // -------------------------------------------------------------------------- dword __fastcall TDIDevCaps::FGetFFMinTimeResolution() { return fDIDEVCAPS.dwFFMinTimeResolution; } // -------------------------------------------------------------------------- void __fastcall TDIDevCaps::FSetFFMinTimeResolution( dword pFFMinTimeResolution ) { fDIDEVCAPS.dwFFMinTimeResolution = pFFMinTimeResolution; } // -------------------------------------------------------------------------- // Property: FFSamplePeriod // Description: The FFSamplePeriod property defines the minimum time, in // microseconds, that is allowed between the playback of // consecutive force feedback commands. // -------------------------------------------------------------------------- dword __fastcall TDIDevCaps::FGetFFSamplePeriod() { return fDIDEVCAPS.dwFFSamplePeriod; } // -------------------------------------------------------------------------- void __fastcall TDIDevCaps::FSetFFSamplePeriod( dword pFFSamplePeriod ) { fDIDEVCAPS.dwFFSamplePeriod = pFFSamplePeriod; } // -------------------------------------------------------------------------- // Property: FirmwareRevision // Description: The FirmwareRevision property defines the firmware revision // of the device. // // There is no standard format for firmware revisions, except // that newer revisions will have a larger value. // -------------------------------------------------------------------------- dword __fastcall TDIDevCaps::FGetFirmwareRevision() { return fDIDEVCAPS.dwFirmwareRevision; } // -------------------------------------------------------------------------- void __fastcall TDIDevCaps::FSetFirmwareRevision( dword pFirmwareRevision ) { fDIDEVCAPS.dwFirmwareRevision = pFirmwareRevision; } // -------------------------------------------------------------------------- // Property: Flags // Description: The Flags property defines flags indicating the force // feedback and reporting capabilities the device has available. // The described effect applies when the flag is set. // Flags: DIDC_ALIAS - // The device duplicates another input device. // // An alias device will not be enumerated by // TDx_Input::EnumDevices() unless specifically requested. // DIDC_ATTACHED - // The device is physically attached to the system. // // It is possible to have a device installed but not attached, // like if you have a mouse driver installed, but the mouse is // not physically plugged in. // DIDC_DEADBAND - // Support for deadband on at least one force feedback // condition is available. // DIDC_EMULATED - // The device's data is not coming directly from a kernel mode // driver. // // There may be some performance degradation, depending on the // functionality being used. // DIDC_FFATTACK - // Support for force feedback attack envelope parameters on at // least one effect is available. // // TDIEnvelope::AttackLevel and TDIEnvelope::AttackTime will // be ignored if attack is not supported for a given effect. // After calling TDx_InputDevice::GetEffectInfo(), an // individual effect will set the DIEFT_FFATTACK flag if // attack is supported for that effect. // DIDC_FFFADE - // Support for force feedback fade envelope parameters on at // least one effect is available. // // TDIEnvelope::FadeLevel and TDIEnvelope::FadeTime will be // ignored if fade is not supported for a given effect. // After calling TDx_InputDevice::GetEffectInfo(), an // individual effect will set the DIEFT_FFFADE flag if fade is // supported for that effect. // DIDC_FORCEFEEDBACK - // Support for force feedback effects is available. // DIDC_PHANTOM - // The device does not actually exist, instead being a // placeholder for a possible future device. // // A phantom device will not be enumerated by // TDx_Input::EnumDevices() unless specifically requested. // DIDC_POLLEDDATAFORMAT - // One or more objects in the current data format must be // polled rather than being interrupt driven. // // TDx_InputDevice::Poll() must be explicitly called in order // to obtain data from objects that have to be polled. // DIDC_POLLEDDEVICE - // One or more parts of the device must be polled rather than // being interrupt driven. // // TDx_InputDevice::Poll() must be explicitly called in order // to obtain data from device objects that have to be polled. // A HID may have both polled and non-polled objects present. // DIDC_POSNEGCOEFFICIENTS - // Support for both positive and negative coefficient values // for conditions is available for at least one condition. // // After calling TDx_InputDevice::GetEffectInfo(), an // individual condition will set DIEFT_POSNEGCOEFFICIENTS if // separate positive and negative coefficients are supported // for that condition. // // If this flag isn't set then the positive coefficient is // used for both the positive and negative values. // DIDC_POSNEGSATURATION - // Support for both positive and negative saturation values // for conditions is available for at least one condition. // // After calling TDx_InputDevice::GetEffectInfo(), an // individual condition will set DIEFT_POSNEGSATURATION if // separate positive and negative saturations are supported // for that condition. // // If this flag isn't set then the positive saturation is used // for both the positive and negative values. // DIDC_SATURATION - // Support for saturation values on conditions is available // for at least one condition. // // After calling TDx_InputDevice::GetEffectInfo(), an // individual condition will set DIEFT_SATURATION if // saturation is supported for that condition. // // If the device does not support saturation, then the force // generated by a condition is only limited by the maximum // force the device can generate. // DIDC_STARTDELAY - // Support for delaying the playback of an effect by a // specified time is available. // // If support is not available the TDIEffect::StartDelay // property will be ignored. // -------------------------------------------------------------------------- dword __fastcall TDIDevCaps::FGetFlags() { return fDIDEVCAPS.dwFlags; } // -------------------------------------------------------------------------- void __fastcall TDIDevCaps::FSetFlags( dword pFlags ) { fDIDEVCAPS.dwFlags = pFlags; } // -------------------------------------------------------------------------- // Property: HardwareRevision // Description: The HardwareRevision Defines the hardware revision of the // device. // // There is no standard format for hardware revisions, except // that newer revisions will have a larger value. // -------------------------------------------------------------------------- dword __fastcall TDIDevCaps::FGetHardwareRevision() { return fDIDEVCAPS.dwHardwareRevision; } // -------------------------------------------------------------------------- void __fastcall TDIDevCaps::FSetHardwareRevision( dword pHardwareRevision ) { fDIDEVCAPS.dwHardwareRevision = pHardwareRevision; } // -------------------------------------------------------------------------- // Property: POVs // Description: The POVs property defines the number of 'point of view' // controls on the device. // -------------------------------------------------------------------------- dword __fastcall TDIDevCaps::FGetPOVs() { return fDIDEVCAPS.dwPOVs; } // -------------------------------------------------------------------------- void __fastcall TDIDevCaps::FSetPOVs( dword pPOVs ) { fDIDEVCAPS.dwPOVs = pPOVs; } // -------------------------------------------------------------------------- // Property: Size // Description: The Size property defines the size, in bytes, of the internal // structure used by this component. // -------------------------------------------------------------------------- dword __fastcall TDIDevCaps::FGetSize() { return fDIDEVCAPS.dwSize; } // -------------------------------------------------------------------------- void __fastcall TDIDevCaps::FSetSize( dword pSize ) { fDIDEVCAPS.dwSize = pSize; } // -------------------------------------------------------------------------- // Method: Clear() // Description: The Clear() method can be used to clear the contents of the // TDIDevCaps's internal DIDEVCAPS structure. // Note: if you have manually linked a structure member to a // chunk of memory, make sure you release this memory before // calling Clear(). // -------------------------------------------------------------------------- void __fastcall TDIDevCaps::Clear() { fDIDEVCAPS.dwAxes = 0; fDIDEVCAPS.dwButtons = 0; fDIDEVCAPS.dwDevType = 0; fErrorValue = DI_OK; fDIDEVCAPS.dwFFDriverVersion = 0; fDIDEVCAPS.dwFFMinTimeResolution = 0; fDIDEVCAPS.dwFFSamplePeriod = 0; fDIDEVCAPS.dwFirmwareRevision = 0; fDIDEVCAPS.dwFlags = 0; fDIDEVCAPS.dwHardwareRevision = 0; fDIDEVCAPS.dwPOVs = 0; fDIDEVCAPS.dwSize = sizeof(DIDEVCAPS); } // -------------------------------------------------------------------------- // Internal Structure Access // -------------------------------------------------------------------------- DIDEVCAPS* __fastcall TDIDevCaps::FGetInternal_DIDEVCAPS_Ptr() { return &fDIDEVCAPS; } // -------------------------------------------------------------------------- void __fastcall TDIDevCaps::FSetInternal_DIDEVCAPS( DIDEVCAPS* pDIDEVCAPS ) { if (pDIDEVCAPS==NULL) { fErrorValue = TDX_ERROR; if (FOnError) FOnError(this, "TDIDevCaps::FSetInternal_DIDEVCAPS()", "TDX_ERROR", "The supplied DIDEVCAPS* was NULL" ); return; } CopyMemory( &fDIDEVCAPS, pDIDEVCAPS, sizeof(DIDEVCAPS) ); Internal_DIDEVCAPS_Update(); } // -------------------------------------------------------------------------- void __fastcall TDIDevCaps::Internal_DIDEVCAPS_Update() { } // -------------------------------------------------------------------------- // Method: FGetFlags_ // Description: This method returns a TDIDevCaps_Flags_Set<> of the flags in // the current fDIDEVCAPS.dwFlags. // Note: Wrapper components use the following method to modify flags // via the BCB Object Inspector. // -------------------------------------------------------------------------- TDIDevCaps_Flags_Set __fastcall TDIDevCaps::FGetFlags_() { TDIDevCaps_Flags_Set TempFlags_; TempFlags_.Clear(); if (fDIDEVCAPS.dwFlags & DIDC_ALIAS) TempFlags_ = TempFlags_ << didc_alias; if (fDIDEVCAPS.dwFlags & DIDC_ATTACHED) TempFlags_ = TempFlags_ << didc_attached; if (fDIDEVCAPS.dwFlags & DIDC_DEADBAND) TempFlags_ = TempFlags_ << didc_deadband; if (fDIDEVCAPS.dwFlags & DIDC_EMULATED) TempFlags_ = TempFlags_ << didc_emulated; if (fDIDEVCAPS.dwFlags & DIDC_FFATTACK) TempFlags_ = TempFlags_ << didc_ffattack; if (fDIDEVCAPS.dwFlags & DIDC_FFFADE) TempFlags_ = TempFlags_ << didc_fffade; if (fDIDEVCAPS.dwFlags & DIDC_FORCEFEEDBACK) TempFlags_ = TempFlags_ << didc_forcefeedback; if (fDIDEVCAPS.dwFlags & DIDC_PHANTOM) TempFlags_ = TempFlags_ << didc_phantom; if (fDIDEVCAPS.dwFlags & DIDC_POLLEDDATAFORMAT) TempFlags_ = TempFlags_ << didc_polleddataformat; if (fDIDEVCAPS.dwFlags & DIDC_POLLEDDEVICE) TempFlags_ = TempFlags_ << didc_polleddevice; if (fDIDEVCAPS.dwFlags & DIDC_POSNEGCOEFFICIENTS) TempFlags_ = TempFlags_ << didc_posnegcoefficients; if (fDIDEVCAPS.dwFlags & DIDC_POSNEGSATURATION) TempFlags_ = TempFlags_ << didc_posnegsaturation; if (fDIDEVCAPS.dwFlags & DIDC_SATURATION) TempFlags_ = TempFlags_ << didc_saturation; if (fDIDEVCAPS.dwFlags & DIDC_STARTDELAY) TempFlags_ = TempFlags_ << didc_startdelay; return TempFlags_; } // -------------------------------------------------------------------------- void __fastcall TDIDevCaps::FSetFlags_( TDIDevCaps_Flags_Set pFlags_ ) { fDIDEVCAPS.dwFlags = 0; if (pFlags_.Contains(didc_alias)) fDIDEVCAPS.dwFlags |= DIDC_ALIAS; if (pFlags_.Contains(didc_attached)) fDIDEVCAPS.dwFlags |= DIDC_ATTACHED; if (pFlags_.Contains(didc_deadband)) fDIDEVCAPS.dwFlags |= DIDC_DEADBAND; if (pFlags_.Contains(didc_emulated)) fDIDEVCAPS.dwFlags |= DIDC_EMULATED; if (pFlags_.Contains(didc_ffattack)) fDIDEVCAPS.dwFlags |= DIDC_FFATTACK; if (pFlags_.Contains(didc_fffade)) fDIDEVCAPS.dwFlags |= DIDC_FFFADE; if (pFlags_.Contains(didc_forcefeedback)) fDIDEVCAPS.dwFlags |= DIDC_FORCEFEEDBACK; if (pFlags_.Contains(didc_phantom)) fDIDEVCAPS.dwFlags |= DIDC_PHANTOM; if (pFlags_.Contains(didc_polleddataformat)) fDIDEVCAPS.dwFlags |= DIDC_POLLEDDATAFORMAT; if (pFlags_.Contains(didc_polleddevice)) fDIDEVCAPS.dwFlags |= DIDC_POLLEDDEVICE; if (pFlags_.Contains(didc_posnegcoefficients)) fDIDEVCAPS.dwFlags |= DIDC_POSNEGCOEFFICIENTS; if (pFlags_.Contains(didc_posnegsaturation)) fDIDEVCAPS.dwFlags |= DIDC_POSNEGSATURATION; if (pFlags_.Contains(didc_saturation)) fDIDEVCAPS.dwFlags |= DIDC_SATURATION; if (pFlags_.Contains(didc_startdelay)) fDIDEVCAPS.dwFlags |= DIDC_STARTDELAY; } // -------------------------------------------------------------------------- // Method: FGetFlags_Strings() // This method creates and then returns a TStringList containing // the current set of 'Flags' flags. // Note: You must manually delete the retrieved TStringList after use // to avoid memory corruption. // -------------------------------------------------------------------------- TStringList* __fastcall TDIDevCaps::FGetFlags_Strings() { // if the strings have not been allocated if (fFlags_Strings==NULL) { // attempt to allocate the strings fFlags_Strings = new TStringList(); // if the allocation failed if (fFlags_Strings==NULL) { fErrorValue = TDX_ERROR; if (FOnError) FOnError(this, "TDIDevCaps::FGetFlags_Strings()", "TDX_ERROR", "Could not allocate memory used to retrieve various Flags_Strings" ); return NULL; } } fFlags_Strings->Clear(); if (fDIDEVCAPS.dwFlags & DIDC_ALIAS) fFlags_Strings->Add("DIDC_ALIAS"); if (fDIDEVCAPS.dwFlags & DIDC_ATTACHED) fFlags_Strings->Add("DIDC_ATTACHED"); if (fDIDEVCAPS.dwFlags & DIDC_DEADBAND) fFlags_Strings->Add("DIDC_DEADBAND"); if (fDIDEVCAPS.dwFlags & DIDC_EMULATED) fFlags_Strings->Add("DIDC_EMULATED"); if (fDIDEVCAPS.dwFlags & DIDC_FFATTACK) fFlags_Strings->Add("DIDC_FFATTACK"); if (fDIDEVCAPS.dwFlags & DIDC_FFFADE) fFlags_Strings->Add("DIDC_FFFADE"); if (fDIDEVCAPS.dwFlags & DIDC_FORCEFEEDBACK) fFlags_Strings->Add("DIDC_FORCEFEEDBACK"); if (fDIDEVCAPS.dwFlags & DIDC_PHANTOM) fFlags_Strings->Add("DIDC_PHANTOM"); if (fDIDEVCAPS.dwFlags & DIDC_POLLEDDATAFORMAT) fFlags_Strings->Add("DIDC_POLLEDDATAFORMAT"); if (fDIDEVCAPS.dwFlags & DIDC_POLLEDDEVICE) fFlags_Strings->Add("DIDC_POLLEDDEVICE"); if (fDIDEVCAPS.dwFlags & DIDC_POSNEGCOEFFICIENTS) fFlags_Strings->Add("DIDC_POSNEGCOEFFICIENTS"); if (fDIDEVCAPS.dwFlags & DIDC_POSNEGSATURATION) fFlags_Strings->Add("DIDC_POSNEGSATURATION"); if (fDIDEVCAPS.dwFlags & DIDC_SATURATION) fFlags_Strings->Add("DIDC_SATURATION"); if (fDIDEVCAPS.dwFlags & DIDC_STARTDELAY) fFlags_Strings->Add("DIDC_STARTDELAY"); return fFlags_Strings; } // --------------------------------------------------------------------------