From d3f046f0d094cdb842eccdcfbf52868a36b32081 Mon Sep 17 00:00:00 2001 From: illyum <90023277+itzilly@users.noreply.github.com> Date: Thu, 8 Aug 2024 22:56:58 -0600 Subject: [PATCH] Add sliders for channels 1,2,3 --- main.cpp | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/main.cpp b/main.cpp index bb2e50b..e135f18 100644 --- a/main.cpp +++ b/main.cpp @@ -7,6 +7,7 @@ #include "imgui.h" #include "imgui_impl_glfw.h" #include "imgui_impl_opengl3.h" +#include // Forward declarations void generateRandomColors(unsigned char& r, unsigned char& g, unsigned char& b); @@ -23,6 +24,15 @@ GLFWwindow* initOpenGL(); // Serial port handle HANDLE hSerial; +std::atomic running(true); + +void dmxThreadFunc() { + while (running) { + // Send DMX data with a refresh rate of 25ms + sendDMXData(hSerial, buffer, num_channels); + std::this_thread::sleep_for(std::chrono::milliseconds(25)); + } +} int main() { // Open the serial port @@ -76,6 +86,9 @@ int main() { // Setup ImGui setupImGui(window); + // Start the DMX thread + std::thread dmxThread(dmxThreadFunc); + // Main loop while (!glfwWindowShouldClose(window)) { // Poll events @@ -89,9 +102,6 @@ int main() { // Render ImGui components renderImGui(); - // Update DMX data with values from sliders - sendDMXData(hSerial, buffer, num_channels); - // Rendering ImGui::Render(); int display_w, display_h; @@ -103,11 +113,12 @@ int main() { // Swap buffers glfwSwapBuffers(window); - - // Simulate DMX refresh rate - std::this_thread::sleep_for(std::chrono::milliseconds(25)); } + // Stop the DMX thread + running = false; + dmxThread.join(); + // Cleanup ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); @@ -184,13 +195,23 @@ void setupImGui(GLFWwindow* window) { } void renderImGui() { + // Temporary variables to hold the slider values + int channel1 = buffer[0]; + int channel2 = buffer[1]; + int channel3 = buffer[2]; + // Create a window ImGui::Begin("DMX Controller"); // Create sliders for the first three DMX channels - ImGui::SliderInt("Channel 1", (int*)&buffer[0], 0, 255); - ImGui::SliderInt("Channel 2", (int*)&buffer[1], 0, 255); - ImGui::SliderInt("Channel 3", (int*)&buffer[2], 0, 255); + ImGui::SliderInt("Channel 1", &channel1, 0, 255); + ImGui::SliderInt("Channel 2", &channel2, 0, 255); + ImGui::SliderInt("Channel 3", &channel3, 0, 255); + + // Assign the slider values back to the DMX buffer + buffer[0] = static_cast(channel1); + buffer[1] = static_cast(channel2); + buffer[2] = static_cast(channel3); ImGui::End(); }