Skip to content

Commit

Permalink
Improvements to monitor and serial cmd handler
Browse files Browse the repository at this point in the history
  • Loading branch information
jedi98 committed Nov 13, 2015
1 parent cb40201 commit 5dd9442
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 188 deletions.
18 changes: 10 additions & 8 deletions bargraph.cpp
Expand Up @@ -23,7 +23,6 @@ along with Foobar. If not, see <http://www.gnu.org/licenses/>.
#include <QPainter>

#include "config.h"
//#include "scandata.h"
#include "bargraph.h"

//extern ScanData scandata;
Expand All @@ -49,6 +48,8 @@ BarGraph::BarGraph(QWidget *parent) :

font = QFont("Arial",9);
font_h = QFontMetrics(font).height();

//setAutoFillBackground(true);
}

BarGraph::~BarGraph()
Expand All @@ -70,18 +71,18 @@ void BarGraph::Draw(QPainter &painter)
double scale;
int x/*,y*/;

int xo = margin+font_h, yo=height()-margin-10-font_h,
h=height()-2*(margin)-10-font_h,
int xo = margin+font_h, yo=height()-margin-6-font_h,
h=height()-2*(margin)-6-font_h,
w=width()-2*margin-2*font_h;

painter.setPen(Qt::NoPen);
//painter.setPen(pen);
painter.setBrush(brush);
//painter.setFont(font);
painter.setFont(font);

//Bar
scale = (w) / (vmax-vmin);
painter.drawRect(xo+(vorig-vmin)*scale,yo,(value-vorig)*scale,-h);
painter.drawRect(xo+(vorig-vmin)*scale,yo,(constrain(value,vmin,vmax)-vorig)*scale,-h);

//Scale
painter.setPen(pen);
Expand All @@ -95,10 +96,10 @@ void BarGraph::Draw(QPainter &painter)
x=xo + (v-vmin)*scale;
//printf("x=%d\n",x);
//printf("v=%f\n",v);
painter.drawLine(x,yo,x,yo + 10);
painter.drawLine(x,yo,x,yo + 6);

x=x - QFontMetrics(font).boundingRect(s).width()/2;
painter.drawText(x,yo + 10 + font_h,s);
painter.drawText(x,yo + 6 + font_h,s);
}

}
Expand All @@ -110,7 +111,8 @@ void BarGraph::paintEvent(QPaintEvent *)
////////////////////

painter.setBackgroundMode(Qt::OpaqueMode); //??
painter.setBackground(Qt::white);
//painter.setBackground(Qt::white);
//painter.setAutoFillBackground(true);
painter.eraseRect(painter.viewport());

painter.setBackgroundMode(Qt::TransparentMode); //??
Expand Down
19 changes: 3 additions & 16 deletions bargraph.h
Expand Up @@ -8,7 +8,7 @@ and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Sark-100-antenna-analyzerr is distributed in the hope that it will be
Sark-100-antenna-analyzer is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Expand All @@ -23,10 +23,8 @@ along with Foobar. If not, see <http://www.gnu.org/licenses/>.
#include <QWidget>
#include <QPen>
#include <QBrush>
//#include <QMouseEvent>

//#include "graph.h"
//#include "graphcursor.h"
#define constrain(v,v1,v2) ((v)<(v1)?v1:((v)>(v2)?v2:v))

class BarGraph : public QWidget
{
Expand All @@ -35,13 +33,6 @@ class BarGraph : public QWidget
explicit BarGraph(QWidget *parent = 0);
~BarGraph();

//GraphCursor *cursor;

//Graph graph;
//GraphScale *xscale,*yscale1, *yscale2;
//GraphTrace *swrtrace, *ztrace, *xtrace, *rtrace;
//GraphVertLine *swrminline;
//GraphHorizLine *ZZeroLine, *ZTargetline,*SWRTargetline;
void Draw(QPainter &painter);
void SetIncAuto();

Expand All @@ -50,18 +41,14 @@ class BarGraph : public QWidget
QBrush brush;
double vmin, vmax, vinc, value, labdiv, vorig;
QString labsuffix;
QFont font;

signals:
//void cursorMoved(double pos);

public slots:

private:
QFont font;
int font_h;

void paintEvent(QPaintEvent *);
//void mouseMoveEvent(QMouseEvent *ev);
};

#endif // BARGRAPH_H
59 changes: 29 additions & 30 deletions mainwindow.cpp
Expand Up @@ -8,7 +8,7 @@ and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Sark-100-antenna-analyzerr is distributed in the hope that it will be
Sark-100-antenna-analyzer is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Expand Down Expand Up @@ -80,7 +80,7 @@ setlinebuf(stdout);

link = new SerialLink("/dev/ttyUSB0",57600);
if (link->IsUp())
link->Cmd_Off(this);
link->Cmd_Off();

ui->band_cb->setCurrentIndex(16);

Expand Down Expand Up @@ -114,6 +114,7 @@ void MainWindow::RaiseEvent(event_t event,int arg)
{
case progress_event:
ui->progressBar->setValue(arg);
//draw_graph1();
break;
}
}
Expand Down Expand Up @@ -207,7 +208,7 @@ void MainWindow::Slot_scanBtn_click()
(long)((scandata.freq_end-scandata.freq_start)/scandata.GetPointCount()),
ui->useraw_chk->checkState()==Qt::Checked,
this);
link->Cmd_Off(this);
link->Cmd_Off();
}

populate_table();
Expand Down Expand Up @@ -463,7 +464,7 @@ void MainWindow::Slot_menuDevice_Select(QAction *act)
link = new SerialLink(QString("/dev/" + act->text()).toLatin1().data(),57600);

