Skip to content
Permalink
Browse files

pluigins/dmxusb: partially revert changes on open DMX

Apparently QElapsedTimer is not as accurate as it is supposed to be, especially on Windows.
  • Loading branch information...
mcallegari committed Feb 14, 2019
1 parent f2f977b commit e8be10a3554dc94545086c737bd924d18c55d0d2
@@ -152,6 +152,8 @@ class DMXUSBWidget

/** The output frequency in Hertz */
int m_frequency;

/** The DMX frame time duration in microseconds */
int m_frameTimeUs;

/** Array of output lines supported by the device. This is resized on setOutputsNumber */
@@ -163,10 +163,15 @@ void EnttecDMXUSBOpen::stop()

void EnttecDMXUSBOpen::run()
{
QElapsedTimer timer;

// Wait for device to settle in case the device was opened just recently
// Also measure, whether timer granularity is OK
QTime time;
time.start();
usleep(1000);
if (time.elapsed() > 3)
m_granularity = Bad;
else
m_granularity = Good;

if (interface()->type() == DMXInterface::QtSerial)
{
@@ -184,12 +189,10 @@ void EnttecDMXUSBOpen::run()
}

m_running = true;
// let's assume this is a good adapter...
m_granularity = Good;

while (m_running == true)
{
timer.restart();
// Measure how much time passes during these calls
time.restart();

if (interface()->setBreak(true) == false)
goto framesleep;
@@ -208,17 +211,9 @@ void EnttecDMXUSBOpen::run()

framesleep:
// Sleep for the remainder of the DMX frame time
// and set granularity accordingly
long timetoSleep = m_frameTimeUs - (timer.nsecsElapsed() / 1000);
if (timetoSleep < 0)
{
qWarning() << "DMX output is running late !";
m_granularity = Bad;
}
if (m_granularity == Good)
while (time.elapsed() < (m_frameTimeUs / 1000)) { usleep(1000); }
else
{
usleep(timetoSleep);
m_granularity = Good;
}
while (time.elapsed() < (m_frameTimeUs / 1000)) { /* Busy sleep */ }
}
}
@@ -281,6 +281,7 @@ bool FTD2XXInterface::setLineProperties()
}
else
{
FT_SetTimeouts(m_handle, 100, 1);
return true;
}
}

0 comments on commit e8be10a

Please sign in to comment.
You can’t perform that action at this time.