BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

HID Devices (JvHidDeviceController) & Modal Form

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi (General)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Wed Feb 07, 2007 5:47 am    Post subject: HID Devices (JvHidDeviceController) & Modal Form Reply with quote



I'm stumped and could use some help. I have a program which interacts
with a USB joystick. Since I know almost nothing about reading USB
devices I downloaded some really nice components by Robert Marquardt
at http://www.delphi-gems.com/HID.php and installed them.

Now here's what I'm attempting to do. My program consists of only two
forms. The main form is a "menu" more or less. It's a string grid and
as the user moves the joystick up or down the selected cell inside the
grid changes. When the user finds the cell he wants he pressed the
button on the joystick. All this action is controlled by the
JvHidDeviceController component on the main form which keeps track of
the HID devices. (This all works great in my code). After the button
is pressed the main form creates the second form and shows it as a
modal form. The second form doesn't really do anything other than show
a picture. I want the user to be able to press the button again at
which time the second form closes and returns focus to the main form.
The problem is the second form is modal and the controller component
on the main form, which reads the USB devices, no longer seems to get
the input. The button press seems to get ignored and the form never
closes. Here is a very basic outline of the code:



unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, JvHidControllerClass, StdCtrls;

type
TForm1 = class(TForm)
JvHidDeviceController: TJvHidDeviceController;
lstHidDevices: TListBox;
procedure JvHidDeviceControllerDeviceChange(Sender: TObject);
function JvHidDeviceControllerEnumerate(HidDev: TJvHidDevice;
const Idx: Integer): Boolean;
private
{ Private declarations }
public
{ Public declarations }
procedure ReadJoysticks(HidDev: TJvHidDevice; ReportID: Byte;
const Data: Pointer; Size: Word);
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

uses frmPictureForm;

procedure TForm1.JvHidDeviceControllerDeviceChange(Sender: TObject);
var
Count: Integer;
Dev: TJvHidDevice;
begin
//This procedure clears all the HID items:

//Check in all items and remove objects from the list
for Count := 0 to lstHidDevices.Items.Count - 1 do
begin
Dev := TJvHidDevice(lstHidDevices.Items.Objects[Count]);
JvHidDeviceController.CheckIn(Dev);
lstHidDevices.Items.Objects[Count] := nil;
end;

//Clear the listbox
lstHidDevices.Items.Clear;

//Get a list of connected HID items
JvHidDeviceController.Enumerate;
end;

function TForm1.JvHidDeviceControllerEnumerate(HidDev: TJvHidDevice;
const Idx: Integer): Boolean;
var
Dev: TJvHidDevice;
DevID: Integer;
begin
//This procedure gets all the HID items:

// add a descriptive entry to the listbox for the device
if HidDev.ProductName <> '' then
DevID := lstHidDevices.Items.Add(HidDev.ProductName)
else
DevID := lstHidDevices.Items.Add(Format('Device VID=%x PID=%x',
[HidDev.Attributes.VendorID, HidDev.Attributes.ProductID]));

//Retrive the device and assign it to the list
JvHidDeviceController.CheckOutByIndex(Dev, Idx);
lstHidDevices.Items.Objects[DevID] := Dev;

//If this device is a joystick then set its OnData property to read
its input
Dev.OnData := ReadJoysticks;

//Return true so we can move on to the next device
Result := True;
end;

procedure TForm1.ReadJoysticks(HidDev: TJvHidDevice; ReportID: Byte;
const Data: Pointer; Size: Word);
var
Xaxis, Yaxis, Btn: Integer;
begin
//Check the X and Y axis
Xaxis := Cardinal(PChar(Data)[3]);
Yaxis := Cardinal(PChar(Data)[1]);

//Check the button(s) value
Btn := Cardinal(PChar(Data)[4]);

//string grid code goes here (Xaxis and Yaxis)

//Launch the second form if a button is pressed
if Btn > 0 then
begin
if not Assigned(fPictureForm) then
begin
Application.CreateForm(TfPictureForm, fPictureForm);
fPictureForm.ShowModal;
end
else
begin
fPictureForm.Free;
fPictureForm := nil;
end;
end;
end;

end.

How can I get the JvHidDeviceController to continue to receive input
when the modal form is shown?
Back to top
Guest






PostPosted: Mon Feb 12, 2007 6:56 pm    Post subject: Re: HID Devices (JvHidDeviceController) & Modal Form Reply with quote



On 7 Feb., 00:47, cybero...@hotmail.com wrote:
Quote:
I'm stumped and could use some help. I have a program which interacts
with a USB joystick. Since I know almost nothing about reading USB
devices I downloaded some really nice components by Robert Marquardt
at http://www.delphi-gems.com/HID.phpand installed them.

There should be no problem receiving data from the joystick.
Please contact me directly robert_marquardt att gmx dott de
Back to top
Guest






PostPosted: Mon Feb 26, 2007 11:01 pm    Post subject: Re: HID Devices (JvHidDeviceController) & Modal Form Reply with quote



On Feb 12, 4:56 am, robert_marqua...@gmx.de wrote:
Quote:
On 7 Feb., 00:47, cybero...@hotmail.com wrote:

I'm stumped and could use some help. I have a program which interacts
with a USB joystick. Since I know almost nothing about reading USB
devices I downloaded some really nice components by Robert Marquardt
at http://www.delphi-gems.com/HID.phpandinstalled them.

There should be no problem receiving data from the joystick.
Please contact me directly robert_marquardt att gmx dott de

Anyone else have any experience with this by chance?
Back to top
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi (General) All times are GMT
Page 1 of 1

 
 


Powered by phpBB © 2001, 2006 phpBB Group
.