Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Libretro
flycast
Commits
3dc97132
Commit
3dc97132
authored
Aug 12, 2015
by
Jan Holthuis
Browse files
linux-dist: Move evdev/joystick setup into their own functions
parent
6137152f
Changes
1
Hide whitespace changes
Inline
Side-by-side
core/linux-dist/main.cpp
View file @
3dc97132
...
...
@@ -133,60 +133,71 @@ const u32 JMapAxis_360[MAP_SIZE] =
const
u32
*
JMapBtn
=
JMapBtn_USB
;
const
u32
*
JMapAxis
=
JMapAxis_USB
;
void
SetupInput
()
int
setup_input_evdev
(
const
char
*
device
)
{
#if HOST_OS != OS_DARWIN && !defined(TARGET_EMSCRIPTEN)
#ifdef TARGET_PANDORA
const
char
*
device
=
"/dev/input/event4"
;
#else
const
char
*
device
=
"/dev/event2"
;
#endif
char
name
[
256
]
=
"Unknown"
;
if
((
kbfd
=
open
(
device
,
O_RDONLY
))
>
0
)
{
fcntl
(
kbfd
,
F_SETFL
,
O_NONBLOCK
);
if
(
ioctl
(
kbfd
,
EVIOCGNAME
(
sizeof
(
name
)),
name
)
<
0
)
{
perror
(
"evdev ioctl"
);
}
char
name
[
256
]
=
"Unknown"
;
printf
(
"The device on %s says its name is %s
\n
"
,
device
,
name
);
int
fd
=
open
(
device
,
O_RDONLY
);
}
else
if
(
fd
>=
0
)
{
fcntl
(
fd
,
F_SETFL
,
O_NONBLOCK
);
if
(
ioctl
(
fd
,
EVIOCGNAME
(
sizeof
(
name
)),
name
)
<
0
)
{
perror
(
"evdev
open
"
);
perror
(
"evdev
: ioctl
"
);
}
printf
(
"evdev: Found '%s' at '%s'
\n
"
,
name
,
device
);
}
else
{
perror
(
"evdev: open"
);
}
// Open joystick device
JoyFD
=
open
(
"/dev/input/js0"
,
O_RDONLY
);
return
fd
;
}
if
(
JoyFD
>=
0
)
{
int
AxisCount
,
ButtonCount
;
char
Name
[
128
];
int
setup_input_joystick
(
const
char
*
device
)
{
int
axis_count
=
0
;
int
button_count
=
0
;
char
name
[
128
]
=
"Unknown"
;
AxisCount
=
0
;
ButtonCount
=
0
;
Name
[
0
]
=
'\0'
;
int
fd
=
open
(
device
,
O_RDONLY
);
fcntl
(
JoyFD
,
F_SETFL
,
O_NONBLOCK
);
ioctl
(
JoyFD
,
JSIOCGAXES
,
&
AxisCount
);
ioctl
(
JoyFD
,
JSIOCGBUTTONS
,
&
ButtonCount
);
ioctl
(
JoyFD
,
JSIOCGNAME
(
sizeof
(
Name
)),
&
Name
);
if
(
fd
>=
0
)
{
fcntl
(
fd
,
F_SETFL
,
O_NONBLOCK
);
ioctl
(
fd
,
JSIOCGAXES
,
&
axis_count
);
ioctl
(
fd
,
JSIOCGBUTTONS
,
&
button_count
);
ioctl
(
fd
,
JSIOCGNAME
(
sizeof
(
name
)),
&
name
);
printf
(
"
SDK
: Found '%s'
joystick
with %d axis and %d buttons
\n
"
,
N
ame
,
A
xis
C
ount
,
B
utton
C
ount
);
printf
(
"
joystick
: Found '%s' with %d axis and %d buttons
at '%s'.
\n
"
,
n
ame
,
a
xis
_c
ount
,
b
utton
_c
ount
,
device
);
if
(
strcmp
(
Name
,
"Microsoft X-Box 360 pad"
)
==
0
)
{
JMapBtn
=
JMapBtn_360
;
JMapAxis
=
JMapAxis_360
;
printf
(
"Using Xbox 360 map
\n
"
);
}
if
(
strcmp
(
name
,
"Microsoft X-Box 360 pad"
)
==
0
)
{
JMapBtn
=
JMapBtn_360
;
JMapAxis
=
JMapAxis_360
;
printf
(
"joystick: Using Xbox 360 map
\n
"
);
}
}
else
{
perror
(
"joystick: open"
);
}
return
fd
;
}
void
SetupInput
()
{
#if HOST_OS != OS_DARWIN && !defined(TARGET_EMSCRIPTEN)
#ifdef TARGET_PANDORA
#define EVDEV_DEVICE "/dev/input/event4"
#else
#define EVDEV_DEVICE "/dev/event2"
#endif
kbfd
=
setup_input_evdev
(
EVDEV_DEVICE
);
JoyFD
=
setup_input_joystick
(
"/dev/input/js0"
);
#endif
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment