Add sliders for channels 1,2,3
This commit is contained in:
parent
ecaa2d17fc
commit
d3f046f0d0
39
main.cpp
39
main.cpp
@ -7,6 +7,7 @@
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_glfw.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
#include <atomic>
|
||||
|
||||
// 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<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() {
|
||||
// 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<unsigned char>(channel1);
|
||||
buffer[1] = static_cast<unsigned char>(channel2);
|
||||
buffer[2] = static_cast<unsigned char>(channel3);
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user