-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for third party joycons and xbox orientation #116
Open
lainproliant
wants to merge
2
commits into
DanielOgorchock:master
Choose a base branch
from
lainproliant:xbox-orientation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "moonlight"] | ||
path = moonlight | ||
url = [email protected]:/lainproliant/moonlight |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef JOYCOND_CONFIG_H | ||
#define JOYCOND_CONFIG_H | ||
|
||
#include "phys_ctlr.h" | ||
#include <map> | ||
|
||
typedef std::pair<std::string, std::string> CombinedMACs; | ||
|
||
struct ControllerProps { | ||
bool xbox_orientation = false; | ||
}; | ||
|
||
class Config { | ||
public: | ||
Config(const std::string& filename = "/etc/joycond.conf"); | ||
~Config() { } | ||
|
||
static const Config& get(); | ||
|
||
std::optional<phys_ctlr::Model> get_mac_device_override(const std::string& mac_addr) const; | ||
const ControllerProps& get_combined_joycons_props(const CombinedMACs& macs) const; | ||
void set_combined_joycons_props(const CombinedMACs& macs, const ControllerProps& props); | ||
|
||
private: | ||
void process_config_file(std::istream& infile); | ||
void process_config_line(const std::string& line); | ||
void parse_and_set_controller_prop(ControllerProps& props, const std::string& name, const std::string& value) const; | ||
|
||
std::map<std::string, phys_ctlr::Model> _mac_model_overrides; | ||
std::map<CombinedMACs, ControllerProps> _combined_joycons_props; | ||
}; | ||
|
||
#endif /* !JOYCOND_CONFIG_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mac_device 98:B6:E9:F8:6F:86 Left_Joycon | ||
mac_device 98:B6:E9:33:EF:5C Right_Joycon | ||
prop combined_joycons 98:B6:E9:F8:6F:86 98:B6:E9:33:EF:5C xbox_orientation 1 |
Submodule moonlight
added at
c8f04d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#include "config.h" | ||
#include "moonlight/file.h" | ||
#include "moonlight/shlex.h" | ||
|
||
static const Config _config; | ||
static const ControllerProps _default_props; | ||
|
||
// ctor | ||
Config::Config(const std::string& filename) { | ||
try { | ||
auto infile = moonlight::file::open_r(filename); | ||
process_config_file(infile); | ||
|
||
} catch (const moonlight::core::RuntimeError& e) { | ||
std::cout << "Failed to open config file " << filename << ", skipping." << std::endl; | ||
} | ||
} | ||
|
||
// public static | ||
const Config& Config::get() { | ||
return _config; | ||
} | ||
|
||
// public | ||
std::optional<phys_ctlr::Model> Config::get_mac_device_override(const std::string& mac_addr) const { | ||
auto iter = _mac_model_overrides.find(mac_addr); | ||
if (iter == _mac_model_overrides.end()) { | ||
return {}; | ||
} | ||
return iter->second; | ||
} | ||
|
||
const ControllerProps& Config::get_combined_joycons_props(const CombinedMACs& macs) const { | ||
auto iter = _combined_joycons_props.find(macs); | ||
if (iter == _combined_joycons_props.end()) { | ||
return _default_props; | ||
} | ||
|
||
return iter->second; | ||
} | ||
|
||
void Config::set_combined_joycons_props(const CombinedMACs& macs, const ControllerProps& props) { | ||
_combined_joycons_props.insert({macs, props}); | ||
} | ||
|
||
// private | ||
void Config::process_config_file(std::istream& infile) { | ||
std::string line; | ||
while (std::getline(infile, line)) { | ||
process_config_line(line); | ||
} | ||
} | ||
|
||
// private | ||
void Config::process_config_line(const std::string& line) { | ||
auto tokens = moonlight::shlex::split(line); | ||
if (tokens.size() < 1) { | ||
return; | ||
} | ||
|
||
if (tokens[0].starts_with("#")) { | ||
return; | ||
} | ||
|
||
if (tokens[0] == "mac_device") { | ||
if (tokens.size() != 3) { | ||
std::cout << "Malformed `mac_device` directive in config file." << std::endl; | ||
return; | ||
} | ||
|
||
auto mac_address = tokens[1]; | ||
auto device_name = tokens[2]; | ||
|
||
auto iter = phys_ctlr::models_by_name().find(device_name); | ||
if (iter == phys_ctlr::models_by_name().end()) { | ||
std::cout << "Invalid device name in `mac_device` directive: " << device_name << std::endl; | ||
return; | ||
} | ||
|
||
_mac_model_overrides[mac_address] = iter->second; | ||
|
||
|
||
} else if (tokens[0] == "prop") { | ||
if (tokens.size() < 5) { | ||
std::cout << "Malformed `prop` directive in config file." << std::endl; | ||
return; | ||
} | ||
|
||
auto controller_type = tokens[1]; | ||
|
||
if (controller_type == "combined_joycons") { | ||
if (tokens.size() < 6) { | ||
std::cout << "Malformed `prop` directive for `combined_joycons` controller in config file." << std::endl; | ||
return; | ||
} | ||
|
||
auto left_mac = tokens[2]; | ||
auto right_mac = tokens[3]; | ||
auto name = tokens[4]; | ||
auto value = tokens[5]; | ||
|
||
std::cout << "Setting controller prop " << name << " to " << value << " for combined joycons " << left_mac << " and " << right_mac << std::endl; | ||
|
||
auto props = get_combined_joycons_props({left_mac, right_mac}); | ||
parse_and_set_controller_prop(props, name, value); | ||
set_combined_joycons_props({left_mac, right_mac}, props); | ||
|
||
} else { | ||
std::cout << "Unsupported controller type for `prop` directive: " << controller_type << std::endl; | ||
return; | ||
} | ||
|
||
} else { | ||
std::cout << "Unknown directive in config file: " << tokens[0] << std::endl; | ||
} | ||
} | ||
|
||
// private | ||
void Config::parse_and_set_controller_prop(ControllerProps& props, const std::string& name, const std::string& value) const { | ||
if (name == "xbox_orientation") { | ||
try { | ||
props.xbox_orientation = std::stoi(value); | ||
|
||
} catch (...) { | ||
std::cout << "Failed to parse value for `xbox_orientation`." << std::endl; | ||
return; | ||
} | ||
} else { | ||
std::cout << "Unsupported property: " << name << std::endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,7 @@ ctlr_detector_udev::ctlr_detector_udev(ctlr_mgr& ctlr_manager, epoll_mgr& epoll_ | |
udev_mon_fd = udev_monitor_get_fd(mon); | ||
|
||
subscriber = std::make_shared<epoll_subscriber>(std::vector({udev_mon_fd}), | ||
[=](int event_fd){epoll_event_callback(event_fd);}); | ||
[=, this](int event_fd){epoll_event_callback(event_fd);}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implicit capture of |
||
epoll_manager.add_subscriber(subscriber); | ||
|
||
// Detect any existing controllers prior to daemon start | ||
|
@@ -83,4 +83,3 @@ ctlr_detector_udev::~ctlr_detector_udev() | |
{ | ||
epoll_manager.remove_subscriber(subscriber); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the config file I'm currently using.