Changeset 259 in flair-src for trunk/tools


Ignore:
Timestamp:
Jul 25, 2018, 5:27:17 PM (6 years ago)
Author:
Sanahuja Guillaume
Message:

add history to us sensor plot

Location:
trunk/tools/FlairGCS/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/FlairGCS/src/UsSensorPlot.cpp

    r244 r259  
    1414#include <qwt_legend.h>
    1515#include <qwt_plot_panner.h>
    16 #include <qwt_plot_rescaler.h>
    1716#include <qwt_plot_marker.h>
    1817#include <QMouseEvent>
    1918#include <QMenu>
    2019#include <QInputDialog>
     20#include <QVBoxLayout>
     21#include <QScrollBar>
    2122#include <qendian.h>
    2223#include <qwt_symbol.h>
     
    2526                       QString y_name, float ymin, float ymax, uint32_t nbSamples,QString datasType,bool enabled, int period)
    2627    : DataRemote(plot_name, "UsSensorPlot", parent, enabled, period) {
     28  visible_widget = new QWidget();
     29
     30  parent->addWidget(visible_widget, row, col);
     31  QVBoxLayout* layout = new QVBoxLayout(visible_widget);
     32     
    2733  plot = new QwtPlot(NULL);
    2834  plot->setEnabled(enabled);
    29 
    30   parent->addWidget(plot, row, col);
    31   visible_widget = plot;
    3235 
    3336  this->nbSamples=nbSamples;
     
    4447#endif
    4548
     49  //scroll bar
     50  scrollbar=new QScrollBar(Qt::Horizontal);
     51  scrollbar->setSingleStep(1);
     52  scrollbar->setRange(0,0);
     53  scrolling=true;
     54  connect(scrollbar,SIGNAL(valueChanged(int)),this,SLOT(scrollBarMoved(int)));
     55  layout->addWidget(scrollbar);
     56  layout->addWidget(plot);
     57
    4658  alignScales();
    4759
    4860  // Assign a title
    4961  plot->setTitle(plot_name);
    50 
     62 
    5163  // Axis
    5264  plot->setAxisTitle(QwtPlot::xBottom, "samples");
    5365  setXAxisScale(0, nbSamples-1);
    54 
     66 
    5567  plot->setAxisTitle(QwtPlot::yLeft, y_name);
    5668  setYAxisScale(ymin, ymax);
    57 
    58   //QwtPlotRescaler *rescaler = new QwtPlotRescaler(plot->canvas());
    59   //rescaler->setRescalePolicy(QwtPlotRescaler::Fixed);
    60   /*
    61  rescaler->setReferenceAxis(QwtPlot::xBottom);
    62  rescaler->setAspectRatio(QwtPlot::yLeft, 1.0);*/
    6369
    6470  // grid
     
    7783 
    7884  dx = (double *)malloc(nbSamples* sizeof(double));
    79   dy = (double *)malloc(nbSamples* sizeof(double));
    8085  for (int i = 0; i < nbSamples; i++) dx[i] = i;
    8186 
     
    8691
    8792  datas->setVisible(true);
    88 
    89   // Attach (don't copy) data
    90   datas->setRawSamples(dx,dy, nbSamples);
    9193
    9294  if (datasType == "float") {
     
    104106  QwtSymbol* s1=new QwtSymbol( QwtSymbol::Diamond, Qt::blue, Qt::NoPen, QSize( 10, 10 ) );
    105107  firstPeakStart->setSymbol(s1);
    106   //m->setLabel("toto" );
    107108  firstPeakStart->attach( plot );
    108109 
     
    125126UsSensorPlot::~UsSensorPlot() {
    126127  free(dx);
    127   free(dy);
     128  for(int i=0;i<measures.count();i++) {
     129    free(measures.at(i).dy);
     130  }
    128131}
    129132
     
    185188  if (IsEnabled() == false || RefreshRate_ms() != period)
    186189    return;
     190   
     191  measure_t measure;
     192  measure.dy = (double *)malloc(nbSamples* sizeof(double));
    187193
    188194  if (datasType == "float") {
    189195    float *data=(float*)*buf;
    190196    for (int i = 0; i < nbSamples; i++) {
    191       dy[i]=data[i];
     197      measure.dy[i]=data[i];
    192198    }
    193199    *buf += nbSamples*sizeof(float);
     
    195201    int8_t *data=(int8_t*)*buf;
    196202    for (int i = 0; i < nbSamples; i++) {
    197       dy[i]=data[i];
     203      measure.dy[i]=data[i];
    198204    }
    199205    *buf += nbSamples*sizeof(int8_t);
     
    201207    uint8_t *data=(uint8_t*)*buf;
    202208    for (int i = 0; i < nbSamples; i++) {
    203       dy[i]=data[i];
     209      measure.dy[i]=data[i];
    204210    }
    205211    *buf += nbSamples*sizeof(uint8_t);
     
    207213    int16_t *data=(int16_t*)*buf;
    208214    for (int i = 0; i < nbSamples; i++) {
    209       dy[i]=data[i];
     215      measure.dy[i]=data[i];
    210216    }
    211217    *buf += nbSamples*sizeof(int16_t);
     
    213219    uint16_t *data=(uint16_t*)*buf;
    214220    for (int i = 0; i < nbSamples; i++) {
    215       dy[i]=data[i];
     221      measure.dy[i]=data[i];
    216222    }
    217223    *buf += nbSamples*sizeof(uint16_t);
     
    222228  *buf += 4*sizeof(uint16_t);
    223229 
    224   firstPeakStart->setValue( QPointF( data[0], dy[data[0]] ) );
    225   firstPeakEnd->setValue( QPointF( data[1], dy[data[1]] ) );
    226   secondPeakStart->setValue( QPointF( data[2], dy[data[2]] ) );
    227   secondPeakEnd->setValue( QPointF( data[3], dy[data[3]] ) );
     230  measure.firstPeakStartIndex=data[0];
     231  measure.firstPeakEndIndex=data[1];
     232  measure.secondPeakStartIndex=data[2];
     233  measure.secondPeakEndIndex=data[3];
     234  measures.append(measure);
     235
     236  scrollbar->setRange(0,measures.count()-1);
     237  if(scrolling) {
     238    scrollbar->blockSignals(true);//block valuechanged signal
     239    scrollbar->setValue(measures.count()-1);
     240    scrollbar->blockSignals(false);
     241   
     242    plotMeasure(measures.count()-1);
     243  }
     244}
     245
     246void UsSensorPlot::plotMeasure(int index) {
     247  firstPeakStart->setValue( QPointF(measures.at(index).firstPeakStartIndex,measures.at(index).dy[measures.at(index).firstPeakStartIndex] ) );
     248  firstPeakEnd->setValue( QPointF(measures.at(index).firstPeakEndIndex,measures.at(index).dy[measures.at(index).firstPeakEndIndex] ) );
     249  secondPeakStart->setValue( QPointF(measures.at(index).secondPeakStartIndex,measures.at(index).dy[measures.at(index).secondPeakStartIndex] ) );
     250  secondPeakEnd->setValue( QPointF(measures.at(index).secondPeakEndIndex,measures.at(index).dy[measures.at(index).secondPeakEndIndex] ) );
     251 
     252  // Attach (don't copy) data
     253  datas->setRawSamples(dx,measures.at(index).dy, nbSamples);
    228254 
    229255  plot->replot();
    230256}
    231 
    232 
    233257// context menu
    234258void UsSensorPlot::mousePressEvent(QMouseEvent *event) {
     
    241265    a = menu->addAction("reset zoom");
    242266    menu->addSeparator();
    243 
    244267
    245268    appendmenu(menu);
     
    254277  }
    255278}
     279
     280void UsSensorPlot::scrollBarMoved(int value) {
     281  if(value==scrollbar->maximum()) {
     282    scrolling=true;
     283  } else {
     284    scrolling=false;
     285  }
     286  plotMeasure(value);
     287}
  • trunk/tools/FlairGCS/src/UsSensorPlot.h

    r221 r259  
    1616class QMouseEvent;
    1717class QwtPlotMarker;
     18class QScrollBar;
    1819
    1920class UsSensorPlot : public DataRemote {
     
    3334  void alignScales(void);
    3435  float xmin_orig, xmax_orig, ymin_orig, ymax_orig;
     36  QScrollBar* scrollbar;
    3537
    3638  QwtPlotCurve *datas;
    3739  QwtPlotMarker *firstPeakStart,*firstPeakEnd,*secondPeakStart,*secondPeakEnd;
    3840  QString datasType;
    39   bool datas_first_update;
    4041  double *dx;
    41   double *dy;
     42 
     43  struct measure_t {
     44    double *dy;
     45    uint16_t firstPeakStartIndex;
     46    uint16_t firstPeakEndIndex;
     47    uint16_t secondPeakStartIndex;
     48    uint16_t secondPeakEndIndex;
     49  };
     50  QList<measure_t> measures;
     51       
     52 
    4253  uint32_t nbSamples;
     54  bool scrolling;
    4355
    4456  bool eventFilter(QObject *, QEvent *);
     
    4658  void setXAxisScale(float xmin, float xmax);
    4759  void BufEvent(char **buf, int *buf_size, uint16_t period, bool big_endian);
     60  void plotMeasure(int index);
     61 
     62 private slots:
     63    void scrollBarMoved(int value);
    4864};
    4965
Note: See TracChangeset for help on using the changeset viewer.