QMainWindow(parent),
ui(new Ui::jstt)
{
- int i;
-
ui->setupUi(this);
- if( SDL_Init(SDL_INIT_JOYSTICK) == 0 ) {
- for(i = 0; i < SDL_NumJoysticks(); i++) {
- this->jsNames.append(SDL_JoystickName(i));
- }
- ui->Joysticks->addItems(this->jsNames);
- }
+ this->joystick = NULL;
+ this->init();
}
jstt::~jstt()
{
delete ui;
+
+ if( jsIsOpen() ) jsClose();
+
+ SDL_Quit();
+}
+
+void jstt::init()
+{
+ QStringList jsNames;
+
+ if( SDL_Init(SDL_INIT_JOYSTICK) == 0 ) {
+
+ for(int i = 0; i < SDL_NumJoysticks(); i++) {
+ jsNames.append(SDL_JoystickName(i));
+ }
+ connect(&jsPullTimer, SIGNAL(timeout()), this, SLOT(processJs()));
+
+ ui->Joysticks->addItems(jsNames);
+ ui->Joysticks->setCurrentIndex(0); // This will trigger on_Joysticks_currentIndexChanged(int)
+ }
}
-void jstt::changeEvent(QEvent *e)
+void jstt::jsOpen(int js)
{
- QMainWindow::changeEvent(e);
- switch (e->type()) {
- case QEvent::LanguageChange:
- ui->retranslateUi(this);
- break;
- default:
- break;
+ if( jsIsOpen() ) jsClose();
+
+ joystick = SDL_JoystickOpen(js);
+ if( joystick ) {
+ jsPullTimer.start(eventTimeout);
+ /*
+
+ TODO:
+
+ numAxes = SDL_JoystickNumAxes(joystick);
+ numButtons = SDL_JoystickNumButtons(joystick);
+ numHats = SDL_JoystickNumHats(joystick);
+ numTrackballs = SDL_JoystickNumBalls(joystick);
+ JoystickTimer.start(eventTimeout);
+
+ When we have found out how many axes, buttons etc, we can expand the GUI further
+ */
+ return;
+ } else {
+ /*
+ One should make sure the program will react on this situation instead of just
+ returning.
+ */
+ return;
}
}
+
+void jstt::jsClose()
+{
+ this->jsPullTimer.stop();
+ if( joystick ) SDL_JoystickClose(joystick);
+ joystick = NULL;
+}
+
+void jstt::processJs()
+{
+ ui->Chan_1_bar->setValue(30);
+}
+
+void jstt::on_Joysticks_currentIndexChanged(int index)
+{
+ this->jsOpen(index);
+}