Did some things
This commit is contained in:
32
main.cpp
32
main.cpp
@@ -23,6 +23,7 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
|
||||
enum class XBoxButton : uint8_t
|
||||
{
|
||||
@@ -79,14 +80,14 @@ size_t get_button_count(int fd)
|
||||
|
||||
|
||||
struct Axes {
|
||||
short LeftThumbX;
|
||||
short LeftThumbY;
|
||||
short RightThumbX;
|
||||
short RightThumbY;
|
||||
short DPadX;
|
||||
short DPadY;
|
||||
short LeftTrigger;
|
||||
short RightTrigger;
|
||||
short LeftThumbX = 0;
|
||||
short LeftThumbY = 0;
|
||||
short RightThumbX = 0;
|
||||
short RightThumbY = 0;
|
||||
short DPadX = 0;
|
||||
short DPadY = 0;
|
||||
short LeftTrigger = 0;
|
||||
short RightTrigger = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -95,7 +96,7 @@ struct Axes {
|
||||
/// the X axis is an even number, and the Y axis is an odd number. However, this
|
||||
/// is usually a safe assumption.
|
||||
/// @returns the axis that the event indicated.
|
||||
size_t get_axis_state(struct js_event *event, struct Axes axes)
|
||||
size_t get_axis_state(struct js_event *event, struct Axes& axes)
|
||||
{
|
||||
/// Mappings on my device, meaning these assumptions are incorrect.
|
||||
// LStick X = 0
|
||||
@@ -120,6 +121,10 @@ size_t get_axis_state(struct js_event *event, struct Axes axes)
|
||||
if (axis == 6) axes.DPadX = value;
|
||||
if (axis == 7) axes.DPadY = value;
|
||||
|
||||
|
||||
std::cout << std::format("axis_index: {}, val: {}", axis, value) << std::endl;
|
||||
std::cout << std::format("lthumb: {},{} ltrigger: {}, rthumb: {},{}, rtrigger: {}, dp: {},{}", axes.LeftThumbX, axes.LeftThumbY, axes.LeftTrigger, axes.RightThumbX, axes.RightThumbY, axes.RightTrigger, axes.DPadX, axes.DPadY) << std::endl;
|
||||
|
||||
/*size_t axis = event->number / 2;
|
||||
|
||||
if (axis < 3)
|
||||
@@ -131,6 +136,7 @@ size_t get_axis_state(struct js_event *event, struct Axes axes)
|
||||
}
|
||||
|
||||
return axis;*/
|
||||
return axis;
|
||||
}
|
||||
|
||||
uint8_t get_num_axes(int joystick_handle) {
|
||||
@@ -178,12 +184,14 @@ void disconnect_device() {
|
||||
close(js);
|
||||
}
|
||||
|
||||
#define ENUM_TO_STRING(var) (#var)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *device;
|
||||
|
||||
struct js_event event;
|
||||
struct Axes axes;
|
||||
struct Axes axes = {};
|
||||
size_t axis;
|
||||
|
||||
if (argc > 1)
|
||||
@@ -244,8 +252,8 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
case JS_EVENT_AXIS:
|
||||
axis = get_axis_state(&event, axes);
|
||||
if (axis < 3)
|
||||
printf("Axis %zu at (%6d, %6d)\n", axis, axes[axis].x, axes[axis].y);
|
||||
//if (axis < 3)
|
||||
//printf("Axis %zu at (%6d, %6d)\n", axis, axes[axis].x, axes[axis].y);
|
||||
break;
|
||||
case JS_EVENT_INIT:
|
||||
default:
|
||||
|
Reference in New Issue
Block a user