Enforce parity with Linux api.
This commit is contained in:
2
main.cpp
2
main.cpp
@@ -18,6 +18,8 @@ int main() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int hwid = jstick::Connect(0);
|
||||
|
||||
while (jstick::JoystickDetected()) {
|
||||
jstick::ReadEventLoop();
|
||||
|
||||
|
@@ -1,15 +1,8 @@
|
||||
#include <jstick.hpp>
|
||||
|
||||
#ifdef UNIX
|
||||
#include <linux/joystick.h>
|
||||
#include <unistd.h>
|
||||
#include <bits/fs_fwd.h>
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
//#include <joystickapi.h>
|
||||
#endif
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
#include <fcntl.h>
|
||||
@@ -55,6 +48,9 @@ std::string js_device_file(int hwid) {
|
||||
return std::format("/dev/input/js{}", hwid);
|
||||
}
|
||||
|
||||
|
||||
bool jstick::Initialize() { return true;}
|
||||
|
||||
bool jstick::JoystickDetected(int jsHandle) {
|
||||
return std::filesystem::exists(js_device_file(jsHandle));
|
||||
}
|
||||
@@ -215,37 +211,37 @@ void jstick::ReadEventLoop() {
|
||||
}
|
||||
}
|
||||
|
||||
bool jstick::IsButtonDown(const XBoxButton &btn) {
|
||||
bool jstick::IsButtonDown(const XBoxButton &btn, int hwid) {
|
||||
return btn_state[(uint8_t)btn];
|
||||
}
|
||||
|
||||
Vector2 jstick::GetLeftThumbstickAxis(float deadzone) { return l_thumb;}
|
||||
Vector2 jstick::GetRightThumbstickAxis(float deadzone) { return r_thumb; }
|
||||
Vector2 jstick::GetDPadAxis(float deadzone) { return dpad; }
|
||||
Vector2 jstick::GetLeftThumbstickAxis(float deadzone, int hwid) { return l_thumb;}
|
||||
Vector2 jstick::GetRightThumbstickAxis(float deadzone, int hwid) { return r_thumb; }
|
||||
Vector2 jstick::GetDPadAxis(float deadzone, int hwid) { return dpad; }
|
||||
|
||||
|
||||
short jstick::GetRightTrigger() { return r_trigger;}
|
||||
short jstick::GetLeftTrigger() { return l_trigger; }
|
||||
short jstick::GetRightTrigger(int hwid) { return r_trigger;}
|
||||
short jstick::GetLeftTrigger(int hwid) { return l_trigger; }
|
||||
|
||||
constexpr float short_range = 32768.f;
|
||||
|
||||
Vector2 jstick::GetLeftThumbstickAxisNormalized(float deadzone) {
|
||||
return l_thumb / short_range;
|
||||
Vector2 jstick::GetLeftThumbstickAxisNormalized(float deadzone, int hwid) {
|
||||
return GetLeftThumbstickAxis(deadzone, hwid) / short_range;
|
||||
}
|
||||
|
||||
Vector2 jstick::GetRightThumbstickAxisNormalized(float deadzone) {
|
||||
return r_thumb / short_range;
|
||||
Vector2 jstick::GetRightThumbstickAxisNormalized(float deadzone, int hwid) {
|
||||
return GetRightThumbstickAxis(deadzone, hwid) / short_range;
|
||||
}
|
||||
|
||||
Vector2 jstick::GetDPadAxisNormalized(float deadzone) {
|
||||
Vector2 jstick::GetDPadAxisNormalized(float deadzone, int hwid) {
|
||||
return dpad / short_range;
|
||||
}
|
||||
|
||||
float jstick::GetLeftTriggerNormalized() {
|
||||
float jstick::GetLeftTriggerNormalized(int hwid) {
|
||||
return l_trigger / short_range;
|
||||
}
|
||||
|
||||
float jstick::GetRightTriggerNormalized() {
|
||||
float jstick::GetRightTriggerNormalized(int hwid) {
|
||||
return r_trigger / short_range;
|
||||
}
|
||||
|
||||
@@ -256,3 +252,7 @@ jstick::ControllerType jstick::GetDeviceTypeFromName(const std::string &name) {
|
||||
|
||||
return ControllerType::Unknown;
|
||||
}
|
||||
|
||||
void jstick::Vibrate(int LV, int RV, int hwid) {
|
||||
|
||||
}
|
Reference in New Issue
Block a user