Initial Commit
This commit is contained in:
commit
2c8d0b8150
BIN
.cache/clangd/index/main.cpp.F0A0A455395D2B3A.idx
Normal file
BIN
.cache/clangd/index/main.cpp.F0A0A455395D2B3A.idx
Normal file
Binary file not shown.
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
# Ignore build dirs
|
||||
/build
|
||||
/build-vs
|
||||
|
||||
# Generated nvim files
|
||||
compile_commands.json
|
||||
|
||||
# Binaries
|
||||
main.exe
|
||||
|
65
CMakeLists.txt
Normal file
65
CMakeLists.txt
Normal file
@ -0,0 +1,65 @@
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
|
||||
# Need this to make FETCHCONTENT_QUIET off
|
||||
if(POLICY CMP0077)
|
||||
cmake_policy(SET CMP0077 NEW)
|
||||
endif()
|
||||
|
||||
set(PROJECT_NAME DmxShow)
|
||||
project(${PROJECT_NAME})
|
||||
|
||||
# Make sure this is here for nvim and fleet users
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
set(FETCHCONTENT_QUIET OFF)
|
||||
|
||||
add_executable(${PROJECT_NAME} main.cpp)
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
imgui
|
||||
GIT_REPOSITORY https://github.com/ocornut/imgui.git
|
||||
GIT_TAG master
|
||||
GIT_SHALLOW ON
|
||||
GIT_PROGRESS ON
|
||||
)
|
||||
FetchContent_MakeAvailable(imgui)
|
||||
|
||||
FetchContent_Declare(
|
||||
glfw
|
||||
GIT_REPOSITORY https://github.com/glfw/glfw.git
|
||||
GIT_TAG master
|
||||
GIT_SHALLOW ON
|
||||
GIT_PROGRESS ON
|
||||
)
|
||||
FetchContent_MakeAvailable(glfw)
|
||||
|
||||
FetchContent_Declare(
|
||||
glew
|
||||
GIT_REPOSITORY https://github.com/Perlmint/glew-cmake.git
|
||||
GIT_TAG master
|
||||
GIT_SHALLOW ON
|
||||
GIT_PROGRESS ON
|
||||
)
|
||||
FetchContent_MakeAvailable(glew)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${imgui_SOURCE_DIR}
|
||||
${imgui_SOURCE_DIR}/backends
|
||||
${glfw_SOURCE_DIR}/include
|
||||
${glew_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
target_sources(${PROJECT_NAME} PRIVATE
|
||||
${imgui_SOURCE_DIR}/imgui.cpp
|
||||
${imgui_SOURCE_DIR}/imgui_demo.cpp
|
||||
${imgui_SOURCE_DIR}/imgui_draw.cpp
|
||||
${imgui_SOURCE_DIR}/imgui_tables.cpp
|
||||
${imgui_SOURCE_DIR}/imgui_widgets.cpp
|
||||
${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.cpp
|
||||
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE glfw libglew_static opengl32)
|
118
app.cpp
Normal file
118
app.cpp
Normal file
@ -0,0 +1,118 @@
|
||||
#include <iostream>
|
||||
#include <windows.h>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <csignal>
|
||||
|
||||
|
||||
HANDLE hSerial = INVALID_HANDLE_VALUE;
|
||||
// Number of channels in the universe
|
||||
const int num_channels = 512;
|
||||
bool blackoutMode = false;
|
||||
|
||||
void sendDMXData(HANDLE hSerial, unsigned char* data, int length);
|
||||
|
||||
void signalHandler(int signum) {
|
||||
std::cout << "Interrupt signal (" << signum << ") received.\n";
|
||||
blackoutMode = true;
|
||||
|
||||
if (hSerial != INVALID_HANDLE_VALUE) {
|
||||
std::cout << "Closing serial port...\n";
|
||||
CloseHandle(hSerial);
|
||||
}
|
||||
|
||||
exit(signum);
|
||||
}
|
||||
|
||||
void sendDMXData(HANDLE hSerial, unsigned char* data, int length) {
|
||||
// Start with a DMX break condition
|
||||
EscapeCommFunction(hSerial, SETBREAK);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
EscapeCommFunction(hSerial, CLRBREAK);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
|
||||
|
||||
DWORD bytesWritten;
|
||||
unsigned char startCode = 0;
|
||||
WriteFile(hSerial, &startCode, 1, &bytesWritten, NULL);
|
||||
WriteFile(hSerial, data, length, &bytesWritten, NULL);
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Register the signal handler for SIGINT (Ctrl+C)
|
||||
std::signal(SIGINT, signalHandler);
|
||||
|
||||
// Open the serial port
|
||||
hSerial = CreateFileA("\\\\.\\COM3", GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
if (hSerial == INVALID_HANDLE_VALUE) {
|
||||
std::cerr << "Error opening COM3 port" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Configure the serial port
|
||||
DCB dcbSerialParams = { 0 };
|
||||
dcbSerialParams.DCBlength = sizeof(dcbSerialParams);
|
||||
if (!GetCommState(hSerial, &dcbSerialParams)) {
|
||||
std::cerr << "Error getting COM3 state" << std::endl;
|
||||
CloseHandle(hSerial);
|
||||
return 1;
|
||||
}
|
||||
|
||||
dcbSerialParams.BaudRate = 250000; // DMX512 uses 250000 baud
|
||||
dcbSerialParams.ByteSize = 8;
|
||||
dcbSerialParams.StopBits = TWOSTOPBITS; // DMX512 uses 2 stop bits
|
||||
dcbSerialParams.Parity = NOPARITY;
|
||||
|
||||
if (!SetCommState(hSerial, &dcbSerialParams)) {
|
||||
std::cerr << "Error setting COM3 state" << std::endl;
|
||||
CloseHandle(hSerial);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Set timeouts
|
||||
COMMTIMEOUTS timeouts = { 0 };
|
||||
timeouts.ReadIntervalTimeout = 50;
|
||||
timeouts.ReadTotalTimeoutConstant = 50;
|
||||
timeouts.ReadTotalTimeoutMultiplier = 10;
|
||||
timeouts.WriteTotalTimeoutConstant = 50;
|
||||
timeouts.WriteTotalTimeoutMultiplier = 10;
|
||||
|
||||
if (!SetCommTimeouts(hSerial, &timeouts)) {
|
||||
std::cerr << "Error setting COM3 timeouts" << std::endl;
|
||||
CloseHandle(hSerial);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// DMX data (512 channels, all set to 255)
|
||||
unsigned char buffer[num_channels];
|
||||
memset(buffer, 255, sizeof(buffer)); // Fill the buffer with 255
|
||||
|
||||
// Send DMX data in an infinite loop
|
||||
while (!blackoutMode) {
|
||||
sendDMXData(hSerial, buffer, num_channels);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(25));
|
||||
// Set random colors for channels 1, 2, and 3 of device 1
|
||||
std::srand(std::time(0)); // Seed random number generator
|
||||
|
||||
buffer[0] = std::rand() % 256; // Random value for channel 1
|
||||
buffer[1] = std::rand() % 256; // Random value for channel 2
|
||||
buffer[2] = std::rand() % 256; //
|
||||
}
|
||||
|
||||
// Blackout buffer (512 channels, all set to 0)
|
||||
unsigned char blackoutBuffer[num_channels];
|
||||
memset(blackoutBuffer, 0, sizeof(blackoutBuffer)); // Fill the buffer with 0
|
||||
|
||||
for (int x = 0; x < 10; x++) {
|
||||
printf("step: %d\n", x);
|
||||
sendDMXData(hSerial, blackoutBuffer, num_channels);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(25));
|
||||
}
|
||||
|
||||
printf("Done!\n");
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
11
libs/CMakeLists.txt
Normal file
11
libs/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
project(imgui)
|
||||
|
||||
file(GLOB imgui_sources
|
||||
"${CMAKE_SOURCE_DIR}/thirdparty/imgui/*.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/thirdparty/imgui/*.h"
|
||||
)
|
||||
|
||||
add_library(imgui STATIC ${imgui_sources})
|
||||
|
||||
target_include_directories(imgui PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
287
libs/cmake-glew/CMakeLists.txt
Normal file
287
libs/cmake-glew/CMakeLists.txt
Normal file
@ -0,0 +1,287 @@
|
||||
cmake_minimum_required(VERSION 2.8.12...3.5)
|
||||
|
||||
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/config/version _VERSION_MAJOR_STRING REGEX "GLEW_MAJOR[ ]*=[ ]*[0-9]+.*")
|
||||
string(REGEX REPLACE "GLEW_MAJOR[ ]*=[ ]*([0-9]+)" "\\1" MAJOR_VERSION ${_VERSION_MAJOR_STRING})
|
||||
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/config/version _VERSION_MINOR_STRING REGEX "GLEW_MINOR[ ]*=[ ]*[0-9]+.*")
|
||||
string(REGEX REPLACE "GLEW_MINOR[ ]*=[ ]*([0-9]+)" "\\1" MINOR_VERSION ${_VERSION_MINOR_STRING})
|
||||
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/config/version _VERSION_PATCH_STRING REGEX "GLEW_MICRO[ ]*=[ ]*[0-9]+.*")
|
||||
string(REGEX REPLACE "GLEW_MICRO[ ]*=[ ]*([0-9]+)" "\\1" PATCH_VERSION ${_VERSION_PATCH_STRING})
|
||||
set(GLEW_VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION})
|
||||
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.0)
|
||||
cmake_policy(SET CMP0048 NEW)
|
||||
project("glew" VERSION ${GLEW_VERSION} LANGUAGES C)
|
||||
else()
|
||||
project("glew" C)
|
||||
set(CPACK_PACKAGE_VERSION_MAJOR ${MAJOR_VERSION})
|
||||
set(CPACK_PACKAGE_VERSION_MINOR ${MAJOR_VERSION})
|
||||
set(CPACK_PACKAGE_VERSION_PATCH ${MAJOR_VERSION})
|
||||
endif()
|
||||
|
||||
set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
set(INCLUDE_DIR "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>$<INSTALL_INTERFACE:include>")
|
||||
set(RC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)
|
||||
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
|
||||
|
||||
include("GeneratePkgConfig.cmake")
|
||||
|
||||
if (POLICY CMP0077)
|
||||
cmake_policy(SET CMP0077 NEW)
|
||||
endif()
|
||||
|
||||
option(glew-cmake_BUILD_SHARED "Build the shared glew library" ON)
|
||||
option(glew-cmake_BUILD_STATIC "Build the static glew library" ON)
|
||||
option(USE_GLU "Use GLU" OFF)
|
||||
option(GLEW_OSMESA "Off-screen Mesa mode" OFF)
|
||||
option(PKG_CONFIG_REPRESENTATIVE_TARGET "Generate pc file for specified target as glew. libglew_static|libglew_shared" OFF)
|
||||
option(ONLY_LIBS "Do not build executables" OFF)
|
||||
|
||||
set(LIBGLEW_SRCS ${SRC_DIR}/glew.c)
|
||||
|
||||
set(DEFINITIONS)
|
||||
if(WIN32)
|
||||
list(APPEND DEFINITIONS -DWIN32_MEAN_AND_LEAN -DVC_EXTRALEAN -D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
list(APPEND LIBGLEW_SRCS ${RC_DIR}/glew.rc)
|
||||
endif()
|
||||
|
||||
# Use namespaced libraries when supported
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.14)
|
||||
set(USE_NAMESPACED_LIB YES)
|
||||
else()
|
||||
set(USE_NAMESPACED_LIB NO)
|
||||
endif()
|
||||
|
||||
if(POLICY CMP0028)
|
||||
cmake_policy(SET CMP0028 NEW)
|
||||
endif()
|
||||
|
||||
if(POLICY CMP0042)
|
||||
cmake_policy(SET CMP0042 NEW)
|
||||
endif()
|
||||
|
||||
if(POLICY CMP0072)
|
||||
set(OpenGL_GL_PREFERENCE GLVND)
|
||||
endif()
|
||||
|
||||
if(NOT (WIN32 OR APPLE))
|
||||
message("Try to find OpenGL with GLVND")
|
||||
find_package(OpenGL REQUIRED
|
||||
COMPONENTS OpenGL GLX)
|
||||
endif()
|
||||
|
||||
if(OPENGL_FOUND AND OpenGL_GLX_FOUND AND TARGET OpenGL::OpenGL)
|
||||
set(USE_GLVND YES)
|
||||
else()
|
||||
message("GLVND not supported. Try find OpenGL legacy")
|
||||
find_package(OpenGL REQUIRED)
|
||||
set(USE_GLVND NO)
|
||||
endif()
|
||||
|
||||
set(pc_requires)
|
||||
|
||||
if(NOT USE_GLU)
|
||||
list(APPEND DEFINITIONS -DGLEW_NO_GLU)
|
||||
else()
|
||||
if(NOT OPENGL_GLU_FOUND)
|
||||
message(FATAL_ERROR "GLU is not found. but GLU option is enabled")
|
||||
endif()
|
||||
|
||||
list(APPEND pc_requires glu)
|
||||
|
||||
if(USE_NAMESPACED_LIB)
|
||||
list(APPEND LIBRARIES OpenGL::GLU)
|
||||
else()
|
||||
list(APPEND LIBRARIES ${OPENGL_glu_LIBRARY})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
list(APPEND pc_requires gl)
|
||||
if(USE_NAMESPACED_LIB)
|
||||
if(USE_GLVND)
|
||||
list(APPEND LIBRARIES OpenGL::OpenGL)
|
||||
else()
|
||||
list(APPEND LIBRARIES OpenGL::GL)
|
||||
endif()
|
||||
else()
|
||||
if(USE_GLVND)
|
||||
list(APPEND LIBRARIES ${OPENGL_opengl_LIBRARY})
|
||||
else()
|
||||
list(APPEND LIBRARIES ${OPENGL_gl_LIBRARY})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# OS Specific dependencies
|
||||
if(APPLE)
|
||||
find_library(AGL_LIBRARY AGL REQUIRED)
|
||||
list(APPEND LIBRARIES ${AGL_LIBRARY})
|
||||
elseif(NOT WIN32)
|
||||
if(GLEW_OSMESA)
|
||||
find_library(OSMESA_LIBRARY OSMesa REQUIRED)
|
||||
list(APPEND LIBRARIES ${OSMESA_LIBRARY})
|
||||
list(APPEND DEFINITIONS -DGLEW_OSMESA)
|
||||
list(APPEND pc_requires osmesa)
|
||||
else()
|
||||
if(USE_GLVND)
|
||||
if(NOT OpenGL_GLX_FOUND)
|
||||
message(FATAL_ERROR "GLX is not found. Try with PREFER_GLVND=NO")
|
||||
endif()
|
||||
|
||||
if(USE_NAMESPACED_LIB)
|
||||
list(APPEND LIBRARIES OpenGL::GLX)
|
||||
else()
|
||||
list(APPEND LIBRARIES ${OPENGL_glx_LIBRARY})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
find_package(X11 REQUIRED)
|
||||
|
||||
list(APPEND pc_requires x11 xext)
|
||||
if(USE_NAMESPACED_LIB)
|
||||
list(APPEND LIBRARIES X11::X11 X11::Xext)
|
||||
else()
|
||||
list(APPEND LIBRARIES ${X11_X11_LIB} ${X11_Xext_LIB})
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(GLEW_TARGETS)
|
||||
|
||||
if(NOT CMAKE_INSTALL_LIBDIR)
|
||||
set(INSTALL_LIBDIR lib)
|
||||
else()
|
||||
set(INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/test_fs_support_case_sensitivity
|
||||
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/test_fs_support_CASE_sensitivity)
|
||||
file(GLOB TEST_FILE_LIST ${CMAKE_BINARY_DIR}/test_fs_support_*_sensitivity)
|
||||
list(LENGTH TEST_FILE_LIST TEST_FILE_COUNT)
|
||||
if(TEST_FILE_COUNT EQUAL 2)
|
||||
set(SUPPORT_CASE_SENSITIVE_FS YES)
|
||||
else()
|
||||
set(SUPPORT_CASE_SENSITIVE_FS NO)
|
||||
endif()
|
||||
|
||||
function(set_representative_target TARGET)
|
||||
set_target_properties(${TARGET} PROPERTIES
|
||||
OUTPUT_NAME "glew"
|
||||
DEBUG_POSTFIX d)
|
||||
|
||||
# Windows & macOS use case-insensetive FS. do not create symbolic link
|
||||
if(SUPPORT_CASE_SENSITIVE_FS)
|
||||
get_target_property(TARGET_TYPE ${TARGET} TYPE)
|
||||
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
|
||||
if(CMAKE_BUILD_TYPE_LOWER STREQUAL "debug" AND NOT ANDROID)
|
||||
set(GLEW_DEBUG_SUFFIX "d")
|
||||
else()
|
||||
set(GLEW_DEBUG_SUFFIX "")
|
||||
endif()
|
||||
if(TARGET_TYPE STREQUAL STATIC_LIBRARY)
|
||||
set(EXT ".a")
|
||||
get_target_property(OUT_DIR ${TARGET} ARCHIVE_OUTPUT_DIRECTORY)
|
||||
else()
|
||||
set(EXT ".so")
|
||||
get_target_property(OUT_DIR ${TARGET} LIBRARY_OUTPUT_DIRECTORY)
|
||||
endif()
|
||||
if(NOT ${CMAKE_VERSION} VERSION_LESS 3.0)
|
||||
add_custom_command(TARGET ${TARGET} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E create_symlink libglew${GLEW_DEBUG_SUFFIX}${EXT} libGLEW${GLEW_DEBUG_SUFFIX}${EXT}
|
||||
WORKING_DIRECTORY ${OUT_DIR}
|
||||
BYPRODUCTS ${OUT_DIR}/libGLEW${GLEW_DEBUG_SUFFIX}${EXT}
|
||||
COMMENT "create libGLEW${GLEW_DEBUG_SUFFIX} symbolic link")
|
||||
else()
|
||||
add_custom_command(TARGET ${TARGET} POST_BUILD
|
||||
COMMAND bash ARGS -c "( test ! -e ${OUT_DIR}/libGLEW${GLEW_DEBUG_SUFFIX}${EXT} && cd ${OUT_DIR} && ${CMAKE_COMMAND} -E create_symlink libglew${GLEW_DEBUG_SUFFIX}${EXT} libGLEW${GLEW_DEBUG_SUFFIX}${EXT} ) || true"
|
||||
COMMENT "create libGLEW${GLEW_DEBUG_SUFFIX} symbolic link"
|
||||
VERBATIM)
|
||||
endif()
|
||||
|
||||
if(NOT ${CMAKE_VERSION} VERSION_LESS 3.14)
|
||||
install(FILES ${OUT_DIR}/libGLEW${GLEW_DEBUG_SUFFIX}${EXT} TYPE LIB)
|
||||
else()
|
||||
install(FILES ${OUT_DIR}/libGLEW${GLEW_DEBUG_SUFFIX}${EXT} DESTINATION ${INSTALL_LIBDIR})
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
if(glew-cmake_BUILD_STATIC)
|
||||
add_library(libglew_static STATIC ${LIBGLEW_SRCS})
|
||||
|
||||
set_representative_target(libglew_static)
|
||||
|
||||
target_compile_definitions(libglew_static PUBLIC GLEW_STATIC)
|
||||
list(APPEND GLEW_TARGETS libglew_static)
|
||||
endif()
|
||||
|
||||
if(glew-cmake_BUILD_SHARED)
|
||||
add_library(libglew_shared SHARED ${LIBGLEW_SRCS})
|
||||
|
||||
if(glew-cmake_BUILD_STATIC)
|
||||
set_target_properties(libglew_shared PROPERTIES
|
||||
OUTPUT_NAME "glew-shared"
|
||||
DEBUG_POSTFIX d)
|
||||
else()
|
||||
set_representative_target(libglew_shared)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(libglew_shared PRIVATE GLEW_BUILD)
|
||||
if(MINGW)
|
||||
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
|
||||
target_link_options(libglew_shared PRIVATE -nostdlib)
|
||||
else()
|
||||
target_link_libraries(libglew_shared PRIVATE -nostdlib)
|
||||
endif()
|
||||
endif()
|
||||
list(APPEND GLEW_TARGETS libglew_shared)
|
||||
endif()
|
||||
|
||||
foreach(GLEW_TARGET ${GLEW_TARGETS})
|
||||
target_compile_definitions(${GLEW_TARGET} PUBLIC ${DEFINITIONS})
|
||||
target_include_directories(${GLEW_TARGET} PUBLIC ${INCLUDE_DIR})
|
||||
target_link_libraries(${GLEW_TARGET} PUBLIC ${LIBRARIES})
|
||||
set_target_properties(${GLEW_TARGET} PROPERTIES VERSION ${GLEW_VERSION})
|
||||
endforeach()
|
||||
|
||||
if(PKG_CONFIG_REPRESENTATIVE_TARGET)
|
||||
GeneratePkgConfigFile(${PKG_CONFIG_REPRESENTATIVE_TARGET} "The OpenGL Extension Wrangler library"
|
||||
NAME "glew"
|
||||
LIBRARY_DIR ${INSTALL_LIBDIR}
|
||||
REQUIRES ${pc_requires})
|
||||
endif()
|
||||
|
||||
install(TARGETS ${GLEW_TARGETS} EXPORT glew-cmake
|
||||
ARCHIVE DESTINATION ${INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${INSTALL_LIBDIR})
|
||||
install(EXPORT glew-cmake DESTINATION ${INSTALL_LIBDIR}/cmake/glew FILE glewConfig.cmake)
|
||||
|
||||
file(GLOB PUBLIC_HEADERS "include/GL/*.h")
|
||||
install(FILES ${PUBLIC_HEADERS} DESTINATION include/GL/)
|
||||
|
||||
if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR} AND NOT ONLY_LIBS)
|
||||
set(GLEWINFO_SRCS ${SRC_DIR}/glewinfo.c)
|
||||
set(VISUALINFO_SRCS ${SRC_DIR}/visualinfo.c)
|
||||
if(MSVS)
|
||||
list(APPEND GLEWINFO_SRCS ${RC_DIR}/glewinfo.rc)
|
||||
list(APPEND VISUALINFO_SRCS ${RC_DIR}/visualinfo.rc)
|
||||
endif()
|
||||
|
||||
add_executable(glewinfo ${GLEWINFO_SRCS})
|
||||
add_executable(visualinfo ${VISUALINFO_SRCS})
|
||||
|
||||
if(glew-cmake_BUILD_STATIC)
|
||||
target_link_libraries(glewinfo libglew_static)
|
||||
target_link_libraries(visualinfo libglew_static)
|
||||
else()
|
||||
target_link_libraries(glewinfo libglew_shared)
|
||||
target_link_libraries(visualinfo libglew_shared)
|
||||
endif()
|
||||
|
||||
install(TARGETS glewinfo visualinfo DESTINATION bin)
|
||||
endif()
|
91
main.cpp
Normal file
91
main.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
#include <iostream>
|
||||
#include <windows.h>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
void generateRandomColors(unsigned char& r, unsigned char& g, unsigned char& b);
|
||||
|
||||
void sendDMXData(HANDLE hSerial, unsigned char* data, int length) {
|
||||
// Start with a DMX break condition
|
||||
EscapeCommFunction(hSerial, SETBREAK);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1)); // Break duration
|
||||
EscapeCommFunction(hSerial, CLRBREAK);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1)); // Mark-after-break duration
|
||||
|
||||
// Write the start code followed by the DMX data
|
||||
DWORD bytesWritten;
|
||||
unsigned char startCode = 0;
|
||||
WriteFile(hSerial, &startCode, 1, &bytesWritten, NULL);
|
||||
WriteFile(hSerial, data, length, &bytesWritten, NULL);
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Open the serial port
|
||||
HANDLE hSerial = CreateFileA("\\\\.\\COM3", GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
if (hSerial == INVALID_HANDLE_VALUE) {
|
||||
std::cerr << "Error opening COM3 port" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Configure the serial port
|
||||
DCB dcbSerialParams = { 0 };
|
||||
dcbSerialParams.DCBlength = sizeof(dcbSerialParams);
|
||||
if (!GetCommState(hSerial, &dcbSerialParams)) {
|
||||
std::cerr << "Error getting COM3 state" << std::endl;
|
||||
CloseHandle(hSerial);
|
||||
return 1;
|
||||
}
|
||||
|
||||
dcbSerialParams.BaudRate = 250000; // DMX512 uses 250000 baud
|
||||
dcbSerialParams.ByteSize = 8;
|
||||
dcbSerialParams.StopBits = TWOSTOPBITS; // DMX512 uses 2 stop bits
|
||||
dcbSerialParams.Parity = NOPARITY;
|
||||
|
||||
if (!SetCommState(hSerial, &dcbSerialParams)) {
|
||||
std::cerr << "Error setting COM3 state" << std::endl;
|
||||
CloseHandle(hSerial);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Set timeouts
|
||||
COMMTIMEOUTS timeouts = { 0 };
|
||||
timeouts.ReadIntervalTimeout = 50;
|
||||
timeouts.ReadTotalTimeoutConstant = 50;
|
||||
timeouts.ReadTotalTimeoutMultiplier = 10;
|
||||
timeouts.WriteTotalTimeoutConstant = 50;
|
||||
timeouts.WriteTotalTimeoutMultiplier = 10;
|
||||
|
||||
if (!SetCommTimeouts(hSerial, &timeouts)) {
|
||||
std::cerr << "Error setting COM3 timeouts" << std::endl;
|
||||
CloseHandle(hSerial);
|
||||
return 1;
|
||||
}
|
||||
|
||||
srand(static_cast<unsigned int>(time(nullptr)));
|
||||
|
||||
// DMX data (512 channels, all set to 255)
|
||||
const int num_channels = 512;
|
||||
unsigned char buffer[num_channels];
|
||||
memset(buffer, 255, sizeof(buffer)); // Fill the buffer with 255
|
||||
|
||||
// Send DMX data in an infinite loop
|
||||
while (true) {
|
||||
// Generate and send random colors for channels 1, 2, and 3
|
||||
generateRandomColors(buffer[0], buffer[1], buffer[2]);
|
||||
|
||||
// Send DMX data with random colors
|
||||
sendDMXData(hSerial, buffer, num_channels);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(25)); // DMX refresh rate
|
||||
}
|
||||
|
||||
// Close the serial port
|
||||
CloseHandle(hSerial);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void generateRandomColors(unsigned char& r, unsigned char& g, unsigned char& b) {
|
||||
r = rand() % 256;
|
||||
g = rand() % 256;
|
||||
b = rand() % 256;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user