Created
December 3, 2016 20:30
-
-
Save Quintus/3308846ade1e0d87eebe21e56db4a073 to your computer and use it in GitHub Desktop.
Super-simple test program for TSC joystick testing
This file contains hidden or 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
/* Super-simple joystick testing program. | |
* Written by Marvin Gülker, on 2016-12-03. | |
* Compile with: | |
* $ g++ joystick.cpp -o joystick -lsfml-graphics -lsfml-window -lsfml-system | |
* Run as: | |
* ./joystick | |
*/ | |
#include <iostream> | |
#include <SFML/Graphics.hpp> | |
#define JOYSTICK_NUM 0 | |
int main() | |
{ | |
sf::RenderWindow window(sf::VideoMode(800, 600), "Joystick test"); | |
sf::Joystick::update(); | |
if (sf::Joystick::isConnected(JOYSTICK_NUM)) { | |
sf::Joystick::Identification info = sf::Joystick::getIdentification(JOYSTICK_NUM); | |
std::string name(reinterpret_cast<const char*>(info.name.toUtf8().c_str())); | |
std::cout << "Joystick detected: " | |
<< name | |
<< "(" << info.vendorId << ":" << info.productId << ")" | |
<< std::endl; | |
std::cout << "Button count: " << sf::Joystick::getButtonCount(JOYSTICK_NUM) << std::endl; | |
for (int i=0; i < sf::Joystick::AxisCount; i++) { | |
sf::Joystick::Axis a = static_cast<sf::Joystick::Axis>(i); | |
std::cout << "Axis " << i << "? "; | |
if (sf::Joystick::hasAxis(JOYSTICK_NUM, a)) { | |
std::cout << "yes, currently at " | |
<< sf::Joystick::getAxisPosition(JOYSTICK_NUM, a); | |
} | |
else { | |
std::cout << "no"; | |
} | |
std::cout << std::endl; | |
} | |
std::cout << std::endl; | |
} | |
else { | |
std::cout << "No joystick detected" << std::endl; | |
} | |
while (window.isOpen()) { | |
sf::Event evt; | |
while (window.pollEvent(evt)) { | |
if (evt.type == sf::Event::Closed) { | |
window.close(); | |
} | |
} | |
window.clear(sf::Color::Black); | |
window.display(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment