| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
SwitchKit is a C++ library for interacting with controllers for the Nintendo Switch on a PC/Mac. It is relatively "pure", with hidapi as the only dependency. Functionality is listed below.
SwitchKit is compatible with the following controllers:
Warning
At this time, SwitchKit is not compatible with Nintendo Switch 2 controllers, including the Joy-Con 2 controllers or the Nintendo Switch 2 Pro Controller.
If you have information on how to get these controllers to interface with a PC/Mac, please let me know - I'd love to add support!
See main.cpp for my testing ground of SwitchKit's features.
In general, the flow is:
Here's a simple example program that connects to the Joy-Con (R), sets the player LEDs, and then prints the Joy-Con's orientation (via gyro) while it waits for the player to press the A button.
#include <hidapi/hidapi.h>
#include "switch_controller.h"
int main(void)
{
int res;
// Initialize the hidapi library
res = hid_init();
hid_device *jc_r_handle = hid_open(0x57E, 0x2007, NULL);
SwitchKit::SwitchController controller(jc_r_handle);
controller.set_input_report_mode(SwitchKit::InputReportMode::MODE_STANDARD);
controller.set_imu_enabled(true);
controller.request_device_info();
controller.request_stick_calibration();
controller.request_imu_calibration();
controller.request_color_data();
controller.set_player_lights(
SwitchKit::SwitchController::LIGHT_ON,
SwitchKit::SwitchController::LIGHT_OFF,
SwitchKit::SwitchController::LIGHT_FLASH,
SwitchKit::SwitchController::LIGHT_ON
);
bool leave = false;
while (!leave)
{
controller.poll();
// Print the controller orientation.
SwitchKit::Vector3 g = controller.get_gyro();
printf("Gyro: %.2lf, %.2lf, %.2lf\n", g.x, g.y, g.z);
// Close the program once the player presses the A button on the Joy-Con (R).
if (controller.get_button_pressed_this_frame(SwitchKit::SwitchControllerReport::BTN_A)) {
leave = true;
}
}
hid_close(handle);
res = hid_exit();
}So far, SwitchKit has been solely developed and thus tested on macOS. Please contribute usage instructions for other platforms if you're able!
Run the command
make dynamic_macosto create a dynamic library file switchkit.dylib.
Alternatively, run
make static_macosto create an object file switchkit.o that you can statically link to other code.
If these build instructions seem awful, it's probably because I'm new to developing cross-platform C++ libraries like this. So, file an issue or pull request or something with a better way. I would appreciate learning better practices!
MIT
| Back | FazBrowse Home | New Git URL |