Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Build directory
[Bb]uild/

# IDE directories
.vscode/
.vs/

# Compiled Object files
*.slo
*.lo
Expand Down
26 changes: 21 additions & 5 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@
"${workspaceRoot}"
]
},
"intelliSenseMode": "clang-x64"
"intelliSenseMode": "clang-x64",
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17"
},
{
"name": "Linux",
Expand All @@ -32,7 +39,10 @@
"${workspaceRoot}"
]
},
"intelliSenseMode": "clang-x64"
"intelliSenseMode": "clang-x64",
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17"
},
{
"name": "Win32",
Expand All @@ -47,7 +57,10 @@
"${workspaceRoot}"
]
},
"intelliSenseMode": "msvc-x64"
"intelliSenseMode": "msvc-x64",
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17"
},
{
"name": "KeyPad",
Expand All @@ -62,8 +75,11 @@
"${workspaceRoot}"
]
},
"intelliSenseMode": "clang-x64"
"intelliSenseMode": "clang-x64",
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17"
}
],
"version": 2
"version": 4
}
22 changes: 22 additions & 0 deletions Code/input_parameter_parser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <inputparameterparser.h>

InputParameterParser::InputParameterParser(int& argc, char** argv) {
for (int i = 1; i < argc; ++i) {
this->_tokens.push_back(string(argv[i]));
}
}

const string& InputParameterParser::getCmdOption(const string& option) const {
vector<string>::const_iterator iterator;
iterator = find(this->tokens.begin(), this->tokens.end(), option);
if (iterator != this->_tokens.end() && ++iterator != this->_tokens.end()) {
return *iterator;
}

static const string empty_string("");
return empty_string;
}

bool InputParameterParser::cmdOptionExists(const string& option) const {
return find(this->_tokens.begin(), this-_tokens.end(), option) != this->_tokens.end();
}
49 changes: 49 additions & 0 deletions ExampleMappings/linux_example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# The below mappings is for mapping a joystick button press to a keyboard key in the Linux OS.
# The file type should stay as TXT
# Joystick Button Codes (using Xbox controller face buttons)
# ---------------------
# 0 -> A
# 1 -> B
# 2 -> X
# 3 -> Y
# 4 -> LEFT_SHOULDER_BUTTON
# 5 -> RIGHT_SHOULDER_BUTTON
# 6 -> BACK_BUTTON
# 7 -> MENU_BUTTON
# 8 -> HOME_BUTTON
# 9 -> LEFT_STICK_BUTTON
# 10 -> RIGHT_STICK_BUTTON
# 11 -> DPAD_RIGHT
# 12 -> DPAD_LEFT
# 13 -> DPAD_UP
# 14 -> DPAD_DOWN
# 15 -> LEFT_STICK_LEFT
# 16 -> LEFT_STICK_UP
# 17 -> LEFT_STICK_RIGHT
# 18 -> LEFT_STICK_DOWN
# NULL means that it isn't mapped
# ---------------------
# Linux keyboard codes can be found at https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h
#
# This file maps the ABXY to SDAW keyboard keys (in that order), the DPAD directions to the arrow keys,
# the back button to the spacebar, and the menu button (start button) to the enter key.
# The left joystick is not mapped to anything (although could map to the arrow keys just like the DPAD)
0=31
1=32
2=30
3=21
4=16
5=18
6=57
7=28
8=NULL
9=NULL
10=NULL
11=106
12=105
13=103
14=108
15=NULL
16=NULL
17=NULL
18=NULL
17 changes: 17 additions & 0 deletions Headers/inputparameterparser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef INPUTPARAMETERPARSER_H
#define INPUTPARAMETERPARSER_H

using namespace std;

class InputParameterParser
{
private:
vector<string> _tokens;

public:
InputParameterParser(int& argc, char** argv);
bool cmdOptionExists(const string& option) const;
const string& getCmdOption(const string& option) const;
}

#endif
9 changes: 7 additions & 2 deletions keypadservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <settings.h>
#include <keymapping.h>
#include <keybindconverter.h>
#include <inputparameterparser.h>

#if PLATFORM_LINUX
#include <linuxjoystick.h>
Expand Down Expand Up @@ -41,13 +42,17 @@ int main (int argc, char** argv) {
Keyboard* pKeyboard = NULL;
Joystick* pJoystick = NULL;
ConsoleLogger logger;
InputParameterParser inputParser(argc, argv);
setupSignalHandler();

try {
Settings settings(settingsFileLocation.c_str());
settings.load();

std::string fileLocation = settings.getValue("keybindings_location");
std::string fileLocation = inputParser.cmdOptionExists("-f")
? inputParser.getCmdOption("-f")
: settings.getValue("keybindings_location");

KeyMapping keyMap = buildKeyMap(fileLocation);
pKeyboard = createKeyboard(&logger, &settings);
pJoystick = createJoystick(&logger, &settings);
Expand Down Expand Up @@ -142,7 +147,7 @@ KeyMapping buildKeyMap(std::string fileLocation) {

std::string line;
while (getline(inFile, line)) {
if (line.length() == 0) {
if (line.length() == 0 || line[0] == '#') {
continue;
}

Expand Down