apply @holiman s graph changes +

add demod data to graph.
some bugs are known:
if you close the graph window data plot will not bring it back.
exiting the application without closing the widget form results in
error.
autocorrect graph y labels are ugly
form has old askdemod tab.
sticky button purpose not defined/labeled well.
doesn't clear s_Buff when new graph loaded or sampled.
probably more...
This commit is contained in:
marshmellow42 2017-04-12 14:35:07 -04:00
commit b8fdac9e6f
12 changed files with 995 additions and 185 deletions

View file

@ -28,6 +28,8 @@
uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN];
uint8_t g_debugMode=0;
size_t DemodBufferLen=0;
int g_DemodStartIdx=0;
int g_DemodClock=0;
static int CmdHelp(const char *Cmd);
@ -245,7 +247,6 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType,
return 0;
}
if (verbose || g_debugMode) PrintAndLog("\nUsing Clock:%d, Invert:%d, Bits Found:%d",clk,invert,BitLen);
//output
setDemodBuf(BitStream,BitLen,0);
setClockGrid(clk, startIdx);
@ -295,11 +296,11 @@ int Cmdaskmandemod(const char *Cmd)
}
bool st = true;
if (Cmd[0]=='s')
return ASKDemod_ext(Cmd++, true, true, 1, &st);
return ASKDemod_ext(Cmd++, true, false, 1, &st);
else if (Cmd[1] == 's')
return ASKDemod_ext(Cmd+=2, true, true, 1, &st);
return ASKDemod_ext(Cmd+=2, true, false, 1, &st);
else
return ASKDemod(Cmd, true, true, 1);
return ASKDemod(Cmd, true, false, 1);
}
//by marshmellow
@ -797,7 +798,7 @@ int FSKrawDemod(const char *Cmd, bool verbose)
if (size > 0) {
setDemodBuf(BitStream,size,0);
setClockGrid(rfLen, startIdx);
// Now output the bitstream to the scrollback by line of 16 bits
if (verbose || g_debugMode) {
PrintAndLog("\nUsing Clock:%u, invert:%u, fchigh:%u, fclow:%u", (unsigned int)rfLen, (unsigned int)invert, (unsigned int)fchigh, (unsigned int)fclow);
@ -1057,6 +1058,9 @@ int CmdRawDemod(const char *Cmd)
}
void setClockGrid(int clk, int offset) {
g_DemodStartIdx = offset;
g_DemodClock = clk;
PrintAndLog("demodoffset %d, clk %d",offset,clk);
if (offset > clk) offset %= clk;
if (offset < 0) offset += clk;
@ -1213,6 +1217,7 @@ int getSamples(int n, bool silent)
GraphTraceLen = n;
}
setClockGrid(0,0);
RepaintGraphWindow();
return 0;
}
@ -1316,6 +1321,7 @@ int CmdLoad(const char *Cmd)
}
fclose(f);
PrintAndLog("loaded %d samples", GraphTraceLen);
setClockGrid(0,0);
RepaintGraphWindow();
return 0;
}

View file

@ -69,6 +69,8 @@ void setClockGrid(int clk, int offset);
#define MAX_DEMOD_BUF_LEN (1024*128)
extern uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN];
extern size_t DemodBufferLen;
extern int g_DemodStartIdx;
extern int g_DemodClock;
extern uint8_t g_debugMode;
#define BIGBUF_SIZE 40000

View file

