Add gui for serial configuration

This commit is contained in:
Mario Hüttel 2020-07-16 22:18:18 +02:00
parent 6edc570a26
commit 94d60ad56f
3 changed files with 66 additions and 1 deletions

View File

@ -15,6 +15,11 @@ class ImuSerial
void start(); void start();
void stop(); void stop();
void set_device(const std::string &device);
void set_baudrate(const unsigned int baud);
unsigned int get_baudrate();
const std::string &get_device();
bool runs();
glm::quat get_quaternion(); glm::quat get_quaternion();
glm::vec3 get_accel(); glm::vec3 get_accel();
glm::vec3 get_gyro(); glm::vec3 get_gyro();

View File

@ -244,6 +244,34 @@ void ImuSerial::stop()
} }
} }
void ImuSerial::set_device(const std::string &device)
{
this->serial_device = device;
}
void ImuSerial::set_baudrate(const unsigned int baud)
{
this->baud = baud;
}
unsigned int ImuSerial::get_baudrate()
{
return this->baud;
}
const std::string &ImuSerial::get_device()
{
return this->serial_device;
}
bool ImuSerial::runs()
{
if (this->worker.joinable() && this->stop_flag == 0)
return true;
else
return false;
}
glm::quat ImuSerial::get_quaternion() glm::quat ImuSerial::get_quaternion()
{ {
std::lock_guard(this->quat_mutex); std::lock_guard(this->quat_mutex);

View File

@ -16,6 +16,38 @@
#define WINDOW_WIDTH 1500 #define WINDOW_WIDTH 1500
#define WINDOW_HEIGHT 1000 #define WINDOW_HEIGHT 1000
static void handle_serial_port_gui(ImuSerial &imu_comm)
{
static char foo[512] = {0};
static int baud_rate;
static bool first = true;
bool runs = imu_comm.runs();
if (first) {
imu_comm.get_device().copy(foo, sizeof(foo), 0);
baud_rate = imu_comm.get_baudrate();
first = false;
}
ImGui::Begin("Serial Config");
ImGui::InputText("Serial Device", foo, sizeof(foo));
ImGui::InputInt("Baudrate", &baud_rate);
bool button = ImGui::Button((runs ? "Stop" : "Start"));
ImGui::End();
if (button) {
if (runs) {
imu_comm.stop();
} else {
imu_comm.set_device(std::string(foo));
imu_comm.set_baudrate((unsigned int)baud_rate);
imu_comm.start();
}
}
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
(void)argc; (void)argc;
@ -73,7 +105,6 @@ int main(int argc, char **argv)
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
auto imu_serial = ImuSerial("/dev/ttyUSB0", 115200); auto imu_serial = ImuSerial("/dev/ttyUSB0", 115200);
imu_serial.start();
while (run) { while (run) {
@ -108,6 +139,7 @@ int main(int argc, char **argv)
ImGui_ImplSDL2_NewFrame(window->getWindow()); ImGui_ImplSDL2_NewFrame(window->getWindow());
ImGui::NewFrame(); ImGui::NewFrame();
handle_serial_port_gui(imu_serial);
ImGui::Begin("Camera"); ImGui::Begin("Camera");