mirror of
https://github.com/lostjared/Acid.Cam.v2.Qt.git
synced 2025-12-14 10:50:01 +01:00
adding joystick support
This commit is contained in:
@@ -9,12 +9,12 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
|||||||
CONFIG += c++11
|
CONFIG += c++11
|
||||||
DEPENDPATH += .
|
DEPENDPATH += .
|
||||||
INCLUDEPATH += . /usr/include/ /usr/local/include
|
INCLUDEPATH += . /usr/include/ /usr/local/include
|
||||||
LIBS += `pkg-config acidcam opencv --libs` -lGL
|
LIBS += `pkg-config acidcam opencv sdl2 --libs` -lGL
|
||||||
#LIBS += -lopencv_contrib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_video
|
#LIBS += -lopencv_contrib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_video
|
||||||
#LIBS += -L/usr/local/lib -lopencv_world
|
#LIBS += -L/usr/local/lib -lopencv_world
|
||||||
QMAKE_CXXFLAGS += `pkg-config acidcam opencv --cflags`
|
QMAKE_CXXFLAGS += `pkg-config acidcam opencv sdl2 --cflags`
|
||||||
RESOURCES += qresource.qrc
|
RESOURCES += qresource.qrc
|
||||||
QMAKE_CFLAGS_ISYSTEM = -I
|
QMAKE_CFLAGS_ISYSTEM = -I
|
||||||
# Input
|
# Input
|
||||||
HEADERS += main_window.h new_dialog.h plugin.h qtheaders.h select_image.h display_window.h playback_thread.h search_box.h goto_window.h chroma_window.h user_define.h dl-man.h image_window.h options_window.h gl_display.h
|
HEADERS += main_window.h new_dialog.h plugin.h qtheaders.h select_image.h display_window.h playback_thread.h search_box.h goto_window.h chroma_window.h user_define.h dl-man.h image_window.h options_window.h gl_display.h controller.h
|
||||||
SOURCES += main.cpp main_window.cpp new_dialog.cpp plugin.cpp select_image.cpp display_window.cpp playback_thread.cpp search_box.cpp goto_window.cpp chroma_window.cpp user_define.cpp dl-man.cpp image_window.cpp options_window.cpp gl_display.cpp
|
SOURCES += main.cpp main_window.cpp new_dialog.cpp plugin.cpp select_image.cpp display_window.cpp playback_thread.cpp search_box.cpp goto_window.cpp chroma_window.cpp user_define.cpp dl-man.cpp image_window.cpp options_window.cpp gl_display.cpp controller.cpp
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
|||||||
CONFIG += c++11
|
CONFIG += c++11
|
||||||
DEPENDPATH += .
|
DEPENDPATH += .
|
||||||
INCLUDEPATH += . /usr/include/ /usr/local/include
|
INCLUDEPATH += . /usr/include/ /usr/local/include
|
||||||
LIBS += `pkg-config acidcam opencv4 --libs` -framework OpenGL
|
LIBS += `pkg-config acidcam opencv4 sdl2 --libs` -framework OpenGL
|
||||||
#LIBS += -lopencv_contrib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_video
|
#LIBS += -lopencv_contrib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_video
|
||||||
#LIBS += -L/usr/local/lib -lopencv_world
|
#LIBS += -L/usr/local/lib -lopencv_world
|
||||||
QMAKE_CXXFLAGS += `pkg-config acidcam opencv4 --cflags`
|
QMAKE_CXXFLAGS += `pkg-config acidcam opencv4 sdl2 --cflags`
|
||||||
RESOURCES += qresource.qrc
|
RESOURCES += qresource.qrc
|
||||||
QMAKE_CFLAGS_ISYSTEM = -I
|
QMAKE_CFLAGS_ISYSTEM = -I
|
||||||
# Input
|
# Input
|
||||||
HEADERS += main_window.h new_dialog.h plugin.h qtheaders.h select_image.h display_window.h playback_thread.h search_box.h goto_window.h chroma_window.h user_define.h dl-man.h image_window.h options_window.h gl_display.h
|
HEADERS += main_window.h new_dialog.h plugin.h qtheaders.h select_image.h display_window.h playback_thread.h search_box.h goto_window.h chroma_window.h user_define.h dl-man.h image_window.h options_window.h gl_display.h controller.h
|
||||||
SOURCES += main.cpp main_window.cpp new_dialog.cpp plugin.cpp select_image.cpp display_window.cpp playback_thread.cpp search_box.cpp goto_window.cpp chroma_window.cpp user_define.cpp dl-man.cpp image_window.cpp options_window.cpp gl_display.cpp
|
SOURCES += main.cpp main_window.cpp new_dialog.cpp plugin.cpp select_image.cpp display_window.cpp playback_thread.cpp search_box.cpp goto_window.cpp chroma_window.cpp user_define.cpp dl-man.cpp image_window.cpp options_window.cpp gl_display.cpp controller.cpp
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
|||||||
CONFIG += c++11
|
CONFIG += c++11
|
||||||
DEPENDPATH += .
|
DEPENDPATH += .
|
||||||
INCLUDEPATH += . /usr/include/ /usr/local/include
|
INCLUDEPATH += . /usr/include/ /usr/local/include
|
||||||
LIBS += `pkg-config acidcam opencv4 --libs` -lGLU
|
LIBS += `pkg-config acidcam opencv4 sdl2 --libs` -lGLU
|
||||||
#LIBS += -lopencv_contrib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_video
|
#LIBS += -lopencv_contrib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_video
|
||||||
#LIBS += -L/usr/local/lib -lopencv_world
|
#LIBS += -L/usr/local/lib -lopencv_world
|
||||||
QMAKE_CXXFLAGS += `pkg-config acidcam opencv4 --cflags`
|
QMAKE_CXXFLAGS += `pkg-config acidcam opencv4 sdl2 --cflags`
|
||||||
RESOURCES += qresource.qrc
|
RESOURCES += qresource.qrc
|
||||||
QMAKE_CFLAGS_ISYSTEM = -I
|
QMAKE_CFLAGS_ISYSTEM = -I
|
||||||
# Input
|
# Input
|
||||||
HEADERS += main_window.h new_dialog.h plugin.h qtheaders.h select_image.h display_window.h playback_thread.h search_box.h goto_window.h chroma_window.h user_define.h dl-man.h image_window.h options_window.h gl_display.h
|
HEADERS += main_window.h new_dialog.h plugin.h qtheaders.h select_image.h display_window.h playback_thread.h search_box.h goto_window.h chroma_window.h user_define.h dl-man.h image_window.h options_window.h gl_display.h controller.h
|
||||||
SOURCES += main.cpp main_window.cpp new_dialog.cpp plugin.cpp select_image.cpp display_window.cpp playback_thread.cpp search_box.cpp goto_window.cpp chroma_window.cpp user_define.cpp dl-man.cpp image_window.cpp options_window.cpp gl_display.cpp
|
SOURCES += main.cpp main_window.cpp new_dialog.cpp plugin.cpp select_image.cpp display_window.cpp playback_thread.cpp search_box.cpp goto_window.cpp chroma_window.cpp user_define.cpp dl-man.cpp image_window.cpp options_window.cpp gl_display.cpp controller.cpp
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
|||||||
CONFIG += c++11
|
CONFIG += c++11
|
||||||
DEPENDPATH += .
|
DEPENDPATH += .
|
||||||
INCLUDEPATH += . /usr/include/ /usr/local/include
|
INCLUDEPATH += . /usr/include/ /usr/local/include
|
||||||
LIBS += `pkg-config acidcam opencv4 --libs` -framework OpenGL
|
LIBS += `pkg-config acidcam opencv4 sdl2 --libs` -framework OpenGL
|
||||||
#LIBS += -lopencv_contrib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_video
|
#LIBS += -lopencv_contrib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_video
|
||||||
#LIBS += -L/usr/local/lib -lopencv_world
|
#LIBS += -L/usr/local/lib -lopencv_world
|
||||||
QMAKE_CXXFLAGS += `pkg-config acidcam opencv4 --cflags`
|
QMAKE_CXXFLAGS += `pkg-config acidcam opencv4 sdl2 --cflags`
|
||||||
RESOURCES += qresource.qrc
|
RESOURCES += qresource.qrc
|
||||||
QMAKE_CFLAGS_ISYSTEM = -I
|
QMAKE_CFLAGS_ISYSTEM = -I
|
||||||
# Input
|
# Input
|
||||||
HEADERS += main_window.h new_dialog.h plugin.h qtheaders.h select_image.h display_window.h playback_thread.h search_box.h goto_window.h chroma_window.h user_define.h dl-man.h image_window.h options_window.h gl_display.h
|
HEADERS += main_window.h new_dialog.h plugin.h qtheaders.h select_image.h display_window.h playback_thread.h search_box.h goto_window.h chroma_window.h user_define.h dl-man.h image_window.h options_window.h gl_display.h controller.h
|
||||||
SOURCES += main.cpp main_window.cpp new_dialog.cpp plugin.cpp select_image.cpp display_window.cpp playback_thread.cpp search_box.cpp goto_window.cpp chroma_window.cpp user_define.cpp dl-man.cpp image_window.cpp options_window.cpp gl_display.cpp
|
SOURCES += main.cpp main_window.cpp new_dialog.cpp plugin.cpp select_image.cpp display_window.cpp playback_thread.cpp search_box.cpp goto_window.cpp chroma_window.cpp user_define.cpp dl-man.cpp image_window.cpp options_window.cpp gl_display.cpp controller.cpp
|
||||||
|
|||||||
35
src/controller.cpp
Normal file
35
src/controller.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
|
||||||
|
#include"controller.h"
|
||||||
|
#include<iostream>
|
||||||
|
|
||||||
|
|
||||||
|
bool Controller::open(int index) {
|
||||||
|
stick = SDL_JoystickOpen(index);
|
||||||
|
if(!stick)
|
||||||
|
return false;
|
||||||
|
std::cout << "Opened: " << SDL_JoystickName(stick) << "\n";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Controller::close() {
|
||||||
|
if(stick != 0)
|
||||||
|
SDL_JoystickClose(stick);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Controller::button(int index) {
|
||||||
|
if(stick != 0 && SDL_JoystickGetButton(stick, index))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint8 Controller::hat(int h) {
|
||||||
|
if(stick != 0)
|
||||||
|
return SDL_JoystickGetHat(stick, h);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Controller::axis(int index) {
|
||||||
|
if(stick != 0)
|
||||||
|
return SDL_JoystickGetAxis(stick, index);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
26
src/controller.h
Normal file
26
src/controller.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
#ifndef __CONTROLLER_H__
|
||||||
|
#define __CONTROLLER_H__
|
||||||
|
|
||||||
|
#include "SDL.h"
|
||||||
|
|
||||||
|
class Controller {
|
||||||
|
public:
|
||||||
|
static void init() {
|
||||||
|
SDL_Init(SDL_INIT_JOYSTICK);
|
||||||
|
atexit(SDL_Quit);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool open(int index);
|
||||||
|
void close();
|
||||||
|
bool button(int index);
|
||||||
|
Uint8 hat(int h);
|
||||||
|
int axis(int index);
|
||||||
|
|
||||||
|
private:
|
||||||
|
SDL_Joystick *stick;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -173,7 +173,9 @@ AC_MainWindow::AC_MainWindow(QWidget *parent) : QMainWindow(parent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
Controller::init();
|
||||||
|
joy_timer = new QTimer(this);
|
||||||
|
connect(joy_timer, SIGNAL(timeout()), this, SLOT(chk_Joystick()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1048,6 +1050,13 @@ bool AC_MainWindow::startCamera(int res, int dev, const QString &outdir, bool re
|
|||||||
if(rt_val == false) return false;
|
if(rt_val == false) return false;
|
||||||
playback->Play();
|
playback->Play();
|
||||||
disp->show();
|
disp->show();
|
||||||
|
if(controller.open(0)) {
|
||||||
|
std::cout << "Controller connected...\n";
|
||||||
|
joy_timer->start();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
std::cout << "No controller detected...\n";
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1146,6 +1155,12 @@ bool AC_MainWindow::startVideo(const QString &filename, const QString &outdir, b
|
|||||||
playback->setVideo(capture_video,writer,recording);
|
playback->setVideo(capture_video,writer,recording);
|
||||||
playback->Play();
|
playback->Play();
|
||||||
disp->show();
|
disp->show();
|
||||||
|
if(controller.open(0)) {
|
||||||
|
std::cout << "Controller connected...\n";
|
||||||
|
joy_timer->start();
|
||||||
|
} else {
|
||||||
|
std::cout << "No controller detected...\n";
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1797,3 +1812,15 @@ void AC_MainWindow::prev_filter() {
|
|||||||
void AC_MainWindow::showGLDisplay() {
|
void AC_MainWindow::showGLDisplay() {
|
||||||
disp->showGL();
|
disp->showGL();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AC_MainWindow::chk_Joystick() {
|
||||||
|
SDL_Event e;
|
||||||
|
while(SDL_PollEvent(&e)) {
|
||||||
|
if(controller.button(1)) {
|
||||||
|
prev_filter();
|
||||||
|
}
|
||||||
|
if(controller.button(0)) {
|
||||||
|
next_filter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "image_window.h"
|
#include "image_window.h"
|
||||||
#include "options_window.h"
|
#include "options_window.h"
|
||||||
#include "gl_display.h"
|
#include "gl_display.h"
|
||||||
|
#include "controller.h"
|
||||||
|
|
||||||
class SearchWindow;
|
class SearchWindow;
|
||||||
|
|
||||||
@@ -64,6 +65,7 @@ public:
|
|||||||
QAction *select_next_filter, *select_prev_filter;
|
QAction *select_next_filter, *select_prev_filter;
|
||||||
QAction *cycle_custom;
|
QAction *cycle_custom;
|
||||||
QAction *show_glDisplay;
|
QAction *show_glDisplay;
|
||||||
|
QTimer *joy_timer;
|
||||||
double speed_actions[7];
|
double speed_actions[7];
|
||||||
QRadioButton *filter_single, *filter_custom;
|
QRadioButton *filter_single, *filter_custom;
|
||||||
void updateList();
|
void updateList();
|
||||||
@@ -74,6 +76,7 @@ public:
|
|||||||
void setOptionString(std::string op, std::string value);
|
void setOptionString(std::string op, std::string value);
|
||||||
void setProcMode(int index);
|
void setProcMode(int index);
|
||||||
public slots:
|
public slots:
|
||||||
|
void chk_Joystick();
|
||||||
void addClicked();
|
void addClicked();
|
||||||
void rmvClicked();
|
void rmvClicked();
|
||||||
void upClicked();
|
void upClicked();
|
||||||
@@ -164,6 +167,7 @@ private:
|
|||||||
bool loading;
|
bool loading;
|
||||||
int speed_index;
|
int speed_index;
|
||||||
cv::ocl::Context context;
|
cv::ocl::Context context;
|
||||||
|
Controller controller;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const char *filer_names[];
|
extern const char *filer_names[];
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "qtheaders.h"
|
#include "qtheaders.h"
|
||||||
#include<atomic>
|
#include<atomic>
|
||||||
|
|
||||||
|
|
||||||
enum VideoMode { MODE_CAMERA = 0, MODE_VIDEO };
|
enum VideoMode { MODE_CAMERA = 0, MODE_VIDEO };
|
||||||
|
|
||||||
class Playback : public QThread {
|
class Playback : public QThread {
|
||||||
|
|||||||
Reference in New Issue
Block a user