20 changed files with 0 additions and 2219 deletions
@ -1,7 +0,0 @@ |
|||
obj |
|||
*.xcworkspace |
|||
*.xcuserdatad |
|||
*~ |
|||
bin/*.app |
|||
bin/example-gamepad |
|||
bin/libs |
@ -1,13 +0,0 @@ |
|||
# Attempt to load a config.make file.
|
|||
# If none is found, project defaults in config.project.make will be used.
|
|||
ifneq ($(wildcard config.make),) |
|||
include config.make |
|||
endif |
|||
|
|||
# make sure the the OF_ROOT location is defined
|
|||
ifndef OF_ROOT |
|||
OF_ROOT=$(realpath ../../..) |
|||
endif |
|||
|
|||
# call the project makefile!
|
|||
include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk |
@ -1,17 +0,0 @@ |
|||
//THE PATH TO THE ROOT OF OUR OF PATH RELATIVE TO THIS PROJECT. |
|||
//THIS NEEDS TO BE DEFINED BEFORE CoreOF.xcconfig IS INCLUDED |
|||
OF_PATH = ../../.. |
|||
|
|||
//THIS HAS ALL THE HEADER AND LIBS FOR OF CORE |
|||
#include "../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig" |
|||
|
|||
//ICONS - NEW IN 0072 |
|||
ICON_NAME_DEBUG = icon-debug.icns |
|||
ICON_NAME_RELEASE = icon.icns |
|||
ICON_FILE_PATH = $(OF_PATH)/libs/openFrameworksCompiled/project/osx/ |
|||
|
|||
//IF YOU WANT AN APP TO HAVE A CUSTOM ICON - PUT THEM IN YOUR DATA FOLDER AND CHANGE ICON_FILE_PATH to: |
|||
//ICON_FILE_PATH = bin/data/ |
|||
|
|||
OTHER_LDFLAGS = $(OF_CORE_LIBS) $(OF_CORE_FRAMEWORKS) |
|||
HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS) |
@ -1,36 +0,0 @@ |
|||
# Gamepad Example |
|||
|
|||
This example demonstrates how to use SDL2 with ofxPiMapper in order to use gamepad for mapping. Below is what you have to do. |
|||
|
|||
## Install SDL2 |
|||
|
|||
``` |
|||
sudo apt-get update |
|||
sudo apt-get -y install libsdl2-dev |
|||
``` |
|||
|
|||
In order to compile the example, one has to add extra compiler flags (see `config.make`). |
|||
|
|||
``` |
|||
PROJECT_LDFLAGS += -I/usr/include/SDL2 -lSDL2 |
|||
``` |
|||
|
|||
What it does is the following: `-I/usr/include/SDL2` includes SDL2, `-lSDL2` links our program against it. |
|||
|
|||
**Note:** This is tested on Raspberry Pi so far. |
|||
|
|||
## Define Game Controller |
|||
|
|||
On each system a speciffic controller will have a different GUID. When `example_gamepad` is launched, it reads connected USB game controllers. |
|||
|
|||
``` |
|||
Joystick INIT success |
|||
Joystick num axes: 2 |
|||
Joystick ID: 0 |
|||
Joystick Name: usb gamepad |
|||
Joystick GUID: 030000001008000001e5000010010000 |
|||
``` |
|||
|
|||
Use this to add another config block in `controllers.xml` |
|||
|
|||
|
@ -1,4 +0,0 @@ |
|||
ofxGui |
|||
ofxPiMapper |
|||
ofxXmlSettings |
|||
ofxOMXPlayer |
@ -1,3 +0,0 @@ |
|||
ofxGui |
|||
ofxPiMapper |
|||
ofxXmlSettings |
@ -1,71 +0,0 @@ |
|||
<controllers> |
|||
|
|||
<controller> |
|||
<name>Wireless Controller</name> |
|||
<guid_osx>4c05000000000000c405000000000000</guid_osx> |
|||
<guid_linux>030000004c050000c405000011010000</guid_linux> |
|||
<guid_windows></guid_windows> |
|||
<left>h0:8</left> |
|||
<right>h0:2</right> |
|||
<up>h0:1</up> |
|||
<down>h0:4</down> |
|||
<a>b1</a> |
|||
<b>b2</b> |
|||
<x>b0</x> |
|||
<y>b3</y> |
|||
<select>b12</select> |
|||
<start>b13</start> |
|||
</controller> |
|||
|
|||
<controller> |
|||
<name>USB gamepad</name> |
|||
<guid_osx>1f0800000000000001e4000000000000</guid_osx> |
|||
<guid_linux>030000001f08000001e4000010010000</guid_linux> |
|||
<guid_windows></guid_windows> |
|||
<left>a0</left> |
|||
<right>a0</right> |
|||
<up>a1</up> |
|||
<down>a1</down> |
|||
<a>b2</a> |
|||
<b>b1</b> |
|||
<x>b3</x> |
|||
<y>b0</y> |
|||
<select>b8</select> |
|||
<start>b9</start> |
|||
</controller> |
|||
|
|||
<controller> |
|||
<name>Generic USB Joystick</name> |
|||
<guid_osx>79000000000000000600000000000000</guid_osx> |
|||
<guid_linux>03000000790000000600000010010000</guid_linux> |
|||
<guid_windows></guid_windows> |
|||
<left>a0</left> |
|||
<right>a0</right> |
|||
<up>a1</up> |
|||
<down>a1</down> |
|||
<a>b2</a> |
|||
<b>b1</b> |
|||
<x>b3</x> |
|||
<y>b0</y> |
|||
<select>b8</select> |
|||
<start>b9</start> |
|||
</controller> |
|||
|
|||
<controller> |
|||
<name>Exlene USB Game Controller</name> |
|||
<guid_osx></guid_osx> |
|||
<guid_linux>030000001008000001e5000010010000</guid_linux> |
|||
<guid_windows></guid_windows> |
|||
<left>a0</left> |
|||
<right>a0</right> |
|||
<up>a1</up> |
|||
<down>a1</down> |
|||
<a>b2</a> |
|||
<b>b1</b> |
|||
<x>b3</x> |
|||
<y>b0</y> |
|||
<select>b8</select> |
|||
<start>b9</start> |
|||
</controller> |
|||
|
|||
</controllers> |
@ -1,81 +0,0 @@ |
|||
<surfaces> |
|||
<surface type="0"> |
|||
<vertices> |
|||
<vertex> |
|||
<x>400.000000000</x> |
|||
<y>21.000000000</y> |
|||
</vertex> |
|||
<vertex> |
|||
<x>744.000000000</x> |
|||
<y>353.000000000</y> |
|||
</vertex> |
|||
<vertex> |
|||
<x>51.000000000</x> |
|||
<y>425.000000000</y> |
|||
</vertex> |
|||
</vertices> |
|||
<texCoords> |
|||
<texCoord> |
|||
<x>0.500000000</x> |
|||
<y>0.000000000</y> |
|||
</texCoord> |
|||
<texCoord> |
|||
<x>1.000000000</x> |
|||
<y>1.000000000</y> |
|||
</texCoord> |
|||
<texCoord> |
|||
<x>0.000000000</x> |
|||
<y>1.000000000</y> |
|||
</texCoord> |
|||
</texCoords> |
|||
<source> |
|||
<source-type>video</source-type> |
|||
<source-name>BEAMMM (loop)-HD.mp4</source-name> |
|||
</source> |
|||
</surface> |
|||
<surface type="1"> |
|||
<vertices> |
|||
<vertex> |
|||
<x>243.000000000</x> |
|||
<y>149.000000000</y> |
|||
</vertex> |
|||
<vertex> |
|||
<x>687.040527344</x> |
|||
<y>189.606384277</y> |
|||
</vertex> |
|||
<vertex> |
|||
<x>692.000000000</x> |
|||
<y>397.000000000</y> |
|||
</vertex> |
|||
<vertex> |
|||
<x>212.000000000</x> |
|||
<y>425.000000000</y> |
|||
</vertex> |
|||
</vertices> |
|||
<texCoords> |
|||
<texCoord> |
|||
<x>0.000000000</x> |
|||
<y>0.000000000</y> |
|||
</texCoord> |
|||
<texCoord> |
|||
<x>1.000000000</x> |
|||
<y>0.000000000</y> |
|||
</texCoord> |
|||
<texCoord> |
|||
<x>1.000000000</x> |
|||
<y>1.000000000</y> |
|||
</texCoord> |
|||
<texCoord> |
|||
<x>0.000000000</x> |
|||
<y>1.000000000</y> |
|||
</texCoord> |
|||
</texCoords> |
|||
<source> |
|||
<source-type>image</source-type> |
|||
<source-name>clipartist-net-WSPOD7-clipart.png</source-name> |
|||
</source> |
|||
<properties> |
|||
<perspectiveWarping>1</perspectiveWarping> |
|||
</properties> |
|||
</surface> |
|||
</surfaces> |
Before Width: | Height: | Size: 181 KiB |
Binary file not shown.
@ -1 +0,0 @@ |
|||
PROJECT_LDFLAGS += -I/usr/include/SDL2 -lSDL2 |
File diff suppressed because it is too large
@ -1,81 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<Scheme |
|||
LastUpgradeVersion = "0720" |
|||
version = "1.3"> |
|||
<BuildAction |
|||
parallelizeBuildables = "YES" |
|||
buildImplicitDependencies = "YES"> |
|||
<BuildActionEntries> |
|||
<BuildActionEntry |
|||
buildForTesting = "YES" |
|||
buildForRunning = "YES" |
|||
buildForProfiling = "YES" |
|||
buildForArchiving = "YES" |
|||
buildForAnalyzing = "YES"> |
|||
<BuildableReference |
|||
BuildableIdentifier = "primary" |
|||
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2" |
|||
BuildableName = "example_gamepad.app" |
|||
BlueprintName = "example_gamepad" |
|||
ReferencedContainer = "container:example_gamepad.xcodeproj"> |
|||
</BuildableReference> |
|||
</BuildActionEntry> |
|||
</BuildActionEntries> |
|||
</BuildAction> |
|||
<TestAction |
|||
buildConfiguration = "Debug" |
|||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" |
|||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" |
|||
shouldUseLaunchSchemeArgsEnv = "YES"> |
|||
<Testables> |
|||
</Testables> |
|||
<AdditionalOptions> |
|||
</AdditionalOptions> |
|||
</TestAction> |
|||
<LaunchAction |
|||
buildConfiguration = "Debug" |
|||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" |
|||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" |
|||
launchStyle = "0" |
|||
useCustomWorkingDirectory = "NO" |
|||
ignoresPersistentStateOnLaunch = "NO" |
|||
debugDocumentVersioning = "YES" |
|||
debugServiceExtension = "internal" |
|||
allowLocationSimulation = "YES"> |
|||
<BuildableProductRunnable |
|||
runnableDebuggingMode = "0"> |
|||
<BuildableReference |
|||
BuildableIdentifier = "primary" |
|||
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2" |
|||
BuildableName = "example_gamepad.app" |
|||
BlueprintName = "example_gamepad" |
|||
ReferencedContainer = "container:example_gamepad.xcodeproj"> |
|||
</BuildableReference> |
|||
</BuildableProductRunnable> |
|||
<AdditionalOptions> |
|||
</AdditionalOptions> |
|||
</LaunchAction> |
|||
<ProfileAction |
|||
buildConfiguration = "Debug" |
|||
shouldUseLaunchSchemeArgsEnv = "YES" |
|||
savedToolIdentifier = "" |
|||
useCustomWorkingDirectory = "NO" |
|||
debugDocumentVersioning = "YES"> |
|||
<MacroExpansion> |
|||
<BuildableReference |
|||
BuildableIdentifier = "primary" |
|||
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2" |
|||
BuildableName = "example_gamepad.app" |
|||
BlueprintName = "example_gamepad" |
|||
ReferencedContainer = "container:example_gamepad.xcodeproj"> |
|||
</BuildableReference> |
|||
</MacroExpansion> |
|||
</ProfileAction> |
|||
<AnalyzeAction |
|||
buildConfiguration = "Debug"> |
|||
</AnalyzeAction> |
|||
<ArchiveAction |
|||
buildConfiguration = "Debug" |
|||
revealArchiveInOrganizer = "YES"> |
|||
</ArchiveAction> |
|||
</Scheme> |
@ -1,81 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<Scheme |
|||
LastUpgradeVersion = "0720" |
|||
version = "1.3"> |
|||
<BuildAction |
|||
parallelizeBuildables = "YES" |
|||
buildImplicitDependencies = "YES"> |
|||
<BuildActionEntries> |
|||
<BuildActionEntry |
|||
buildForTesting = "YES" |
|||
buildForRunning = "YES" |
|||
buildForProfiling = "YES" |
|||
buildForArchiving = "YES" |
|||
buildForAnalyzing = "YES"> |
|||
<BuildableReference |
|||
BuildableIdentifier = "primary" |
|||
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2" |
|||
BuildableName = "example_gamepad.app" |
|||
BlueprintName = "example_gamepad" |
|||
ReferencedContainer = "container:example_gamepad.xcodeproj"> |
|||
</BuildableReference> |
|||
</BuildActionEntry> |
|||
</BuildActionEntries> |
|||
</BuildAction> |
|||
<TestAction |
|||
buildConfiguration = "Release" |
|||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" |
|||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" |
|||
shouldUseLaunchSchemeArgsEnv = "YES"> |
|||
<Testables> |
|||
</Testables> |
|||
<AdditionalOptions> |
|||
</AdditionalOptions> |
|||
</TestAction> |
|||
<LaunchAction |
|||
buildConfiguration = "Release" |
|||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" |
|||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" |
|||
launchStyle = "0" |
|||
useCustomWorkingDirectory = "NO" |
|||
ignoresPersistentStateOnLaunch = "NO" |
|||
debugDocumentVersioning = "YES" |
|||
debugServiceExtension = "internal" |
|||
allowLocationSimulation = "YES"> |
|||
<BuildableProductRunnable |
|||
runnableDebuggingMode = "0"> |
|||
<BuildableReference |
|||
BuildableIdentifier = "primary" |
|||
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2" |
|||
BuildableName = "example_gamepad.app" |
|||
BlueprintName = "example_gamepad" |
|||
ReferencedContainer = "container:example_gamepad.xcodeproj"> |
|||
</BuildableReference> |
|||
</BuildableProductRunnable> |
|||
<AdditionalOptions> |
|||
</AdditionalOptions> |
|||
</LaunchAction> |
|||
<ProfileAction |
|||
buildConfiguration = "Release" |
|||
shouldUseLaunchSchemeArgsEnv = "YES" |
|||
savedToolIdentifier = "" |
|||
useCustomWorkingDirectory = "NO" |
|||
debugDocumentVersioning = "YES"> |
|||
<MacroExpansion> |
|||
<BuildableReference |
|||
BuildableIdentifier = "primary" |
|||
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2" |
|||
BuildableName = "example_gamepad.app" |
|||
BlueprintName = "example_gamepad" |
|||
ReferencedContainer = "container:example_gamepad.xcodeproj"> |
|||
</BuildableReference> |
|||
</MacroExpansion> |
|||
</ProfileAction> |
|||
<AnalyzeAction |
|||
buildConfiguration = "Release"> |
|||
</AnalyzeAction> |
|||
<ArchiveAction |
|||
buildConfiguration = "Release" |
|||
revealArchiveInOrganizer = "YES"> |
|||
</ArchiveAction> |
|||
</Scheme> |
@ -1,22 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
|||
<plist version="1.0"> |
|||
<dict> |
|||
<key>CFBundleDevelopmentRegion</key> |
|||
<string>English</string> |
|||
<key>CFBundleExecutable</key> |
|||
<string>${EXECUTABLE_NAME}</string> |
|||
<key>CFBundleIconFile</key> |
|||
<string>${ICON}</string> |
|||
<key>CFBundleIdentifier</key> |
|||
<string>cc.openFrameworks.ofapp</string> |
|||
<key>CFBundleInfoDictionaryVersion</key> |
|||
<string>6.0</string> |
|||
<key>CFBundlePackageType</key> |
|||
<string>APPL</string> |
|||
<key>CFBundleSignature</key> |
|||
<string>????</string> |
|||
<key>CFBundleVersion</key> |
|||
<string>1.0</string> |
|||
</dict> |
|||
</plist> |
@ -1,282 +0,0 @@ |
|||
#include "InputHandler.h" |
|||
|
|||
InputHandler * InputHandler::_instance = 0; |
|||
|
|||
InputHandler * InputHandler::instance(){ |
|||
if(_instance == 0){ |
|||
_instance = new InputHandler(); |
|||
} |
|||
return _instance; |
|||
} |
|||
|
|||
void InputHandler::initialise(){ |
|||
|
|||
if(SDL_Init(SDL_INIT_JOYSTICK) >= 0){ |
|||
std::cout << "Joystick INIT success" << std::endl; |
|||
} |
|||
|
|||
if(SDL_NumJoysticks() > 0){ |
|||
for(int i = 0; i < SDL_NumJoysticks(); ++i){ |
|||
SDL_Joystick * joystick = SDL_JoystickOpen(i); |
|||
if(SDL_JoystickGetAttached(joystick) == SDL_TRUE){ |
|||
std::cout << "Joystick num axes: " << SDL_JoystickNumAxes(joystick) << std::endl; |
|||
std::cout << "Joystick ID: " << SDL_JoystickInstanceID(joystick) << std::endl; |
|||
std::cout << "Joystick Name: " << SDL_JoystickName(joystick) << std::endl; |
|||
|
|||
SDL_JoystickGUID guid = SDL_JoystickGetDeviceGUID(i); |
|||
char guid_str[1024]; |
|||
SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str)); |
|||
std::cout << "Joystick GUID: " << guid_str << std::endl; |
|||
|
|||
_joysticks.push_back(joystick); |
|||
}else{ |
|||
std::cout << SDL_GetError() << std::endl; |
|||
} |
|||
} |
|||
SDL_JoystickEventState(SDL_ENABLE); |
|||
_initialised = true; |
|||
std::cout << "Initialised " << _joysticks.size() << " joysticks" << std::endl; |
|||
}else{ |
|||
_initialised = false; |
|||
std::cout << "No joysticks initialised" << std::endl; |
|||
return; |
|||
} |
|||
|
|||
// Load the controllers.xml file if exists.
|
|||
if(ofFile::doesFileExist("controllers.xml")){ |
|||
ofxXmlSettings xml; |
|||
if(!xml.load("controllers.xml")){ |
|||
std::cout << "Failed to load controllers.xml" << std::endl; |
|||
} |
|||
|
|||
std::cout << "Loaded controllers.xml" << std::endl; |
|||
|
|||
// Find the right map for each initialized controller
|
|||
for(auto i = 0; i < _joysticks.size(); ++i){ |
|||
|
|||
// Get controller GUID first
|
|||
SDL_JoystickGUID guid = SDL_JoystickGetDeviceGUID(i); |
|||
char guid_str[1024]; |
|||
SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str)); |
|||
std::string guidString(guid_str); |
|||
|
|||
// Search for GUID in XML
|
|||
if(xml.tagExists("controllers")){ |
|||
xml.pushTag("controllers"); |
|||
|
|||
for(int ci = 0; ci < xml.getNumTags("controller"); ci++){ |
|||
if(xml.tagExists("controller", ci)){ |
|||
xml.pushTag("controller", ci); |
|||
|
|||
if(xml.getValue("guid_osx", "") == guidString || |
|||
xml.getValue("guid_linux", "") == guidString || |
|||
xml.getValue("guid_windows", "") == guidString){ |
|||
|
|||
std::cout << "Found map for GUID: " << guidString << std::endl; |
|||
|
|||
// We found our controller for the initialized joystick, let's map it
|
|||
std::map<ControllerCommand, ControllerItem> map; |
|||
map[COMMAND_LEFT] = getControllerItem(xml.getValue("left", "")); |
|||
map[COMMAND_RIGHT] = getControllerItem(xml.getValue("right", "")); |
|||
map[COMMAND_UP] = getControllerItem(xml.getValue("up", "")); |
|||
map[COMMAND_DOWN] = getControllerItem(xml.getValue("down", "")); |
|||
map[COMMAND_A] = getControllerItem(xml.getValue("a", "")); |
|||
map[COMMAND_B] = getControllerItem(xml.getValue("b", "")); |
|||
map[COMMAND_X] = getControllerItem(xml.getValue("x", "")); |
|||
map[COMMAND_Y] = getControllerItem(xml.getValue("y", "")); |
|||
map[COMMAND_SELECT] = getControllerItem(xml.getValue("select", "")); |
|||
map[COMMAND_START] = getControllerItem(xml.getValue("start", "")); |
|||
|
|||
// Add map to our database for a controller only if it is found
|
|||
_controllerMap[i] = map; |
|||
|
|||
// Return the xml oblect to the state before the for loop
|
|||
xml.popTag(); // controller[ci]
|
|||
|
|||
// Break the for loop as we found what we wanted
|
|||
break; |
|||
} |
|||
|
|||
// Return the xml oblect to the state before the for loop
|
|||
xml.popTag(); // controller[ci]
|
|||
} |
|||
} |
|||
xml.popTag(); // controllers
|
|||
} // if(xml.tagExists("controllers"))
|
|||
} // ofFile::doesFileExist("controllers.xml")
|
|||
}else{ |
|||
std::cout << "controllers.xml does not exist" << std::endl; |
|||
} |
|||
} |
|||
|
|||
void InputHandler::update(){ |
|||
SDL_Event event; |
|||
while(SDL_PollEvent(&event)){ |
|||
|
|||
ControllerCommand command = ControllerCommand::COMMAND_NONE; |
|||
|
|||
if(event.type == SDL_JOYHATMOTION){ |
|||
std::cout << "SDL_JOYHATMOTION" << std::endl; |
|||
|
|||
ControllerItem item; |
|||
item.type = CONTROLLER_HAT; |
|||
item.index = (int)event.jhat.hat; |
|||
item.value = (int)event.jhat.value; |
|||
|
|||
command = getControllerCommand((int)event.jhat.which, item); |
|||
std::cout << "hat value: " << item.value << std::endl; |
|||
std::cout << "command: " << controllerCommandToString(command) << std::endl; |
|||
std::cout << "----------" << std::endl; |
|||
} |
|||
|
|||
if(event.type == SDL_JOYAXISMOTION){ |
|||
if((event.jaxis.value < -3200) || (event.jaxis.value > 3200)){ |
|||
std::cout << "SDL_JOYAXISMOTION" << std::endl; |
|||
|
|||
ControllerItem item; |
|||
item.type = CONTROLLER_AXIS; |
|||
item.index = (int)event.jaxis.axis; |
|||
item.value = (int)event.jaxis.value; |
|||
|
|||
command = getControllerCommand((int)event.jaxis.which, item); |
|||
std::cout << "command: " << controllerCommandToString(command) << std::endl; |
|||
std::cout << "----------" << std::endl; |
|||
|
|||
} |
|||
} |
|||
|
|||
if(event.type == SDL_JOYBUTTONDOWN){ |
|||
std::cout << "SDL_JOYBUTTONDOWN" << std::endl; |
|||
|
|||
ControllerItem item; |
|||
item.type = CONTROLLER_BUTTON; |
|||
item.index = (int)event.jbutton.button; |
|||
item.value = 1; // Button has only one value
|
|||
|
|||
command = getControllerCommand((int)event.jbutton.which, item); |
|||
std::cout << "command: " << controllerCommandToString(command) << std::endl; |
|||
std::cout << "----------" << std::endl; |
|||
} |
|||
|
|||
if(command != ControllerCommand::COMMAND_NONE){ |
|||
ofSendMessage(ofMessage(ofToString(command))); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void InputHandler::clean(){ |
|||
if(_initialised){ |
|||
for(int i = 0; i < _joysticks.size(); ++i){ |
|||
SDL_JoystickClose(_joysticks[i]); |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
bool InputHandler::initialised(){ |
|||
return _initialised; |
|||
} |
|||
|
|||
ControllerItem InputHandler::getControllerItem(std::string code){ |
|||
ControllerItem item; |
|||
|
|||
// Determine type
|
|||
if(code.substr(0, 1) == "b"){ |
|||
item.type = CONTROLLER_BUTTON; |
|||
}else if(code.substr(0, 1) == "h"){ |
|||
item.type = CONTROLLER_HAT; |
|||
}else if(code.substr(0, 1) == "a"){ |
|||
item.type = CONTROLLER_AXIS; |
|||
} |
|||
|
|||
// If it is a hat, we need a value, otherwise set it to -1
|
|||
if(item.type == CONTROLLER_HAT){ |
|||
item.index = ofToInt(code.substr(1, 1)); |
|||
item.value = ofToInt(code.substr(3)); |
|||
}else{ |
|||
item.index = ofToInt(code.substr(1)); |
|||
item.value = -1; |
|||
} |
|||
|
|||
return item; |
|||
} |
|||
|
|||
ControllerCommand InputHandler::getControllerCommand(int controllerIndex, ControllerItem & item){ |
|||
std::cout << "controllerIndex: " << controllerIndex << std::endl; |
|||
|
|||
std::map<int, std::map<ControllerCommand, ControllerItem>>::iterator it; |
|||
it = _controllerMap.find(controllerIndex); |
|||
if(it == _controllerMap.end()){ |
|||
return ControllerCommand::COMMAND_NONE; |
|||
} |
|||
|
|||
std::map<ControllerCommand, ControllerItem>::iterator mit; |
|||
for(mit = it->second.begin(); mit != it->second.end(); mit++){ |
|||
if(mit->second.type == item.type && mit->second.index == item.index){ |
|||
|
|||
// In case of axes, we need to check the sign
|
|||
if(mit->second.type == CONTROLLER_AXIS){ |
|||
if(mit->first == ControllerCommand::COMMAND_LEFT && item.value > 0){ |
|||
continue; // value must be negative for left
|
|||
} |
|||
|
|||
if(mit->first == ControllerCommand::COMMAND_RIGHT && item.value < 0){ |
|||
continue; // value must be positive for right
|
|||
} |
|||
|
|||
if(mit->first == ControllerCommand::COMMAND_UP && item.value > 0){ |
|||
continue; // value must be negative for up
|
|||
} |
|||
|
|||
if(mit->first == ControllerCommand::COMMAND_DOWN && item.value < 0){ |
|||
continue; // value must be positive for down
|
|||
} |
|||
|
|||
return mit->first; |
|||
} |
|||
|
|||
// In case of hat, we need to compare hat values
|
|||
if(mit->second.type == CONTROLLER_HAT){ |
|||
if(mit->second.value == item.value){ |
|||
return mit->first; |
|||
}else{ |
|||
continue; |
|||
} |
|||
} |
|||
|
|||
// In case of buttons type and index is enough
|
|||
return mit->first; |
|||
} |
|||
} |
|||
|
|||
return ControllerCommand::COMMAND_NONE; |
|||
} |
|||
|
|||
std::string InputHandler::controllerCommandToString(ControllerCommand com){ |
|||
if(com == COMMAND_NONE){ |
|||
return "COMMAND_NONE"; |
|||
}else if(com == COMMAND_LEFT){ |
|||
return "COMMAND_LEFT"; |
|||
}else if(com == COMMAND_RIGHT){ |
|||
return "COMMAND_RIGHT"; |
|||
}else if(com == COMMAND_UP){ |
|||
return "COMMAND_UP"; |
|||
}else if(com == COMMAND_DOWN){ |
|||
return "COMMAND_DOWN"; |
|||
}else if(com == COMMAND_A){ |
|||
return "COMMAND_A"; |
|||
}else if(com == COMMAND_B){ |
|||
return "COMMAND_B"; |
|||
}else if(com == COMMAND_X){ |
|||
return "COMMAND_X"; |
|||
}else if(com == COMMAND_Y){ |
|||
return "COMMAND_Y"; |
|||
}else if(com == COMMAND_SELECT){ |
|||
return "COMMAND_SELECT"; |
|||
}else if(com == COMMAND_START){ |
|||
return "COMMAND_START"; |
|||
} |
|||
|
|||
return "COMMAND_NONE"; |
|||
} |
|||
|
@ -1,61 +0,0 @@ |
|||
#pragma once |
|||
|
|||
// These are the std::strings reported by SDL2's SDL_JoystickGetGUIDString:
|
|||
// https://wiki.libsdl.org/SDL_JoystickGetGUIDString
|
|||
|
|||
#include <vector> |
|||
#include <string> |
|||
#include <sstream> |
|||
#include <iostream> |
|||
#include "ofMain.h" |
|||
#include "ofxXmlSettings.h" |
|||
#include <SDL2/SDL.h> |
|||
|
|||
enum ControllerItemType{ |
|||
CONTROLLER_BUTTON, |
|||
CONTROLLER_AXIS, |
|||
CONTROLLER_HAT |
|||
}; |
|||
|
|||
enum ControllerCommand{ |
|||
COMMAND_NONE, |
|||
COMMAND_LEFT, |
|||
COMMAND_RIGHT, |
|||
COMMAND_UP, |
|||
COMMAND_DOWN, |
|||
COMMAND_A, |
|||
COMMAND_B, |
|||
COMMAND_X, |
|||
COMMAND_Y, |
|||
COMMAND_SELECT, |
|||
COMMAND_START |
|||
}; |
|||
|
|||
struct ControllerItem{ |
|||
ControllerItemType type; |
|||
int index; |
|||
int value; |
|||
}; |
|||
|
|||
class InputHandler{ |
|||
public: |
|||
static InputHandler * instance(); |
|||
|
|||
void initialise(); |
|||
void update(); |
|||
void clean(); |
|||
|
|||
bool initialised(); |
|||
|
|||
ControllerItem getControllerItem(std::string code); |
|||
ControllerCommand getControllerCommand(int controllerIndex, ControllerItem & item); |
|||
std::string controllerCommandToString(ControllerCommand com); |
|||
|
|||
private: |
|||
InputHandler(){} |
|||
~InputHandler(){} |
|||
static InputHandler * _instance; |
|||
bool _initialised; |
|||
std::vector<SDL_Joystick *> _joysticks; |
|||
std::map<int, std::map<ControllerCommand, ControllerItem>> _controllerMap; |
|||
}; |
@ -1,24 +0,0 @@ |
|||
#include "ofMain.h" |
|||
#include "ofApp.h" |
|||
#include <string> |
|||
#include <vector> |
|||
|
|||
int main(int argc, char * argv[]){ |
|||
bool fullscreen = false; |
|||
|
|||
std::vector<std::string> arguments = std::vector<std::string>(argv, argv + argc); |
|||
for(int i = 0; i < arguments.size(); ++i){ |
|||
if(arguments.at(i) == "-f"){ |
|||
fullscreen = true; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if(fullscreen){ |
|||
ofSetupOpenGL(800, 450, OF_FULLSCREEN); |
|||
}else{ |
|||
ofSetupOpenGL(800, 450, OF_WINDOW); |
|||
} |
|||
|
|||
ofRunApp(new ofApp()); |
|||
} |
@ -1,98 +0,0 @@ |
|||
#include "ofApp.h" |
|||
|
|||
void ofApp::setup(){ |
|||
ofBackground(0); |
|||
|
|||
#ifdef TARGET_RASPBERRY_PI |
|||
ofSetFullscreen(true); |
|||
#endif |
|||
|
|||
mapper.setup(); |
|||
InputHandler::instance()->initialise(); |
|||
} |
|||
|
|||
void ofApp::update(){ |
|||
mapper.update(); |
|||
InputHandler::instance()->update(); |
|||
} |
|||
|
|||
void ofApp::draw(){ |
|||
mapper.draw(); |
|||
} |
|||
|
|||
void ofApp::keyPressed(int key){ |
|||
mapper.keyPressed(key); |
|||
} |
|||
|
|||
void ofApp::keyReleased(int key){ |
|||
mapper.keyReleased(key); |
|||
} |
|||
|
|||
void ofApp::mousePressed(int x, int y, int button){ |
|||
mapper.mousePressed(x, y, button); |
|||
} |
|||
|
|||
void ofApp::mouseDragged(int x, int y, int button){ |
|||
mapper.mouseDragged(x, y, button); |
|||
} |
|||
|
|||
void ofApp::mouseReleased(int x, int y, int button){ |
|||
mapper.mouseReleased(x, y, button); |
|||
} |
|||
|
|||
void ofApp::messageReceived(ofMessage & message){ |
|||
ControllerCommand com = (ControllerCommand)ofToInt(message.message); |
|||
handleController(com); |
|||
} |
|||
|
|||
/* These values we take into consideration
|
|||
|
|||
↖ ↑ ↗ y |
|||
← → -- x b |
|||
↙ ↓ ↘ a |
|||
|
|||
*/ |
|||
void ofApp::handleController(ControllerCommand com){ |
|||
if(com == ControllerCommand::COMMAND_LEFT){ |
|||
mapper.moveSelection(ofx::piMapper::Vec3(-5.0f, 0.0f, 0.0f)); |
|||
}else if(com == ControllerCommand::COMMAND_RIGHT){ |
|||
mapper.moveSelection(ofx::piMapper::Vec3(5.0f, 0.0f, 0.0f)); |
|||
}else if(com == ControllerCommand::COMMAND_UP){ |
|||
mapper.moveSelection(ofx::piMapper::Vec3(0.0f, -5.0f, 0.0f)); |
|||
}else if(com == ControllerCommand::COMMAND_DOWN){ |
|||
mapper.moveSelection(ofx::piMapper::Vec3(0.0f, 5.0f, 0.0f)); |
|||
}else if(com == ControllerCommand::COMMAND_A){ |
|||
if(mapper.getMode() == ofx::piMapper::Mode::MAPPING_MODE){ |
|||
mapper.selectNextVertex(); |
|||
}else if(mapper.getMode() == ofx::piMapper::Mode::TEXTURE_MODE){ |
|||
mapper.selectNextTexCoord(); |
|||
}else{ |
|||
mapper.setMode(ofx::piMapper::Mode::MAPPING_MODE); |
|||
} |
|||
}else if(com == ControllerCommand::COMMAND_B){ |
|||
if(mapper.getMode() == ofx::piMapper::Mode::MAPPING_MODE){ |
|||
mapper.selectNextSurface(); |
|||
}else{ |
|||
mapper.setMode(ofx::piMapper::Mode::MAPPING_MODE); |
|||
} |
|||
}else if(com == ControllerCommand::COMMAND_X){ |
|||
if(mapper.getMode() == ofx::piMapper::Mode::MAPPING_MODE){ |
|||
mapper.setNextSource(); |
|||
}else{ |
|||
mapper.setMode(ofx::piMapper::Mode::MAPPING_MODE); |
|||
} |
|||
}else if(com == ControllerCommand::COMMAND_Y){ |
|||
if(mapper.getMode() == ofx::piMapper::Mode::MAPPING_MODE){ |
|||
mapper.setMode(ofx::piMapper::Mode::TEXTURE_MODE); |
|||
}else if(mapper.getMode() == ofx::piMapper::Mode::TEXTURE_MODE){ |
|||
mapper.setMode(ofx::piMapper::Mode::MAPPING_MODE); |
|||
}else{ |
|||
mapper.setMode(ofx::piMapper::Mode::MAPPING_MODE); |
|||
} |
|||
}else if(com == ControllerCommand::COMMAND_SELECT){ |
|||
mapper.togglePause(); |
|||
}else if(com == ControllerCommand::COMMAND_START){ |
|||
mapper.saveProject(); |
|||
mapper.setMode(ofx::piMapper::Mode::PRESENTATION_MODE); |
|||
} |
|||
} |
@ -1,26 +0,0 @@ |
|||
#pragma once |
|||
|
|||
#include "ofMain.h" |
|||
#include "ofxPiMapper.h" |
|||
#include "InputHandler.h" |
|||
#include "Vec3.h" |
|||
|
|||
class ofApp : public ofBaseApp { |
|||
public: |
|||
void setup(); |
|||
void update(); |
|||
void draw(); |
|||
|
|||
void keyPressed(int key); |
|||
void keyReleased(int key); |
|||
|
|||
void mousePressed(int x, int y, int button); |
|||
void mouseDragged(int x, int y, int button); |
|||
void mouseReleased(int x, int y, int button); |
|||
|
|||
void messageReceived(ofMessage & message); |
|||
|
|||
void handleController(ControllerCommand com); |
|||
|
|||
ofxPiMapper mapper; |
|||
}; |
Loading…
Reference in new issue