34 #include <linux/joystick.h>
55 open(std::string
const& deviceName, std::string
const& deviceEventName)
58 fd =
::open(deviceName.c_str(), O_RDONLY);
60 if (!deviceEventName.empty())
63 fdEvent =
::open(deviceEventName.c_str(), O_RDWR | O_CLOEXEC);
80 ioctl(fd, JSIOCGNAME(255), &
name[0]);
101 int bytes =
read(fd, &event,
sizeof(event));
105 if (bytes == -1 || bytes !=
sizeof(event))
110 if (event.type & JS_EVENT_BUTTON)
114 else if (event.type & JS_EVENT_AXIS)
116 axis[
event.number] =
event.value;
125 if(fdEvent < 0)
return;
139 ret = ioctl(fdEvent, EVIOCGEFFECTS, &effects);
148 struct input_event ie;
152 ie.value = 0xFFFFUL * gain / 100;
154 if (
write(fdEvent, &ie,
sizeof(ie)) == -1)
168 e.type = FF_PERIODIC;
170 e.replay.length = 5000;
171 e.replay.delay = 500;
172 e.u.periodic.waveform = FF_SQUARE;
173 e.u.periodic.period = 1000;
174 e.u.periodic.magnitude = 0xFF;
175 e.u.periodic.offset = 0xFF;
177 ret = ioctl(fdEvent, EVIOCSFF, &e);
186 play.code =
static_cast<std::uint16_t
>(e.id);
189 ret =
write(fdEvent, &play,
sizeof(play));
195 for (
int i = 0; i < 5; i++)
198 input_event statusIe;
199 statusIe.type = EV_FF_STATUS;
200 statusIe.code = e.id;
203 ret =
write(fdEvent, &statusIe,
sizeof(statusIe));
223 [[maybe_unused]]
const int stopStatus =
write(fdEvent,
static_cast<const void*
>(&stop),
sizeof(stop));
226 ret = ioctl(fdEvent, EVIOCRMFF, e.id);