more pipeline workn begun cmake work

master
Yorick GEOFFRE 3 years ago
parent 89d234c99d
commit 9ade31e72f

@ -2,5 +2,75 @@
"files.exclude": {
"**/.vscode/": true,
"**/media/": true
},
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"shared_mutex": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp"
}
}

@ -1,91 +0,0 @@
#include "./serial.hpp"
bool SerialPortManager::shouldRun;
int SerialPortManager::serialPort;
void SerialPortManager::init(){
struct termios tty;
cout << "opening serial port /dev/ttyUSB0" << endl;
serialPort = open("/dev/ttyUSB0", O_RDWR); //open serial port
cout << "done" << endl;
if (serialPort < 0){
printf("Error %i from open: %s\n", errno, strerror(errno));
return;
}
if(tcgetattr(serialPort, &tty) != 0){ //read serial port configuration
printf("Error %i from tcgetattr: %s\n", errno, strerror(errno));
return;
}
//local flags
tty.c_lflag &= ~ICANON; //enable canonical mode
tty.c_lflag &= ~ECHO; // Disable echo
tty.c_lflag &= ~ECHOE; // Disable erasure
tty.c_lflag &= ~ECHONL; // Disable new-line echo
tty.c_lflag &= ~ISIG; // Disable interpretation of INTR, QUIT and SUSP
//input modes
tty.c_iflag &= ~(IXON | IXOFF | IXANY); // Turn off s/w flow ctrl
tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL); // Disable any special handling of received bytes
//output modes
tty.c_oflag &= ~OPOST; // Prevent special interpretation of output bytes (e.g. newline chars)
tty.c_oflag &= ~ONLCR; // Prevent conversion of newline to carriage return/line feed
//c_cc
tty.c_cc[VTIME] = 1; // Wait for up to 1s (10 deciseconds), returning as soon as any data is received.
tty.c_cc[VMIN] = 0;
//baudrate
cfsetispeed(&tty, B9600); //set baudrate (input)
cfsetospeed(&tty, B9600); // (output)
// Save tty settings, also checking for error
if (tcsetattr(serialPort, TCSANOW, &tty) != 0) {
printf("Error %i from tcsetattr: %s\n", errno, strerror(errno));
return;
}
shouldRun = false;
cout << "starting hardware watcher thread" << endl;
std::thread* t = new std::thread(SerialPortManager::runPort);
cout << "done" << endl;
Threadweaver::stick_this_thread_to_core(t,CAMCORE);
Threadweaver::hardwareWatcherThread = t;
shouldRun = true;
}
void SerialPortManager::runPort(){
while(!shouldRun){}
char read_buf [256];
int n = 0;
while(shouldRun){
n = read(serialPort, &read_buf, sizeof(read_buf));
if(n > 0){
char c = read_buf[0];
switch(c){
case 'U':
cout << c << "++" << endl;
ui::UiController::selectedUp();
break;
case 'D':
cout << c << "--" << endl;
ui::UiController::selectedDown();
break;
case '1':
ui::UiController::click();
break;
case '2':
ui::UiController::click();
break;
case '3':
ui::UiController::click();
break;
case '4':
ui::UiController::click();
break;
default:
break;
}
}
std::fill_n(read_buf, n, 0);
}
}

@ -1,22 +0,0 @@
// C library headers
#include <stdio.h>
#include <string.h>
// Linux headers
#include <fcntl.h> // Contains file controls like O_RDWR
#include <errno.h> // Error integer and strerror() function
#include <termios.h> // Contains POSIX terminal control definitions
#include <unistd.h> // write(), read(), close()
#include <thread>
#include <vector>
#include "../../ui/_ui.hpp"
class SerialPortManager{
public:
static void init();
static void runPort();
static bool shouldRun;
static int serialPort;
};