@ -152,7 +152,8 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo )
if (Em410xDecode(BitStream, &BitLen, &idx, hi, lo)) {
//set GraphBuffer for clone or sim command
setDemodBuf(BitStream, BitLen, idx);
setDemodBuf(DemodBuffer, (BitLen==40) ? 64 : 128, idx+1);
g_DemodStartIdx += (idx+1)*g_DemodClock;
if (g_debugMode) {
PrintAndLog("DEBUG: idx: %d, Len: %d, Printing Demod Buffer:", idx, BitLen);
printDemodBuff();

View file

@ -18,6 +18,9 @@
int GraphBuffer[MAX_GRAPH_TRACE_LEN];
int GraphTraceLen;
int s_Buff[MAX_GRAPH_TRACE_LEN];
/* write a manchester bit to the graph */
void AppendGraph(int redraw, int clock, int bit)
{
@ -290,3 +293,57 @@ bool graphJustNoise(int *BitStream, int size)
}
return justNoise1;
}
int autoCorr(const int* in, int *out, size_t len, int window)
{
static int CorrelBuffer[MAX_GRAPH_TRACE_LEN];
if (window == 0) {
PrintAndLog("needs a window");
return 0;
}
if (window >= len) {
PrintAndLog("window must be smaller than trace (%d samples)",
len);
return 0;
}
PrintAndLog("performing %d correlations", len - window);
for (int i = 0; i < len - window; ++i) {
int sum = 0;
for (int j = 0; j < window; ++j) {
sum += (in[j]*in[i + j]) / 256;
}
CorrelBuffer[i] = sum;
}
//GraphTraceLen = GraphTraceLen - window;
memcpy(out, CorrelBuffer, len * sizeof (int));
return 0;
}
int directionalThreshold(const int* in, int *out, size_t len, int8_t up, int8_t down)
{
int lastValue = in[0];
out[0] = 0; // Will be changed at the end, but init 0 as we adjust to last samples value if no threshold kicks in.
for (int i = 1; i < len; ++i) {
// Apply first threshold to samples heading up
if (in[i] >= up && in[i] > lastValue)
{
lastValue = out[i]; // Buffer last value as we overwrite it.
out[i] = 1;
}
// Apply second threshold to samples heading down
else if (in[i] <= down && in[i] < lastValue)
{
lastValue = out[i]; // Buffer last value as we overwrite it.
out[i] = -1;
}
else
{
lastValue = out[i]; // Buffer last value as we overwrite it.
out[i] = out[i-1];
}
}
out[0] = out[1]; // Align with first edited sample.
return 0;
}

View file

@ -35,4 +35,9 @@ void DetectHighLowInGraph(int *high, int *low, bool addFuzz);
extern int GraphBuffer[MAX_GRAPH_TRACE_LEN];
extern int GraphTraceLen;
extern int s_Buff[MAX_GRAPH_TRACE_LEN];
int autoCorr(const int* in, int *out, size_t len, int window);
int directionalThreshold(const int* in, int *out, size_t len, int8_t up, int8_t down);
#endif

View file

@ -12,6 +12,9 @@
extern "C" {
#endif
#include <stdint.h>
#include <string.h>
void ShowGraphWindow(void);
void HideGraphWindow(void);
void RepaintGraphWindow(void);
@ -22,12 +25,25 @@ void ExitGraphics(void);
#define MAX_GRAPH_TRACE_LEN (40000*8)
extern int GraphBuffer[MAX_GRAPH_TRACE_LEN];
extern int GraphTraceLen;
extern int s_Buff[MAX_GRAPH_TRACE_LEN];
extern double CursorScaleFactor;
extern int PlotGridX, PlotGridY, PlotGridXdefault, PlotGridYdefault, CursorCPos, CursorDPos, GridOffset;
extern int CommandFinished;
extern int offline;
extern bool GridLocked;
//Operations defined in data_operations
extern int autoCorr(const int* in, int *out, size_t len, int window);
extern int directionalThreshold(const int* in, int *out, size_t len, int8_t up, int8_t down);
extern void save_restoreGB(uint8_t saveOpt);
#define MAX_DEMOD_BUF_LEN (1024*128)
extern uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN];
extern size_t DemodBufferLen;
extern size_t g_DemodStartIdx;
extern bool showDemod;
#ifdef __cplusplus
}
#endif

View file

