diff --git a/src/.vscode/c_cpp_properties.json b/src/.vscode/c_cpp_properties.json index 4501a51..275fce8 100644 --- a/src/.vscode/c_cpp_properties.json +++ b/src/.vscode/c_cpp_properties.json @@ -10,7 +10,8 @@ "compilerPath": "/usr/bin/gcc", "cStandard": "gnu17", "cppStandard": "gnu++17", - "intelliSenseMode": "linux-gcc-x64" + "intelliSenseMode": "linux-gcc-x64", + "configurationProvider": "ms-vscode.cmake-tools" } ], "version": 4 diff --git a/src/model/controllers/CMakeFiles/controllers.dir/compiler_depend.internal b/src/model/controllers/CMakeFiles/controllers.dir/compiler_depend.internal index 0519a08..a085373 100644 --- a/src/model/controllers/CMakeFiles/controllers.dir/compiler_depend.internal +++ b/src/model/controllers/CMakeFiles/controllers.dir/compiler_depend.internal @@ -269,6 +269,9 @@ model/controllers/CMakeFiles/controllers.dir/ui/menu.cpp.o /home/kanken/code/AHRS_core/src/model/hardware/ihidapi/_hidapi.hpp /usr/local/include/hidapi/hidapi.h /home/kanken/code/AHRS_core/src/model/patterns/commands/commands.hpp + /usr/include/c++/11/atomic + /usr/include/c++/11/bits/atomic_base.h + /usr/include/c++/11/bits/atomic_lockfree_defines.h model/controllers/CMakeFiles/controllers.dir/ui/uiController.cpp.o /home/kanken/code/AHRS_core/src/model/controllers/ui/uiController.cpp diff --git a/src/model/controllers/CMakeFiles/controllers.dir/compiler_depend.make b/src/model/controllers/CMakeFiles/controllers.dir/compiler_depend.make index e6a51e1..3c08847 100644 --- a/src/model/controllers/CMakeFiles/controllers.dir/compiler_depend.make +++ b/src/model/controllers/CMakeFiles/controllers.dir/compiler_depend.make @@ -267,7 +267,10 @@ model/controllers/CMakeFiles/controllers.dir/ui/menu.cpp.o: model/controllers/ui model/hardware/psvr/_psvr.hpp \ model/hardware/ihidapi/_hidapi.hpp \ /usr/local/include/hidapi/hidapi.h \ - model/patterns/commands/commands.hpp + model/patterns/commands/commands.hpp \ + /usr/include/c++/11/atomic \ + /usr/include/c++/11/bits/atomic_base.h \ + /usr/include/c++/11/bits/atomic_lockfree_defines.h model/controllers/CMakeFiles/controllers.dir/ui/uiController.cpp.o: model/controllers/ui/uiController.cpp \ /usr/include/stdc-predef.h \ @@ -1710,6 +1713,12 @@ model/patterns/commands/commands.hpp: /usr/include/c++/11/bits/regex_automaton.h: +/usr/lib/gcc/x86_64-linux-gnu/11/include/adxintrin.h: + +/usr/include/c++/11/bits/atomic_base.h: + +/usr/include/c++/11/bits/atomic_lockfree_defines.h: + /usr/include/c++/11/memory: /usr/include/c++/11/bits/stl_tempbuf.h: @@ -1730,10 +1739,6 @@ model/patterns/commands/commands.hpp: /usr/include/c++/11/bits/regex.h: -/usr/include/c++/11/bits/atomic_base.h: - -/usr/include/c++/11/bits/atomic_lockfree_defines.h: - /usr/include/x86_64-linux-gnu/bits/types/__FILE.h: /usr/include/c++/11/backward/auto_ptr.h: @@ -1788,6 +1793,10 @@ model/patterns/commands/commands.hpp: /usr/include/c++/11/bits/regex_constants.h: +/usr/include/c++/11/atomic: + +/usr/include/c++/11/bits/regex_error.h: + /usr/include/c++/11/bits/stream_iterator.h: /usr/include/c++/11/bits/regex_scanner.tcc: @@ -1818,12 +1827,6 @@ model/patterns/observer/observer.hpp: /usr/include/oneapi/tbb/detail/_config.h: -/usr/include/c++/11/bits/regex_error.h: - -/usr/include/c++/11/atomic: - -/usr/lib/gcc/x86_64-linux-gnu/11/include/adxintrin.h: - /usr/include/c++/11/bits/fs_dir.h: /usr/include/oneapi/tbb/detail/_machine.h: diff --git a/src/model/controllers/ui/menu.cpp b/src/model/controllers/ui/menu.cpp index 4116d07..a92f9f9 100644 --- a/src/model/controllers/ui/menu.cpp +++ b/src/model/controllers/ui/menu.cpp @@ -35,7 +35,7 @@ void Menu::selectedDown() switch (_items.at(selectedIndex)->getTrueType()) { case NumberPickerItemT: - static_cast(_items.at(selectedIndex))->increment(); + static_cast(_items.at(selectedIndex))->decrement(); break; case CheckerItemT: @@ -49,6 +49,7 @@ void Menu::selectedDown() } else { + std::cout << "not selecting, down " << selectedIndex << std::endl; if (selectedIndex > 0) --selectedIndex; else @@ -62,12 +63,14 @@ void Menu::clickb2() {} void Menu::clickok() { + if(_items.size() <= 0) return; if (_items.at(selectedIndex) != nullptr) { switch (_items.at(selectedIndex)->getTrueType()) { case NumberPickerItemT: - static_cast(_items.at(selectedIndex))->selected = true; + //static_cast(_items.at(selectedIndex))->selected = true; + selecting = true; break; case CheckerItemT: @@ -78,11 +81,11 @@ void Menu::clickok() static_cast(_items.at(selectedIndex))->navigate(); break; + case ExectuableT: + static_cast(_items.at(selectedIndex))->click(); + break; + default: - if (selectedIndex > 0) - --selectedIndex; - else - selectedIndex = _items.size() - 1; break; } } diff --git a/src/model/controllers/ui/menu.hpp b/src/model/controllers/ui/menu.hpp index 11f8ba4..c96f17b 100644 --- a/src/model/controllers/ui/menu.hpp +++ b/src/model/controllers/ui/menu.hpp @@ -12,6 +12,7 @@ protected: public: Menu(std::string name, Menu *previous, Command* navigateBackCommand) : _name(name), _previous(previous), _navigateBackCommand(navigateBackCommand) {} void addItem(baseItem *item) { _items.push_back(item); } + std::vector getItems(){return _items;} void selectedUp(); void selectedDown(); void clickb1(); @@ -19,5 +20,6 @@ public: void clickok(); void clickback(); std::string getName(){return _name;} - std::atomic_bool selecting; + std::atomic_bool selecting = false; + int getSelectedIndex(){return selectedIndex;} }; \ No newline at end of file diff --git a/src/model/controllers/ui/menuItem.hpp b/src/model/controllers/ui/menuItem.hpp index 91e6a22..ddbe84e 100644 --- a/src/model/controllers/ui/menuItem.hpp +++ b/src/model/controllers/ui/menuItem.hpp @@ -42,23 +42,26 @@ public: class NumberPickerItem : public baseItem //menu item used to display and pick a number (increment/decrement) { protected: - int data; - + int _data; + std::string _name; + std::string _targetValue; public: - NumberPickerItem(){type = NumberPickerItemT;} - void decrement(){++data; sendMessage("data", std::to_string(data));} - void increment(){--data; sendMessage("data", std::to_string(data));} - int getData(){ return data; } + NumberPickerItem(std::string name, std::string targetValue, int value = 0):_name(name),_targetValue(targetValue),_data(value){type = NumberPickerItemT;} + void decrement(){--_data; sendMessage(_targetValue, std::to_string(_data));} + void increment(){++_data; sendMessage(_targetValue, std::to_string(_data));} + int getData(){ return _data; } + std::string getName(){return _name;} }; class CheckerItem : public baseItem { protected: bool data; + std::string _name; Command* _ifFalse; Command* _ifTrue; public: - CheckerItem(Command* ifFalse, Command* ifTrue): _ifFalse(ifFalse), _ifTrue(ifTrue) {type = CheckerItemT;} + CheckerItem(std::string name, Command* ifFalse, Command* ifTrue): _name(name),_ifFalse(ifFalse), _ifTrue(ifTrue) {type = CheckerItemT;} void toggle() { data = !data; @@ -70,6 +73,8 @@ public: { return data; } + + std::string getName(){return _name;} }; class ButtonItem : public baseItem diff --git a/src/model/controllers/ui/uiController.cpp b/src/model/controllers/ui/uiController.cpp index 705bcd2..2f67aeb 100644 --- a/src/model/controllers/ui/uiController.cpp +++ b/src/model/controllers/ui/uiController.cpp @@ -7,40 +7,41 @@ UiController::UiController(psvr::Psvr *hmd) : _hmd(hmd) menuSize = cv::Size2i(400, 400); menuPos = cv::Point2i(DEFAULT_UI_SIZE_X - menuSize.width, (DEFAULT_UI_SIZE_Y / 2) - (menuSize.height / 2)); // centered right selectedIndex = 0; - menuItemNames = {"set vr mode", "set cinema mode", "settings","quit"}; + menuItemNames = {"set vr mode", "set cinema mode", "settings", "quit"}; unsigned int i = 0; update(); buildMenu(); cout << "done init ui controller" << endl; } -void UiController::Update(const std::string &key,const std::string &value) +void UiController::Update(const std::string &key, const std::string &value) { char c = value[0]; switch (c) { case 'U': - cout << c << "++" << endl; + DEBUG_LOG(c << "++"); menus[_activeMenu]->selectedUp(); break; case 'D': - cout << c << "--" << endl; + DEBUG_LOG(c << "--"); + cout << _activeMenu << endl; menus[_activeMenu]->selectedDown(); break; - case '1': //1 - cout << c << "1" << endl; + case '1': // 1 + DEBUG_LOG(c << "1"); menus[_activeMenu]->clickback(); break; - case '2': //< - cout << c << "2" << endl; + case '2': //< + DEBUG_LOG(c << "2"); menus[_activeMenu]->clickb1(); break; - case '3': //> - cout << c << "3" << endl; + case '3': //> + DEBUG_LOG(c << "3"); menus[_activeMenu]->clickb2(); break; - case '0': //2 - cout << c << "0" << endl; + case '0': // 2 + DEBUG_LOG(c << "0"); menus[_activeMenu]->clickok(); break; default: @@ -56,31 +57,42 @@ void UiController::update() menuTitle = std::string("P-OS ") + VERSION + " " + menutime; } -void UiController::buildMenu(){ +void UiController::buildMenu() +{ menus.clear(); _activeMenu = "main menu"; +#pragma region main_menu + + ExitAppCommand *ex = new ExitAppCommand(); - Command* navigateToMain = new NavigateCommand(_activeMenu,this); - Menu* main = new Menu(_activeMenu,main,navigateToMain); //it's the root so it navigates back to itself + Command *navigateToMain = new NavigateCommand(_activeMenu, this); + Menu *main = new Menu(_activeMenu, main, navigateToMain); // it's the root so it navigates back to itself menus[main->getName()] = main; - Menu* psvrMenu = new Menu("PSVR options",main, navigateToMain); + ButtonItem *exitBtn = new ButtonItem(ex); + exitBtn->setData("exit the app"); + main->addItem(exitBtn); +#pragma endregion main_menu +#pragma region psvr_menu + Menu *psvrMenu = new Menu("PSVR options", main, navigateToMain); menus[psvrMenu->getName()] = psvrMenu; - Command* navigateToPsvr = new NavigateCommand(psvrMenu->getName(),this); + Command *navigateToPsvr = new NavigateCommand(psvrMenu->getName(), this); - menuitem* psvrOptions = new menuitem(navigateToPsvr); + menuitem *psvrOptions = new menuitem(navigateToPsvr); psvrOptions->setData("open psvr options"); - Command* startup = new StartupCommand(_hmd); - Command* shutdown = new ShutdownCommand(_hmd); - Command* vrmode = new VrModeCommand(_hmd); - Command* cinemamode = new CinemaModeCommand(_hmd); + main->addItem(psvrOptions); - ButtonItem* startBtn = new ButtonItem(startup); - ButtonItem* stopBtn = new ButtonItem(shutdown); - ButtonItem* vrBtn = new ButtonItem(vrmode); - ButtonItem* cinemaBtn = new ButtonItem(cinemamode); + Command *startup = new StartupCommand(_hmd); + Command *shutdown = new ShutdownCommand(_hmd); + Command *vrmode = new VrModeCommand(_hmd); + Command *cinemamode = new CinemaModeCommand(_hmd); + + ButtonItem *startBtn = new ButtonItem(startup); + ButtonItem *stopBtn = new ButtonItem(shutdown); + ButtonItem *vrBtn = new ButtonItem(vrmode); + ButtonItem *cinemaBtn = new ButtonItem(cinemamode); startBtn->setData("startup psvr"); stopBtn->setData("shutdown psvr"); @@ -91,4 +103,22 @@ void UiController::buildMenu(){ psvrMenu->addItem(stopBtn); psvrMenu->addItem(vrBtn); psvrMenu->addItem(cinemaBtn); +#pragma endregion psvr_menu +#pragma region fps_menu + Menu *fpsMenu = new Menu("EPS options", main, navigateToMain); + menus[fpsMenu->getName()] = fpsMenu; + + Command *navigateToEPS = new NavigateCommand(fpsMenu->getName(), this); + + menuitem *fpsOptions = new menuitem(navigateToEPS); + fpsOptions->setData("open EPS options"); + main->addItem(fpsOptions); + + fpsMenu->addItem(new NumberPickerItem("camera EPS limit","fpsLimit",60)); //must be in the same order as when the pipeline is created + fpsMenu->addItem(new NumberPickerItem("zbar EPS limit","fpsLimit",15)); + fpsMenu->addItem(new NumberPickerItem("ui drawer EPS limit","fpsLimit",30)); + fpsMenu->addItem(new NumberPickerItem("ui merger EPS limit","fpsLimit",60)); + fpsMenu->addItem(new NumberPickerItem("display EPS limit","fpsLimit",60)); + +#pragma endregion fps_menu } \ No newline at end of file diff --git a/src/model/controllers/ui/uiController.hpp b/src/model/controllers/ui/uiController.hpp index 38576d0..2a6d1aa 100644 --- a/src/model/controllers/ui/uiController.hpp +++ b/src/model/controllers/ui/uiController.hpp @@ -38,6 +38,8 @@ public: char *menutime; unsigned int selectedIndex; void activeMenuChange(std::string activeMenu){_activeMenu = activeMenu;} + Menu* getActiveMenu(){return menus[_activeMenu];} + Menu* getSpecificMenu(std::string name){return menus[name];} private: std::string _activeMenu = ""; psvr::Psvr *_hmd; @@ -52,4 +54,9 @@ class NavigateCommand : public Command{ public: NavigateCommand(std::string menuName, UiController* backController) : _destination(menuName), _backController(backController){} void Execute() const override { _backController->activeMenuChange(_destination);} +}; + +class ExitAppCommand : public Command{ + public: + void Execute() const override { exit(0);} }; \ No newline at end of file diff --git a/src/pipeline/abstract/pipelineNode.hpp b/src/pipeline/abstract/pipelineNode.hpp index d7c6afe..8a7f2a3 100644 --- a/src/pipeline/abstract/pipelineNode.hpp +++ b/src/pipeline/abstract/pipelineNode.hpp @@ -19,7 +19,7 @@ class SubNode{ }; /// @brief this class represents a threaded node of the graphics pipeline -class PipelineNode{ +class PipelineNode : public MapObserver{ public: PipelineNode(); std::atomic_int fpsLimit = 60; @@ -38,6 +38,10 @@ class PipelineNode{ std::mutex outputLock; std::mutex subNodesLock; std::atomic_bool disabled = false; //if true short circuit your input to your output + void Update(const std::string &key, const std::string &value) override{ + if(key == "fpsLimit") + this->fpsLimit = stoi(value); + } protected: std::vector subNodes; cv::UMat output; diff --git a/src/pipeline/members/uiDrawerNode.cpp b/src/pipeline/members/uiDrawerNode.cpp index 746588e..f495df8 100644 --- a/src/pipeline/members/uiDrawerNode.cpp +++ b/src/pipeline/members/uiDrawerNode.cpp @@ -23,17 +23,43 @@ void UiDrawerNode::processFrame() unsigned int stackerIndex = 0; cv::UMat MenuMat = cv::UMat(cv::Size(960, 1080), CV_8UC3, cv::Scalar(0, 0, 0)); cv::rectangle(MenuMat, cv::Rect2i(0, 0, wd, he), cv::Scalar(255, 0, 0), 5, 8, 0); + cv::rectangle(MenuMat, cv::Rect2i(0, 0, wd, 45), cv::Scalar(255, 0, 0), 3, 8, 0); _backController->update(); + Menu* activeMenu = _backController->getActiveMenu(); cv::putText(MenuMat, _backController->menuTitle, cv::Point2i(5, stackerIndex += 20), cv::HersheyFonts::FONT_HERSHEY_PLAIN, 1, Scalar(255, 255, 255), 1, 8, false); - for (String str : _backController->menuItemNames) + cv::putText(MenuMat, cv::format("%s", activeMenu->getName().c_str()), cv::Point2i(5, stackerIndex += 20), cv::HersheyFonts::FONT_HERSHEY_PLAIN, 1, cv::Scalar(255, 255, 255), 1, 8, false); + unsigned int i = 0; + for(baseItem* b : activeMenu->getItems()){ + cv::Scalar color = activeMenu->getSelectedIndex() == i ? Scalar(0, 0, 200) : Scalar(255, 255, 255); + switch (b->getTrueType()) + { + case MenuitemT: + cv::putText(MenuMat, cv::format("%s", static_cast(b)->getData().c_str()), cv::Point2i(5, stackerIndex += 20), cv::HersheyFonts::FONT_HERSHEY_PLAIN, 1, color, 1, 8, false); + break; + case CheckerItemT: + cv::circle(MenuMat, cv::Point2i(0, stackerIndex), 5, (0, 0, 255), static_cast(b)->getData() ? -1 : 1); + cv::putText(MenuMat, cv::format(" %s", static_cast(b)->getName().c_str()), cv::Point2i(5, stackerIndex += 20), cv::HersheyFonts::FONT_HERSHEY_PLAIN, 1, color, 1, 8, false); + break; + case ExectuableT: + cv::putText(MenuMat, cv::format("> %s", static_cast(b)->getData().c_str()), cv::Point2i(5, stackerIndex += 20), cv::HersheyFonts::FONT_HERSHEY_PLAIN, 1, color, 1, 8, false); + break; + case NumberPickerItemT: + cv::putText(MenuMat, cv::format("< %d > %s", static_cast(b)->getData(), static_cast(b)->getName().c_str()), cv::Point2i(5, stackerIndex += 20), cv::HersheyFonts::FONT_HERSHEY_PLAIN, 1, color, activeMenu->selecting && i == activeMenu->getSelectedIndex() ? 2 : 1, 8, false); + break; + + default: + break; + } + i++; + } + /*for (String str : _backController->menuItemNames) { cv::putText(MenuMat, str, cv::Point2i(5, stackerIndex += 20), cv::HersheyFonts::FONT_HERSHEY_PLAIN, 1, Scalar(255, 255, 255), 1, 8, false); - } + }*/ Point2d pc = Point2d(0,stackerIndex); + cv::rectangle(MenuMat, cv::Rect2i(0, stackerIndex+5, wd, 1), Scalar(200, 0, 0), 3, 8, 0); for (SubNode* sn : subNodes) if(sn->enabled) sn->processFrame(MenuMat,pc); - stackerIndex = pc.y; - cv::rectangle(MenuMat, cv::Rect2i(0, ((20 * _backController->selectedIndex) + 20) + 5, wd, 20), Scalar(200, 0, 0), 3, 8, 0); outputLock.lock(); output = MenuMat; outputLock.unlock(); diff --git a/src/pipeline/pipeline.cpp b/src/pipeline/pipeline.cpp index 51c3152..a19349c 100644 --- a/src/pipeline/pipeline.cpp +++ b/src/pipeline/pipeline.cpp @@ -31,6 +31,11 @@ Pipeline::Pipeline(){ nodes.at(1)->disabled = true; + Menu* epsMenu = uc->getSpecificMenu("EPS options"); + + for(int i = 0; i < nodes.size() && i < epsMenu->getItems().size(); i++) + epsMenu->getItems().at(i)->Attach(nodes.at(i)); + for(PipelineNode* pn : nodes) fc->addChecker(pn->getName(),pn->localES); diff --git a/src/prog b/src/prog index 1582b02..fd3c6c0 100755 Binary files a/src/prog and b/src/prog differ