Skip to content

Commit

Permalink
Edired README and removed TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Dafarra committed Apr 29, 2024
1 parent 8dbedeb commit af10579
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# yarp-device-keyboard-joypad
Repository containing the implementation of a yarp device to use a keyboard as a joypad.
Repository containing the implementation of a yarp device to emulate a joypad using the keyboard, the touchscreen and/or an actual joypad.

## Example usage
By running the following command,
```
yarpdev --device keyboardJoypad --name /keyboard --buttons "(none, test, c:prova, c:prova, v, b, test, c:prova, 8, g-h:Multi)" --axes "(ws, ad, ad, none, -left_right, up_down)"
```
a GUI will be opened with a similar layout:

https://github.com/ami-iit/yarp-device-keyboard-joypad/assets/18591940/7717159e-8eef-4a5b-9273-814fa55f5560



## Dependencies
- [``YARP``](https://github.com/robotology/yarp) (>= 3.4.0)
Expand Down Expand Up @@ -30,8 +41,13 @@ The device can be configured using the following parameters. They are all option
- ``axes``: definition of the list of axes. The allowed values are "ws", "ad", "up_down" and "left_right". It is possible to select the default sign for an axis prepending a "+" or a "-" to the axis name. For example, "+ws" will set the "ws" axis with the default sign, while "-ws" will set the "ws" axis with the inverted sign. It is also possible to repeat some axis, and use "none" or "" to have dummy axes with always zero value. The order matters. (default: ("ad", "ws", "left_right", "up_down"))
- ``wasd_label``: label for the "WASD" widget (default: "WASD")
- ``arrows_label``: label for the "Arrows" widget (default: "Arrows")
- ``buttons``: definition of the list of buttons. The allowed values are all the letters from A to Z, all the numbers from 0 to 9, "SPACE", "ENTER", "ESCAPE", "BACKSPACE", "DELETE", "LEFT", "RIGHT", "UP", "DOWN". It is possible to repeat some button. It is possible to specify an alias after a ":". For example "A:Some Text" will create a button with the label "Some Text" that can be activated by pressing "A". It is possible to use "none" or "" to indicate a dummy button always zero. It is possible to spcify multiple keys using the "-" delimiter. For example, "A-B:Some Text" creates a button named "Some Text" that can be activated pressing either A or B. It is possible to repeat buttons. The order matters. (default: ())

- ``buttons``: definition of the list of buttons. The allowed values are all the letters from A to Z, all the numbers from 0 to 9, "SPACE", "ENTER", "ESCAPE", "BACKSPACE", "DELETE", "LEFT", "RIGHT", "UP", "DOWN". With "J" followed by a number it is possible to map a joypad button, when connected. It is possible to repeat some button. It is possible to specify an alias after a ":". For example "A:Some Text" will create a button with the label "Some Text" that can be activated by pressing "A". It is possible to use "none" or "" to indicate a dummy button always zero. It is possible to specify multiple keys using the "-" delimiter. For example, "A-B-J5:Some Text" creates a button named "Some Text" that can be activated pressing either A, or B, or the joypad button with index 5. It is possible to repeat buttons. The order matters. (default: ())
- ``joypad_indices``: definition of the joypads to consider in case multiple joypads are connected. The value can be a single integer or a list of integers. The indices are 0-based. In case a joypad is not found, it is ignored. The axis and buttons values are stack together in the order provided. (default: 0)
- ``joypad_deadzone``: deadzone for the joypad axes (default: 0.1)
- ``ad_joypad_axis_index``: index of the axis for the "ad" axis in the joypad (default: 0)
- ``ws_joypad_axis_index``: index of the axis for the "ws" axis in the joypad (default: 1)
- ``left_right_joypad_axis_index``: index of the axis for the "left_right" axis in the joypad (default: 2)
- ``up_down_joypad_axis_index``: index of the axis for the "up_down" axis in the joypad (default: 3)

## Maintainers
* Stefano Dafarra ([@S-Dafarra](https://github.com/S-Dafarra))
20 changes: 11 additions & 9 deletions src/devices/keyboard-joypad/KeyboardJoypad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,10 @@ struct Settings {
return false;
}

if (!parseFloat(cfg, "deadzone", 0.f, 1.f, deadzone))
if (!parseFloat(cfg, "joypad_deadzone", 0.f, 1.f, deadzone))
{
return false;
}
//TODO: Edit README

if (!parseInt(cfg, "window_width", 1, static_cast<int>(1e4), window_width))
{
Expand Down Expand Up @@ -338,7 +337,7 @@ struct Settings {
return false;
}

if (cfg.check("joypad_indices")) //TODO: README
if (cfg.check("joypad_indices"))
{
yarp::os::Value joypadsValue = cfg.find("joypad_indices");
if (joypadsValue.isInt32() || joypadsValue.isInt64())
Expand Down Expand Up @@ -519,7 +518,6 @@ struct AxesSettings
return false;
}
}
//TODO: Edit README

return true;
}
Expand Down Expand Up @@ -688,7 +686,7 @@ class yarp::dev::KeyboardJoypad::Impl
button.end(), [](unsigned char c) { return !std::isdigit(c); }) == button.end()) //J followed by a number
{
int joypad_button = std::stoi(button.substr(1));
newButton.joypadButtonIndices.push_back(joypad_button); //TODO: README
newButton.joypadButtonIndices.push_back(joypad_button);
}
else if (supportedButtons.find(button) != supportedButtons.end())
{
Expand Down Expand Up @@ -1032,9 +1030,9 @@ class yarp::dev::KeyboardJoypad::Impl
ImGui::SliderFloat("Font multiplier", &this->settings.font_multiplier, this->settings.min_font_multiplier, this->settings.max_font_multiplier);
if (this->using_joypad)
{
ImGui::SliderFloat("Joypad Deadzone", &this->settings.deadzone, 0.0, 1.0);
ImGui::SliderFloat("Joypad deadzone", &this->settings.deadzone, 0.0, 1.0);
// Display the joypad values
std::string connectedJoypads = "Connected Joypads: ";
std::string connectedJoypads = "Connected joypads: ";
for (size_t i = 0; i < this->joypads.size(); ++i)
{
connectedJoypads += this->joypads[i].name;
Expand All @@ -1051,7 +1049,7 @@ class yarp::dev::KeyboardJoypad::Impl
// Print the values of the axes in the format "axis_index: value" with a 1 decimal precision
std::stringstream stream;
stream << std::fixed << std::setprecision(2) << this->joypad_axis_values[i];
std::string sign = this->joypad_axis_values[i] > 0 ? "+" : "";
std::string sign = this->joypad_axis_values[i] >= 0 ? "+" : "";
axes_values += "<" + std::to_string(i) + "> " + sign + stream.str();
if (i != this->joypad_axis_values.size() - 1)
{
Expand All @@ -1077,7 +1075,7 @@ class yarp::dev::KeyboardJoypad::Impl
// Print the values of the axes in the format "axis_index: value" with a 1 decimal precision
std::stringstream stream;
stream << std::fixed << std::setprecision(2) << this->axes_values[i];
std::string sign = this->axes_values[i] > 0 ? "+" : "";
std::string sign = this->axes_values[i] >= 0 ? "+" : "";
output_axes_values += "<" + std::to_string(i) + "> " + sign + stream.str();
if (i != this->axes_values.size() - 1)
{
Expand All @@ -1086,6 +1084,10 @@ class yarp::dev::KeyboardJoypad::Impl
}
ImGui::Text(output_axes_values.c_str());
std::string output_buttons_values = "Output buttons values: ";
if (this->buttons_values.empty())
{
output_buttons_values += "None";
}
for (size_t i = 0; i < this->buttons_values.size(); ++i)
{
std::stringstream stream;
Expand Down

0 comments on commit af10579

Please sign in to comment.