@ -19,8 +19,13 @@
#include <math.h>
#include <limits.h>
#include <stdio.h>
#include <QHBoxLayout>
#include <string.h>
#include "proxguiqt.h"
#include "proxgui.h"
#include <QtGui>
//#include <ctime>
int startMax;
int PageWidth;
@ -86,6 +91,7 @@ ProxGuiQT::ProxGuiQT(int argc, char **argv) : plotapp(NULL), plotwidget(NULL),
ProxGuiQT::~ProxGuiQT(void)
{
if (plotwidget) {
//plotwidget->close();
delete plotwidget;
plotwidget = NULL;
}
@ -97,15 +103,304 @@ ProxGuiQT::~ProxGuiQT(void)
}
}
void ProxWidget::paintEvent(QPaintEvent *event)
//--------------------
void ProxWidget::applyOperation()
{
printf("ApplyOperation()");
save_restoreGB(1);
memcpy(GraphBuffer,s_Buff, sizeof(int) * GraphTraceLen);
RepaintGraphWindow();
}
void ProxWidget::stickOperation()
{
save_restoreGB(0);
printf("stickOperation()");
}
void ProxWidget::vchange_autocorr(int v)
{
autoCorr(GraphBuffer,s_Buff, GraphTraceLen, v);
printf("vchange_autocorr(%d)\n", v);
RepaintGraphWindow();
}
void ProxWidget::vchange_dthr_up(int v)
{
int down = opsController->horizontalSlider_dirthr_down->value();
directionalThreshold(GraphBuffer,s_Buff, GraphTraceLen, v, down);
printf("vchange_dthr_up(%d)", v);
RepaintGraphWindow();
}
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);
RepaintGraphWindow();
}
ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent)
{
this->master = master;
resize(800,500);
/** Setup the controller widget **/
QWidget* controlWidget = new QWidget();
opsController = new Ui::Form();
opsController->setupUi(controlWidget);
//Due to quirks in QT Designer, we need to fiddle a bit
opsController->horizontalSlider_dirthr_down->setMinimum(-128);
opsController->horizontalSlider_dirthr_down->setMaximum(0);
opsController->horizontalSlider_dirthr_down->setValue(-20);
QObject::connect(opsController->pushButton_apply, SIGNAL(clicked()), this, SLOT(applyOperation()));
QObject::connect(opsController->pushButton_sticky, SIGNAL(clicked()), this, SLOT(stickOperation()));
QObject::connect(opsController->horizontalSlider_window, SIGNAL(valueChanged(int)), this, SLOT(vchange_autocorr(int)));
QObject::connect(opsController->horizontalSlider_dirthr_up, SIGNAL(valueChanged(int)), this, SLOT(vchange_dthr_up(int)));
QObject::connect(opsController->horizontalSlider_dirthr_down, SIGNAL(valueChanged(int)), this, SLOT(vchange_dthr_down(int)));
controlWidget->show();
// Set up the plot widget, which does the actual plotting
plot = new Plot(this);
/*
QSlider* slider = new QSlider(Qt::Horizontal);
slider->setFocusPolicy(Qt::StrongFocus);
slider->setTickPosition(QSlider::TicksBothSides);
slider->setTickInterval(10);
slider->setSingleStep(1);
*/
QVBoxLayout *layout = new QVBoxLayout;
//layout->addWidget(slider);
layout->addWidget(plot);
setLayout(layout);
//printf("Proxwidget Constructor just set layout\r\n");
}
//----------- Plotting
int Plot::xCoordOf(int i, QRect r )
{
return r.left() + (int)((i - GraphStart)*GraphPixelsPerPoint);
}
int Plot::yCoordOf(int v, QRect r, int maxVal)
{
int z = (r.bottom() - r.top())/2;
return -(z * v) / maxVal + z;
}
int Plot::valueOf_yCoord(int y, QRect r, int maxVal)
{
int z = (r.bottom() - r.top())/2;
return (y-z) * maxVal / z;
}
static const QColor GREEN = QColor(100,255,100);
static const QColor RED = QColor(255,100,100);
static const QColor BLUE = QColor(100,100,255);
static const QColor GRAY = QColor(240,240,240);
QColor Plot::getColor(int graphNum)
{
switch (graphNum) {
case 0: return GREEN; //Green
case 1: return RED; //Red
case 2: return BLUE; //Blue
default: return GRAY; //Gray
}
}
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;
//clock_t begin = clock();
QPainterPath penPath;
int grid_delta_x = PlotGridX;
int first_delta_x = grid_delta_x; //(plotOffset > 0) ? PlotGridX : (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 (BitStart > len) return;
int delta_x = 0;
int v = 0;
//printf("first_delta_x %i, grid_delta_x %i, DemodStart %i, BitStart %i\n",first_delta_x,grid_delta_x,DemodStart, BitStart);
painter->setPen(getColor(graphNum));
char str[5];
int absVMax = (int)(100*1.05+1);
int x = xCoordOf(DemodStart, plotRect);
int y = yCoordOf((buffer[BitStart]*200-100)*-1,plotRect,absVMax);
penPath.moveTo(x, y);
delta_x = 0;
int clk = first_delta_x;
for(int i = BitStart; i < len && xCoordOf(delta_x+DemodStart, plotRect) < plotRect.right(); i++) {
for (int ii = 0; ii < (clk) && i < len && xCoordOf(DemodStart+delta_x+ii, plotRect) < plotRect.right() ; ii++ ) {
x = xCoordOf(DemodStart+delta_x+ii, plotRect);
v = buffer[i]*200-100;
y = yCoordOf( v, plotRect, absVMax);
penPath.lineTo(x, y);
if(GraphPixelsPerPoint > 10) {
QRect f(QPoint(x - 3, y - 3),QPoint(x + 3, y + 3));
painter->fillRect(f, QColor(100, 255, 100));
}
if (ii == (int)clk/2) {
//print label
sprintf(str, "%u",buffer[i]);
painter->drawText(x-8, y + ((buffer[i] > 0) ? 18 : -6), str);
}
}
delta_x += clk;
clk = grid_delta_x;
}
//Graph annotations
painter->drawPath(penPath);
}
void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum)
{
if (len == 0) return;
//clock_t begin = clock();
QPainterPath penPath;
startMax = (len - (int)((plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint));
if(startMax < 0) {
startMax = 0;
}
if(GraphStart > startMax) {
GraphStart = startMax;
}
if (GraphStart > len) return;
int vMin = INT_MAX, vMax = INT_MIN, vMean = 0, v = 0, absVMax = 0;
int sample_index = GraphStart ;
for( ; sample_index < len && xCoordOf(sample_index,plotRect) < plotRect.right() ; sample_index++) {
v = buffer[sample_index];
if(v < vMin) vMin = v;
if(v > vMax) vMax = v;
vMean += v;
}
vMean /= (sample_index - GraphStart);
if(fabs( (double) vMin) > absVMax) absVMax = (int)fabs( (double) vMin);
if(fabs( (double) vMax) > absVMax) absVMax = (int)fabs( (double) vMax);
absVMax = (int)(absVMax*1.25 + 1);
// number of points that will be plotted
int span = (int)((plotRect.right() - plotRect.left()) / GraphPixelsPerPoint);
// one label every 100 pixels, let us say
int labels = (plotRect.right() - plotRect.left() - 40) / 100;
if(labels <= 0) labels = 1;
int pointsPerLabel = span / labels;
if(pointsPerLabel <= 0) pointsPerLabel = 1;
int x = xCoordOf(GraphStart, plotRect);
int y = yCoordOf(buffer[GraphStart],plotRect,absVMax);
penPath.moveTo(x, y);
for(int i = GraphStart; i < len && xCoordOf(i, plotRect) < plotRect.right(); i++) {
x = xCoordOf(i, plotRect);
v = buffer[i];
y = yCoordOf( v, plotRect, absVMax);//(y * (r.top() - r.bottom()) / (2*absYMax)) + zeroHeight;
penPath.lineTo(x, y);
if(GraphPixelsPerPoint > 10) {
QRect f(QPoint(x - 3, y - 3),QPoint(x + 3, y + 3));
painter->fillRect(f, QColor(100, 255, 100));
}
}
painter->setPen(getColor(graphNum));
//Draw y-axis
int xo = 5+(graphNum*40);
painter->drawLine(xo, plotRect.top(),xo, plotRect.bottom());
int vMarkers = (absVMax - (absVMax % 10)) / 5;
int minYDist = 40; //Minimum pixel-distance between markers
char yLbl[20];
int n = 0;
int lasty0 = 65535;
for(int v = vMarkers; yCoordOf(v,plotRect,absVMax) > plotRect.top() && n < 20; v+= vMarkers ,n++)
{
int y0 = yCoordOf(v,plotRect,absVMax);
int y1 = yCoordOf(-v,plotRect,absVMax);
if(lasty0 - y0 < minYDist) continue;
painter->drawLine(xo-5,y0, xo+5, y0);
sprintf(yLbl, "%d", v);
painter->drawText(xo+8,y0+7,yLbl);
painter->drawLine(xo-5, y1, xo+5, y1);
sprintf(yLbl, "%d",-v);
painter->drawText(xo+8, y1+5 , yLbl);
lasty0 = y0;
}
//Graph annotations
painter->drawPath(penPath);
char str[200];
sprintf(str, "max=%d min=%d mean=%d n=%d/%d CursorAVal=[%d] CursorBVal=[%d]",
vMax, vMin, vMean, sample_index, len, buffer[CursorAPos], buffer[CursorBPos]);
painter->drawText(20, annotationRect.bottom() - 23 - 20 * graphNum, str);
//clock_t end = clock();
//double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
//printf("Plot time %f\n", elapsed_secs);
}
void Plot::plotGridLines(QPainter* painter,QRect r)
{
int zeroHeight = r.top() + (r.bottom() - r.top()) / 2;
int i;
int grid_delta_x = (int) (PlotGridX * GraphPixelsPerPoint);
int grid_delta_y = (int) (PlotGridY * GraphPixelsPerPoint);
if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) {
for(i = (GridOffset * GraphPixelsPerPoint); i < r.right(); i += grid_delta_x) {
painter->drawLine(r.left()+i, r.top(), r.left()+i, r.bottom());
}
}
if ((PlotGridY > 0) && ((PlotGridY * GraphPixelsPerPoint) > 1)){
for(i = 0; i < ((r.top() + r.bottom())>>1); i += grid_delta_y) {
painter->drawLine(r.left(),zeroHeight + i,r.right(),zeroHeight + i);
painter->drawLine(r.left(),zeroHeight - i,r.right(),zeroHeight - i);
}
}
}
#define HEIGHT_INFO 60
#define WIDTH_AXES 80
void Plot::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QPainterPath penPath, whitePath, greyPath, lightgreyPath, cursorAPath, cursorBPath, cursorCPath, cursorDPath;
QRect r;
//QPainterPath penPath, whitePath, greyPath, lightgreyPath, cursorAPath, cursorBPath, cursorCPath, cursorDPath;
//QRect r;
QBrush brush(QColor(100, 255, 100));
QPen pen(QColor(100, 255, 100));
painter.setFont(QFont("Arial", 10));
painter.setFont(QFont("Courier New", 10));
if(GraphStart < 0) {
GraphStart = 0;
@ -120,176 +415,64 @@ void ProxWidget::paintEvent(QPaintEvent *event)
if(CursorDPos > GraphTraceLen)
CursorDPos= 0;
r = rect();
QRect plotRect(WIDTH_AXES, 0, width()-WIDTH_AXES, height()-HEIGHT_INFO);
QRect infoRect(0, height()-HEIGHT_INFO, width(), HEIGHT_INFO);
painter.fillRect(r, QColor(0, 0, 0));
//Grey background
painter.fillRect(rect(), QColor(60, 60, 60));
//Black foreground
painter.fillRect(plotRect, QColor(0, 0, 0));
whitePath.moveTo(r.left() + 40, r.top());
whitePath.lineTo(r.left() + 40, r.bottom());
int zeroHeight = r.top() + (r.bottom() - r.top()) / 2;
greyPath.moveTo(r.left(), zeroHeight);
greyPath.lineTo(r.right(), zeroHeight);
// center line
int zeroHeight = plotRect.top() + (plotRect.bottom() - plotRect.top()) / 2;
painter.setPen(QColor(100, 100, 100));
painter.drawPath(greyPath);
painter.drawLine(plotRect.left(), zeroHeight, plotRect.right(), zeroHeight);
// plot X and Y grid lines
plotGridLines(&painter, plotRect);
PageWidth= (int)((r.right() - r.left() - 40) / GraphPixelsPerPoint);
// plot X and Y grid lines
int i;
if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) {
for(i = 40 + (GridOffset * GraphPixelsPerPoint); i < r.right(); i += (int)(PlotGridX * GraphPixelsPerPoint)) {
//SelectObject(hdc, GreyPenLite);
//MoveToEx(hdc, r.left + i, r.top, NULL);
//LineTo(hdc, r.left + i, r.bottom);
lightgreyPath.moveTo(r.left()+i,r.top());
lightgreyPath.lineTo(r.left()+i,r.bottom());
painter.drawPath(lightgreyPath);
}
}
if ((PlotGridY > 0) && ((PlotGridY * GraphPixelsPerPoint) > 1)){
for(i = 0; i < ((r.top() + r.bottom())>>1); i += (int)(PlotGridY * GraphPixelsPerPoint)) {
lightgreyPath.moveTo(r.left() + 40,zeroHeight + i);
lightgreyPath.lineTo(r.right(),zeroHeight + i);
painter.drawPath(lightgreyPath);
lightgreyPath.moveTo(r.left() + 40,zeroHeight - i);
lightgreyPath.lineTo(r.right(),zeroHeight - i);
painter.drawPath(lightgreyPath);
}
}
startMax = (GraphTraceLen - (int)((r.right() - r.left() - 40) / GraphPixelsPerPoint));
if(startMax < 0) {
startMax = 0;
//Start painting graph
PlotGraph(GraphBuffer, GraphTraceLen,plotRect,infoRect,&painter,0);
PlotGraph(s_Buff, GraphTraceLen,plotRect,infoRect,&painter,1);
if (showDemod && DemodBufferLen > 8) {
PlotDemod(DemodBuffer, DemodBufferLen,plotRect,infoRect,&painter,2,g_DemodStartIdx);
}
if(GraphStart > startMax) {
GraphStart = startMax;
// End graph drawing
//Draw the cursors
if(CursorAPos > GraphStart && xCoordOf(CursorAPos, plotRect) < plotRect.right())
{
painter.setPen(QColor(255, 255, 0));
painter.drawLine(xCoordOf(CursorAPos, plotRect),plotRect.top(),xCoordOf(CursorAPos, plotRect),plotRect.bottom());
}
if(CursorBPos > GraphStart && xCoordOf(CursorBPos, plotRect) < plotRect.right())
{
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())
{
painter.setPen(QColor(255, 153, 0)); //orange
painter.drawLine(xCoordOf(CursorCPos, plotRect),plotRect.top(),xCoordOf(CursorCPos, plotRect),plotRect.bottom());
}
if(CursorDPos > GraphStart && xCoordOf(CursorDPos, plotRect) < plotRect.right())
{
painter.setPen(QColor(0, 0, 205)); //light blue
painter.drawLine(xCoordOf(CursorDPos, plotRect),plotRect.top(),xCoordOf(CursorDPos, plotRect),plotRect.bottom());
}
int absYMax = 1;
for(i = GraphStart; ; i++) {
if(i >= GraphTraceLen) {
break;
}
if(fabs((double)GraphBuffer[i]) > absYMax) {
absYMax = (int)fabs((double)GraphBuffer[i]);
}
int x = 40 + (int)((i - GraphStart)*GraphPixelsPerPoint);
if(x > r.right()) {
break;
}
}
absYMax = (int)(absYMax*1.2 + 1);
// number of points that will be plotted
int span = (int)((r.right() - r.left()) / GraphPixelsPerPoint);
// one label every 100 pixels, let us say
int labels = (r.right() - r.left() - 40) / 100;
if(labels <= 0) labels = 1;
int pointsPerLabel = span / labels;
if(pointsPerLabel <= 0) pointsPerLabel = 1;
int yMin = INT_MAX;
int yMax = INT_MIN;
int yMean = 0;
int n = 0;
for(i = GraphStart; ; i++) {
if(i >= GraphTraceLen) {
break;
}
int x = 40 + (int)((i - GraphStart)*GraphPixelsPerPoint);
if(x > r.right() + GraphPixelsPerPoint) {
break;
}
int y = GraphBuffer[i];
if(y < yMin) {
yMin = y;
}
if(y > yMax) {
yMax = y;
}
yMean += y;
n++;
y = (y * (r.top() - r.bottom()) / (2*absYMax)) + zeroHeight;
if(i == GraphStart) {
penPath.moveTo(x, y);
} else {
penPath.lineTo(x, y);
}
if(GraphPixelsPerPoint > 10) {
QRect f(QPoint(x - 3, y - 3),QPoint(x + 3, y + 3));
painter.fillRect(f, brush);
}
if(((i - GraphStart) % pointsPerLabel == 0) && i != GraphStart) {
whitePath.moveTo(x, zeroHeight - 3);
whitePath.lineTo(x, zeroHeight + 3);
char str[100];
sprintf(str, "+%d", (i - GraphStart));
painter.setPen(QColor(255, 255, 255));
QRect size;
QFontMetrics metrics(painter.font());
size = metrics.boundingRect(str);
painter.drawText(x - (size.right() - size.left()), zeroHeight + 9, str);
penPath.moveTo(x,y);
}
if(i == CursorAPos || i == CursorBPos || i == CursorCPos || i == CursorDPos) {
QPainterPath *cursorPath;
if(i == CursorAPos) {
cursorPath = &cursorAPath;
} else if (i == CursorBPos) {
cursorPath = &cursorBPath;
} else if (i == CursorCPos) {
cursorPath = &cursorCPath;
} else {
cursorPath = &cursorDPath;
}
cursorPath->moveTo(x, r.top());
cursorPath->lineTo(x, r.bottom());
penPath.moveTo(x, y);
}
}
if(n != 0) {
yMean /= n;
}
painter.setPen(QColor(255, 255, 255));
painter.drawPath(whitePath);
painter.setPen(pen);
painter.drawPath(penPath);
painter.setPen(QColor(255, 255, 0));
painter.drawPath(cursorAPath);
painter.setPen(QColor(255, 0, 255));
painter.drawPath(cursorBPath);
painter.setPen(QColor(255, 153, 0)); //orange
painter.drawPath(cursorCPath);
painter.setPen(QColor(0, 0, 205)); //light blue
painter.drawPath(cursorDPath);
//Draw annotations
char str[200];
sprintf(str, "@%d max=%d min=%d mean=%d n=%d/%d dt=%d [%.3f] zoom=%.3f CursorA=%d [%d] CursorB=%d [%d] GridX=%d GridY=%d (%s)",
GraphStart, yMax, yMin, yMean, n, GraphTraceLen,
CursorBPos - CursorAPos, (CursorBPos - CursorAPos)/CursorScaleFactor,GraphPixelsPerPoint,CursorAPos,GraphBuffer[CursorAPos],CursorBPos,GraphBuffer[CursorBPos],PlotGridXdefault,PlotGridYdefault,GridLocked?"Locked":"Unlocked");
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);
painter.setPen(QColor(255, 255, 255));
painter.drawText(50, r.bottom() - 20, str);
painter.drawText(20, infoRect.bottom() - 3, str);
}
ProxWidget::ProxWidget(QWidget *parent) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1)
Plot::Plot(QWidget *parent) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1)
{
setFocusPolicy( Qt::StrongFocus);
resize(600, 300);
QPalette palette(QColor(0,0,0,0));
@ -300,18 +483,20 @@ ProxWidget::ProxWidget(QWidget *parent) : QWidget(parent), GraphStart(0), GraphP
setAutoFillBackground(true);
CursorAPos = 0;
CursorBPos = 0;
setWindowTitle(tr("Sliders"));
}
void ProxWidget::closeEvent(QCloseEvent *event)
void Plot::closeEvent(QCloseEvent *event)
{
event->ignore();
this->hide();
}
void ProxWidget::mouseMoveEvent(QMouseEvent *event)
void Plot::mouseMoveEvent(QMouseEvent *event)
{
int x = event->x();
x -= 40;
x -= WIDTH_AXES;
x = (int)(x / GraphPixelsPerPoint);
x += GraphStart;
if((event->buttons() & Qt::LeftButton)) {
@ -324,7 +509,7 @@ void ProxWidget::mouseMoveEvent(QMouseEvent *event)
this->update();
}
void ProxWidget::keyPressEvent(QKeyEvent *event)
void Plot::keyPressEvent(QKeyEvent *event)
{
int offset;
int gridchanged;

View file

@ -13,26 +13,66 @@
#include <QObject>
#include <QWidget>
#include <QPainter>
#include <QtGui>
#include "ui/ui_overlays.h"
/**
* @brief The actual plot, black area were we paint the graph
*/
class Plot: public QWidget
{
private:
int GraphStart;
double GraphPixelsPerPoint;
int CursorAPos;
int CursorBPos;
void PlotGraph(int *buffer, int len, QRect r,QRect r2, QPainter* painter, int graphNum);
void PlotDemod(uint8_t *buffer, size_t len, QRect r,QRect r2, QPainter* painter, int graphNum, int plotOffset);
void plotGridLines(QPainter* painter,QRect r);
int xCoordOf(int i, QRect r );
int yCoordOf(int v, QRect r, int maxVal);
int valueOf_yCoord(int y, QRect r, int maxVal);
QColor getColor(int graphNum);
public:
Plot(QWidget *parent = 0);
protected:
void paintEvent(QPaintEvent *event);
void closeEvent(QCloseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event) { mouseMoveEvent(event); }
void keyPressEvent(QKeyEvent *event);
};
class ProxGuiQT;
/**
* The window with plot and controls
*/
class ProxWidget : public QWidget
{
Q_OBJECT;
private:
int GraphStart;
double GraphPixelsPerPoint;
int CursorAPos;
int CursorBPos;
Plot *plot;
Ui::Form *opsController;
ProxGuiQT *master;
public:
ProxWidget(QWidget *parent = 0);
ProxWidget(QWidget *parent = 0, ProxGuiQT *master = NULL);
protected:
void paintEvent(QPaintEvent *event);
void closeEvent(QCloseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event) { mouseMoveEvent(event); }
void keyPressEvent(QKeyEvent *event);
//protected:
// void paintEvent(QPaintEvent *event);
// void closeEvent(QCloseEvent *event);
// void mouseMoveEvent(QMouseEvent *event);
// void mousePressEvent(QMouseEvent *event) { mouseMoveEvent(event); }
// void keyPressEvent(QKeyEvent *event);
public slots:
void applyOperation();
void stickOperation();
void vchange_autocorr(int v);
void vchange_dthr_up(int v);
void vchange_dthr_down(int v);
};
class ProxGuiQT : public QObject

View file

@ -19,11 +19,12 @@
#include "ui.h"
double CursorScaleFactor = 1;
int PlotGridX, PlotGridY, PlotGridXdefault= 64, PlotGridYdefault= 64, CursorCPos= 0, CursorDPos= 0;
int PlotGridX=0, PlotGridY=0, PlotGridXdefault= 64, PlotGridYdefault= 64, CursorCPos= 0, CursorDPos= 0;
int offline;
int flushAfterWrite = 0; //buzzy
int GridOffset = 0;
bool GridLocked = false;
bool showDemod = true;
extern pthread_mutex_t print_lock;

View file

@ -25,5 +25,6 @@ extern int PlotGridX, PlotGridY, PlotGridXdefault, PlotGridYdefault, CursorCPos,
extern int offline;
extern int flushAfterWrite; //buzzy
extern bool GridLocked;
extern bool showDemod;
#endif

272
client/ui/overlays.ui Normal file
View file

@ -0,0 +1,272 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>614</width>
<height>286</height>
</rect>
</property>
<property name="windowTitle">
<string>Overlays</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QTabWidget" name="tabWidget_overlays">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<attribute name="title">
<string>Autocorrelate</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Window size</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_5">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QSlider" name="horizontalSlider_window">
<property name="minimum">
<number>10</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
<property name="value">
<number>2000</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string>Askdemod</string>
</attribute>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Dirthreshold</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Up</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_6">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QSlider" name="horizontalSlider_dirthr_up">
<property name="maximum">
<number>128</number>
</property>
<property name="value">
<number>20</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Down</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_7">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QSlider" name="horizontalSlider_dirthr_down">
<property name="maximum">
<number>127</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButton_apply">
<property name="text">
<string>Apply</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_sticky">
<property name="text">
<string>Sticky</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>horizontalSlider_window</sender>
<signal>valueChanged(int)</signal>
<receiver>label_4</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>29</x>
<y>90</y>
</hint>
<hint type="destinationlabel">
<x>597</x>
<y>257</y>
</hint>
</hints>
</connection>
<connection>
<sender>horizontalSlider_window</sender>
<signal>valueChanged(int)</signal>
<receiver>label_5</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>153</x>
<y>84</y>
</hint>
<hint type="destinationlabel">
<x>161</x>
<y>69</y>
</hint>
</hints>
</connection>
<connection>
<sender>horizontalSlider_dirthr_up</sender>
<signal>valueChanged(int)</signal>
<receiver>label_6</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>53</x>
<y>92</y>
</hint>
<hint type="destinationlabel">
<x>68</x>
<y>67</y>
</hint>
</hints>
</connection>
<connection>
<sender>horizontalSlider_dirthr_down</sender>
<signal>valueChanged(int)</signal>
<receiver>label_7</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>184</x>
<y>161</y>
</hint>
<hint type="destinationlabel">
<x>149</x>
<y>135</y>
</hint>
</hints>
</connection>
</connections>
</ui>

224
client/ui/ui_overlays.h Normal file
View file

@ -0,0 +1,224 @@
/********************************************************************************
** Form generated from reading UI file 'overlaystQ7020.ui'
**
** Created by: Qt User Interface Compiler version 4.8.6
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef OVERLAYSTQ7020_H
#define OVERLAYSTQ7020_H
#include <QtCore/QVariant>
#include <QAction>
#include <QApplication>
#include <QButtonGroup>
#include <QFormLayout>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QLabel>
#include <QPushButton>
#include <QSlider>
#include <QSpacerItem>
#include <QTabWidget>
#include <QVBoxLayout>
#include <QWidget>
QT_BEGIN_NAMESPACE
class Ui_Form
{
public:
QVBoxLayout *verticalLayout_3;
QTabWidget *tabWidget_overlays;
QWidget *tab;
QVBoxLayout *verticalLayout_2;
QFormLayout *formLayout;
QLabel *label;
QLabel *label_5;
QSlider *horizontalSlider_window;
QSpacerItem *verticalSpacer;
QWidget *tab_3;
QWidget *tab_2;
QVBoxLayout *verticalLayout;
QFormLayout *formLayout_2;
QLabel *label_2;
QLabel *label_6;
QSlider *horizontalSlider_dirthr_up;
QFormLayout *formLayout_3;
QLabel *label_3;
QLabel *label_7;
QSlider *horizontalSlider_dirthr_down;
QSpacerItem *verticalSpacer_2;
QHBoxLayout *horizontalLayout;
QPushButton *pushButton_apply;
QPushButton *pushButton_sticky;
QSpacerItem *horizontalSpacer;
QLabel *label_4;
void setupUi(QWidget *Form)
{
if (Form->objectName().isEmpty())
Form->setObjectName(QString::fromUtf8("Form"));
Form->resize(614, 286);
verticalLayout_3 = new QVBoxLayout(Form);
verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3"));
tabWidget_overlays = new QTabWidget(Form);
tabWidget_overlays->setObjectName(QString::fromUtf8("tabWidget_overlays"));
tab = new QWidget();
tab->setObjectName(QString::fromUtf8("tab"));
tab->setFocusPolicy(Qt::StrongFocus);
verticalLayout_2 = new QVBoxLayout(tab);
verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
formLayout = new QFormLayout();
formLayout->setObjectName(QString::fromUtf8("formLayout"));
label = new QLabel(tab);
label->setObjectName(QString::fromUtf8("label"));
formLayout->setWidget(0, QFormLayout::LabelRole, label);
label_5 = new QLabel(tab);
label_5->setObjectName(QString::fromUtf8("label_5"));
formLayout->setWidget(0, QFormLayout::FieldRole, label_5);
verticalLayout_2->addLayout(formLayout);
horizontalSlider_window = new QSlider(tab);
horizontalSlider_window->setObjectName(QString::fromUtf8("horizontalSlider_window"));
horizontalSlider_window->setMinimum(10);
horizontalSlider_window->setMaximum(10000);
horizontalSlider_window->setValue(2000);
horizontalSlider_window->setOrientation(Qt::Horizontal);
verticalLayout_2->addWidget(horizontalSlider_window);
verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout_2->addItem(verticalSpacer);
tabWidget_overlays->addTab(tab, QString());
tab_3 = new QWidget();
tab_3->setObjectName(QString::fromUtf8("tab_3"));
tabWidget_overlays->addTab(tab_3, QString());
tab_2 = new QWidget();
tab_2->setObjectName(QString::fromUtf8("tab_2"));
verticalLayout = new QVBoxLayout(tab_2);
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
formLayout_2 = new QFormLayout();
formLayout_2->setObjectName(QString::fromUtf8("formLayout_2"));
label_2 = new QLabel(tab_2);
label_2->setObjectName(QString::fromUtf8("label_2"));
formLayout_2->setWidget(0, QFormLayout::LabelRole, label_2);
label_6 = new QLabel(tab_2);
label_6->setObjectName(QString::fromUtf8("label_6"));
formLayout_2->setWidget(0, QFormLayout::FieldRole, label_6);
verticalLayout->addLayout(formLayout_2);
horizontalSlider_dirthr_up = new QSlider(tab_2);
horizontalSlider_dirthr_up->setObjectName(QString::fromUtf8("horizontalSlider_dirthr_up"));
horizontalSlider_dirthr_up->setMaximum(128);
horizontalSlider_dirthr_up->setValue(20);
horizontalSlider_dirthr_up->setOrientation(Qt::Horizontal);
verticalLayout->addWidget(horizontalSlider_dirthr_up);
formLayout_3 = new QFormLayout();
formLayout_3->setObjectName(QString::fromUtf8("formLayout_3"));
label_3 = new QLabel(tab_2);
label_3->setObjectName(QString::fromUtf8("label_3"));
formLayout_3->setWidget(0, QFormLayout::LabelRole, label_3);
label_7 = new QLabel(tab_2);
label_7->setObjectName(QString::fromUtf8("label_7"));
formLayout_3->setWidget(0, QFormLayout::FieldRole, label_7);
verticalLayout->addLayout(formLayout_3);
horizontalSlider_dirthr_down = new QSlider(tab_2);
horizontalSlider_dirthr_down->setObjectName(QString::fromUtf8("horizontalSlider_dirthr_down"));
horizontalSlider_dirthr_down->setMaximum(127);
horizontalSlider_dirthr_down->setOrientation(Qt::Horizontal);
verticalLayout->addWidget(horizontalSlider_dirthr_down);
verticalSpacer_2 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout->addItem(verticalSpacer_2);
tabWidget_overlays->addTab(tab_2, QString());
verticalLayout_3->addWidget(tabWidget_overlays);
horizontalLayout = new QHBoxLayout();
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
pushButton_apply = new QPushButton(Form);
pushButton_apply->setObjectName(QString::fromUtf8("pushButton_apply"));
horizontalLayout->addWidget(pushButton_apply);
pushButton_sticky = new QPushButton(Form);
pushButton_sticky->setObjectName(QString::fromUtf8("pushButton_sticky"));
horizontalLayout->addWidget(pushButton_sticky);
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout->addItem(horizontalSpacer);
label_4 = new QLabel(Form);
label_4->setObjectName(QString::fromUtf8("label_4"));
horizontalLayout->addWidget(label_4);
verticalLayout_3->addLayout(horizontalLayout);
retranslateUi(Form);
QObject::connect(horizontalSlider_window, SIGNAL(valueChanged(int)), label_4, SLOT(setNum(int)));
QObject::connect(horizontalSlider_window, SIGNAL(valueChanged(int)), label_5, SLOT(setNum(int)));
QObject::connect(horizontalSlider_dirthr_up, SIGNAL(valueChanged(int)), label_6, SLOT(setNum(int)));
QObject::connect(horizontalSlider_dirthr_down, SIGNAL(valueChanged(int)), label_7, SLOT(setNum(int)));
tabWidget_overlays->setCurrentIndex(0);
QMetaObject::connectSlotsByName(Form);
} // setupUi
void retranslateUi(QWidget *Form)
{
Form->setWindowTitle(QApplication::translate("Form", "Overlays", 0));
label->setText(QApplication::translate("Form", "Window size", 0));
label_5->setText(QString());
tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab), QApplication::translate("Form", "Autocorrelate", 0));
tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_3), QApplication::translate("Form", "Askdemod", 0));
label_2->setText(QApplication::translate("Form", "Up", 0));
label_6->setText(QString());
label_3->setText(QApplication::translate("Form", "Down", 0));
label_7->setText(QString());
tabWidget_overlays->setTabText(tabWidget_overlays->indexOf(tab_2), QApplication::translate("Form", "Dirthreshold", 0));
pushButton_apply->setText(QApplication::translate("Form", "Apply", 0));
pushButton_sticky->setText(QApplication::translate("Form", "Sticky", 0));
label_4->setText(QApplication::translate("Form", "TextLabel", 0));
} // retranslateUi
};
namespace Ui {
class Form: public Ui_Form {};
} // namespace Ui
QT_END_NAMESPACE
#endif // OVERLAYSTQ7020_H