fixed: buffer tcpdata in CDebugWindow and simulate the timing of the bitpanel

This commit is contained in:
Bob van Loosen 2013-02-20 15:22:32 +01:00
parent ef067a0e14
commit f1da87ef6d
2 changed files with 42 additions and 12 deletions

View file

@ -64,7 +64,10 @@ void CDebugWindow::Enable(int width, int height, int scale)
void CDebugWindow::Disable() void CDebugWindow::Disable()
{ {
AsyncStopThread(); AsyncStopThread();
CLock lock(m_condition);
m_process = true;
m_condition.Signal(); m_condition.Signal();
lock.Leave();
StopThread(); StopThread();
} }
@ -73,7 +76,8 @@ void CDebugWindow::DisplayFrame(CTcpData& data)
if (m_running) if (m_running)
{ {
CLock lock(m_condition); CLock lock(m_condition);
m_data = data; m_data.push_back(data);
m_process = true;
m_condition.Signal(); m_condition.Signal();
} }
} }
@ -122,6 +126,8 @@ bool CDebugWindow::Setup()
m_transform.matrix[1][1] = m_width; m_transform.matrix[1][1] = m_width;
m_transform.matrix[2][2] = m_width * m_scale; m_transform.matrix[2][2] = m_width * m_scale;
m_process = false;
return true; return true;
} }
@ -170,12 +176,17 @@ void CDebugWindow::Cleanup()
} }
} }
#define BYTESPERFRAME (120 * 48 / 4 + 3)
#define BAUDRATE (500000)
void CDebugWindow::ProcessInternal() void CDebugWindow::ProcessInternal()
{ {
bool render = true; bool render = true;
int count = -3; int count = -3;
int xcount = 0; int xcount = 0;
int ycount = 0; int ycount = 0;
int64_t lastrender = GetTimeUs();
while (!m_stop) while (!m_stop)
{ {
if (render) if (render)
@ -186,17 +197,33 @@ void CDebugWindow::ProcessInternal()
XRenderComposite(m_dpy, PictOpSrc, m_srcpicture, None, m_dstpicture, XRenderComposite(m_dpy, PictOpSrc, m_srcpicture, None, m_dstpicture,
0, 0, 0, 0, 0, 0, m_width * m_scale, m_height * m_scale); 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); XFlush(m_dpy);
render = false; render = false;
} }
CLock lock(m_condition); CLock lock(m_condition);
m_condition.Wait(); if (m_data.empty())
CTcpData data = m_data; {
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(); lock.Leave();
int size = m_data.GetSize(); int size = data.GetSize();
uint8_t* dataptr = (uint8_t*)m_data.GetData(); uint8_t* dataptr = (uint8_t*)data.GetData();
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
if (count == -3) if (count == -3)
@ -217,8 +244,8 @@ void CDebugWindow::ProcessInternal()
for (int j = 0; j < 4; j++) for (int j = 0; j < 4; j++)
{ {
pixelptr++; pixelptr++;
*(pixelptr++) = ((dataptr[i] >> (j * 2)) & 1) ? 0xFF : 0; *(pixelptr++) = ((dataptr[i] << (j * 2 + 1)) & 128) ? 0xFF : 0;
*(pixelptr++) = ((dataptr[i] >> (j * 2 + 1)) & 1) ? 0xFF : 0; *(pixelptr++) = ((dataptr[i] << (j * 2)) & 128) ? 0xFF : 0;
pixelptr++; pixelptr++;
xcount++; xcount++;
if (xcount == m_width) if (xcount == m_width)

View file

@ -23,6 +23,8 @@
#include "condition.h" #include "condition.h"
#include "tcpsocket.h" #include "tcpsocket.h"
#include <deque>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/extensions/Xrender.h> #include <X11/extensions/Xrender.h>
@ -45,7 +47,8 @@ class CDebugWindow : public CThread
int m_scale; int m_scale;
CCondition m_condition; CCondition m_condition;
CTcpData m_data; bool m_process;
std::deque<CTcpData> m_data;
Display* m_dpy; Display* m_dpy;
int m_width; int m_width;