if (link->IsUp())
link->Cmd_Off(this);
link->Cmd_Off();
}

void MainWindow::Slot_about()
Expand Down Expand Up @@ -507,27 +508,31 @@ void MainWindow::Slot_monStart_click()
ui->SWR_Bar->SetIncAuto();
ui->SWR_Bar->value = 1;

ui->Z_Bar->brush = QBrush(qRgb(255,85,0));
ui->Z_Bar->vmin = 0;
ui->Z_Bar->vmax = 200;
ui->Z_Bar->value = 50;
ui->Z_Bar->SetIncAuto();

ui->R_Bar->brush = QBrush(Qt::darkGreen);
ui->R_Bar->vmin = 0;
ui->R_Bar->vmax = 200;
ui->R_Bar->value = 50;
ui->R_Bar->SetIncAuto();

ui->X_Bar->brush = QBrush(Qt::red);
ui->X_Bar->vmin = -100;
ui->X_Bar->vmax = 200;
ui->X_Bar->value = 0;
ui->X_Bar->SetIncAuto();

if (link->IsUp())
{
link->Cmd_Freq((long)(ui->monfreq->value()*1000000),this);
link->Cmd_On(this);
link->Cmd_Freq((long)(ui->monfreq->value()*1000000));
link->Cmd_On();
}

Slot_montimer_timeout();
montimer.start((long)(ui->monrate->value()));
}

Expand All @@ -536,9 +541,7 @@ void MainWindow::Slot_monStop_click()
montimer.stop();

if (link->IsUp())
{
link->Cmd_Off(this);
}
link->Cmd_Off();
}

void MainWindow::Slot_montimer_timeout()
Expand All @@ -547,26 +550,22 @@ void MainWindow::Slot_montimer_timeout()

if (link->IsUp())
{
link->Cmd_Raw(sample, this);

ui->SWR_Bar->value = sample.swr;
//ui->SWR_Bar->value += 1.0;
//if (ui->SWR_Bar->value>ui->SWR_Bar->vmax) ui->SWR_Bar->value=ui->SWR_Bar->vmin;
ui->SWR_lbl->setText(QString("%1:1").arg(sample.swr, 0,'f',1));
ui->SWR_Bar->update();

ui->Z_Bar->value = sample.Z;
//ui->Z_Bar->value += 15.0;
//if (ui->Z_Bar->value>ui->Z_Bar->vmax) ui->Z_Bar->value=ui->Z_Bar->vmin;
ui->Z_lbl->setText(QString("%1").arg(sample.Z, 0,'f',1));
ui->Z_Bar->update();

ui->R_Bar->value = sample.R;
ui->R_lbl->setText(QString("%1").arg(sample.R, 0,'f',1));
ui->R_Bar->update();

ui->X_Bar->value = sample.X;
ui->X_lbl->setText(QString("%1").arg(sample.X, 0,'f',1));
ui->X_Bar->update();
link->Cmd_Raw(sample);

ui->SWR_lbl->setText(QString("%1:1").arg(sample.swr, 0,'f',1));
ui->SWR_Bar->value = sample.swr;
ui->SWR_Bar->update();

ui->Z_lbl->setText(QString("%1").arg(sample.Z, 0,'f',1));
ui->Z_Bar->value = sample.Z;
ui->Z_Bar->update();

ui->R_lbl->setText(QString("%1").arg(sample.R, 0,'f',1));
ui->R_Bar->value = sample.R;
ui->R_Bar->update();

ui->X_lbl->setText(QString("%1").arg(sample.X, 0,'f',1));
ui->X_Bar->value = sample.X;
ui->X_Bar->update();
}
}
2 changes: 1 addition & 1 deletion mainwindow.ui
Expand Up @@ -25,7 +25,7 @@
<bool>true</bool>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab_4">
<attribute name="title">
Expand Down
10 changes: 6 additions & 4 deletions serialdev.cpp
Expand Up @@ -8,7 +8,7 @@ and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Sark-100-antenna-analyzerr is distributed in the hope that it will be
Sark-100-antenna-analyzer is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Expand Down Expand Up @@ -82,9 +82,11 @@ int SerialDev::RxFlush()
{

pollfd fds[] = {{devfd, POLLIN, 0 }};
int timeout = 500; //500msec, move somewhere
int timeout = 50; //500msec, move somewhere
int pstatus,rstatus;

printf("%ld> RxFlush\n",time(NULL));

for (rxbufflen=0;;)
{
pstatus = poll(fds, 1, timeout);
Expand All @@ -105,7 +107,7 @@ int SerialDev::RxFlush()
}
else
{
printf("RxFlush: %c\n",rxbuff[rxbufflen]);
//printf("%ld> RxFlush: %c\n",time(NULL),rxbuff[rxbufflen]);
}
}
}
Expand Down Expand Up @@ -143,7 +145,7 @@ int SerialDev::RxLine()
}
else
{
//printf("RxLine: c=%c (0x%02x)\n",rxbuff[rxbufflen],rxbuff[rxbufflen]);
//printf("%ld> RxLine: c=%c (0x%02x)\n",time(NULL),rxbuff[rxbufflen],rxbuff[rxbufflen]);
switch (rxbuff[rxbufflen])
{
case '\r': break;
Expand Down
2 changes: 1 addition & 1 deletion serialdev.h
Expand Up @@ -8,7 +8,7 @@ and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Sark-100-antenna-analyzerr is distributed in the hope that it will be
Sark-100-antenna-analyzer is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Expand Down

0 comments on commit 5dd9442

Please sign in to comment.