Skeletal Animation Multithread Face
Public Member Functions | Private Member Functions | Private Attributes | List of all members
MenuHandler Class Reference

Class MenuHandler. More...

#include <menu_handler.h>

Public Member Functions

 MenuHandler (igl::opengl::glfw::imgui::ImGuiMenu *menu)
 Constructor. More...
 
void callback (void)
 Menu callback function. More...
 
bool are_ports_set (void)
 Check whether the USB ports have been sent by the user (Is OK pressed?). More...
 
std::string get_left_exoskeleton_port (void)
 Get the USB port for the left exoskeleton. More...
 
std::string get_right_exoskeleton_port (void)
 Get the USB port for the right exoskeleton. More...
 

Private Member Functions

std::vector< std::string > get_available_usb_ports (void)
 Get available USB ports. More...
 

Private Attributes

igl::opengl::glfw::imgui::ImGuiMenu * m_menu
 ImGui menu handle pointer. More...
 
std::string m_left_exoskeleton_port
 Name of the left exoskeleton USB port. More...
 
std::string m_right_exoskeleton_port
 Name of the right exoskeleton USB port. More...
 
bool m_ports_set = 0
 Flag that stores the state of the USB port (whether are set or not). More...
 

Detailed Description

Class MenuHandler.

This class handles the animation menu.

Definition at line 22 of file menu_handler.h.

Constructor & Destructor Documentation

◆ MenuHandler()

MenuHandler::MenuHandler ( igl::opengl::glfw::imgui::ImGuiMenu *  menu)

Constructor.

Construct a new Menu Handler:: Menu Handler object.

Parameters
menuThe menu pointer provided by ImGui.

Definition at line 8 of file menu_handler.cpp.

9{
10 // Copy menu pointer
11 m_menu = menu;
12}
igl::opengl::glfw::imgui::ImGuiMenu * m_menu
ImGui menu handle pointer.
Definition: menu_handler.h:42

Member Function Documentation

◆ are_ports_set()

bool MenuHandler::are_ports_set ( void  )
inline

Check whether the USB ports have been sent by the user (Is OK pressed?).

Definition at line 32 of file menu_handler.h.

32{ return m_ports_set; }
bool m_ports_set
Flag that stores the state of the USB port (whether are set or not).
Definition: menu_handler.h:56
Here is the caller graph for this function:

◆ callback()

void MenuHandler::callback ( void  )

Menu callback function.

The callback function responds to the actions of the ImGui menu. This function is passed as a lambda function to the menu handler (see main.cpp).

Definition at line 19 of file menu_handler.cpp.

20{
21 // Draw viewer menu
22 m_menu->draw_viewer_menu();
23
24 // Add new group
25 if (ImGui::CollapsingHeader("Set USB Ports", ImGuiTreeNodeFlags_DefaultOpen))
26 {
27 if (!m_ports_set)
28 {
29 // Get available usb poirts
30 std::vector<std::string> available_ports = get_available_usb_ports();
31
32 static std::vector<std::string> choices;
33
34 static int left_exo_idx_choise = 0;
35 static int right_exo_idx_choise = 0;
36
37 // Get left exoskeleton port
38 ImGui::Combo("Left exoskeleton", &left_exo_idx_choise,
39 available_ports);
40
41 // Get right exoskeleton port
42 ImGui::Combo("Right exoskeleton", &right_exo_idx_choise,
43 available_ports);
44
45 if (ImGui::Button("OK"))
46 {
47 m_left_exoskeleton_port = available_ports.at(left_exo_idx_choise);
48 m_right_exoskeleton_port = available_ports.at(right_exo_idx_choise);
49 m_ports_set = 1;
50 }
51 }
52 }
53}
std::string m_right_exoskeleton_port
Name of the right exoskeleton USB port.
Definition: menu_handler.h:53
std::vector< std::string > get_available_usb_ports(void)
Get available USB ports.
std::string m_left_exoskeleton_port
Name of the left exoskeleton USB port.
Definition: menu_handler.h:50
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_available_usb_ports()

std::vector< std::string > MenuHandler::get_available_usb_ports ( void  )
private

Get available USB ports.

This function simply generates the available USB ports.

Returns
std::vector<std::string> The available USB ports

Definition at line 59 of file menu_handler.cpp.

60{
61 // Initialize all ports
62 std::vector<std::string> ports;
63
64 // Get the listed usb ports
65 std::string usb_path("/dev/");
66 std::string key("tty");
67 for (const auto & entry : std::filesystem::directory_iterator(usb_path))
68 {
69 //Get path string
70 std::string path_string = entry.path().string();
71
72 // Check if key is in path string
73 if (path_string.find(key) != std::string::npos)
74 {
75 ports.push_back(path_string);
76 }
77 }
78
79 // Initialize availale ports
80 std::vector<std::string> available_ports;
81
82 // Check for all ports if they are available
83 for (size_t i = 0; i < ports.size(); i++)
84 {
85 int serial_port = open(ports.at(i).c_str(), O_RDWR);
86
87 struct termios tty;
88 if(tcgetattr(serial_port, &tty) == 0) {
89 available_ports.push_back(ports.at(i));
90 }
91
92 close(serial_port);
93 }
94
95 return available_ports;
96}
Here is the caller graph for this function:

◆ get_left_exoskeleton_port()

std::string MenuHandler::get_left_exoskeleton_port ( void  )
inline

Get the USB port for the left exoskeleton.

Definition at line 35 of file menu_handler.h.

Here is the caller graph for this function:

◆ get_right_exoskeleton_port()

std::string MenuHandler::get_right_exoskeleton_port ( void  )
inline

Get the USB port for the right exoskeleton.

Definition at line 38 of file menu_handler.h.

Here is the caller graph for this function:

Member Data Documentation

◆ m_left_exoskeleton_port

std::string MenuHandler::m_left_exoskeleton_port
private

Name of the left exoskeleton USB port.

Definition at line 50 of file menu_handler.h.

◆ m_menu

igl::opengl::glfw::imgui::ImGuiMenu* MenuHandler::m_menu
private

ImGui menu handle pointer.

Definition at line 42 of file menu_handler.h.

◆ m_ports_set

bool MenuHandler::m_ports_set = 0
private

Flag that stores the state of the USB port (whether are set or not).

Definition at line 56 of file menu_handler.h.

◆ m_right_exoskeleton_port

std::string MenuHandler::m_right_exoskeleton_port
private

Name of the right exoskeleton USB port.

Definition at line 53 of file menu_handler.h.


The documentation for this class was generated from the following files: