fixup QT GUI

This commit is contained in:
Michael Farrell 2017-07-08 22:53:28 +10:00
commit b4a56dd774
10 changed files with 106 additions and 84 deletions

View file

@ -25,6 +25,8 @@
#include "loclass/cipherutils.h" // for decimating samples in getsamples
#include "cmdlfem4x.h"// for em410x demod
uint8_t g_debugMode=0;
static int CmdHelp(pm3_connection* conn, const char *Cmd);
//set the demod buffer with given array of binary (one bit per byte)

View file

@ -6,6 +6,7 @@
#include "usb_cmd.h"
#include "uart.h"
#include "util_posix.h"
#ifndef CMD_BUFFER_SIZE
#define CMD_BUFFER_SIZE 50

View file

@ -25,7 +25,14 @@ uint8_t fskClocks(pm3_connection* conn, uint8_t *fc1, uint8_t *fc2, uint8_t *rf1
//uint8_t fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, bool verbose);
bool graphJustNoise(int *BitStream, int size);
void setGraphBuf(pm3_connection* conn, uint8_t *buff, size_t size);
#ifdef __cplusplus
extern "C" {
#endif
void save_restoreGB(pm3_connection* conn, uint8_t saveOpt);
#ifdef __cplusplus
}
#endif
bool HasGraphData();
void DetectHighLowInGraph(pm3_connection* conn, int *high, int *low, bool addFuzz);

View file

@ -21,8 +21,8 @@ extern "C" void ShowGraphWindow(pm3_connection* conn)
}
}
extern "C" void HideGraphWindow(pm3_connection* conn) {}
extern "C" void RepaintGraphWindow(pm3_connection* conn) {}
extern "C" void MainGraphics() {}
extern "C" void HideGraphWindow() {}
extern "C" void RepaintGraphWindow() {}
extern "C" void MainGraphics(pm3_connection* conn) {}
extern "C" void InitGraphics(int argc, char **argv) {}
extern "C" void ExitGraphics(void) {}

View file

@ -16,11 +16,9 @@
static ProxGuiQT *gui = NULL;
static WorkerThread *main_loop_thread = NULL;
WorkerThread::WorkerThread(char *script_cmds_file, bool usb_present,
serial_port* sp, bool flush_after_write)
: script_cmds_file(script_cmds_file), usb_present(usb_present),
sp(sp), flush_after_write(flush_after_write)
WorkerThread::WorkerThread(char *script_cmds_file, bool usb_present, serial_port* port, bool flush_after_write)
: script_cmds_file(script_cmds_file), usb_present(usb_present), port(port), flush_after_write(flush_after_write)
{
}
@ -29,7 +27,7 @@ WorkerThread::~WorkerThread()
}
void WorkerThread::run() {
main_loop(script_cmds_file, usb_present, sp, flush_after_write);
main_loop(script_cmds_file, usb_present, port, flush_after_write);
}
extern "C" void ShowGraphWindow(void)
@ -56,16 +54,16 @@ extern "C" void RepaintGraphWindow(void)
gui->RepaintGraphWindow();
}
extern "C" void MainGraphics(void)
extern "C" void MainGraphics(pm3_connection* conn)
{
if (!gui)
return;
main_loop_thread->start();
gui->MainLoop();
gui->MainLoop(conn);
}
extern "C" void InitGraphics(int argc, char **argv, char *script_cmds_file, bool usb_present, serial_port* sp, bool flush_after_write)
extern "C" void InitGraphics(int argc, char **argv, char *script_cmds_file, bool usb_present, serial_port* port, bool flush_after_write)
{
#ifdef Q_WS_X11
bool useGUI = getenv("DISPLAY") != 0;
@ -76,7 +74,7 @@ extern "C" void InitGraphics(int argc, char **argv, char *script_cmds_file, bool
return;
gui = new ProxGuiQT(argc, argv);
main_loop_thread = new WorkerThread(script_cmds_file, usb_present, sp, flush_after_write);
main_loop_thread = new WorkerThread(script_cmds_file, usb_present, port, flush_after_write);
QObject::connect(main_loop_thread, SIGNAL(finished()), main_loop_thread, SLOT(deleteLater()));
QObject::connect(main_loop_thread, SIGNAL(finished()), gui, SLOT(_Exit()));
}

View file

@ -17,10 +17,10 @@ extern "C" {
#include "uart.h"
#include "comms.h"
void ShowGraphWindow(pm3_connection* conn);
void HideGraphWindow(pm3_connection* conn);
void RepaintGraphWindow(pm3_connection* conn);
void MainGraphics(void);
void ShowGraphWindow(void);
void HideGraphWindow(void);
void RepaintGraphWindow(void);
void MainGraphics(pm3_connection* conn);
void InitGraphics(int argc, char **argv, char *script_cmds_file, bool usb_present, serial_port* port, bool flush_after_write);
void ExitGraphics(void);

View file

@ -26,6 +26,8 @@
#include <string.h>
#include "proxgui.h"
#include <QtGui>
#include "graph.h"
#include "ui.h"
//#include <ctime>
bool g_useOverlays = false;
@ -85,7 +87,7 @@ void ProxGuiQT::_Exit(void) {
delete this;
}
void ProxGuiQT::MainLoop()
void ProxGuiQT::MainLoop(pm3_connection *conn)
{
plotapp = new QApplication(argc, argv);
@ -94,6 +96,7 @@ void ProxGuiQT::MainLoop()
connect(this, SIGNAL(HideGraphWindowSignal()), this, SLOT(_HideGraphWindow()));
connect(this, SIGNAL(ExitSignal()), this, SLOT(_Exit()));
this->conn = conn;
plotapp->exec();
}
@ -120,19 +123,19 @@ ProxGuiQT::~ProxGuiQT(void)
void ProxWidget::applyOperation()
{
//printf("ApplyOperation()");
save_restoreGB(GRAPH_SAVE);
memcpy(GraphBuffer, s_Buff, sizeof(int) * GraphTraceLen);
save_restoreGB(master->conn, GRAPH_SAVE);
memcpy(master->conn->GraphBuffer, master->conn->s_Buff, sizeof(int) * master->conn->GraphTraceLen);
RepaintGraphWindow();
}
void ProxWidget::stickOperation()
{
save_restoreGB(GRAPH_RESTORE);
save_restoreGB(master->conn, GRAPH_RESTORE);
//printf("stickOperation()");
}
void ProxWidget::vchange_autocorr(int v)
{
int ans;
ans = AutoCorrelate(GraphBuffer, s_Buff, GraphTraceLen, v, true, false);
ans = AutoCorrelate(master->conn->GraphBuffer, master->conn->s_Buff, master->conn->GraphTraceLen, v, true, false);
if (g_debugMode) printf("vchange_autocorr(w:%d): %d\n", v, ans);
g_useOverlays = true;
RepaintGraphWindow();
@ -141,7 +144,7 @@ void ProxWidget::vchange_askedge(int v)
{
int ans;
//extern int AskEdgeDetect(const int *in, int *out, int len, int threshold);
ans = AskEdgeDetect(GraphBuffer, s_Buff, GraphTraceLen, v);
ans = AskEdgeDetect(master->conn->GraphBuffer, master->conn->s_Buff, master->conn->GraphTraceLen, v);
if (g_debugMode) printf("vchange_askedge(w:%d)%d\n", v, ans);
g_useOverlays = true;
RepaintGraphWindow();
@ -149,7 +152,7 @@ void ProxWidget::vchange_askedge(int v)
void ProxWidget::vchange_dthr_up(int v)
{
int down = opsController->horizontalSlider_dirthr_down->value();
directionalThreshold(GraphBuffer, s_Buff, GraphTraceLen, v, down);
directionalThreshold(master->conn->GraphBuffer, master->conn->s_Buff, master->conn->GraphTraceLen, v, down);
//printf("vchange_dthr_up(%d)", v);
g_useOverlays = true;
RepaintGraphWindow();
@ -158,7 +161,7 @@ void ProxWidget::vchange_dthr_down(int v)
{
//printf("vchange_dthr_down(%d)", v);
int up = opsController->horizontalSlider_dirthr_up->value();
directionalThreshold(GraphBuffer,s_Buff, GraphTraceLen, v, up);
directionalThreshold(master->conn->GraphBuffer,master->conn->s_Buff, master->conn->GraphTraceLen, v, up);
g_useOverlays = true;
RepaintGraphWindow();
}
@ -194,7 +197,7 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent)
// Set up the plot widget, which does the actual plotting
plot = new Plot(this);
plot = new Plot(this, master);
/*
QSlider* slider = new QSlider(Qt::Horizontal);
slider->setFocusPolicy(Qt::StrongFocus);
@ -306,20 +309,20 @@ void Plot::setMaxAndStart(int *buffer, int len, QRect plotRect)
void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum, int plotOffset)
{
if (len == 0 || PlotGridX <= 0) return;
if (len == 0 || master->conn->PlotGridX <= 0) return;
//clock_t begin = clock();
QPainterPath penPath;
int grid_delta_x = PlotGridX;
int first_delta_x = grid_delta_x; //(plotOffset > 0) ? PlotGridX : (PlotGridX +);
int grid_delta_x = master->conn->PlotGridX;
int first_delta_x = grid_delta_x; //(plotOffset > 0) ? master->conn->PlotGridX : (master->conn->PlotGridX +);
if (GraphStart > plotOffset) first_delta_x -= (GraphStart-plotOffset);
int DemodStart = GraphStart;
if (plotOffset > GraphStart) DemodStart = plotOffset;
int BitStart = 0;
// round down
if (DemodStart-plotOffset > 0) BitStart = (int)(((DemodStart-plotOffset)+(PlotGridX-1))/PlotGridX)-1;
first_delta_x += BitStart * PlotGridX;
if (DemodStart-plotOffset > 0) BitStart = (int)(((DemodStart-plotOffset)+(master->conn->PlotGridX-1))/master->conn->PlotGridX)-1;
first_delta_x += BitStart * master->conn->PlotGridX;
if (BitStart > (int)len) return;
int delta_x = 0;
int v = 0;
@ -435,26 +438,26 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect,
void Plot::plotGridLines(QPainter* painter,QRect r)
{
// set GridOffset
if (PlotGridX <= 0) return;
int offset = GridOffset;
if (GridLocked && PlotGridX) {
offset = GridOffset + PlotGridX - (GraphStart % PlotGridX);
} else if (!GridLocked && GraphStart > 0 && PlotGridX) {
offset = PlotGridX-((GraphStart - offset) % PlotGridX) + GraphStart - unlockStart;
// set master->conn->GridOffset
if (master->conn->PlotGridX <= 0) return;
int offset = master->conn->GridOffset;
if (master->conn->GridLocked && master->conn->PlotGridX) {
offset = master->conn->GridOffset + master->conn->PlotGridX - (GraphStart % master->conn->PlotGridX);
} else if (!master->conn->GridLocked && GraphStart > 0 && master->conn->PlotGridX) {
offset = master->conn->PlotGridX-((GraphStart - offset) % master->conn->PlotGridX) + GraphStart - unlockStart;
}
offset %= PlotGridX;
if (offset < 0) offset += PlotGridX;
offset %= master->conn->PlotGridX;
if (offset < 0) offset += master->conn->PlotGridX;
int i;
int grid_delta_x = (int) (PlotGridX * GraphPixelsPerPoint);
int grid_delta_y = PlotGridY;
if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) {
int grid_delta_x = (int) (master->conn->PlotGridX * GraphPixelsPerPoint);
int grid_delta_y = master->conn->PlotGridY;
if ((master->conn->PlotGridX > 0) && ((master->conn->PlotGridX * GraphPixelsPerPoint) > 1)) {
for(i = (offset * GraphPixelsPerPoint); i < r.right(); i += grid_delta_x) {
painter->drawLine(r.left()+i, r.top(), r.left()+i, r.bottom());
}
}
if (PlotGridY > 0) {
if (master->conn->PlotGridY > 0) {
for(i = 0; yCoordOf(i,r,g_absVMax) > r.top(); i += grid_delta_y) {
painter->drawLine( r.left(), yCoordOf(i,r,g_absVMax), r.right(), yCoordOf(i,r,g_absVMax) );
painter->drawLine( r.left(), yCoordOf(i*-1,r,g_absVMax), r.right(), yCoordOf(i*-1,r,g_absVMax) );
@ -478,14 +481,14 @@ void Plot::paintEvent(QPaintEvent *event)
GraphStart = 0;
}
if (CursorAPos > GraphTraceLen)
if (CursorAPos > master->conn->GraphTraceLen)
CursorAPos= 0;
if(CursorBPos > GraphTraceLen)
if(CursorBPos > master->conn->GraphTraceLen)
CursorBPos= 0;
if(CursorCPos > GraphTraceLen)
CursorCPos= 0;
if(CursorDPos > GraphTraceLen)
CursorDPos= 0;
if(master->conn->CursorCPos > master->conn->GraphTraceLen)
master->conn->CursorCPos= 0;
if(master->conn->CursorDPos > master->conn->GraphTraceLen)
master->conn->CursorDPos= 0;
QRect plotRect(WIDTH_AXES, 0, width()-WIDTH_AXES, height()-HEIGHT_INFO);
QRect infoRect(0, height()-HEIGHT_INFO, width(), HEIGHT_INFO);
@ -496,7 +499,7 @@ void Plot::paintEvent(QPaintEvent *event)
painter.fillRect(plotRect, QColor(0, 0, 0));
//init graph variables
setMaxAndStart(GraphBuffer,GraphTraceLen,plotRect);
setMaxAndStart(master->conn->GraphBuffer,master->conn->GraphTraceLen,plotRect);
// center line
int zeroHeight = plotRect.top() + (plotRect.bottom() - plotRect.top()) / 2;
@ -506,14 +509,14 @@ void Plot::paintEvent(QPaintEvent *event)
plotGridLines(&painter, plotRect);
//Start painting graph
PlotGraph(GraphBuffer, GraphTraceLen,plotRect,infoRect,&painter,0);
if (showDemod && DemodBufferLen > 8) {
PlotDemod(DemodBuffer, DemodBufferLen,plotRect,infoRect,&painter,2,g_DemodStartIdx);
PlotGraph(master->conn->GraphBuffer, master->conn->GraphTraceLen,plotRect,infoRect,&painter,0);
if (master->conn->showDemod && master->conn->DemodBufferLen > 8) {
PlotDemod(master->conn->DemodBuffer, master->conn->DemodBufferLen,plotRect,infoRect,&painter,2,master->conn->g_DemodStartIdx);
}
if (g_useOverlays) {
//init graph variables
setMaxAndStart(s_Buff,GraphTraceLen,plotRect);
PlotGraph(s_Buff, GraphTraceLen,plotRect,infoRect,&painter,1);
setMaxAndStart(master->conn->s_Buff,master->conn->GraphTraceLen,plotRect);
PlotGraph(master->conn->s_Buff, master->conn->GraphTraceLen,plotRect,infoRect,&painter,1);
}
// End graph drawing
@ -528,29 +531,31 @@ void Plot::paintEvent(QPaintEvent *event)
painter.setPen(QColor(255, 0, 255));
painter.drawLine(xCoordOf(CursorBPos, plotRect),plotRect.top(),xCoordOf(CursorBPos, plotRect),plotRect.bottom());
}
if(CursorCPos > GraphStart && xCoordOf(CursorCPos, plotRect) < plotRect.right())
if(master->conn->CursorCPos > GraphStart && xCoordOf(master->conn->CursorCPos, plotRect) < plotRect.right())
{
painter.setPen(QColor(255, 153, 0)); //orange
painter.drawLine(xCoordOf(CursorCPos, plotRect),plotRect.top(),xCoordOf(CursorCPos, plotRect),plotRect.bottom());
painter.drawLine(xCoordOf(master->conn->CursorCPos, plotRect),plotRect.top(),xCoordOf(master->conn->CursorCPos, plotRect),plotRect.bottom());
}
if(CursorDPos > GraphStart && xCoordOf(CursorDPos, plotRect) < plotRect.right())
if(master->conn->CursorDPos > GraphStart && xCoordOf(master->conn->CursorDPos, plotRect) < plotRect.right())
{
painter.setPen(QColor(0, 0, 205)); //light blue
painter.drawLine(xCoordOf(CursorDPos, plotRect),plotRect.top(),xCoordOf(CursorDPos, plotRect),plotRect.bottom());
painter.drawLine(xCoordOf(master->conn->CursorDPos, plotRect),plotRect.top(),xCoordOf(master->conn->CursorDPos, plotRect),plotRect.bottom());
}
//Draw annotations
char str[200];
sprintf(str, "@%d dt=%d [%2.2f] zoom=%2.2f CursorAPos=%d CursorBPos=%d GridX=%d GridY=%d (%s) GridXoffset=%d",
GraphStart, CursorBPos - CursorAPos, (CursorBPos - CursorAPos)/CursorScaleFactor,
GraphPixelsPerPoint,CursorAPos,CursorBPos,PlotGridXdefault,PlotGridYdefault,GridLocked?"Locked":"Unlocked",GridOffset);
GraphStart, CursorBPos - CursorAPos, (CursorBPos - CursorAPos)/master->conn->CursorScaleFactor,
GraphPixelsPerPoint,CursorAPos,CursorBPos,master->conn->PlotGridXdefault,master->conn->PlotGridYdefault,master->conn->GridLocked?"Locked":"Unlocked",master->conn->GridOffset);
painter.setPen(QColor(255, 255, 255));
painter.drawText(20, infoRect.bottom() - 3, str);
}
Plot::Plot(QWidget *parent) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1)
Plot::Plot(QWidget *parent, ProxGuiQT *master) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1)
{
this->master = master;
//Need to set this, otherwise we don't receive keypress events
setFocusPolicy( Qt::StrongFocus);
resize(600, 300);
@ -595,8 +600,8 @@ void Plot::keyPressEvent(QKeyEvent *event)
int offset;
if(event->modifiers() & Qt::ShiftModifier) {
if (PlotGridX)
offset= PageWidth - (PageWidth % PlotGridX);
if (master->conn->PlotGridX)
offset= PageWidth - (PageWidth % master->conn->PlotGridX);
else
offset= PageWidth;
} else
@ -635,12 +640,12 @@ void Plot::keyPressEvent(QKeyEvent *event)
break;
case Qt::Key_G:
if(PlotGridX || PlotGridY) {
PlotGridX= 0;
PlotGridY= 0;
if(master->conn->PlotGridX || master->conn->PlotGridY) {
master->conn->PlotGridX= 0;
master->conn->PlotGridY= 0;
} else {
PlotGridX= PlotGridXdefault;
PlotGridY= PlotGridYdefault;
master->conn->PlotGridX= master->conn->PlotGridXdefault;
master->conn->PlotGridY= master->conn->PlotGridYdefault;
}
break;
@ -666,9 +671,9 @@ void Plot::keyPressEvent(QKeyEvent *event)
break;
case Qt::Key_L:
GridLocked = !GridLocked;
if (GridLocked)
GridOffset += (GraphStart - unlockStart);
master->conn->GridLocked = !master->conn->GridLocked;
if (master->conn->GridLocked)
master->conn->GridOffset += (GraphStart - unlockStart);
else
unlockStart = GraphStart;
break;

View file

@ -24,6 +24,9 @@
#include "uart.h"
#include "ui/ui_overlays.h"
#include "uart.h"
#include "comms.h"
class ProxGuiQT;
/**
* @brief The actual plot, black area were we paint the graph
@ -31,6 +34,7 @@
class Plot: public QWidget
{
private:
ProxGuiQT *master;
int GraphStart;
double GraphPixelsPerPoint;
int CursorAPos;
@ -44,7 +48,7 @@ private:
void setMaxAndStart(int *buffer, int len, QRect plotRect);
QColor getColor(int graphNum);
public:
Plot(QWidget *parent = 0);
Plot(QWidget *parent = 0, ProxGuiQT *master = NULL);
protected:
void paintEvent(QPaintEvent *event);
@ -54,7 +58,6 @@ protected:
void keyPressEvent(QKeyEvent *event);
};
class ProxGuiQT;
/**
* The window with plot and controls
@ -101,15 +104,18 @@ class ProxGuiQT : public QObject
int argc;
char **argv;
void (*main_func)(void);
public:
ProxGuiQT(int argc, char **argv);
~ProxGuiQT(void);
void ShowGraphWindow(void);
void RepaintGraphWindow(void);
void HideGraphWindow(void);
void MainLoop(void);
void MainLoop(pm3_connection *conn);
void Exit(void);
// Shared for ProxWidget
pm3_connection *conn;
private slots:
void _ShowGraphWindow(void);
void _RepaintGraphWindow(void);
@ -132,7 +138,7 @@ public:
private:
char *script_cmds_file = NULL;
bool usb_present;
serial_port *sp = NULL;
serial_port *port = NULL;
bool flush_after_write = false;
};

View file

@ -56,6 +56,11 @@ void main_loop(char *script_cmds_file, bool usb_present, serial_port* port, bool
conn.offline = true;
}
#ifdef HAVE_GUI
// Setup GUI with reference to our connection struct.
MainGraphics(&conn);
#endif
FILE *script_file = NULL;
char script_cmd_buf[256]; // iceman, needs lua script the same file_path_buffer as the rest
@ -234,14 +239,12 @@ int main(int argc, char* argv[]) {
#ifdef HAVE_GUI
#ifdef _WIN32
InitGraphics(argc, argv, script_cmds_file, usb_present, sp, flush_after_write);
MainGraphics();
#else
char* display = getenv("DISPLAY");
if (display && strlen(display) > 1)
{
InitGraphics(argc, argv, script_cmds_file, usb_present, sp, flush_after_write);
MainGraphics();
}
else
{
@ -249,7 +252,7 @@ int main(int argc, char* argv[]) {
}
#endif
#else
main_loop(script_cmds_file, usb_present, sp);
main_loop(script_cmds_file, usb_present, sp, flush_after_write);
#endif
// Clean up the port

View file

@ -21,9 +21,9 @@ pthread_mutex_t print_lock;
extern uint8_t g_debugMode;
void ShowGui(void);
void HideGraphWindow(pm3_connection* conn);
void ShowGraphWindow(pm3_connection* conn);
void RepaintGraphWindow(pm3_connection* conn);
void HideGraphWindow();
void ShowGraphWindow();
void RepaintGraphWindow();
void PrintAndLog(char *fmt, ...);
void SetLogFilename(char *fn);
void SetFlushAfterWrite(bool flush_after_write);