Update to v093r12 release.
byuu says:
I've completely redone the ethos InputManager and ruby to work on
HID::Device objects instead of one giant scancode pool.
Currently only the udev driver supports the changes to ruby, so only
Linux users will be able to compile and run this WIP build.
The nice thing about the new system is that it's now possible to
uniquely identify controllers, so if you swap out gamepads, you won't
end up with it working but with all the mappings all screwed up. Since
higan lets you map multiple physical inputs to one emulated input, you
can now configure your keyboard and multiple gamepads to the same
emulated input, and then just use whatever controller you want.
Because USB gamepad makers failed to provide unique serial#s with each
controller, we have to limit the mapping to specific USB ports.
Otherwise, we couldn't distinguish two otherwise identical gamepads. So
basically your computer USB ports act like real game console input port
numbers. Which is kind of neat, I guess.
And the really nice thing about the new system is that we now have the
capability to support hotplugging input devices. I haven't yet added
this to any drivers, but I'm definitely going to add it to udev for v094
official.
Finally, with the device ID (vendor ID + product ID) exposed, we gain
one last really cool feature that we may be able to develop more in the
future. Say we created a joypad.bml file to include with higan. In it,
we'd store the Xbox 360 controller, and pre-defined button mappings for
each emulated system. So if higan detects you have an Xbox 360
controller, you can just plug it in and use it. Even better, we can
clearly specify the difference between triggers and analog axes, and
name each individual input. So you'd see "Xbox 360 Gamepad #1: Left
Trigger" instead of higan v093's "JP0::Axis2.Hi"
Note: for right now, ethos' input manager isn't filtering the device IDs
to look pretty. So you're going to see a 64-bit hex value for a device
ID right now instead of something like Joypad#N for now.
2013-12-23 11:43:51 +00:00
|
|
|
#ifndef RUBY_INPUT_JOYPAD_UDEV
|
|
|
|
#define RUBY_INPUT_JOYPAD_UDEV
|
|
|
|
|
2013-12-21 10:45:58 +00:00
|
|
|
namespace ruby {
|
|
|
|
|
|
|
|
struct InputJoypadUdev {
|
|
|
|
udev* context = nullptr;
|
|
|
|
udev_monitor* monitor = nullptr;
|
|
|
|
udev_enumerate* enumerator = nullptr;
|
|
|
|
udev_list_entry* devices = nullptr;
|
|
|
|
udev_list_entry* item = nullptr;
|
|
|
|
|
2014-01-05 09:59:17 +00:00
|
|
|
struct JoypadInput {
|
2013-12-21 10:45:58 +00:00
|
|
|
signed code = 0;
|
|
|
|
unsigned id = 0;
|
|
|
|
int16_t value = 0;
|
|
|
|
input_absinfo info;
|
|
|
|
|
2014-01-05 09:59:17 +00:00
|
|
|
JoypadInput() {}
|
|
|
|
JoypadInput(signed code) : code(code) {}
|
|
|
|
JoypadInput(signed code, unsigned id) : code(code), id(id) {}
|
|
|
|
bool operator< (const JoypadInput& source) const { return code < source.code; }
|
|
|
|
bool operator==(const JoypadInput& source) const { return code == source.code; }
|
2013-12-21 10:45:58 +00:00
|
|
|
};
|
|
|
|
|
2014-01-05 09:59:17 +00:00
|
|
|
struct Joypad {
|
Update to v093r12 release.
byuu says:
I've completely redone the ethos InputManager and ruby to work on
HID::Device objects instead of one giant scancode pool.
Currently only the udev driver supports the changes to ruby, so only
Linux users will be able to compile and run this WIP build.
The nice thing about the new system is that it's now possible to
uniquely identify controllers, so if you swap out gamepads, you won't
end up with it working but with all the mappings all screwed up. Since
higan lets you map multiple physical inputs to one emulated input, you
can now configure your keyboard and multiple gamepads to the same
emulated input, and then just use whatever controller you want.
Because USB gamepad makers failed to provide unique serial#s with each
controller, we have to limit the mapping to specific USB ports.
Otherwise, we couldn't distinguish two otherwise identical gamepads. So
basically your computer USB ports act like real game console input port
numbers. Which is kind of neat, I guess.
And the really nice thing about the new system is that we now have the
capability to support hotplugging input devices. I haven't yet added
this to any drivers, but I'm definitely going to add it to udev for v094
official.
Finally, with the device ID (vendor ID + product ID) exposed, we gain
one last really cool feature that we may be able to develop more in the
future. Say we created a joypad.bml file to include with higan. In it,
we'd store the Xbox 360 controller, and pre-defined button mappings for
each emulated system. So if higan detects you have an Xbox 360
controller, you can just plug it in and use it. Even better, we can
clearly specify the difference between triggers and analog axes, and
name each individual input. So you'd see "Xbox 360 Gamepad #1: Left
Trigger" instead of higan v093's "JP0::Axis2.Hi"
Note: for right now, ethos' input manager isn't filtering the device IDs
to look pretty. So you're going to see a 64-bit hex value for a device
ID right now instead of something like Joypad#N for now.
2013-12-23 11:43:51 +00:00
|
|
|
HID::Joypad hid;
|
|
|
|
|
2013-12-21 10:45:58 +00:00
|
|
|
int fd = -1;
|
Update to v093r12 release.
byuu says:
I've completely redone the ethos InputManager and ruby to work on
HID::Device objects instead of one giant scancode pool.
Currently only the udev driver supports the changes to ruby, so only
Linux users will be able to compile and run this WIP build.
The nice thing about the new system is that it's now possible to
uniquely identify controllers, so if you swap out gamepads, you won't
end up with it working but with all the mappings all screwed up. Since
higan lets you map multiple physical inputs to one emulated input, you
can now configure your keyboard and multiple gamepads to the same
emulated input, and then just use whatever controller you want.
Because USB gamepad makers failed to provide unique serial#s with each
controller, we have to limit the mapping to specific USB ports.
Otherwise, we couldn't distinguish two otherwise identical gamepads. So
basically your computer USB ports act like real game console input port
numbers. Which is kind of neat, I guess.
And the really nice thing about the new system is that we now have the
capability to support hotplugging input devices. I haven't yet added
this to any drivers, but I'm definitely going to add it to udev for v094
official.
Finally, with the device ID (vendor ID + product ID) exposed, we gain
one last really cool feature that we may be able to develop more in the
future. Say we created a joypad.bml file to include with higan. In it,
we'd store the Xbox 360 controller, and pre-defined button mappings for
each emulated system. So if higan detects you have an Xbox 360
controller, you can just plug it in and use it. Even better, we can
clearly specify the difference between triggers and analog axes, and
name each individual input. So you'd see "Xbox 360 Gamepad #1: Left
Trigger" instead of higan v093's "JP0::Axis2.Hi"
Note: for right now, ethos' input manager isn't filtering the device IDs
to look pretty. So you're going to see a 64-bit hex value for a device
ID right now instead of something like Joypad#N for now.
2013-12-23 11:43:51 +00:00
|
|
|
dev_t device = 0;
|
|
|
|
string deviceName;
|
2014-01-05 09:59:17 +00:00
|
|
|
string deviceNode;
|
Update to v093r12 release.
byuu says:
I've completely redone the ethos InputManager and ruby to work on
HID::Device objects instead of one giant scancode pool.
Currently only the udev driver supports the changes to ruby, so only
Linux users will be able to compile and run this WIP build.
The nice thing about the new system is that it's now possible to
uniquely identify controllers, so if you swap out gamepads, you won't
end up with it working but with all the mappings all screwed up. Since
higan lets you map multiple physical inputs to one emulated input, you
can now configure your keyboard and multiple gamepads to the same
emulated input, and then just use whatever controller you want.
Because USB gamepad makers failed to provide unique serial#s with each
controller, we have to limit the mapping to specific USB ports.
Otherwise, we couldn't distinguish two otherwise identical gamepads. So
basically your computer USB ports act like real game console input port
numbers. Which is kind of neat, I guess.
And the really nice thing about the new system is that we now have the
capability to support hotplugging input devices. I haven't yet added
this to any drivers, but I'm definitely going to add it to udev for v094
official.
Finally, with the device ID (vendor ID + product ID) exposed, we gain
one last really cool feature that we may be able to develop more in the
future. Say we created a joypad.bml file to include with higan. In it,
we'd store the Xbox 360 controller, and pre-defined button mappings for
each emulated system. So if higan detects you have an Xbox 360
controller, you can just plug it in and use it. Even better, we can
clearly specify the difference between triggers and analog axes, and
name each individual input. So you'd see "Xbox 360 Gamepad #1: Left
Trigger" instead of higan v093's "JP0::Axis2.Hi"
Note: for right now, ethos' input manager isn't filtering the device IDs
to look pretty. So you're going to see a 64-bit hex value for a device
ID right now instead of something like Joypad#N for now.
2013-12-23 11:43:51 +00:00
|
|
|
|
2013-12-21 10:45:58 +00:00
|
|
|
uint8_t evbit[(EV_MAX + 7) / 8] = {0};
|
|
|
|
uint8_t keybit[(KEY_MAX + 7) / 8] = {0};
|
|
|
|
uint8_t absbit[(ABS_MAX + 7) / 8] = {0};
|
|
|
|
uint8_t ffbit[(FF_MAX + 7) / 8] = {0};
|
|
|
|
unsigned effects = 0;
|
|
|
|
|
|
|
|
string name;
|
|
|
|
string manufacturer;
|
|
|
|
string product;
|
|
|
|
string serial;
|
|
|
|
string vendorID;
|
|
|
|
string productID;
|
|
|
|
|
2014-01-05 09:59:17 +00:00
|
|
|
set<JoypadInput> axes;
|
|
|
|
set<JoypadInput> hats;
|
|
|
|
set<JoypadInput> buttons;
|
2013-12-21 10:45:58 +00:00
|
|
|
bool rumble = false;
|
|
|
|
unsigned effectID = 0;
|
|
|
|
};
|
2014-01-05 09:59:17 +00:00
|
|
|
vector<Joypad> joypads;
|
2013-12-21 10:45:58 +00:00
|
|
|
|
Update to v093r12 release.
byuu says:
I've completely redone the ethos InputManager and ruby to work on
HID::Device objects instead of one giant scancode pool.
Currently only the udev driver supports the changes to ruby, so only
Linux users will be able to compile and run this WIP build.
The nice thing about the new system is that it's now possible to
uniquely identify controllers, so if you swap out gamepads, you won't
end up with it working but with all the mappings all screwed up. Since
higan lets you map multiple physical inputs to one emulated input, you
can now configure your keyboard and multiple gamepads to the same
emulated input, and then just use whatever controller you want.
Because USB gamepad makers failed to provide unique serial#s with each
controller, we have to limit the mapping to specific USB ports.
Otherwise, we couldn't distinguish two otherwise identical gamepads. So
basically your computer USB ports act like real game console input port
numbers. Which is kind of neat, I guess.
And the really nice thing about the new system is that we now have the
capability to support hotplugging input devices. I haven't yet added
this to any drivers, but I'm definitely going to add it to udev for v094
official.
Finally, with the device ID (vendor ID + product ID) exposed, we gain
one last really cool feature that we may be able to develop more in the
future. Say we created a joypad.bml file to include with higan. In it,
we'd store the Xbox 360 controller, and pre-defined button mappings for
each emulated system. So if higan detects you have an Xbox 360
controller, you can just plug it in and use it. Even better, we can
clearly specify the difference between triggers and analog axes, and
name each individual input. So you'd see "Xbox 360 Gamepad #1: Left
Trigger" instead of higan v093's "JP0::Axis2.Hi"
Note: for right now, ethos' input manager isn't filtering the device IDs
to look pretty. So you're going to see a 64-bit hex value for a device
ID right now instead of something like Joypad#N for now.
2013-12-23 11:43:51 +00:00
|
|
|
void assign(HID::Joypad& hid, unsigned groupID, unsigned inputID, int16_t value) {
|
|
|
|
auto& group = hid.group[groupID];
|
|
|
|
if(group.input[inputID].value == value) return;
|
|
|
|
if(input.onChange) input.onChange(hid, groupID, inputID, group.input[inputID].value, value);
|
|
|
|
group.input[inputID].value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void poll(vector<HID::Device*>& devices) {
|
2014-01-05 09:59:17 +00:00
|
|
|
while(hotplugDevicesAvailable()) hotplugDevice();
|
|
|
|
|
|
|
|
for(auto& jp : joypads) {
|
Update to v093r12 release.
byuu says:
I've completely redone the ethos InputManager and ruby to work on
HID::Device objects instead of one giant scancode pool.
Currently only the udev driver supports the changes to ruby, so only
Linux users will be able to compile and run this WIP build.
The nice thing about the new system is that it's now possible to
uniquely identify controllers, so if you swap out gamepads, you won't
end up with it working but with all the mappings all screwed up. Since
higan lets you map multiple physical inputs to one emulated input, you
can now configure your keyboard and multiple gamepads to the same
emulated input, and then just use whatever controller you want.
Because USB gamepad makers failed to provide unique serial#s with each
controller, we have to limit the mapping to specific USB ports.
Otherwise, we couldn't distinguish two otherwise identical gamepads. So
basically your computer USB ports act like real game console input port
numbers. Which is kind of neat, I guess.
And the really nice thing about the new system is that we now have the
capability to support hotplugging input devices. I haven't yet added
this to any drivers, but I'm definitely going to add it to udev for v094
official.
Finally, with the device ID (vendor ID + product ID) exposed, we gain
one last really cool feature that we may be able to develop more in the
future. Say we created a joypad.bml file to include with higan. In it,
we'd store the Xbox 360 controller, and pre-defined button mappings for
each emulated system. So if higan detects you have an Xbox 360
controller, you can just plug it in and use it. Even better, we can
clearly specify the difference between triggers and analog axes, and
name each individual input. So you'd see "Xbox 360 Gamepad #1: Left
Trigger" instead of higan v093's "JP0::Axis2.Hi"
Note: for right now, ethos' input manager isn't filtering the device IDs
to look pretty. So you're going to see a 64-bit hex value for a device
ID right now instead of something like Joypad#N for now.
2013-12-23 11:43:51 +00:00
|
|
|
input_event events[32];
|
|
|
|
signed length = 0;
|
2014-01-05 09:59:17 +00:00
|
|
|
while((length = read(jp.fd, events, sizeof(events))) > 0) {
|
Update to v093r12 release.
byuu says:
I've completely redone the ethos InputManager and ruby to work on
HID::Device objects instead of one giant scancode pool.
Currently only the udev driver supports the changes to ruby, so only
Linux users will be able to compile and run this WIP build.
The nice thing about the new system is that it's now possible to
uniquely identify controllers, so if you swap out gamepads, you won't
end up with it working but with all the mappings all screwed up. Since
higan lets you map multiple physical inputs to one emulated input, you
can now configure your keyboard and multiple gamepads to the same
emulated input, and then just use whatever controller you want.
Because USB gamepad makers failed to provide unique serial#s with each
controller, we have to limit the mapping to specific USB ports.
Otherwise, we couldn't distinguish two otherwise identical gamepads. So
basically your computer USB ports act like real game console input port
numbers. Which is kind of neat, I guess.
And the really nice thing about the new system is that we now have the
capability to support hotplugging input devices. I haven't yet added
this to any drivers, but I'm definitely going to add it to udev for v094
official.
Finally, with the device ID (vendor ID + product ID) exposed, we gain
one last really cool feature that we may be able to develop more in the
future. Say we created a joypad.bml file to include with higan. In it,
we'd store the Xbox 360 controller, and pre-defined button mappings for
each emulated system. So if higan detects you have an Xbox 360
controller, you can just plug it in and use it. Even better, we can
clearly specify the difference between triggers and analog axes, and
name each individual input. So you'd see "Xbox 360 Gamepad #1: Left
Trigger" instead of higan v093's "JP0::Axis2.Hi"
Note: for right now, ethos' input manager isn't filtering the device IDs
to look pretty. So you're going to see a 64-bit hex value for a device
ID right now instead of something like Joypad#N for now.
2013-12-23 11:43:51 +00:00
|
|
|
length /= sizeof(input_event);
|
|
|
|
for(unsigned i = 0; i < length; i++) {
|
|
|
|
signed code = events[i].code;
|
|
|
|
signed type = events[i].type;
|
|
|
|
signed value = events[i].value;
|
|
|
|
|
|
|
|
if(type == EV_ABS) {
|
2014-01-05 09:59:17 +00:00
|
|
|
if(auto input = jp.axes.find({code})) {
|
Update to v093r12 release.
byuu says:
I've completely redone the ethos InputManager and ruby to work on
HID::Device objects instead of one giant scancode pool.
Currently only the udev driver supports the changes to ruby, so only
Linux users will be able to compile and run this WIP build.
The nice thing about the new system is that it's now possible to
uniquely identify controllers, so if you swap out gamepads, you won't
end up with it working but with all the mappings all screwed up. Since
higan lets you map multiple physical inputs to one emulated input, you
can now configure your keyboard and multiple gamepads to the same
emulated input, and then just use whatever controller you want.
Because USB gamepad makers failed to provide unique serial#s with each
controller, we have to limit the mapping to specific USB ports.
Otherwise, we couldn't distinguish two otherwise identical gamepads. So
basically your computer USB ports act like real game console input port
numbers. Which is kind of neat, I guess.
And the really nice thing about the new system is that we now have the
capability to support hotplugging input devices. I haven't yet added
this to any drivers, but I'm definitely going to add it to udev for v094
official.
Finally, with the device ID (vendor ID + product ID) exposed, we gain
one last really cool feature that we may be able to develop more in the
future. Say we created a joypad.bml file to include with higan. In it,
we'd store the Xbox 360 controller, and pre-defined button mappings for
each emulated system. So if higan detects you have an Xbox 360
controller, you can just plug it in and use it. Even better, we can
clearly specify the difference between triggers and analog axes, and
name each individual input. So you'd see "Xbox 360 Gamepad #1: Left
Trigger" instead of higan v093's "JP0::Axis2.Hi"
Note: for right now, ethos' input manager isn't filtering the device IDs
to look pretty. So you're going to see a 64-bit hex value for a device
ID right now instead of something like Joypad#N for now.
2013-12-23 11:43:51 +00:00
|
|
|
signed range = input().info.maximum - input().info.minimum;
|
|
|
|
value = (value - input().info.minimum) * 65535ll / range - 32767;
|
2014-01-05 09:59:17 +00:00
|
|
|
assign(jp.hid, HID::Joypad::GroupID::Axis, input().id, sclamp<16>(value));
|
|
|
|
} else if(auto input = jp.hats.find({code})) {
|
Update to v093r12 release.
byuu says:
I've completely redone the ethos InputManager and ruby to work on
HID::Device objects instead of one giant scancode pool.
Currently only the udev driver supports the changes to ruby, so only
Linux users will be able to compile and run this WIP build.
The nice thing about the new system is that it's now possible to
uniquely identify controllers, so if you swap out gamepads, you won't
end up with it working but with all the mappings all screwed up. Since
higan lets you map multiple physical inputs to one emulated input, you
can now configure your keyboard and multiple gamepads to the same
emulated input, and then just use whatever controller you want.
Because USB gamepad makers failed to provide unique serial#s with each
controller, we have to limit the mapping to specific USB ports.
Otherwise, we couldn't distinguish two otherwise identical gamepads. So
basically your computer USB ports act like real game console input port
numbers. Which is kind of neat, I guess.
And the really nice thing about the new system is that we now have the
capability to support hotplugging input devices. I haven't yet added
this to any drivers, but I'm definitely going to add it to udev for v094
official.
Finally, with the device ID (vendor ID + product ID) exposed, we gain
one last really cool feature that we may be able to develop more in the
future. Say we created a joypad.bml file to include with higan. In it,
we'd store the Xbox 360 controller, and pre-defined button mappings for
each emulated system. So if higan detects you have an Xbox 360
controller, you can just plug it in and use it. Even better, we can
clearly specify the difference between triggers and analog axes, and
name each individual input. So you'd see "Xbox 360 Gamepad #1: Left
Trigger" instead of higan v093's "JP0::Axis2.Hi"
Note: for right now, ethos' input manager isn't filtering the device IDs
to look pretty. So you're going to see a 64-bit hex value for a device
ID right now instead of something like Joypad#N for now.
2013-12-23 11:43:51 +00:00
|
|
|
signed range = input().info.maximum - input().info.minimum;
|
|
|
|
value = (value - input().info.minimum) * 65535ll / range - 32767;
|
2014-01-05 09:59:17 +00:00
|
|
|
assign(jp.hid, HID::Joypad::GroupID::Hat, input().id, sclamp<16>(value));
|
Update to v093r12 release.
byuu says:
I've completely redone the ethos InputManager and ruby to work on
HID::Device objects instead of one giant scancode pool.
Currently only the udev driver supports the changes to ruby, so only
Linux users will be able to compile and run this WIP build.
The nice thing about the new system is that it's now possible to
uniquely identify controllers, so if you swap out gamepads, you won't
end up with it working but with all the mappings all screwed up. Since
higan lets you map multiple physical inputs to one emulated input, you
can now configure your keyboard and multiple gamepads to the same
emulated input, and then just use whatever controller you want.
Because USB gamepad makers failed to provide unique serial#s with each
controller, we have to limit the mapping to specific USB ports.
Otherwise, we couldn't distinguish two otherwise identical gamepads. So
basically your computer USB ports act like real game console input port
numbers. Which is kind of neat, I guess.
And the really nice thing about the new system is that we now have the
capability to support hotplugging input devices. I haven't yet added
this to any drivers, but I'm definitely going to add it to udev for v094
official.
Finally, with the device ID (vendor ID + product ID) exposed, we gain
one last really cool feature that we may be able to develop more in the
future. Say we created a joypad.bml file to include with higan. In it,
we'd store the Xbox 360 controller, and pre-defined button mappings for
each emulated system. So if higan detects you have an Xbox 360
controller, you can just plug it in and use it. Even better, we can
clearly specify the difference between triggers and analog axes, and
name each individual input. So you'd see "Xbox 360 Gamepad #1: Left
Trigger" instead of higan v093's "JP0::Axis2.Hi"
Note: for right now, ethos' input manager isn't filtering the device IDs
to look pretty. So you're going to see a 64-bit hex value for a device
ID right now instead of something like Joypad#N for now.
2013-12-23 11:43:51 +00:00
|
|
|
}
|
|
|
|
} else if(type == EV_KEY) {
|
|
|
|
if(code >= BTN_MISC) {
|
2014-01-05 09:59:17 +00:00
|
|
|
if(auto input = jp.buttons.find({code})) {
|
|
|
|
assign(jp.hid, HID::Joypad::GroupID::Button, input().id, (bool)value);
|
2013-12-21 10:45:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-05 09:59:17 +00:00
|
|
|
devices.append(&jp.hid);
|
2013-12-21 10:45:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-05 09:59:17 +00:00
|
|
|
bool rumble(uint64_t id, bool enable) {
|
|
|
|
for(auto& jp : joypads) {
|
|
|
|
if(jp.hid.id != id) continue;
|
|
|
|
if(jp.hid.rumble == false) continue;
|
Update to v093r12 release.
byuu says:
I've completely redone the ethos InputManager and ruby to work on
HID::Device objects instead of one giant scancode pool.
Currently only the udev driver supports the changes to ruby, so only
Linux users will be able to compile and run this WIP build.
The nice thing about the new system is that it's now possible to
uniquely identify controllers, so if you swap out gamepads, you won't
end up with it working but with all the mappings all screwed up. Since
higan lets you map multiple physical inputs to one emulated input, you
can now configure your keyboard and multiple gamepads to the same
emulated input, and then just use whatever controller you want.
Because USB gamepad makers failed to provide unique serial#s with each
controller, we have to limit the mapping to specific USB ports.
Otherwise, we couldn't distinguish two otherwise identical gamepads. So
basically your computer USB ports act like real game console input port
numbers. Which is kind of neat, I guess.
And the really nice thing about the new system is that we now have the
capability to support hotplugging input devices. I haven't yet added
this to any drivers, but I'm definitely going to add it to udev for v094
official.
Finally, with the device ID (vendor ID + product ID) exposed, we gain
one last really cool feature that we may be able to develop more in the
future. Say we created a joypad.bml file to include with higan. In it,
we'd store the Xbox 360 controller, and pre-defined button mappings for
each emulated system. So if higan detects you have an Xbox 360
controller, you can just plug it in and use it. Even better, we can
clearly specify the difference between triggers and analog axes, and
name each individual input. So you'd see "Xbox 360 Gamepad #1: Left
Trigger" instead of higan v093's "JP0::Axis2.Hi"
Note: for right now, ethos' input manager isn't filtering the device IDs
to look pretty. So you're going to see a 64-bit hex value for a device
ID right now instead of something like Joypad#N for now.
2013-12-23 11:43:51 +00:00
|
|
|
|
|
|
|
input_event play;
|
|
|
|
memset(&play, 0, sizeof(input_event));
|
|
|
|
play.type = EV_FF;
|
2014-01-05 09:59:17 +00:00
|
|
|
play.code = jp.effectID;
|
Update to v093r12 release.
byuu says:
I've completely redone the ethos InputManager and ruby to work on
HID::Device objects instead of one giant scancode pool.
Currently only the udev driver supports the changes to ruby, so only
Linux users will be able to compile and run this WIP build.
The nice thing about the new system is that it's now possible to
uniquely identify controllers, so if you swap out gamepads, you won't
end up with it working but with all the mappings all screwed up. Since
higan lets you map multiple physical inputs to one emulated input, you
can now configure your keyboard and multiple gamepads to the same
emulated input, and then just use whatever controller you want.
Because USB gamepad makers failed to provide unique serial#s with each
controller, we have to limit the mapping to specific USB ports.
Otherwise, we couldn't distinguish two otherwise identical gamepads. So
basically your computer USB ports act like real game console input port
numbers. Which is kind of neat, I guess.
And the really nice thing about the new system is that we now have the
capability to support hotplugging input devices. I haven't yet added
this to any drivers, but I'm definitely going to add it to udev for v094
official.
Finally, with the device ID (vendor ID + product ID) exposed, we gain
one last really cool feature that we may be able to develop more in the
future. Say we created a joypad.bml file to include with higan. In it,
we'd store the Xbox 360 controller, and pre-defined button mappings for
each emulated system. So if higan detects you have an Xbox 360
controller, you can just plug it in and use it. Even better, we can
clearly specify the difference between triggers and analog axes, and
name each individual input. So you'd see "Xbox 360 Gamepad #1: Left
Trigger" instead of higan v093's "JP0::Axis2.Hi"
Note: for right now, ethos' input manager isn't filtering the device IDs
to look pretty. So you're going to see a 64-bit hex value for a device
ID right now instead of something like Joypad#N for now.
2013-12-23 11:43:51 +00:00
|
|
|
play.value = enable;
|
2014-01-05 09:59:17 +00:00
|
|
|
write(jp.fd, &play, sizeof(input_event));
|
|
|
|
return true;
|
Update to v093r12 release.
byuu says:
I've completely redone the ethos InputManager and ruby to work on
HID::Device objects instead of one giant scancode pool.
Currently only the udev driver supports the changes to ruby, so only
Linux users will be able to compile and run this WIP build.
The nice thing about the new system is that it's now possible to
uniquely identify controllers, so if you swap out gamepads, you won't
end up with it working but with all the mappings all screwed up. Since
higan lets you map multiple physical inputs to one emulated input, you
can now configure your keyboard and multiple gamepads to the same
emulated input, and then just use whatever controller you want.
Because USB gamepad makers failed to provide unique serial#s with each
controller, we have to limit the mapping to specific USB ports.
Otherwise, we couldn't distinguish two otherwise identical gamepads. So
basically your computer USB ports act like real game console input port
numbers. Which is kind of neat, I guess.
And the really nice thing about the new system is that we now have the
capability to support hotplugging input devices. I haven't yet added
this to any drivers, but I'm definitely going to add it to udev for v094
official.
Finally, with the device ID (vendor ID + product ID) exposed, we gain
one last really cool feature that we may be able to develop more in the
future. Say we created a joypad.bml file to include with higan. In it,
we'd store the Xbox 360 controller, and pre-defined button mappings for
each emulated system. So if higan detects you have an Xbox 360
controller, you can just plug it in and use it. Even better, we can
clearly specify the difference between triggers and analog axes, and
name each individual input. So you'd see "Xbox 360 Gamepad #1: Left
Trigger" instead of higan v093's "JP0::Axis2.Hi"
Note: for right now, ethos' input manager isn't filtering the device IDs
to look pretty. So you're going to see a 64-bit hex value for a device
ID right now instead of something like Joypad#N for now.
2013-12-23 11:43:51 +00:00
|
|
|
}
|
2014-01-05 09:59:17 +00:00
|
|
|
|
|
|
|
return false;
|
2013-12-21 10:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool init() {
|
|
|
|
context = udev_new();
|
|
|
|
if(context == nullptr) return false;
|
|
|
|
|
|
|
|
monitor = udev_monitor_new_from_netlink(context, "udev");
|
|
|
|
if(monitor) {
|
|
|
|
udev_monitor_filter_add_match_subsystem_devtype(monitor, "input", nullptr);
|
|
|
|
udev_monitor_enable_receiving(monitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
enumerator = udev_enumerate_new(context);
|
|
|
|
if(enumerator) {
|
|
|
|
udev_enumerate_add_match_property(enumerator, "ID_INPUT_JOYSTICK", "1");
|
|
|
|
udev_enumerate_scan_devices(enumerator);
|
|
|
|
devices = udev_enumerate_get_list_entry(enumerator);
|
|
|
|
for(udev_list_entry* item = devices; item != nullptr; item = udev_list_entry_get_next(item)) {
|
2014-01-05 09:59:17 +00:00
|
|
|
string name = udev_list_entry_get_name(item);
|
|
|
|
udev_device* device = udev_device_new_from_syspath(context, name);
|
|
|
|
string deviceNode = udev_device_get_devnode(device);
|
|
|
|
if(deviceNode) createJoypad(device, deviceNode);
|
2013-12-21 10:45:58 +00:00
|
|
|
udev_device_unref(device);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void term() {
|
|
|
|
if(enumerator) { udev_enumerate_unref(enumerator); enumerator = nullptr; }
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-01-05 09:59:17 +00:00
|
|
|
bool hotplugDevicesAvailable() {
|
|
|
|
pollfd fd = {0};
|
|
|
|
fd.fd = udev_monitor_get_fd(monitor);
|
|
|
|
fd.events = POLLIN;
|
|
|
|
return (::poll(&fd, 1, 0) == 1) && (fd.revents & POLLIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hotplugDevice() {
|
|
|
|
udev_device* device = udev_monitor_receive_device(monitor);
|
|
|
|
if(device == nullptr) return;
|
|
|
|
|
|
|
|
string value = udev_device_get_property_value(device, "ID_INPUT_JOYSTICK");
|
|
|
|
string action = udev_device_get_action(device);
|
|
|
|
string deviceNode = udev_device_get_devnode(device);
|
|
|
|
if(value == "1") {
|
|
|
|
if(action == "add") {
|
|
|
|
createJoypad(device, deviceNode);
|
|
|
|
}
|
|
|
|
if(action == "remove") {
|
|
|
|
removeJoypad(device, deviceNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void createJoypad(udev_device* device, const string& deviceNode) {
|
|
|
|
Joypad jp;
|
|
|
|
jp.deviceNode = deviceNode;
|
2013-12-21 10:45:58 +00:00
|
|
|
|
|
|
|
struct stat st;
|
2014-01-05 09:59:17 +00:00
|
|
|
if(stat(deviceNode, &st) < 0) return;
|
|
|
|
jp.device = st.st_rdev;
|
2013-12-21 10:45:58 +00:00
|
|
|
|
2014-01-05 09:59:17 +00:00
|
|
|
jp.fd = open(deviceNode, O_RDWR | O_NONBLOCK);
|
|
|
|
if(jp.fd < 0) return;
|
2013-12-21 10:45:58 +00:00
|
|
|
|
|
|
|
uint8_t evbit[(EV_MAX + 7) / 8] = {0};
|
|
|
|
uint8_t keybit[(KEY_MAX + 7) / 8] = {0};
|
|
|
|
uint8_t absbit[(ABS_MAX + 7) / 8] = {0};
|
|
|
|
|
2014-01-05 09:59:17 +00:00
|
|
|
ioctl(jp.fd, EVIOCGBIT(0, sizeof(jp.evbit)), jp.evbit);
|
|
|
|
ioctl(jp.fd, EVIOCGBIT(EV_KEY, sizeof(jp.keybit)), jp.keybit);
|
|
|
|
ioctl(jp.fd, EVIOCGBIT(EV_ABS, sizeof(jp.absbit)), jp.absbit);
|
|
|
|
ioctl(jp.fd, EVIOCGBIT(EV_FF, sizeof(jp.ffbit)), jp.ffbit);
|
|
|
|
ioctl(jp.fd, EVIOCGEFFECTS, &jp.effects);
|
2013-12-21 10:45:58 +00:00
|
|
|
|
|
|
|
#define testBit(buffer, bit) (buffer[(bit) >> 3] & 1 << ((bit) & 7))
|
|
|
|
|
2014-01-05 09:59:17 +00:00
|
|
|
if(testBit(jp.evbit, EV_KEY)) {
|
2013-12-21 10:45:58 +00:00
|
|
|
if(udev_device* parent = udev_device_get_parent_with_subsystem_devtype(device, "input", nullptr)) {
|
2014-01-05 09:59:17 +00:00
|
|
|
jp.name = udev_device_get_sysattr_value(parent, "name");
|
|
|
|
jp.vendorID = udev_device_get_sysattr_value(parent, "id/vendor");
|
|
|
|
jp.productID = udev_device_get_sysattr_value(parent, "id/product");
|
2013-12-21 10:45:58 +00:00
|
|
|
if(udev_device* root = udev_device_get_parent_with_subsystem_devtype(parent, "usb", "usb_device")) {
|
2014-01-05 09:59:17 +00:00
|
|
|
if(jp.vendorID == udev_device_get_sysattr_value(root, "idVendor")
|
|
|
|
&& jp.productID == udev_device_get_sysattr_value(root, "idProduct")
|
2013-12-21 10:45:58 +00:00
|
|
|
) {
|
2014-01-05 09:59:17 +00:00
|
|
|
jp.deviceName = udev_device_get_devpath(root);
|
|
|
|
jp.manufacturer = udev_device_get_sysattr_value(root, "manufacturer");
|
|
|
|
jp.product = udev_device_get_sysattr_value(root, "product");
|
|
|
|
jp.serial = udev_device_get_sysattr_value(root, "serial");
|
2013-12-21 10:45:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned axes = 0;
|
|
|
|
unsigned hats = 0;
|
|
|
|
unsigned buttons = 0;
|
|
|
|
for(signed i = 0; i < ABS_MISC; i++) {
|
2014-01-05 09:59:17 +00:00
|
|
|
if(testBit(jp.absbit, i)) {
|
2013-12-21 10:45:58 +00:00
|
|
|
if(i >= ABS_HAT0X && i <= ABS_HAT3Y) {
|
2014-01-05 09:59:17 +00:00
|
|
|
if(auto hat = jp.hats.insert({i, hats++})) {
|
|
|
|
ioctl(jp.fd, EVIOCGABS(i), &hat().info);
|
2013-12-21 10:45:58 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-01-05 09:59:17 +00:00
|
|
|
if(auto axis = jp.axes.insert({i, axes++})) {
|
|
|
|
ioctl(jp.fd, EVIOCGABS(i), &axis().info);
|
2013-12-21 10:45:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(signed i = BTN_JOYSTICK; i < KEY_MAX; i++) {
|
2014-01-05 09:59:17 +00:00
|
|
|
if(testBit(jp.keybit, i)) {
|
|
|
|
jp.buttons.insert({i, buttons++});
|
2013-12-21 10:45:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for(signed i = BTN_MISC; i < BTN_JOYSTICK; i++) {
|
2014-01-05 09:59:17 +00:00
|
|
|
if(testBit(jp.keybit, i)) {
|
|
|
|
jp.buttons.insert({i, buttons++});
|
2013-12-21 10:45:58 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-05 09:59:17 +00:00
|
|
|
jp.rumble = jp.effects >= 2 && testBit(jp.ffbit, FF_RUMBLE);
|
|
|
|
if(jp.rumble) {
|
2013-12-21 10:45:58 +00:00
|
|
|
ff_effect effect;
|
|
|
|
memset(&effect, 0, sizeof(ff_effect));
|
|
|
|
effect.type = FF_RUMBLE;
|
|
|
|
effect.id = -1;
|
|
|
|
effect.u.rumble.strong_magnitude = 65535;
|
|
|
|
effect.u.rumble.weak_magnitude = 65535;
|
2014-01-05 09:59:17 +00:00
|
|
|
ioctl(jp.fd, EVIOCSFF, &effect);
|
|
|
|
jp.effectID = effect.id;
|
2013-12-21 10:45:58 +00:00
|
|
|
}
|
|
|
|
|
2014-01-05 09:59:17 +00:00
|
|
|
createJoypadHID(jp);
|
|
|
|
joypads.append(jp);
|
2013-12-21 10:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef testBit
|
|
|
|
}
|
Update to v093r12 release.
byuu says:
I've completely redone the ethos InputManager and ruby to work on
HID::Device objects instead of one giant scancode pool.
Currently only the udev driver supports the changes to ruby, so only
Linux users will be able to compile and run this WIP build.
The nice thing about the new system is that it's now possible to
uniquely identify controllers, so if you swap out gamepads, you won't
end up with it working but with all the mappings all screwed up. Since
higan lets you map multiple physical inputs to one emulated input, you
can now configure your keyboard and multiple gamepads to the same
emulated input, and then just use whatever controller you want.
Because USB gamepad makers failed to provide unique serial#s with each
controller, we have to limit the mapping to specific USB ports.
Otherwise, we couldn't distinguish two otherwise identical gamepads. So
basically your computer USB ports act like real game console input port
numbers. Which is kind of neat, I guess.
And the really nice thing about the new system is that we now have the
capability to support hotplugging input devices. I haven't yet added
this to any drivers, but I'm definitely going to add it to udev for v094
official.
Finally, with the device ID (vendor ID + product ID) exposed, we gain
one last really cool feature that we may be able to develop more in the
future. Say we created a joypad.bml file to include with higan. In it,
we'd store the Xbox 360 controller, and pre-defined button mappings for
each emulated system. So if higan detects you have an Xbox 360
controller, you can just plug it in and use it. Even better, we can
clearly specify the difference between triggers and analog axes, and
name each individual input. So you'd see "Xbox 360 Gamepad #1: Left
Trigger" instead of higan v093's "JP0::Axis2.Hi"
Note: for right now, ethos' input manager isn't filtering the device IDs
to look pretty. So you're going to see a 64-bit hex value for a device
ID right now instead of something like Joypad#N for now.
2013-12-23 11:43:51 +00:00
|
|
|
|
2014-01-05 09:59:17 +00:00
|
|
|
void createJoypadHID(Joypad& jp) {
|
2015-03-03 10:14:49 +00:00
|
|
|
uint64_t pathID = Hash::CRC32(jp.deviceName.data(), jp.deviceName.size()).value();
|
2014-01-05 09:59:17 +00:00
|
|
|
jp.hid.id = pathID << 32 | hex(jp.vendorID) << 16 | hex(jp.productID) << 0;
|
|
|
|
|
|
|
|
for(unsigned n = 0; n < jp.axes.size(); n++) jp.hid.axis().append({n});
|
|
|
|
for(unsigned n = 0; n < jp.hats.size(); n++) jp.hid.hat().append({n});
|
|
|
|
for(unsigned n = 0; n < jp.buttons.size(); n++) jp.hid.button().append({n});
|
|
|
|
jp.hid.rumble = jp.rumble;
|
|
|
|
}
|
Update to v093r12 release.
byuu says:
I've completely redone the ethos InputManager and ruby to work on
HID::Device objects instead of one giant scancode pool.
Currently only the udev driver supports the changes to ruby, so only
Linux users will be able to compile and run this WIP build.
The nice thing about the new system is that it's now possible to
uniquely identify controllers, so if you swap out gamepads, you won't
end up with it working but with all the mappings all screwed up. Since
higan lets you map multiple physical inputs to one emulated input, you
can now configure your keyboard and multiple gamepads to the same
emulated input, and then just use whatever controller you want.
Because USB gamepad makers failed to provide unique serial#s with each
controller, we have to limit the mapping to specific USB ports.
Otherwise, we couldn't distinguish two otherwise identical gamepads. So
basically your computer USB ports act like real game console input port
numbers. Which is kind of neat, I guess.
And the really nice thing about the new system is that we now have the
capability to support hotplugging input devices. I haven't yet added
this to any drivers, but I'm definitely going to add it to udev for v094
official.
Finally, with the device ID (vendor ID + product ID) exposed, we gain
one last really cool feature that we may be able to develop more in the
future. Say we created a joypad.bml file to include with higan. In it,
we'd store the Xbox 360 controller, and pre-defined button mappings for
each emulated system. So if higan detects you have an Xbox 360
controller, you can just plug it in and use it. Even better, we can
clearly specify the difference between triggers and analog axes, and
name each individual input. So you'd see "Xbox 360 Gamepad #1: Left
Trigger" instead of higan v093's "JP0::Axis2.Hi"
Note: for right now, ethos' input manager isn't filtering the device IDs
to look pretty. So you're going to see a 64-bit hex value for a device
ID right now instead of something like Joypad#N for now.
2013-12-23 11:43:51 +00:00
|
|
|
|
2014-01-05 09:59:17 +00:00
|
|
|
void removeJoypad(udev_device* device, const string& deviceNode) {
|
|
|
|
for(unsigned n = 0; n < joypads.size(); n++) {
|
|
|
|
if(joypads[n].deviceNode == deviceNode) {
|
|
|
|
close(joypads[n].fd);
|
|
|
|
joypads.remove(n);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
Update to v093r12 release.
byuu says:
I've completely redone the ethos InputManager and ruby to work on
HID::Device objects instead of one giant scancode pool.
Currently only the udev driver supports the changes to ruby, so only
Linux users will be able to compile and run this WIP build.
The nice thing about the new system is that it's now possible to
uniquely identify controllers, so if you swap out gamepads, you won't
end up with it working but with all the mappings all screwed up. Since
higan lets you map multiple physical inputs to one emulated input, you
can now configure your keyboard and multiple gamepads to the same
emulated input, and then just use whatever controller you want.
Because USB gamepad makers failed to provide unique serial#s with each
controller, we have to limit the mapping to specific USB ports.
Otherwise, we couldn't distinguish two otherwise identical gamepads. So
basically your computer USB ports act like real game console input port
numbers. Which is kind of neat, I guess.
And the really nice thing about the new system is that we now have the
capability to support hotplugging input devices. I haven't yet added
this to any drivers, but I'm definitely going to add it to udev for v094
official.
Finally, with the device ID (vendor ID + product ID) exposed, we gain
one last really cool feature that we may be able to develop more in the
future. Say we created a joypad.bml file to include with higan. In it,
we'd store the Xbox 360 controller, and pre-defined button mappings for
each emulated system. So if higan detects you have an Xbox 360
controller, you can just plug it in and use it. Even better, we can
clearly specify the difference between triggers and analog axes, and
name each individual input. So you'd see "Xbox 360 Gamepad #1: Left
Trigger" instead of higan v093's "JP0::Axis2.Hi"
Note: for right now, ethos' input manager isn't filtering the device IDs
to look pretty. So you're going to see a 64-bit hex value for a device
ID right now instead of something like Joypad#N for now.
2013-12-23 11:43:51 +00:00
|
|
|
}
|
2013-12-21 10:45:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
Update to v093r12 release.
byuu says:
I've completely redone the ethos InputManager and ruby to work on
HID::Device objects instead of one giant scancode pool.
Currently only the udev driver supports the changes to ruby, so only
Linux users will be able to compile and run this WIP build.
The nice thing about the new system is that it's now possible to
uniquely identify controllers, so if you swap out gamepads, you won't
end up with it working but with all the mappings all screwed up. Since
higan lets you map multiple physical inputs to one emulated input, you
can now configure your keyboard and multiple gamepads to the same
emulated input, and then just use whatever controller you want.
Because USB gamepad makers failed to provide unique serial#s with each
controller, we have to limit the mapping to specific USB ports.
Otherwise, we couldn't distinguish two otherwise identical gamepads. So
basically your computer USB ports act like real game console input port
numbers. Which is kind of neat, I guess.
And the really nice thing about the new system is that we now have the
capability to support hotplugging input devices. I haven't yet added
this to any drivers, but I'm definitely going to add it to udev for v094
official.
Finally, with the device ID (vendor ID + product ID) exposed, we gain
one last really cool feature that we may be able to develop more in the
future. Say we created a joypad.bml file to include with higan. In it,
we'd store the Xbox 360 controller, and pre-defined button mappings for
each emulated system. So if higan detects you have an Xbox 360
controller, you can just plug it in and use it. Even better, we can
clearly specify the difference between triggers and analog axes, and
name each individual input. So you'd see "Xbox 360 Gamepad #1: Left
Trigger" instead of higan v093's "JP0::Axis2.Hi"
Note: for right now, ethos' input manager isn't filtering the device IDs
to look pretty. So you're going to see a 64-bit hex value for a device
ID right now instead of something like Joypad#N for now.
2013-12-23 11:43:51 +00:00
|
|
|
|
|
|
|
#endif
|