diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..496ee2c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store \ No newline at end of file diff --git a/include/DMXPro.h b/include/DMXPro.h index de31bfd..cb83d29 100755 --- a/include/DMXPro.h +++ b/include/DMXPro.h @@ -12,7 +12,7 @@ #define DMX_PRO_END_MSG 0xE7 // End of message delimiter #define DMX_PRO_LABEL 6 // Output Only Send DMX Packet Request #define BAUD_RATE 57600 // virtual COM doesn't control the usb, this is just a dummy value -#define DMX_FRAME_RATE 40 // dmx send frame rate +#define DMX_FRAME_RATE 38 // dmx send frame rate @@ -34,15 +34,15 @@ class DMXPro{ ci::app::console() << "Device: " << deviceIt->getPath() << std::endl; } }; - - void sendValue(int value, int channel, bool force = false); void sendZeros(); int getValue(int channel); bool isConnected() { return mIsConnected; }; - + + void setValue(int value, int channel); + private: void sendPacket(); diff --git a/src/DMXPro.cpp b/src/DMXPro.cpp index e6f4ae1..0642154 100755 --- a/src/DMXPro.cpp +++ b/src/DMXPro.cpp @@ -33,8 +33,6 @@ mDMXPacket(NULL) initSerial(serialDevicePath); - mHasNewValues = true; // send zeros on start up - // start thread to send data at the specific DMX_FRAME_RATE if (mIsConnected) thread sendDMXDataThread( &DMXPro::sendDMXData, this); @@ -42,18 +40,9 @@ mDMXPacket(NULL) void DMXPro::sendDMXData() { - - boost::unique_lock dataLock(mDMXDataMutex); // get DMX packet UNIQUE lock - dataLock.unlock(); - while(true) { - if(mHasNewValues) { - dataLock.lock(); // lock data - sendPacket(); // send packet - mHasNewValues = false; - dataLock.unlock(); // unlock data - boost::this_thread::sleep(boost::posix_time::milliseconds(mThreadSleepFor)); - } + sendPacket(); // send packet + boost::this_thread::sleep(boost::posix_time::milliseconds(mThreadSleepFor)); } } @@ -83,22 +72,16 @@ Serial::Device DMXPro::findDeviceByPathContains( const string &searchString) { void DMXPro::sendPacket(){ - mSerial.writeBytes(mDMXPacket, mDMXPacketSize); + boost::unique_lock dataLock(mDMXDataMutex); // get DMX packet UNIQUE lock + mSerial.writeBytes(mDMXPacket, mDMXPacketSize); // send data + dataLock.unlock(); // unlock data } -void DMXPro::sendValue(int value, int channel, bool force) { - +void DMXPro::setValue(int value, int channel) { value = math::clamp(value, 0, 255); - - mHasNewValues = force; - - if( mDMXPacket[4+channel] == value ) - return; - boost::unique_lock dataLock(mDMXDataMutex); // get DMX packet UNIQUE lock mDMXPacket[4+channel] = value; // update value - mHasNewValues = true; dataLock.unlock(); // unlock mutex }