Skip to content

Commit

Permalink
removed sendValue() in favour of setValue(), also removed mHasNewValu…
Browse files Browse the repository at this point in the history
…es, the thread always send values even if they don't change(should improve the reliability)
  • Loading branch information
Q authored and Q committed Apr 25, 2011
1 parent f5dc5c7 commit 37d3a70
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
8 changes: 4 additions & 4 deletions include/DMXPro.h
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand All @@ -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();
Expand Down
29 changes: 6 additions & 23 deletions src/DMXPro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,16 @@ 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);
}


void DMXPro::sendDMXData() {

boost::unique_lock<boost::mutex> 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));
}
}

Expand Down Expand Up @@ -83,22 +72,16 @@ Serial::Device DMXPro::findDeviceByPathContains( const string &searchString) {


void DMXPro::sendPacket(){
mSerial.writeBytes(mDMXPacket, mDMXPacketSize);
boost::unique_lock<boost::mutex> 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<int>::clamp(value, 0, 255);

mHasNewValues = force;

if( mDMXPacket[4+channel] == value )
return;

boost::unique_lock<boost::mutex> dataLock(mDMXDataMutex); // get DMX packet UNIQUE lock
mDMXPacket[4+channel] = value; // update value
mHasNewValues = true;
dataLock.unlock(); // unlock mutex
}

Expand Down

0 comments on commit 37d3a70

Please sign in to comment.