Earl Colby Pottinger
2005-08-21 22:51:43 UTC
I can seem to access the joystick under BeOS properly.
If I open as an unenhanced joystick, I have problems detecting the pots'
correct values. But worse in enhanced mode the moment I press a button I
lose the 4 axis.
Here is my sample code:
if (Display == 1006) { // Read the game port info, open the
GamePort/Joystick in non-enhanced mode.
SetFontSize(12); X=20.0; Y=20.0; MovePenTo(BPoint(X,Y)); // Nice font
size, set cursor position.
JoyStick = new BJoystick(); // Create a joystick object.
Device_Count = JoyStick->CountDevices(); sprintf(TextBuffer,"Number of
gameport devices found--> %d ",(int)Device_Count); DrawString(TextBuffer);
Y=Y+15.0; MovePenTo(BPoint(X,Y));
for (int n=0; n<Device_Count; n++) {
JoyStick->GetDeviceName(n, JoyStick_Name); // Get name of GamePort.
sprintf(TextBuffer,"Device name of gameport %d -->
%s",n,JoyStick_Name); DrawString(TextBuffer); Y=Y+15.0;
MovePenTo(BPoint(X,Y)); // Print names of gameport devices.
JoyStick->Open(JoyStick_Name,false); // Open port in unenhanced mode.
JoyStick->GetControllerName(&Control_Name);
sprintf(TextBuffer,"Controller name of gameport -->
%s",Control_Name.String()); DrawString(TextBuffer); Y=Y+25.0;
MovePenTo(BPoint(X,Y)); // Print names of gameport controllers.
JoyStick->Close(); }
status_t Status = JoyStick->GetDeviceName(0, JoyStick_Name); // Get name
of first gameport device.
if (Status == B_OK) {
sprintf(TextBuffer,"Opened first game port in enhanced mode. Device
name of gameport read --> %s ",JoyStick_Name); DrawString(TextBuffer);
Y=Y+15.0; MovePenTo(BPoint(X,Y));
Status = JoyStick->Open(JoyStick_Name,false); // Open GamePort Object
as unenhanced.
if (Status >= B_OK) { // Positive value means successful open.
for (int n=0; n<20; n++) {
JoyStick->Update(); // Read Joystick status.
// JoyStick->horizontal first analog pot input (0-4095) on the
joystick.
// JoyStick->vertical second analog pot input (0-4095) on the
joystick.
// JoyStick->button1 first button found on the joystick.
// JoyStick->button2 second button found on the joystick.
sprintf(TextBuffer,"Joystick Horizontal --> %4d Vertical -->
%4d Button 1 --> %d Button 2 --> %d",
10000+JoyStick->horizontal, 10000+JoyStick->vertical,
(int)JoyStick->button1, (int)JoyStick->button2);
DrawString(TextBuffer); Y=Y+15.0; MovePenTo(BPoint(X,Y)); //
print Joystick information.
if (Timing) { // Wait till next valid time slice to do sampling.
TimeBase = TimeBase + Timing; snooze_until(TimeBase,
B_SYSTEM_TIMEBASE); } }
JoyStick->Close(); // Close GamePort.
}else{
DrawString("First joystick on gameport would not open in unenhanced
mode."); Y=Y+25.0; MovePenTo(BPoint(X,Y)); } }
delete JoyStick; SetFontSize(12); } // Delete BJoystick object. Restore
font size
if (Display == 1007) { // Read the game port info, open the
GamePort/Joystick in enhanced mode.
SetFontSize(12); X=20.0; Y=20.0; MovePenTo(BPoint(X,Y)); // Nice font
size, set cursor position.
JoyStick = new BJoystick(); // Create a joystick object.
Device_Count = JoyStick->CountDevices(); sprintf(TextBuffer,"Number of
gameport devices found--> %d ",(int)Device_Count); DrawString(TextBuffer);
Y=Y+15.0; MovePenTo(BPoint(X,Y));
for (int n=0; n<Device_Count; n++) {
JoyStick->GetDeviceName(n, JoyStick_Name); // Get name of GamePort.
sprintf(TextBuffer,"Device name of gameport %d -->
%s",n,JoyStick_Name); DrawString(TextBuffer); Y=Y+15.0;
MovePenTo(BPoint(X,Y)); // Print names of gameport devices.
JoyStick->Open(JoyStick_Name,true); // Open port in unenhanced mode.
JoyStick->GetControllerName(&Control_Name);
sprintf(TextBuffer,"Controller name of gameport -->
%s",Control_Name.String()); DrawString(TextBuffer); Y=Y+25.0;
MovePenTo(BPoint(X,Y)); // Print names of gameport controllers.
JoyStick->Close(); }
status_t Status = JoyStick->GetDeviceName(0, JoyStick_Name); // Get name
of first gameport device.
if (Status == B_OK) {
sprintf(TextBuffer,"Opened first game port in enhanced mode. Device
name of gameport read --> %s ",JoyStick_Name); DrawString(TextBuffer);
Y=Y+15.0; MovePenTo(BPoint(X,Y));
Status = JoyStick->Open(JoyStick_Name,true); // Open GamePort Object
and Open.
if (Status >= B_OK) { // Positive value means successful open.
Stick_Count = JoyStick->CountSticks();
sprintf(TextBuffer,"Gameport/JoyStick Sticks Count--> %d ",
(int)Stick_Count); DrawString(TextBuffer); Y=Y+15.0; MovePenTo(BPoint(X,Y));
Hat_Count = JoyStick->CountHats();
sprintf(TextBuffer,"Gameport/JoyStick Hats Count--> %d ", (int)Hat_Count);
DrawString(TextBuffer); Y=Y+15.0; MovePenTo(BPoint(X,Y));
Button_Count = JoyStick->CountButtons();
sprintf(TextBuffer,"Gameport/JoyStick Buttons Count--> %d ",
(int)Button_Count); DrawString(TextBuffer); Y=Y+15.0; MovePenTo(BPoint(X,Y));
Axis_Count = JoyStick->CountAxes();
sprintf(TextBuffer,"Gameport/JoyStick Axis Count--> %d ",
(int)Axis_Count); DrawString(TextBuffer); Y=Y+15.0; MovePenTo(BPoint(X,Y));
// int16 Pot_Values[9]; // same as ? =>
int16* axes; axes = (int16 *) malloc(sizeof(int16) * Axis_Count);
// Create array to recieve axis values.
for (int n=0; n<20; n++) {
JoyStick->Update();
Button_Values = JoyStick->ButtonValues();
JoyStick->GetAxisValues(axes,0); // Read Joystick status.
sprintf(TextBuffer,"Joystick 1 Buttons, Axis(1-4)--> %d %d %d
%d %d",(int)Button_Values,
(int)axes[0],(int)axes[1],(int)axes[2],(int)axes[3]);
DrawString(TextBuffer); Y=Y+15.0; MovePenTo(BPoint(X,Y)); }
JoyStick->Close(); // Close GamePort.
}else{
DrawString("Joystick would not open in enhanced mode."); Y=Y+15.0;
MovePenTo(BPoint(X,Y)); } }
delete JoyStick; SetFontSize(12); } // Delete BJoystick object. Restore
font size
If I open as an unenhanced joystick, I have problems detecting the pots'
correct values. But worse in enhanced mode the moment I press a button I
lose the 4 axis.
Here is my sample code:
if (Display == 1006) { // Read the game port info, open the
GamePort/Joystick in non-enhanced mode.
SetFontSize(12); X=20.0; Y=20.0; MovePenTo(BPoint(X,Y)); // Nice font
size, set cursor position.
JoyStick = new BJoystick(); // Create a joystick object.
Device_Count = JoyStick->CountDevices(); sprintf(TextBuffer,"Number of
gameport devices found--> %d ",(int)Device_Count); DrawString(TextBuffer);
Y=Y+15.0; MovePenTo(BPoint(X,Y));
for (int n=0; n<Device_Count; n++) {
JoyStick->GetDeviceName(n, JoyStick_Name); // Get name of GamePort.
sprintf(TextBuffer,"Device name of gameport %d -->
%s",n,JoyStick_Name); DrawString(TextBuffer); Y=Y+15.0;
MovePenTo(BPoint(X,Y)); // Print names of gameport devices.
JoyStick->Open(JoyStick_Name,false); // Open port in unenhanced mode.
JoyStick->GetControllerName(&Control_Name);
sprintf(TextBuffer,"Controller name of gameport -->
%s",Control_Name.String()); DrawString(TextBuffer); Y=Y+25.0;
MovePenTo(BPoint(X,Y)); // Print names of gameport controllers.
JoyStick->Close(); }
status_t Status = JoyStick->GetDeviceName(0, JoyStick_Name); // Get name
of first gameport device.
if (Status == B_OK) {
sprintf(TextBuffer,"Opened first game port in enhanced mode. Device
name of gameport read --> %s ",JoyStick_Name); DrawString(TextBuffer);
Y=Y+15.0; MovePenTo(BPoint(X,Y));
Status = JoyStick->Open(JoyStick_Name,false); // Open GamePort Object
as unenhanced.
if (Status >= B_OK) { // Positive value means successful open.
for (int n=0; n<20; n++) {
JoyStick->Update(); // Read Joystick status.
// JoyStick->horizontal first analog pot input (0-4095) on the
joystick.
// JoyStick->vertical second analog pot input (0-4095) on the
joystick.
// JoyStick->button1 first button found on the joystick.
// JoyStick->button2 second button found on the joystick.
sprintf(TextBuffer,"Joystick Horizontal --> %4d Vertical -->
%4d Button 1 --> %d Button 2 --> %d",
10000+JoyStick->horizontal, 10000+JoyStick->vertical,
(int)JoyStick->button1, (int)JoyStick->button2);
DrawString(TextBuffer); Y=Y+15.0; MovePenTo(BPoint(X,Y)); //
print Joystick information.
if (Timing) { // Wait till next valid time slice to do sampling.
TimeBase = TimeBase + Timing; snooze_until(TimeBase,
B_SYSTEM_TIMEBASE); } }
JoyStick->Close(); // Close GamePort.
}else{
DrawString("First joystick on gameport would not open in unenhanced
mode."); Y=Y+25.0; MovePenTo(BPoint(X,Y)); } }
delete JoyStick; SetFontSize(12); } // Delete BJoystick object. Restore
font size
if (Display == 1007) { // Read the game port info, open the
GamePort/Joystick in enhanced mode.
SetFontSize(12); X=20.0; Y=20.0; MovePenTo(BPoint(X,Y)); // Nice font
size, set cursor position.
JoyStick = new BJoystick(); // Create a joystick object.
Device_Count = JoyStick->CountDevices(); sprintf(TextBuffer,"Number of
gameport devices found--> %d ",(int)Device_Count); DrawString(TextBuffer);
Y=Y+15.0; MovePenTo(BPoint(X,Y));
for (int n=0; n<Device_Count; n++) {
JoyStick->GetDeviceName(n, JoyStick_Name); // Get name of GamePort.
sprintf(TextBuffer,"Device name of gameport %d -->
%s",n,JoyStick_Name); DrawString(TextBuffer); Y=Y+15.0;
MovePenTo(BPoint(X,Y)); // Print names of gameport devices.
JoyStick->Open(JoyStick_Name,true); // Open port in unenhanced mode.
JoyStick->GetControllerName(&Control_Name);
sprintf(TextBuffer,"Controller name of gameport -->
%s",Control_Name.String()); DrawString(TextBuffer); Y=Y+25.0;
MovePenTo(BPoint(X,Y)); // Print names of gameport controllers.
JoyStick->Close(); }
status_t Status = JoyStick->GetDeviceName(0, JoyStick_Name); // Get name
of first gameport device.
if (Status == B_OK) {
sprintf(TextBuffer,"Opened first game port in enhanced mode. Device
name of gameport read --> %s ",JoyStick_Name); DrawString(TextBuffer);
Y=Y+15.0; MovePenTo(BPoint(X,Y));
Status = JoyStick->Open(JoyStick_Name,true); // Open GamePort Object
and Open.
if (Status >= B_OK) { // Positive value means successful open.
Stick_Count = JoyStick->CountSticks();
sprintf(TextBuffer,"Gameport/JoyStick Sticks Count--> %d ",
(int)Stick_Count); DrawString(TextBuffer); Y=Y+15.0; MovePenTo(BPoint(X,Y));
Hat_Count = JoyStick->CountHats();
sprintf(TextBuffer,"Gameport/JoyStick Hats Count--> %d ", (int)Hat_Count);
DrawString(TextBuffer); Y=Y+15.0; MovePenTo(BPoint(X,Y));
Button_Count = JoyStick->CountButtons();
sprintf(TextBuffer,"Gameport/JoyStick Buttons Count--> %d ",
(int)Button_Count); DrawString(TextBuffer); Y=Y+15.0; MovePenTo(BPoint(X,Y));
Axis_Count = JoyStick->CountAxes();
sprintf(TextBuffer,"Gameport/JoyStick Axis Count--> %d ",
(int)Axis_Count); DrawString(TextBuffer); Y=Y+15.0; MovePenTo(BPoint(X,Y));
// int16 Pot_Values[9]; // same as ? =>
int16* axes; axes = (int16 *) malloc(sizeof(int16) * Axis_Count);
// Create array to recieve axis values.
for (int n=0; n<20; n++) {
JoyStick->Update();
Button_Values = JoyStick->ButtonValues();
JoyStick->GetAxisValues(axes,0); // Read Joystick status.
sprintf(TextBuffer,"Joystick 1 Buttons, Axis(1-4)--> %d %d %d
%d %d",(int)Button_Values,
(int)axes[0],(int)axes[1],(int)axes[2],(int)axes[3]);
DrawString(TextBuffer); Y=Y+15.0; MovePenTo(BPoint(X,Y)); }
JoyStick->Close(); // Close GamePort.
}else{
DrawString("Joystick would not open in enhanced mode."); Y=Y+15.0;
MovePenTo(BPoint(X,Y)); } }
delete JoyStick; SetFontSize(12); } // Delete BJoystick object. Restore
font size
--
I make public email sent to me! Hydrogen Peroxide Rockets, OpenBeos,
SerialTransfer 3.0, RAMDISK, BoatBuilding, DIY TabletPC. What happened to
the time? http://webhome.idirect.com/~earlcp
I make public email sent to me! Hydrogen Peroxide Rockets, OpenBeos,
SerialTransfer 3.0, RAMDISK, BoatBuilding, DIY TabletPC. What happened to
the time? http://webhome.idirect.com/~earlcp