Add sliders for channels 1,2,3

This commit is contained in:
illyum 2024-08-08 22:56:58 -06:00
parent ecaa2d17fc
commit d3f046f0d0

View File

@ -7,6 +7,7 @@
#include "imgui.h" #include "imgui.h"
#include "imgui_impl_glfw.h" #include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h" #include "imgui_impl_opengl3.h"
#include <atomic>
// Forward declarations // Forward declarations
void generateRandomColors(unsigned char& r, unsigned char& g, unsigned char& b); void generateRandomColors(unsigned char& r, unsigned char& g, unsigned char& b);
@ -23,6 +24,15 @@ GLFWwindow* initOpenGL();
// Serial port handle // Serial port handle
HANDLE hSerial; HANDLE hSerial;
std::atomic<bool> 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() { int main() {
// Open the serial port // Open the serial port
@ -76,6 +86,9 @@ int main() {
// Setup ImGui // Setup ImGui
setupImGui(window); setupImGui(window);
// Start the DMX thread
std::thread dmxThread(dmxThreadFunc);
// Main loop // Main loop
while (!glfwWindowShouldClose(window)) { while (!glfwWindowShouldClose(window)) {
// Poll events // Poll events
@ -89,9 +102,6 @@ int main() {
// Render ImGui components // Render ImGui components
renderImGui(); renderImGui();
// Update DMX data with values from sliders
sendDMXData(hSerial, buffer, num_channels);
// Rendering // Rendering
ImGui::Render(); ImGui::Render();
int display_w, display_h; int display_w, display_h;
@ -103,11 +113,12 @@ int main() {
// Swap buffers // Swap buffers
glfwSwapBuffers(window); glfwSwapBuffers(window);
// Simulate DMX refresh rate
std::this_thread::sleep_for(std::chrono::milliseconds(25));
} }
// Stop the DMX thread
running = false;
dmxThread.join();
// Cleanup // Cleanup
ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown(); ImGui_ImplGlfw_Shutdown();
@ -184,13 +195,23 @@ void setupImGui(GLFWwindow* window) {
} }
void renderImGui() { void renderImGui() {
// Temporary variables to hold the slider values
int channel1 = buffer[0];
int channel2 = buffer[1];
int channel3 = buffer[2];
// Create a window // Create a window
ImGui::Begin("DMX Controller"); ImGui::Begin("DMX Controller");
// Create sliders for the first three DMX channels // Create sliders for the first three DMX channels
ImGui::SliderInt("Channel 1", (int*)&buffer[0], 0, 255); ImGui::SliderInt("Channel 1", &channel1, 0, 255);
ImGui::SliderInt("Channel 2", (int*)&buffer[1], 0, 255); ImGui::SliderInt("Channel 2", &channel2, 0, 255);
ImGui::SliderInt("Channel 3", (int*)&buffer[2], 0, 255); ImGui::SliderInt("Channel 3", &channel3, 0, 255);
// Assign the slider values back to the DMX buffer
buffer[0] = static_cast<unsigned char>(channel1);
buffer[1] = static_cast<unsigned char>(channel2);
buffer[2] = static_cast<unsigned char>(channel3);
ImGui::End(); ImGui::End();
} }