Add gui for serial configuration
This commit is contained in:
		@@ -15,6 +15,11 @@ class ImuSerial
 | 
			
		||||
		void start();
 | 
			
		||||
		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::vec3 get_accel();
 | 
			
		||||
		glm::vec3 get_gyro();
 | 
			
		||||
 
 | 
			
		||||
@@ -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()
 | 
			
		||||
{
 | 
			
		||||
	std::lock_guard(this->quat_mutex);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										34
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								src/main.cpp
									
									
									
									
									
								
							@@ -16,6 +16,38 @@
 | 
			
		||||
#define WINDOW_WIDTH 1500
 | 
			
		||||
#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)
 | 
			
		||||
{
 | 
			
		||||
	(void)argc;
 | 
			
		||||
@@ -73,7 +105,6 @@ int main(int argc, char **argv)
 | 
			
		||||
	glEnable(GL_DEPTH_TEST);
 | 
			
		||||
 | 
			
		||||
	auto imu_serial = ImuSerial("/dev/ttyUSB0", 115200);
 | 
			
		||||
	imu_serial.start();
 | 
			
		||||
 | 
			
		||||
	while (run) {
 | 
			
		||||
 | 
			
		||||
@@ -108,6 +139,7 @@ int main(int argc, char **argv)
 | 
			
		||||
		ImGui_ImplSDL2_NewFrame(window->getWindow());
 | 
			
		||||
		ImGui::NewFrame();
 | 
			
		||||
 | 
			
		||||
		handle_serial_port_gui(imu_serial);
 | 
			
		||||
 | 
			
		||||
		ImGui::Begin("Camera");
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user