* Return early when opening the device failed and just return B_ERROR as
documented in the BeBook. Sadly the success return is specified as "a positive integer", so I didn't change it to B_OK. * We actually want non-blocking mode, so don't reset the O_NONBLOCK flag. It was ignored before anyway though, so this doesn't change anything. * The legacy buttons 1 and 2 are in the pressed state when false, so initialize them to true instead. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41876 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
30e429b4e4
commit
2682d2fbdd
@ -4,16 +4,11 @@
|
|||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <Joystick.h>
|
#include <Joystick.h>
|
||||||
#include <JoystickTweaker.h>
|
#include <JoystickTweaker.h>
|
||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
@ -53,8 +48,8 @@ BJoystick::BJoystick()
|
|||||||
timestamp(0),
|
timestamp(0),
|
||||||
horizontal(0),
|
horizontal(0),
|
||||||
vertical(0),
|
vertical(0),
|
||||||
button1(0),
|
button1(true),
|
||||||
button2(0),
|
button2(true),
|
||||||
|
|
||||||
fBeBoxMode(false),
|
fBeBoxMode(false),
|
||||||
fFD(-1),
|
fFD(-1),
|
||||||
@ -129,15 +124,10 @@ BJoystick::Open(const char *portName, bool enhanced)
|
|||||||
|
|
||||||
// TODO: BeOS don't use O_EXCL, and this seems to lead to some issues. I
|
// TODO: BeOS don't use O_EXCL, and this seems to lead to some issues. I
|
||||||
// added this flag having read some comments by Marco Nelissen on the
|
// added this flag having read some comments by Marco Nelissen on the
|
||||||
// annotated BeBook. I think BeOS uses O_RDWR|O_NONBLOCK here.
|
// annotated BeBook. I think BeOS uses O_RDWR | O_NONBLOCK here.
|
||||||
fFD = open(nameBuffer, O_RDWR | O_NONBLOCK | O_EXCL);
|
fFD = open(nameBuffer, O_RDWR | O_NONBLOCK | O_EXCL);
|
||||||
|
if (fFD < 0)
|
||||||
if (fFD >= 0) {
|
return B_ERROR;
|
||||||
// we used open() with O_NONBLOCK flag to let it return immediately,
|
|
||||||
// but we want read/write operations to block if needed, so we clear
|
|
||||||
// that bit here.
|
|
||||||
int flags = fcntl(fFD, F_GETFL);
|
|
||||||
fcntl(fFD, F_SETFL, flags & ~O_NONBLOCK);
|
|
||||||
|
|
||||||
// read the Joystick Description file for this port/joystick
|
// read the Joystick Description file for this port/joystick
|
||||||
_BJoystickTweaker joystickTweaker(*this);
|
_BJoystickTweaker joystickTweaker(*this);
|
||||||
@ -170,8 +160,6 @@ BJoystick::Open(const char *portName, bool enhanced)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return fFD;
|
return fFD;
|
||||||
} else
|
|
||||||
return errno;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user