generated from thinkode/modelRepository
Resolve CGO configuration + version in EXE
This commit is contained in:
21
hardware/cpp/generate.bat
Normal file
21
hardware/cpp/generate.bat
Normal file
@@ -0,0 +1,21 @@
|
||||
@REM windres dmxSender.rc dmxSender.o
|
||||
@REM windres detectFTDI.rc detectFTDI.o
|
||||
|
||||
@REM g++ -o dmxSender.exe dmxSender.cpp dmxSender.o -I"include" -L"lib" -lftd2xx -mwindows
|
||||
@REM g++ -o detectFTDI.exe detectFTDI.cpp detectFTDI.o -I"include" -L"lib" -lftd2xx -mwindows
|
||||
|
||||
@REM g++ -o dmxSender.exe dmxSender.cpp -I"include" -L"lib" -lftd2xx
|
||||
@REM g++ -o detectFTDI.exe detectFTDI.cpp -I"include" -L"lib" -lftd2xx
|
||||
|
||||
@REM g++ -c dmxSender.cpp -o dmxSender.o -I"include" -L"lib" -lftd2xx -mwindows
|
||||
|
||||
@REM g++ -c dmxSender_wrapper.cpp -o dmxSender_wrapper.o -I"include" -L"lib" -lftd2xx -mwindows
|
||||
|
||||
@REM g++ -shared -o ../../build/bin/libdmxSender.dll src/dmxSender.cpp -fPIC -Wl,--out-implib,../../build/bin/libdmxSender.dll.a -L"lib" -lftd2xx
|
||||
|
||||
@REM Compiling DMXSENDER library
|
||||
|
||||
g++ -shared -o ../../build/bin/libdmxSender.dll src/dmxSender.cpp -fPIC -L"lib" -lftd2xx
|
||||
|
||||
|
||||
@REM g++ -shared -o libdmxSender.so dmxSender.cpp -fPIC -I"include" -L"lib" -lftd2xx -mwindows
|
||||
15
hardware/cpp/include/dmxSenderBridge.h
Normal file
15
hardware/cpp/include/dmxSenderBridge.h
Normal file
@@ -0,0 +1,15 @@
|
||||
// Declare the C++ function from the shared library
|
||||
|
||||
typedef void DMXDevice;
|
||||
|
||||
extern DMXDevice* dmx_create();
|
||||
|
||||
extern void* dmx_destroy(DMXDevice* dev);
|
||||
|
||||
extern bool dmx_connect(DMXDevice* dev);
|
||||
|
||||
extern void dmx_activate(DMXDevice* dev);
|
||||
|
||||
extern void dmx_deactivate(DMXDevice* dev);
|
||||
|
||||
extern void dmx_setValue(DMXDevice* dev, int channel, int value);
|
||||
BIN
hardware/cpp/lib/ftd2xx.lib
Normal file
BIN
hardware/cpp/lib/ftd2xx.lib
Normal file
Binary file not shown.
127
hardware/cpp/src/dmxSender.cpp
Normal file
127
hardware/cpp/src/dmxSender.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
//dmxSender.cpp
|
||||
|
||||
#include "dmxSender.h"
|
||||
|
||||
#define DMX_START_CODE 0x00
|
||||
#define BREAK_DURATION_US 110
|
||||
#define MAB_DURATION_US 16
|
||||
#define DMX_CHANNELS 512
|
||||
#define FREQUENCY 44
|
||||
#define INTERVAL (1000000 / FREQUENCY)
|
||||
|
||||
// Initialize default values for starting the DMX device
|
||||
DMXDevice::DMXDevice(){
|
||||
ftHandle = nullptr;
|
||||
isOutputActivated = false;
|
||||
}
|
||||
|
||||
// Properly close the DMX device
|
||||
DMXDevice::~DMXDevice(){
|
||||
deactivate();
|
||||
if (ftHandle != nullptr){
|
||||
FT_Close(ftHandle);
|
||||
ftHandle = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// Connect the device on a specific port
|
||||
bool DMXDevice::connect(int port){
|
||||
ftStatus = FT_Open(port, &ftHandle);
|
||||
if (ftStatus != FT_OK) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ftStatus = FT_SetBaudRate(ftHandle, 250000);
|
||||
ftStatus |= FT_SetDataCharacteristics(ftHandle, 8, FT_STOP_BITS_2, FT_PARITY_NONE); // 8 bits, no parity, 1 stop bit
|
||||
ftStatus |= FT_SetFlowControl(ftHandle, FT_FLOW_NONE, 0, 0);
|
||||
if (ftStatus != FT_OK) {
|
||||
FT_Close(ftHandle);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Send the DMX frames
|
||||
std::thread updateThread([this]() {
|
||||
this->sendDMX(ftHandle);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
// Activate the DMX flow
|
||||
void DMXDevice::activate(){
|
||||
isOutputActivated.store(true);
|
||||
}
|
||||
|
||||
// Deactivate the DMX flow
|
||||
void DMXDevice::deactivate(){
|
||||
isOutputActivated.store(false);
|
||||
}
|
||||
|
||||
// Set the value of a DMX channe
|
||||
void DMXDevice::setValue(int channel, int value){
|
||||
dmxData[channel].store(value);
|
||||
}
|
||||
|
||||
// Send a break line
|
||||
void DMXDevice::sendBreak(FT_HANDLE ftHandle) {
|
||||
FT_SetBreakOn(ftHandle); // Set BREAK ON
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(BREAK_DURATION_US));
|
||||
FT_SetBreakOff(ftHandle); // Set BREAK OFF
|
||||
}
|
||||
|
||||
// Continuously send the DMX frame
|
||||
void DMXDevice::sendDMX(FT_HANDLE ftHandle) {
|
||||
while (true) {
|
||||
if(isOutputActivated){
|
||||
// Send the BREAK
|
||||
sendBreak(ftHandle);
|
||||
|
||||
// Send the MAB
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(MAB_DURATION_US));
|
||||
|
||||
DWORD bytesWritten = 0;
|
||||
|
||||
// Send the DMX frame
|
||||
FT_STATUS status = FT_Write(ftHandle, dmxData, DMX_CHANNELS, &bytesWritten);
|
||||
if (status != FT_OK || bytesWritten != DMX_CHANNELS) { // Error detected when trying to send the frame. Deactivate the line.
|
||||
deactivate();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Wait before sending the next frame
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(INTERVAL - BREAK_DURATION_US - MAB_DURATION_US));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Linkable functions from Golang
|
||||
extern "C" {
|
||||
// Create a new DMX device
|
||||
DMXDevice* dmx_create() {
|
||||
return new DMXDevice();
|
||||
}
|
||||
|
||||
// Destroy a DMX device
|
||||
void dmx_destroy(DMXDevice* dev) {
|
||||
dev->~DMXDevice();
|
||||
}
|
||||
|
||||
// Connect a DMX device
|
||||
bool dmx_connect(DMXDevice* dev, int port) {
|
||||
return dev->connect(port);
|
||||
}
|
||||
|
||||
// Activate a DMX device
|
||||
void dmx_activate(DMXDevice* dev) {
|
||||
dev->activate();
|
||||
}
|
||||
|
||||
// Deactivate a DMX device
|
||||
void dmx_deactivate(DMXDevice* dev) {
|
||||
dev->deactivate();
|
||||
}
|
||||
|
||||
// Set the channel value of a DMX device
|
||||
void dmx_setValue(DMXDevice* dev, int channel, int value) {
|
||||
dev->setValue(channel, value);
|
||||
}
|
||||
}
|
||||
49
hardware/cpp/src/dmxSender.h
Normal file
49
hardware/cpp/src/dmxSender.h
Normal file
@@ -0,0 +1,49 @@
|
||||
// dmxSender.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
#include "ftd2xx.h"
|
||||
|
||||
#define DMX_START_CODE 0x00
|
||||
#define BREAK_DURATION_US 110
|
||||
#define MAB_DURATION_US 16
|
||||
#define DMX_CHANNELS 512
|
||||
#define FREQUENCY 44
|
||||
#define INTERVAL (1000000 / FREQUENCY)
|
||||
|
||||
class DMXDevice {
|
||||
public:
|
||||
// Initialize default values for starting the DMX device
|
||||
DMXDevice();
|
||||
|
||||
// Properly close the DMX device
|
||||
~DMXDevice();
|
||||
|
||||
// Connect the device on a specific port
|
||||
bool connect(int port);
|
||||
|
||||
// Activate the DMX flow
|
||||
void activate();
|
||||
|
||||
// Deactivate the DMX flow
|
||||
void deactivate();
|
||||
|
||||
// Set the value of a DMX channel
|
||||
void setValue(int channel, int value);
|
||||
|
||||
private:
|
||||
FT_STATUS ftStatus; // FTDI peripheral status
|
||||
FT_HANDLE ftHandle = nullptr; // FTDI object
|
||||
std::atomic<unsigned char> dmxData[DMX_CHANNELS + 1]; // For storing dynamically the DMX data
|
||||
std::atomic<bool> isOutputActivated = false; // Boolean to start/stop the DMX flow
|
||||
|
||||
// Send a break line
|
||||
void sendBreak(FT_HANDLE ftHandle);
|
||||
|
||||
// Continuously send the DMX frame
|
||||
void sendDMX(FT_HANDLE ftHandle);
|
||||
};
|
||||
1667
hardware/cpp/src/ftd2xx.h
Normal file
1667
hardware/cpp/src/ftd2xx.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user