Sense is a lightweight and efficient solution for using the DualSense controller on Linux.
It provides a fast and reliable way to process controller input by utilizing the linux/joystick.h
interface and reading data directly from /dev/input/js0
or a specified path.
Designed for simplicity, Sense ensures smooth and responsive interaction without unnecessary complexity.
For different kind of applications, it offers a seamless experience with minimal overhead.
// include the header file from the project
#include <sense/dualsense.h>
#include <sense/constants.h>
auto sense = sense::DualSense();
if(!sense.set_open()) { printf("Failed to open path\n"); return -1; }
# in root directory
mkdir build
cd build/
cmake ..
make && make install
# in "/etc/udev/rules.d/" for gpio group on raspberry pi
sudo touch 99-leds.rules
SUBSYSTEM=="leds", ACTION=="add", PROGRAM="/bin/sh -c 'chgrp -R gpio /sys%p && chmod -R g=u /sys%p'"
auto sense = sense::DualSense();
if(!sense.set_open()) { printf("Failed to open path\n"); return -1; }
while (sense.is_active) {
const auto trigger = sense.axis[sense::AXIS_RIGHT_TRIGGER];
const auto button_x = sense.buttons[sense::BUTTON_CROSS];
printf("trigger value %i, button value: %i\n", trigger, button_x);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
auto sense = sense::DualSense();
if(!sense.set_open()) { printf("failed to open path\n"); return 1; }
auto info = sense.get_device_info();
printf("status: %s\n", info[sense::STATUS].c_str());
printf("capacity: %s\n", info[sense::CAPACITY].c_str());
sense.set_led(128, 0, 255);