diff --git a/Documentation/readme.md b/Documentation/readme.md new file mode 100644 index 0000000..b9bc04d --- /dev/null +++ b/Documentation/readme.md @@ -0,0 +1,13 @@ +packages: +```mermaid +flowchart LR + main --> hw + hw --> ui + ui --> cameras + ui --> psvr + ui --> opencv4/imgcodecs + cameras-->threadweaver + cameras-->opencv4 + psvr-->ihidapi + ihidapi-->hidapi +``` \ No newline at end of file diff --git a/Sources/include/Visnode/CMakeLists.txt b/Sources/include/Visnode/CMakeLists.txt deleted file mode 100644 index ec40315..0000000 --- a/Sources/include/Visnode/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -cmake_minimum_required(VERSION 3.22) - -set(CMAKE_CXX_STANDARD 17) - -project( visnode ) - -find_package(OpenCV REQUIRED) - -SET("OpenCV_DIR" "/usr/local/lib/") -include_directories(${OpenCV_INCLUDE_DIRS} ) -link_directories(${Opencv_LINK_DIRS}) - -set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/../bin) -set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) - -add_subdirectory(threadweaver) -add_subdirectory(ihidapi) -add_subdirectory(cameras) -add_subdirectory(psvr) -add_subdirectory(ui) -add_subdirectory(hw) - -set(main_source_files main.cpp main.hpp) - -add_executable(prog ${main_source_files}) - -target_link_libraries(prog hw) - - -SET(GCC_COVERAGE_COMPILE_FLAGS "-L/usr/local/lib") -add_definitions(${GCC_COVERAGE_COMPILE_FLAGS}) \ No newline at end of file diff --git a/Sources/include/Visnode/cameras/_cam.hpp b/Sources/include/Visnode/cameras/_cam.hpp deleted file mode 100644 index 3e77f72..0000000 --- a/Sources/include/Visnode/cameras/_cam.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "../threadweaver/threadweaver.hpp" - -#define DEBUG_ELAPSED_START std::chrono::steady_clock::time_point bgd = std::chrono::steady_clock::now(); -#define DEBUG_ELAPSED_END std::chrono::steady_clock::time_point bge = std::chrono::steady_clock::now(); -#define DEBUG_SHOW_ELAPSED uint elapsed = std::chrono::duration_cast(bge - bgd).count();std::cout << "Time difference = " << elapsed << "[ms] " << (1000/elapsed) <<"[fps]"<< std::endl; - - -using namespace std; -using namespace cv; - -std::vector listCameras(); - -class camera{ - public: - uint path; - VideoCapture* source; - int Yindex = 0; //index for the stitcher -}; - -class cameraManager{ - public: - static std::vector videoSources; - static std::vector captures; - static std::vector accessLocks; - static bool runCaptureThread; - static int init(); - static void runCapture(); - static void stopCapture(); - static void runCaptureForCamera(camera* c, uint index); -}; \ No newline at end of file diff --git a/Sources/include/Visnode/compile.sh b/Sources/include/Visnode/compile.sh deleted file mode 100644 index 2f1f9ac..0000000 --- a/Sources/include/Visnode/compile.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -VERSION=$(dpkg -s libhidapi-dev 2> /dev/null | grep "Version" | cut -d':' -f2) - -HEADERS="./threadweaver/*.hpp ./cameras/_cam.hpp ./hidapi/_hidapi.hpp ./psvr/_psvr.hpp ./ui/uiElements/uiElements.hpp ./ui/_ui.hpp ./hw/*.hpp ./main.hpp" -SOURCES="./threadweaver/*.cpp ./cameras/*.cpp ./hidapi/*.cpp ./psvr/*.cpp ./ui/uiElements/*.cpp ./ui/*.cpp ./hw/*.cpp ./main.cpp" -LIBRARIES="-ltbb -l:libhidapi-hidraw.so.0 -lopencv_core -lopencv_imgcodecs -lopencv_imgproc -lopencv_highgui -lopencv_videoio -std=c++17" - -INCLUDE_PATHS="-I/usr/local/include/opencv4" -# LIBRARY_PATHS="-L/lib/x86_64-linux-gnu/ -L/usr/local/lib/" -LIBRARY_PATHS="-L/lib/aarch64-linux-gnu/ -L/usr/local/lib/" - -if [[ -z $VERSION ]] -then - echo "libhidapi is not installed, installing now" - sudo apt install libhidapi-dev -elif [[ $VERSION != " 0.11.2-1" ]] -then - echo "|"$VERSION"|" - echo "libhidapi is not the right version, updating now" - sudo apt --only-upgrade install libhidapi-dev -else - echo "libhidapi is installed" -fi - -echo "compiling..." -g++ -Ofast -pg $SOURCES $HEADERS $INCLUDE_PATHS $LIBRARY_PATHS $LIBRARIES -o prog -echo "done compiling" diff --git a/Sources/include/Visnode/hw/serial.hpp b/Sources/include/Visnode/hw/serial.hpp deleted file mode 100644 index 55e5ae2..0000000 --- a/Sources/include/Visnode/hw/serial.hpp +++ /dev/null @@ -1,22 +0,0 @@ -// C library headers -#include -#include - -// Linux headers -#include // Contains file controls like O_RDWR -#include // Error integer and strerror() function -#include // Contains POSIX terminal control definitions -#include // write(), read(), close() - -#include -#include - -#include "../ui/_ui.hpp" - -class SerialPortManager{ - public: - static void init(); - static void runPort(); - static bool shouldRun; - static int serialPort; -}; \ No newline at end of file diff --git a/Sources/include/Visnode/ihidapi/_hidapi.hpp b/Sources/include/Visnode/ihidapi/_hidapi.hpp deleted file mode 100644 index 0f3260d..0000000 --- a/Sources/include/Visnode/ihidapi/_hidapi.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#include -#include - -namespace hid_func{ -hid_device* open_device_idx(int manufacturer, int product, int iface, int device_index); -} \ No newline at end of file diff --git a/Sources/include/Visnode/main.cpp b/Sources/include/Visnode/main.cpp deleted file mode 100644 index 162bcfa..0000000 --- a/Sources/include/Visnode/main.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "main.hpp" -#include -using namespace psvr; - -int main(int argc, char* argv[]) -{ -//psvr::Psvr::open(); -ui::UiManager::init(); -std::future fobj = std::async (cameraManager::init); //asynchronous camera manager start -ui::UiController::init(); -std::future menudraw = std::async (ui::UiDrawer::drawMenu); -ui::UiDrawer::drawStartupSequence(); //show startup sequence while camera manager is starting -menudraw.get(); -fobj.get(); -cameraManager::runCapture(); -SerialPortManager::init(); -ui::UiController::exitCalled = false; -while(!ui::UiController::exitCalled){ - std::future uiL = std::async (ui::UiDrawer::drawUiL); - std::future uiR = std::async (ui::UiDrawer::drawUiR); - uiL.get(); - uiR.get(); -} -return 0; -} diff --git a/Sources/include/Visnode/main.hpp b/Sources/include/Visnode/main.hpp deleted file mode 100644 index bae3c94..0000000 --- a/Sources/include/Visnode/main.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "./hw/serial.hpp" \ No newline at end of file diff --git a/Sources/include/Visnode/psvr/_psvr.hpp b/Sources/include/Visnode/psvr/_psvr.hpp deleted file mode 100644 index 90b1761..0000000 --- a/Sources/include/Visnode/psvr/_psvr.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "../ihidapi/_hidapi.hpp" - -const unsigned char psvr_vrmode_off[8] {0x23,0x00,0xaa,0x04,0x00,0x00,0x00,0x00}; -const unsigned char psvr_vrmode_on[8] {0x23,0x00,0xaa,0x04,0x01,0x00,0x00,0x00}; -const unsigned char psvr_power_off[8] {0x17,0x00,0xaa,0x04,0x01,0x00,0x00,0x00}; -const unsigned char psvr_power_on[8] {0x17,0x00,0xaa,0x04,0x00,0x00,0x00,0x00}; - -#define sony_vid 0x054c -#define psvr_pid 0x09af -#define ctrl_device_iface 5 -#define ld_device_iface 4 - -namespace psvr{ - class Psvr{ - public: - static hid_device* handle; - static bool vrMode; - static bool powered; - - static void open(); //default constructor - - static void startup(); - static void shutdown(); - static void vrmode(); - static void cinemaMode(); - - static void close();//default destructor - }; -} \ No newline at end of file diff --git a/Sources/include/Visnode/threadweaver/threadweaver.hpp b/Sources/include/Visnode/threadweaver/threadweaver.hpp deleted file mode 100644 index c8e2df4..0000000 --- a/Sources/include/Visnode/threadweaver/threadweaver.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -//main thread manager -class Threadweaver{ - public: - static std::vector captureThreads; - static std::thread* hardwareWatcherThread; - static std::thread* osUiDrawerThread; -}; \ No newline at end of file diff --git a/Sources/include/Visnode/ui/_ui.hpp b/Sources/include/Visnode/ui/_ui.hpp deleted file mode 100644 index 27e5984..0000000 --- a/Sources/include/Visnode/ui/_ui.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "../cameras/_cam.hpp" -#include "../psvr/_psvr.hpp" -#include - -#define DEFAULT_UI_WINDOW_AMOUNT 2 //2 windows, one for each eye -#define DEFAULT_UI_OFFSET_X 0 //1080 -#define DEFAULT_UI_OFFSET_Y 0 -#define DEFAULT_UI_SIZE_X 960 //psvr is 960x1080 per eye -#define DEFAULT_UI_SIZE_Y 1080 - -int runtest(); - -using namespace std; -using namespace cv; -using namespace psvr; - -namespace ui { - //Defines a single ui window (by default two will be displayed) - class Ui{ - public: - Mat drawSurface; //Current frame - std::string myWindow; - void draw(); - }; - class UiDrawer{ //drawer is static because we only ever need one - public: - static void drawUiR(); - static void drawUiL(); - static void drawStartupSequence(); - static void drawMenu(); - static Mat OverlayMat; //drawn at each frame - static Mat OsMat; //drawn on certain events - static std::mutex OsMatLock; - private: - static Mat prepareUiMat(); - static Mat resizeIn(Mat input); - static Mat OverlayBlackMask(Mat input, Mat toOverlay, int x = 0, int y = 0); - static Mat OverlayHISHMask(Mat input, Mat toOverlay); - }; - class UiManager{ //manager is static because we only ever need one - public: - static vector managedUIs; - static void init(); - static void cleanup(); - }; - class UiController{ - public: - static void init(); - static void selectedUp(); - static void selectedDown(); - static void click(); - static void update(); - static void openSettings(); - static vector menuItemNames; - static bool showMenu; - static bool exitCalled; - static string menuTitle; - static cv::Size2i menuSize; - static cv::Point2i menuPos; - static unsigned int selectedIndex; - static map> menuItems; - static char* menutime; - }; - -} diff --git a/Sources/include/Visnode/ui/uiElements/uiElements.hpp b/Sources/include/Visnode/ui/uiElements/uiElements.hpp deleted file mode 100644 index 0cef26b..0000000 --- a/Sources/include/Visnode/ui/uiElements/uiElements.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include -#include -#include - -using namespace cv; - -//base UI element class (abstract) -struct UiElement{ - unsigned int xPosPixels; - unsigned int yPosPixels; - void drawSelf(Mat &input); -}; -//sized ui element (abstract) -struct SizedUiElement : UiElement{ - unsigned int widthPixels; - unsigned int heightPixels; - void drawSelf(Mat &input); -}; - -struct UiRect : SizedUiElement{ - unsigned int borderColor; - unsigned int fillingColor; - void drawSelf(Mat &input); -}; - -struct UiText : UiElement{ - std::string text; - unsigned int fontSize; - cv::Scalar textColor; - cv::HersheyFonts font = HersheyFonts::FONT_HERSHEY_SIMPLEX; - unsigned int thickness; - unsigned int lineType = 0; - bool leftOrigin = false; - void drawSelf(cv::Mat &input){ - putText(input, UiText::text, Point(xPosPixels,yPosPixels), cv::FONT_HERSHEY_DUPLEX, fontSize, textColor, thickness, lineType, leftOrigin); - } -}; -//menu item container -struct UiMenuItem{ - std::vector elements; -}; \ No newline at end of file diff --git a/Sources/src/Visnode/CMakeLists.txt b/Sources/src/Visnode/CMakeLists.txt index ec40315..33ee687 100644 --- a/Sources/src/Visnode/CMakeLists.txt +++ b/Sources/src/Visnode/CMakeLists.txt @@ -2,11 +2,11 @@ cmake_minimum_required(VERSION 3.22) set(CMAKE_CXX_STANDARD 17) -project( visnode ) +project(visnode) find_package(OpenCV REQUIRED) -SET("OpenCV_DIR" "/usr/local/lib/") +#SET("OpenCV_DIR" "/usr/local/lib/") include_directories(${OpenCV_INCLUDE_DIRS} ) link_directories(${Opencv_LINK_DIRS}) @@ -24,6 +24,8 @@ set(main_source_files main.cpp main.hpp) add_executable(prog ${main_source_files}) +MESSAGE(STATUS "CMAKE FLAGS : ${LINK_OPTIONS}") + target_link_libraries(prog hw) diff --git a/Sources/src/Visnode/cameras/CMakeLists.txt b/Sources/src/Visnode/cameras/CMakeLists.txt index a9ae4c1..9ec4222 100644 --- a/Sources/src/Visnode/cameras/CMakeLists.txt +++ b/Sources/src/Visnode/cameras/CMakeLists.txt @@ -6,7 +6,7 @@ set(cameras_source_files MESSAGE(STATUS "building cameras") add_library(cameras ${cameras_source_files}) -SET("OpenCV_DIR" "/usr/local/lib/") +#SET("OpenCV_DIR" "/usr/local/lib/") find_package( OpenCV REQUIRED ) diff --git a/Sources/src/Visnode/compile.sh b/Sources/src/Visnode/compile.sh index d37228b..b125070 100644 --- a/Sources/src/Visnode/compile.sh +++ b/Sources/src/Visnode/compile.sh @@ -2,8 +2,8 @@ VERSION=$(dpkg -s libhidapi-dev 2> /dev/null | grep "Version" | cut -d':' -f2) -HEADERS="./threadweaver/*.hpp ./cameras/_cam.hpp ./hidapi/_hidapi.hpp ./psvr/_psvr.hpp ./ui/uiElements/uiElements.hpp ./ui/_ui.hpp ./hw/*.hpp ./main.hpp" -SOURCES="./threadweaver/*.cpp ./cameras/*.cpp ./hidapi/*.cpp ./psvr/*.cpp ./ui/uiElements/*.cpp ./ui/*.cpp ./hw/*.cpp ./main.cpp" +HEADERS="./threadweaver/*.hpp ./cameras/_cam.hpp ./ihidapi/_hidapi.hpp ./psvr/_psvr.hpp ./ui/uiElements/uiElements.hpp ./ui/_ui.hpp ./hw/*.hpp ./main.hpp" +SOURCES="./threadweaver/*.cpp ./cameras/*.cpp ./ihidapi/*.cpp ./psvr/*.cpp ./ui/uiElements/*.cpp ./ui/*.cpp ./hw/*.cpp ./main.cpp" LIBRARIES="-ltbb -l:libhidapi-hidraw.so.0 -lopencv_core -lopencv_imgcodecs -lopencv_imgproc -lopencv_highgui -lopencv_videoio -std=c++17" INCLUDE_PATHS="-I/usr/local/include/opencv4" diff --git a/Sources/src/Visnode/prog b/Sources/src/Visnode/prog new file mode 100755 index 0000000..34f908c Binary files /dev/null and b/Sources/src/Visnode/prog differ