mirror of
https://github.com/alexhopeoconnor/firmware.git
synced 2026-10-17 00:51:30 +10:00
add linuxJoystick input module (#10970)
* add linuxJoystick input module * close epollfd to avoid leaks
This commit is contained in:
@@ -1038,6 +1038,25 @@ bool loadConfig(const char *configPath)
|
||||
if (yamlConfig["Input"]) {
|
||||
portduino_config.keyboardDevice = (yamlConfig["Input"]["KeyboardDevice"]).as<std::string>("");
|
||||
portduino_config.pointerDevice = (yamlConfig["Input"]["PointerDevice"]).as<std::string>("");
|
||||
portduino_config.joystickDevice = (yamlConfig["Input"]["JoystickDevice"]).as<std::string>("");
|
||||
if (yamlConfig["Input"]["JoystickButtons"]) {
|
||||
// action name -> evdev button code (hex like 0x122 or decimal); stored inverted
|
||||
// as code -> lowercase action name for the driver to look up per keypress.
|
||||
for (const auto &button : yamlConfig["Input"]["JoystickButtons"]) {
|
||||
std::string action = button.first.as<std::string>("");
|
||||
for (auto &c : action)
|
||||
c = tolower(c);
|
||||
int code = 0;
|
||||
try {
|
||||
// base 0 accepts hex (0x122) or decimal; a malformed value just skips this entry.
|
||||
code = std::stoi(button.second.as<std::string>(""), nullptr, 0);
|
||||
} catch (const std::exception &) {
|
||||
code = 0;
|
||||
}
|
||||
if (code != 0 && action != "")
|
||||
portduino_config.joystickButtons[code] = action;
|
||||
}
|
||||
}
|
||||
|
||||
readGPIOFromYaml(yamlConfig["Input"]["User"], portduino_config.userButtonPin);
|
||||
readGPIOFromYaml(yamlConfig["Input"]["TrackballUp"], portduino_config.tbUpPin);
|
||||
|
||||
@@ -160,6 +160,11 @@ extern struct portduino_config_struct {
|
||||
// Input
|
||||
std::string keyboardDevice = "";
|
||||
std::string pointerDevice = "";
|
||||
std::string joystickDevice = "";
|
||||
// Joystick/gamepad button map: evdev button code -> lowercase action name
|
||||
// ("select", "cancel", "back", "up", "down", "left", "right", "user").
|
||||
// Empty means the LinuxJoystick driver uses its built-in defaults.
|
||||
std::map<int, std::string> joystickButtons;
|
||||
int tbDirection;
|
||||
pinMapping userButtonPin = {"Input", "User"};
|
||||
pinMapping tbUpPin = {"Input", "TrackballUp"};
|
||||
@@ -458,6 +463,14 @@ extern struct portduino_config_struct {
|
||||
out << YAML::Key << "KeyboardDevice" << YAML::Value << keyboardDevice;
|
||||
if (pointerDevice != "")
|
||||
out << YAML::Key << "PointerDevice" << YAML::Value << pointerDevice;
|
||||
if (joystickDevice != "")
|
||||
out << YAML::Key << "JoystickDevice" << YAML::Value << joystickDevice;
|
||||
if (!joystickButtons.empty()) {
|
||||
out << YAML::Key << "JoystickButtons" << YAML::Value << YAML::BeginMap;
|
||||
for (const auto &button : joystickButtons)
|
||||
out << YAML::Key << button.second << YAML::Value << button.first;
|
||||
out << YAML::EndMap;
|
||||
}
|
||||
|
||||
for (const auto *input_pin : all_pins) {
|
||||
if (input_pin->config_section == "Input" && input_pin->enabled) {
|
||||
|
||||
Reference in New Issue
Block a user