Skeletal Animation Multithread Face
menu_handler.cpp
Go to the documentation of this file.
1#include "../include/menu_handler.h"
2
8MenuHandler::MenuHandler(igl::opengl::glfw::imgui::ImGuiMenu* menu)
9{
10 // Copy menu pointer
11 m_menu = menu;
12}
13
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}
54
59std::vector<std::string> MenuHandler::get_available_usb_ports(void)
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}
97
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.
igl::opengl::glfw::imgui::ImGuiMenu * m_menu
ImGui menu handle pointer.
Definition: menu_handler.h:42
void callback(void)
Menu callback function.
bool m_ports_set
Flag that stores the state of the USB port (whether are set or not).
Definition: menu_handler.h:56
std::string m_left_exoskeleton_port
Name of the left exoskeleton USB port.
Definition: menu_handler.h:50
MenuHandler(igl::opengl::glfw::imgui::ImGuiMenu *menu)
Constructor.
Definition: menu_handler.cpp:8