@ -0,0 +1,49 @@
#include "uiController.hpp"
UiController::UiController()
{
std::cout << "init ui controller" << endl;
showMenu = true;
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"};
vector<std::function<void()>> functions = {psvr::Psvr::vrmode, psvr::Psvr::cinemaMode, UiController::openSettings};
unsigned int i = 0;
for (std::string name : menuItemNames)
{
menuItems[name] = functions.at(i);
i++;
}
update();
cout << "done init ui controller" << endl;
}
void UiController::update()
{
time_t now = time(0);
menutime = ctime(&now);
menuTitle = std::string("P-OS ") + VERSION + " " + menutime;
}
void UiController::selectedUp()
{
if (selectedIndex < menuItems.size() - 1)
selectedIndex++;
}
void UiController::selectedDown()
{
if (selectedIndex > 0)
selectedIndex--;
}
void UiController::openSettings()
{
}
void UiController::click()
{
exitCalled = true;
// std::invoke(menuItems[menuItemNames.at(selectedIndex)]);
}

@ -0,0 +1,49 @@
/*#include <iostream>
#include <string>
#include <map>
#include <chrono>
#include <ctime>
#include <functional>
#include <GL/glut.h>
*/
#include "../../hardware/cameras/_cam.hpp"
#include "../../hardware/psvr/_psvr.hpp"
#include <opencv2/imgcodecs/imgcodecs.hpp>
#include <opencv2/core.hpp>
#include <opencv2/core/opengl.hpp>
#include "../../patterns/observer/observable.hpp"
#define DEFAULT_UI_WINDOW_AMOUNT 1 // 2 windows, one for each eye
#define DEFAULT_UI_OFFSET_X 1080 // 1080
#define DEFAULT_UI_OFFSET_Y 0
#define DEFAULT_UI_SIZE_X 1920 // psvr is 960x1080 per eye
#define DEFAULT_UI_SIZE_Y 1080
using namespace std;
using namespace cv;
using namespace cv::ogl;
using namespace psvr;
/// @brief this class is used to process view logic and interaction [model]
class UiController
{
public:
UiController();
void selectedUp();
void selectedDown();
void click();
void update();
void openSettings();
vector<std::string> menuItemNames;
bool showMenu;
bool exitCalled;
bool runIntro;
string menuTitle;
cv::Size2i menuSize;
cv::Point2i menuPos;
unsigned int selectedIndex;
map<std::string, std::function<void()>> menuItems;
char *menutime;
};

@ -0,0 +1,14 @@
#include <vector>
#include <mutex>
/// @brief this class manages the UI(s) [windows] used by the application, right now only one should ever be used, especially in opengl mode
class UiManager
{
public:
static std::vector<std::mutex*> accessLocks;
static std::vector<Ui *> managedUIs;
static bool uiShouldRun;
static void init();
static void cleanup();
static void beginDrawRoutineForUi(Ui *u);
};

@ -14,7 +14,7 @@
#include <chrono>
#include <opencv2/opencv.hpp>
#include <opencv2/videoio/videoio_c.h>
#include "../../threadweaver/threadweaver.hpp"
#include "../../../threadweaver/threadweaver.hpp"
using namespace std;
using namespace cv;
@ -30,12 +30,12 @@ class camera{
class cameraManager{
public:
static std::vector<camera*> videoSources;
static std::vector<UMat> captures;
static std::vector<std::mutex*> accessLocks;
static bool runCaptureThread;
static int init();
static void runCapture();
static void stopCapture();
static void runCaptureForCamera(camera* c, uint index);
std::vector<camera*> videoSources;
std::vector<UMat> captures;
std::vector<std::mutex*> accessLocks;
bool runCaptureThread;
cameraManager();
void runCapture();
void stopCapture();
void runCaptureForCamera(camera* c, uint index);
};

@ -1,9 +1,5 @@
#include "_cam.hpp"
#include <signal.h>
vector<camera*> cameraManager::videoSources;
std::vector<UMat> cameraManager::captures;
bool cameraManager::runCaptureThread;
std::vector<std::mutex*> cameraManager::accessLocks;
void cameraManager::runCaptureForCamera(camera* c, uint index){
while(runCaptureThread){
@ -31,7 +27,7 @@ void cameraManager::runCaptureForCamera(camera* c, uint index){
}
}
int cameraManager::init(){
cameraManager::cameraManager(){
std::cout << "init camera manager" << endl;
vector<std::string> cameras = listCameras();
uint cameraIndex = 0;
@ -66,7 +62,6 @@ int cameraManager::init(){
}
cout << "found " << std::to_string(videoSources.size()) << " valid cameras" << endl;
return videoSources.size();
}
void cameraManager::runCapture(){

@ -0,0 +1,102 @@
#include "./serial.hpp"
#include <string>
SerialPortManager::SerialPortManager()
{
struct termios tty;
std::cout << "opening serial port /dev/ttyUSB0" << std::endl;
serialPort = open("/dev/ttyUSB0", O_RDWR); // open serial port
std::cout << "done" << std::endl;
if (serialPort < 0)
{
printf("Error %i from open: %s\n", errno, strerror(errno));
return;
}
if (tcgetattr(serialPort, &tty) != 0)
{ // read serial port configuration
printf("Error %i from tcgetattr: %s\n", errno, strerror(errno));
return;
}
// local flags
tty.c_lflag &= ~ICANON; // enable canonical mode
tty.c_lflag &= ~ECHO; // Disable echo
tty.c_lflag &= ~ECHOE; // Disable erasure
tty.c_lflag &= ~ECHONL; // Disable new-line echo
tty.c_lflag &= ~ISIG; // Disable interpretation of INTR, QUIT and SUSP
// input modes
tty.c_iflag &= ~(IXON | IXOFF | IXANY); // Turn off s/w flow ctrl
tty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL); // Disable any special handling of received bytes
// output modes
tty.c_oflag &= ~OPOST; // Prevent special interpretation of output bytes (e.g. newline chars)
tty.c_oflag &= ~ONLCR; // Prevent conversion of newline to carriage return/line feed
// c_cc
tty.c_cc[VTIME] = 1; // Wait for up to 1s (10 deciseconds), returning as soon as any data is received.
tty.c_cc[VMIN] = 0;
// baudrate
cfsetispeed(&tty, B9600); // set baudrate (input)
cfsetospeed(&tty, B9600); // (output)
// Save tty settings, also checking for error
if (tcsetattr(serialPort, TCSANOW, &tty) != 0)
{
printf("Error %i from tcsetattr: %s\n", errno, strerror(errno));
return;
}
shouldRun = false;
std::cout << "starting hardware watcher thread" << std::endl;
std::thread *t = new std::thread(runPort);
std::cout << "done" << std::endl;
Threadweaver::stick_this_thread_to_core(t, CAMCORE);
//Threadweaver::hardwareWatcherThread = t;
shouldRun = true;
}
void SerialPortManager::runPort()
{
while (!shouldRun)
{
}
char read_buf[256];
int n = 0;
while (shouldRun)
{
n = read(serialPort, &read_buf, sizeof(read_buf));
if (n > 0)
{
char c = read_buf[0];
sendMessage(std::string()+c);
/*
switch (c)
{
case 'U':
cout << c << "++" << endl;
ui::UiController::selectedUp();
break;
case 'D':
cout << c << "--" << endl;
ui::UiController::selectedDown();
break;
case '1':
ui::UiController::click();
break;
case '2':
ui::UiController::click();
break;
case '3':
ui::UiController::click();
break;
case '4':
ui::UiController::click();
break;
default:
break;
}
*/
}
std::fill_n(read_buf, n, 0);
}
}

@ -0,0 +1,27 @@
// C library headers
#include <stdio.h>
#include <string.h>
// Linux headers
#include <fcntl.h> // Contains file controls like O_RDWR
#include <errno.h> // Error integer and strerror() function
#include <termios.h> // Contains POSIX terminal control definitions
#include <unistd.h> // write(), read(), close()
#include <thread>
#include <vector>
#include "../../patterns/observer/observable.hpp"
#include "../../patterns/observer/observer.hpp"
#include "../../threadweaver/threadweaver.hpp"
class SerialPortManager : Observable
{
public:
SerialPortManager();
void runPort();
private:
bool shouldRun;
int serialPort;
};

@ -13,17 +13,17 @@ const unsigned char psvr_power_on[8] {0x17,0x00,0xaa,0x04,0x00,0x00,0x00,0x00};
namespace psvr{
class Psvr{
public:
static hid_device* handle;
static bool vrMode;
static bool powered;
hid_device* handle;
bool vrMode;
bool powered;
static void open(); //default constructor
Psvr(); //default constructor
~Psvr();
static void startup();
static void shutdown();
static void vrmode();
static void cinemaMode();
static void close();//default destructor
void startup();
void shutdown();
void vrmode();
void cinemaMode();
void close();//default destructor
};
}

@ -1,11 +1,8 @@
#include "_psvr.hpp"
namespace psvr{
hid_device* Psvr::handle;
bool Psvr::vrMode;
bool Psvr::powered;
void Psvr::open(){
Psvr::Psvr(){
int res = hid_init();
handle = hid_func::open_device_idx(sony_vid, psvr_pid, ctrl_device_iface, 0);
@ -58,10 +55,9 @@ void Psvr::cinemaMode(){
vrMode = false;
}
void Psvr::close(){
Psvr::~Psvr(){
if(powered) shutdown();
hid_close(handle);
int res = hid_exit();
}
}

@ -0,0 +1,21 @@
#include "observable.hpp"
void Observable::Attach(Observer *observer)
{
list_observer_.push_back(observer);
}
void Observable::Detach(Observer *observer)
{
list_observer_.remove(observer);
}
void Observable::sendMessage(std::string str)
{
std::list<Observer*>::iterator iterator = list_observer_.begin();
while (iterator != list_observer_.end())
{
(*iterator)->Update(str);
++iterator;
}
}

@ -0,0 +1,14 @@
#include <iostream>
#include <list>
#include <string>
#include "observer.hpp"
class Observable {
public:
~Observable(){};
void Attach(Observer *observer) = 0;
void Detach(Observer *observer) = 0;
void sendMessage(std::string str);
private:
std::list<Observer*> list_observer_;
};

@ -0,0 +1,6 @@
#include <string>
class Observer {
public:
virtual void Update(const std::string &message_from_subject) = 0;
};

@ -0,0 +1,24 @@
#include "window.hpp"
void Window::draw(){
try{
drawAccess.lock();
if(drawSurface.empty()){
drawAccess.unlock();
return;
}
cv::UMat drawBuffer = drawSurface;
drawAccess.unlock();
#ifdef OGLWIN
drawTexture.copyFrom(drawBuffer);
cv::imshow(this->myWindow, this->drawTexture);
#else
cv::imshow(this->myWindow, drawBuffer);
#endif
cv::waitKey(10);
}
catch(...){
drawAccess.unlock();
}
}

@ -0,0 +1,17 @@
#include <opencv2/core/core.hpp>
#include <opencv2/core/opengl.hpp>
#include <opencv2/highgui.hpp>
#include <GL/glut.h>
#include <mutex>
/// @brief this class represents a single window, there should only ever be one if the app is in opengl mode.
class Window
{
public:
cv::UMat drawSurface; // Current frame
cv::ogl::Texture2D drawTexture = cv::ogl::Texture2D();
int id;
std::mutex drawAccess;
std::string myWindow;
void draw();
};

@ -0,0 +1,32 @@
#include "windowManager.hpp"
#include <thread>
namespace ui
{
// initializes the ui manager, following default values
WindowManager::WindowManager()
{
uiShouldRun = false;
for (int i = 0; i < DEFAULT_UI_WINDOW_AMOUNT; i++)
{
Window *newWindow = new Window();
newWindow->myWindow = "project- UI" + std::to_string(i);
#ifndef OGLWIN
cv::namedWindow(newWindow->myWindow); //if we're in opengl mode, the window needs to be created in the same thread as the execution, not here
#endif
cv::moveWindow(newWindow->myWindow, DEFAULT_UI_OFFSET_X + i * 960, DEFAULT_UI_OFFSET_Y);
cv::resizeWindow(newWindow->myWindow, DEFAULT_UI_SIZE_X, DEFAULT_UI_SIZE_Y);
//cout << "window: " << newWindow->myWindow << " created at " << DEFAULT_UI_OFFSET_X + i * 960 << " , " << DEFAULT_UI_OFFSET_Y << endl;
newWindow->id = i;
managedUIs.push_back(newWindow); // add new ui in the ui map, mapped to the window's name
}
uiShouldRun = true;
}
void WindowManager::cleanup()
{
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save