* Add Jamfiles to allow building the stickit sample code. It allows testing of

the BJoystick API and joystick drivers.
* Also fix a few warnings in the code that were caused by using NULL instead of
  0 for BWindow/BView flags.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41852 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz
2011-05-31 02:33:28 +00:00
parent f46bc7f19e
commit f202fdc6ed
4 changed files with 62 additions and 51 deletions
+1
View File
@@ -1,6 +1,7 @@
SubDir HAIKU_TOP src tests kits ; SubDir HAIKU_TOP src tests kits ;
SubInclude HAIKU_TOP src tests kits app ; SubInclude HAIKU_TOP src tests kits app ;
SubInclude HAIKU_TOP src tests kits device ;
SubInclude HAIKU_TOP src tests kits game ; SubInclude HAIKU_TOP src tests kits game ;
SubInclude HAIKU_TOP src tests kits interface ; SubInclude HAIKU_TOP src tests kits interface ;
SubInclude HAIKU_TOP src tests kits locale ; SubInclude HAIKU_TOP src tests kits locale ;
+3
View File
@@ -0,0 +1,3 @@
SubDir HAIKU_TOP src tests kits device ;
SubInclude HAIKU_TOP src tests kits device stickit_BJoystick ;
@@ -0,0 +1,7 @@
SubDir HAIKU_TOP src tests kits device stickit_BJoystick ;
SimpleTest stickit :
JoystickWindow.cpp
StickItApp.cpp
StickItWindow.cpp
: be device ;
@@ -29,7 +29,7 @@
#include "StickItWindow.h" #include "StickItWindow.h"
StickItWindow::StickItWindow(BRect frame) StickItWindow::StickItWindow(BRect frame)
: BWindow(frame, "StickIt", B_TITLED_WINDOW, NULL) : BWindow(frame, "StickIt", B_TITLED_WINDOW, 0)
{ {
frame = Bounds(); frame = Bounds();
frame.InsetBy(5, 5); frame.InsetBy(5, 5);
@@ -37,42 +37,42 @@ StickItWindow::StickItWindow(BRect frame)
// Allocate object // Allocate object
BView* view = new BView(Bounds(), "", B_FOLLOW_ALL_SIDES, NULL); BView* view = new BView(Bounds(), "", B_FOLLOW_ALL_SIDES, 0);
view->SetViewColor(216, 216, 216); view->SetViewColor(216, 216, 216);
view->SetLowColor(216, 216, 216); view->SetLowColor(216, 216, 216);
BRect rectString = BRect(frame.left, frame.top-10, frame.right -30, 30); BRect rectString = BRect(frame.left, frame.top-10, frame.right -30, 30);
BStringView* stringview1 = new BStringView(rectString,"StringView1", BStringView* stringview1 = new BStringView(rectString,"StringView1",
"This list, lists action that StickIt makes."); "This list, lists action that StickIt makes.");
BRect rect = BRect(rectString.left, rectString.bottom + SPACE, BRect rect = BRect(rectString.left, rectString.bottom + SPACE,
rectString.right, rectString.bottom + SPACE + 200); rectString.right, rectString.bottom + SPACE + 200);
fListView1 = new BListView(rect,"ListView1"); fListView1 = new BListView(rect,"ListView1");
rectString = BRect(rect.left, rect.bottom + SPACE, rect.right, rectString = BRect(rect.left, rect.bottom + SPACE, rect.right,
rect.bottom + SPACE + 15); rect.bottom + SPACE + 15);
BStringView* stringview2 = new BStringView(rectString,"StringView2", BStringView* stringview2 = new BStringView(rectString,"StringView2",
"Choose Joystick below if any exists"); "Choose Joystick below if any exists");
rect = BRect(rectString.left, rectString.bottom + SPACE, rectString.right, rect = BRect(rectString.left, rectString.bottom + SPACE, rectString.right,
Bounds().bottom -20); Bounds().bottom -20);
fListView2 = new BListView(rect,"ListView2"); fListView2 = new BListView(rect,"ListView2");
fListView2->SetSelectionMessage(new BMessage(SELECTED)); fListView2->SetSelectionMessage(new BMessage(SELECTED));
fListView2->SetInvocationMessage(new BMessage(INVOKE)); fListView2->SetInvocationMessage(new BMessage(INVOKE));
// Adding object
box->AddChild(new BScrollView("fListView1", fListView1,
B_FOLLOW_LEFT_RIGHT, NULL, false, true));
box->AddChild(new BScrollView("fListView2", fListView2, // Adding object
B_FOLLOW_ALL_SIDES, NULL, false, true)); box->AddChild(new BScrollView("fListView1", fListView1,
B_FOLLOW_LEFT_RIGHT, 0, false, true));
box->AddChild(new BScrollView("fListView2", fListView2,
B_FOLLOW_ALL_SIDES, 0, false, true));
box->AddChild(stringview1); box->AddChild(stringview1);
box->AddChild(stringview2); box->AddChild(stringview2);
view->AddChild(box); view->AddChild(box);
AddChild(view); AddChild(view);
fJoystick = new BJoystick; fJoystick = new BJoystick;
PickJoystick(fJoystick); PickJoystick(fJoystick);
} }
@@ -85,22 +85,22 @@ StickItWindow::QuitRequested(void) {
} }
void void
StickItWindow::MessageReceived(BMessage *message) StickItWindow::MessageReceived(BMessage *message)
{ {
// message->PrintToStream(); // message->PrintToStream();
switch(message->what) switch(message->what)
{ {
case INVOKE: case INVOKE:
case SELECTED: case SELECTED:
{ {
int32 id = fListView2->CurrentSelection(); int32 id = fListView2->CurrentSelection();
BString temp1; BString temp1;
if (id > -1) { if (id > -1) {
char devName[B_OS_NAME_LENGTH]; char devName[B_OS_NAME_LENGTH];
status_t err = fJoystick->GetDeviceName(id, devName); status_t err = fJoystick->GetDeviceName(id, devName);
if (err == B_OK) { if (err == B_OK) {
temp1 << "BJoystick::GetDeviceName(), id = " << id temp1 << "BJoystick::GetDeviceName(), id = " << id
<< ", name = " << devName; << ", name = " << devName;
temp1 = AddToList(fListView1, temp1.String()); temp1 = AddToList(fListView1, temp1.String());
err = fJoystick->Open(devName); err = fJoystick->Open(devName);
@@ -108,16 +108,16 @@ StickItWindow::MessageReceived(BMessage *message)
temp1 = AddToList(fListView1, "BJoystick::Open()"); temp1 = AddToList(fListView1, "BJoystick::Open()");
temp1 = AddToList(fListView1, "BJoystick::Open()"); temp1 = AddToList(fListView1, "BJoystick::Open()");
if(fJoystick->IsCalibrationEnabled()) if(fJoystick->IsCalibrationEnabled())
temp1 = AddToList(fListView1, temp1 = AddToList(fListView1,
"BJoystick::IsCalibrationEnabled() - True"); "BJoystick::IsCalibrationEnabled() - True");
else else
temp1 = AddToList(fListView1, temp1 = AddToList(fListView1,
"BJoystick::IsCalibrationEnabled() - False"); "BJoystick::IsCalibrationEnabled() - False");
fJoystickWindow = new JoystickWindow(fJoystick, fJoystickWindow = new JoystickWindow(fJoystick,
BRect(50, 50, 405, 350)); BRect(50, 50, 405, 350));
fJoystickWindow->Show(); fJoystickWindow->Show();
} else } else
AddToList(fListView1, AddToList(fListView1,
"No controller connected on that port. Try again."); "No controller connected on that port. Try again.");
} else } else
AddToList(fListView1, "Can't use that stick. Try again."); AddToList(fListView1, "Can't use that stick. Try again.");
@@ -127,7 +127,7 @@ StickItWindow::MessageReceived(BMessage *message)
default: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
break; break;
} }
} }
@@ -151,61 +151,61 @@ StickItWindow::PickJoystick(BJoystick *stick)
temp1 = AddToList(fListView1, temp1.String()); temp1 = AddToList(fListView1, temp1.String());
status_t err = B_ERROR; status_t err = B_ERROR;
if (numDevices) { if (numDevices) {
temp1 << "There are " << numDevices temp1 << "There are " << numDevices
<< " Joysticks device types available"; << " Joysticks device types available";
temp1 = AddToList(fListView1, temp1.String()); temp1 = AddToList(fListView1, temp1.String());
for (int32 i = 0; i < numDevices; i++) { for (int32 i = 0; i < numDevices; i++) {
char devName[B_OS_NAME_LENGTH]; char devName[B_OS_NAME_LENGTH];
err = stick->GetDeviceName(i, devName); err = stick->GetDeviceName(i, devName);
temp1 << "BJoystick::GetDeviceName(), id = " << i << ", name = " temp1 << "BJoystick::GetDeviceName(), id = " << i << ", name = "
<< devName; << devName;
temp1 = AddToList(fListView1, temp1.String()); temp1 = AddToList(fListView1, temp1.String());
if (err == B_OK) { if (err == B_OK) {
err = stick->Open(devName); err = stick->Open(devName);
temp1 = AddToList(fListView1, "BJoystick::Open()"); temp1 = AddToList(fListView1, "BJoystick::Open()");
int32 count = stick->CountSticks(); int32 count = stick->CountSticks();
temp1 << "BJoystick::CountSticks(), number of sticks = " temp1 << "BJoystick::CountSticks(), number of sticks = "
<< count; << count;
temp1 = AddToList(fListView1, temp1.String()); temp1 = AddToList(fListView1, temp1.String());
count = stick->CountAxes(); count = stick->CountAxes();
temp1 << "BJoystick::CountAxes(), number of Axes = " temp1 << "BJoystick::CountAxes(), number of Axes = "
<< count; << count;
temp1 = AddToList(fListView1, temp1.String()); temp1 = AddToList(fListView1, temp1.String());
count = stick->CountButtons(); count = stick->CountButtons();
temp1 << "BJoystick::CountButtons(), number of Buttons = " temp1 << "BJoystick::CountButtons(), number of Buttons = "
<< count; << count;
temp1 = AddToList(fListView1, temp1.String()); temp1 = AddToList(fListView1, temp1.String());
count = stick->CountHats(); count = stick->CountHats();
temp1 << "BJoystick::CountHats(), number of Hats = " temp1 << "BJoystick::CountHats(), number of Hats = "
<< count; << count;
temp1 = AddToList(fListView1, temp1.String()); temp1 = AddToList(fListView1, temp1.String());
count = stick->CountDevices(); count = stick->CountDevices();
temp1 << "BJoystick::CountDevices(), number of Devices = " temp1 << "BJoystick::CountDevices(), number of Devices = "
<< count; << count;
temp1 = AddToList(fListView1, temp1.String()); temp1 = AddToList(fListView1, temp1.String());
if (err != B_ERROR) { if (err != B_ERROR) {
BString name; BString name;
err = stick->GetControllerModule(&name); err = stick->GetControllerModule(&name);
temp1 << "BJoystick::GetControllerModule(), name = " temp1 << "BJoystick::GetControllerModule(), name = "
<< name; << name;
temp1 = AddToList(fListView1, temp1.String()); temp1 = AddToList(fListView1, temp1.String());
if (name == "Legacy") { if (name == "Legacy") {
bool b = stick->EnterEnhancedMode(); bool b = stick->EnterEnhancedMode();
if (b) { if (b) {
temp1 << "BJoystick::EnterEnhancedMode(), OK"; temp1 << "BJoystick::EnterEnhancedMode(), OK";
temp1 = AddToList(fListView1, temp1.String()); temp1 = AddToList(fListView1, temp1.String());
} else { } else {
temp1 << "BJoystick::EnterEnhancedMode(), Not OK"; temp1 << "BJoystick::EnterEnhancedMode(), Not OK";
temp1 = AddToList(fListView1, temp1.String()); temp1 = AddToList(fListView1, temp1.String());
} }
} }
err = stick->GetControllerName(&name); err = stick->GetControllerName(&name);
temp1 << "BJoystick::GetControllerName(), name = " << name; temp1 << "BJoystick::GetControllerName(), name = " << name;
temp1 = AddToList(fListView1, temp1.String()); temp1 = AddToList(fListView1, temp1.String());
@@ -217,11 +217,11 @@ StickItWindow::PickJoystick(BJoystick *stick)
} else { } else {
temp1 << "Error = " << strerror(err); temp1 << "Error = " << strerror(err);
temp1 = AddToList(fListView1, temp1.String()); temp1 = AddToList(fListView1, temp1.String());
temp1 << "*** Can't get name of controller " temp1 << "*** Can't get name of controller "
<< devName; << devName;
temp1 = AddToList(fListView1, temp1.String()); temp1 = AddToList(fListView1, temp1.String());
} }
} else { } else {
temp1 << "Error = " << strerror(err) << "err nr = " << err; temp1 << "Error = " << strerror(err) << "err nr = " << err;
temp1 = AddToList(fListView1, temp1.String()); temp1 = AddToList(fListView1, temp1.String());
temp1 << "No controller on " << devName; temp1 << "No controller on " << devName;
@@ -232,7 +232,7 @@ StickItWindow::PickJoystick(BJoystick *stick)
temp1 = AddToList(fListView1, temp1.String()); temp1 = AddToList(fListView1, temp1.String());
temp1 << "*** Error while reading controller list."; temp1 << "*** Error while reading controller list.";
temp1 = AddToList(fListView1, temp1.String()); temp1 = AddToList(fListView1, temp1.String());
} }
} }
} else { } else {
temp1 << "Error = " << strerror(err); temp1 << "Error = " << strerror(err);