From f1da87ef6d24fd0ad330126c2a09b2b4dd5f2668 Mon Sep 17 00:00:00 2001 From: Bob van Loosen Date: Wed, 20 Feb 2013 15:22:32 +0100 Subject: [PATCH] fixed: buffer tcpdata in CDebugWindow and simulate the timing of the bitpanel --- src/util/debugwindow.cpp | 49 +++++++++++++++++++++++++++++++--------- src/util/debugwindow.h | 5 +++- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/util/debugwindow.cpp b/src/util/debugwindow.cpp index 928f46f..211a94c 100644 --- a/src/util/debugwindow.cpp +++ b/src/util/debugwindow.cpp @@ -64,7 +64,10 @@ void CDebugWindow::Enable(int width, int height, int scale) void CDebugWindow::Disable() { AsyncStopThread(); + CLock lock(m_condition); + m_process = true; m_condition.Signal(); + lock.Leave(); StopThread(); } @@ -73,7 +76,8 @@ void CDebugWindow::DisplayFrame(CTcpData& data) if (m_running) { CLock lock(m_condition); - m_data = data; + m_data.push_back(data); + m_process = true; m_condition.Signal(); } } @@ -122,6 +126,8 @@ bool CDebugWindow::Setup() m_transform.matrix[1][1] = m_width; m_transform.matrix[2][2] = m_width * m_scale; + m_process = false; + return true; } @@ -170,12 +176,17 @@ void CDebugWindow::Cleanup() } } +#define BYTESPERFRAME (120 * 48 / 4 + 3) +#define BAUDRATE (500000) + void CDebugWindow::ProcessInternal() { - bool render = true; - int count = -3; - int xcount = 0; - int ycount = 0; + bool render = true; + int count = -3; + int xcount = 0; + int ycount = 0; + int64_t lastrender = GetTimeUs(); + while (!m_stop) { if (render) @@ -186,17 +197,33 @@ void CDebugWindow::ProcessInternal() XRenderComposite(m_dpy, PictOpSrc, m_srcpicture, None, m_dstpicture, 0, 0, 0, 0, 0, 0, m_width * m_scale, m_height * m_scale); + //add a delay, to simulate the bytes being transferred over rs232 to the bitpanel + int64_t frametime = 1000000LL * 10 * BYTESPERFRAME / BAUDRATE; + int64_t now = GetTimeUs(); + USleep(lastrender + frametime - now); + lastrender = GetTimeUs(); + XFlush(m_dpy); render = false; } CLock lock(m_condition); - m_condition.Wait(); - CTcpData data = m_data; + if (m_data.empty()) + { + while (!m_process) + m_condition.Wait(); + m_process = false; + } + + if (m_data.empty()) + continue; + + CTcpData data = m_data.front(); + m_data.pop_front(); lock.Leave(); - int size = m_data.GetSize(); - uint8_t* dataptr = (uint8_t*)m_data.GetData(); + int size = data.GetSize(); + uint8_t* dataptr = (uint8_t*)data.GetData(); for (int i = 0; i < size; i++) { if (count == -3) @@ -217,8 +244,8 @@ void CDebugWindow::ProcessInternal() for (int j = 0; j < 4; j++) { pixelptr++; - *(pixelptr++) = ((dataptr[i] >> (j * 2)) & 1) ? 0xFF : 0; - *(pixelptr++) = ((dataptr[i] >> (j * 2 + 1)) & 1) ? 0xFF : 0; + *(pixelptr++) = ((dataptr[i] << (j * 2 + 1)) & 128) ? 0xFF : 0; + *(pixelptr++) = ((dataptr[i] << (j * 2)) & 128) ? 0xFF : 0; pixelptr++; xcount++; if (xcount == m_width) diff --git a/src/util/debugwindow.h b/src/util/debugwindow.h index 95631b5..904d5ad 100644 --- a/src/util/debugwindow.h +++ b/src/util/debugwindow.h @@ -23,6 +23,8 @@ #include "condition.h" #include "tcpsocket.h" +#include + #include #include @@ -45,7 +47,8 @@ class CDebugWindow : public CThread int m_scale; CCondition m_condition; - CTcpData m_data; + bool m_process; + std::deque m_data; Display* m_dpy; int m_width;