Changeset 16 in flair-src for trunk/demos/Sinus/src/Sinus.cpp


Ignore:
Timestamp:
Apr 8, 2016, 3:48:40 PM (5 years ago)
Author:
Bayard Gildas
Message:

Reformatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/demos/Sinus/src/Sinus.cpp

    r14 r16  
    3030using namespace flair::gui;
    3131
    32 namespace flair { namespace sensor {
     32namespace flair {
     33namespace sensor {
    3334
    34 Sinus::Sinus(const FrameworkManager* parent,string name,int priority) : IODevice(parent,name),Thread(parent,name,priority) {
     35Sinus::Sinus(const FrameworkManager *parent, string name, int priority)
     36    : IODevice(parent, name), Thread(parent, name, priority) {
    3537
    36     plot=NULL;
     38  plot = NULL;
    3739
    38     //1*1 output matrix
    39     cvmatrix_descriptor* desc=new cvmatrix_descriptor(1,1);
    40     desc->SetElementName(0,0,"value");//name will be used for graphs and logs
    41     output=new cvmatrix((IODevice*)this,desc,floatType,name);
    42     output->SetValue(0,0,0);
     40  // 1*1 output matrix
     41  cvmatrix_descriptor *desc = new cvmatrix_descriptor(1, 1);
     42  desc->SetElementName(0, 0, "value"); // name will be used for graphs and logs
     43  output = new cvmatrix((IODevice *)this, desc, floatType, name);
     44  output->SetValue(0, 0, 0);
    4345
     46  AddDataToLog(output);
    4447
    45     AddDataToLog(output);
     48  // interface initialisation
     49  mainTab = new Tab(parent->GetTabWidget(), name);
     50  tabWidget = new TabWidget(mainTab->NewRow(), name);
    4651
    47     //interface initialisation
    48     mainTab=new Tab(parent->GetTabWidget(),name);
    49     tabWidget=new TabWidget(mainTab->NewRow(),name);
     52  Tab *settingsTab = new Tab(tabWidget, "Settings");
     53  GroupBox *sinusGroupBox = new GroupBox(settingsTab->NewRow(), name);
     54  frequency = new DoubleSpinBox(sinusGroupBox->NewRow(), "frequence:", " Hz", 0,
     55                                100, 1);
     56  amplitude = new DoubleSpinBox(sinusGroupBox->LastRowLastCol(), "amplitude:",
     57                                0, 10, 1);
     58  offset =
     59      new DoubleSpinBox(sinusGroupBox->LastRowLastCol(), "offset:", 0, 10, 1);
     60  period =
     61      new SpinBox(settingsTab->NewRow(), "period thread:", " ms", 1, 1000, 1);
    5062
    51     Tab* settingsTab=new Tab(tabWidget,"Settings");
    52     GroupBox* sinusGroupBox=new GroupBox(settingsTab->NewRow(),name);
    53     frequency=new DoubleSpinBox(sinusGroupBox->NewRow(),"frequence:"," Hz",0,100,1);
    54     amplitude=new DoubleSpinBox(sinusGroupBox->LastRowLastCol(),"amplitude:",0,10,1);
    55     offset=new DoubleSpinBox(sinusGroupBox->LastRowLastCol(),"offset:",0,10,1);
    56     period=new SpinBox(settingsTab->NewRow(),"period thread:"," ms",1,1000,1);
    57 
    58     setupLayout=new GridLayout(settingsTab->NewRow(),"setup");//layout sui servira à placer des filtres par exemple
     63  setupLayout = new GridLayout(
     64      settingsTab->NewRow(),
     65      "setup"); // layout sui servira à placer des filtres par exemple
    5966}
    60 
    6167
    6268Sinus::~Sinus() {
    6369
    64     SafeStop();
    65     Join();
     70  SafeStop();
     71  Join();
    6672
    67     //main_tab has the FrameworkManager as parent; it will be destroyed when FrameworkManager is destroyed
    68     //it is cleaner to delete it manually, because main_tab is unnecessary when Sinus is deleted
    69     delete mainTab;
     73  // main_tab has the FrameworkManager as parent; it will be destroyed when
     74  // FrameworkManager is destroyed
     75  // it is cleaner to delete it manually, because main_tab is unnecessary when
     76  // Sinus is deleted
     77  delete mainTab;
    7078}
    7179
    7280void Sinus::UseDefaultPlot(void) {
    73     Tab* plotTab=new Tab(tabWidget,"Graph");
    74     plot=new DataPlot1D(plotTab->NewRow(),"Sinus",-10,10);
    75     plot->AddCurve(output->Element(0),DataPlot::Red);
     81  Tab *plotTab = new Tab(tabWidget, "Graph");
     82  plot = new DataPlot1D(plotTab->NewRow(), "Sinus", -10, 10);
     83  plot->AddCurve(output->Element(0), DataPlot::Red);
    7684}
    7785
    78 GridLayout* Sinus::GetSetupLayout(void) const {
    79     return setupLayout;
     86GridLayout *Sinus::GetSetupLayout(void) const { return setupLayout; }
     87
     88DataPlot1D *Sinus::GetPlot(void) const {
     89  if (plot == NULL)
     90    Printf("Sinus::Plot, plot not yet defined, call UseDefaultPlot first\n");
     91  return plot;
    8092}
    8193
    82 DataPlot1D* Sinus::GetPlot(void) const {
    83     if(plot==NULL) Printf("Sinus::Plot, plot not yet defined, call UseDefaultPlot first\n");
    84     return plot;
    85 }
     94cvmatrix *Sinus::GetMatrix(void) const { return output; }
    8695
    87 cvmatrix *Sinus::GetMatrix(void) const {
    88     return output;
    89 }
     96float Sinus::GetValue(void) const { return output->Value(0, 0); }
    9097
    91 float Sinus::GetValue(void) const {
    92     return output->Value(0,0);
    93 }
    94 
    95 //main function, where  we compute the signal
     98// main function, where  we compute the signal
    9699void Sinus::Run(void) {
    97100
    98     SetPeriodMS(period->Value());
     101  SetPeriodMS(period->Value());
    99102
    100     //warn if changing from primary to secondary mode when in real time
    101     WarnUponSwitches(true);
     103  // warn if changing from primary to secondary mode when in real time
     104  WarnUponSwitches(true);
    102105
    103     Time initTime=GetTime();
     106  Time initTime = GetTime();
    104107
    105     while(!ToBeStopped()) {
    106         WaitPeriod();
     108  while (!ToBeStopped()) {
     109    WaitPeriod();
    107110
    108         if(period->ValueChanged()==true) SetPeriodMS(period->Value());
     111    if (period->ValueChanged() == true)
     112      SetPeriodMS(period->Value());
    109113
    110         //compute sinus
    111         Time actualTime=GetTime();
    112         float value=offset->Value()+amplitude->Value()*sinf(2*PI*frequency->Value()*(actualTime-initTime)/1000000000.);//les temps sont en nanosecondes
     114    // compute sinus
     115    Time actualTime = GetTime();
     116    float value =
     117        offset->Value() +
     118        amplitude->Value() *
     119            sinf(2 * PI * frequency->Value() * (actualTime - initTime) /
     120                 1000000000.); // les temps sont en nanosecondes
    113121
    114         //put the result in output matrix
    115         output->SetValue(0,0,value);
    116         //put corresponding time
    117         output->SetDataTime(actualTime);
     122    // put the result in output matrix
     123    output->SetValue(0, 0, value);
     124    // put corresponding time
     125    output->SetDataTime(actualTime);
    118126
    119         //ProcessUpdate is very important
    120         //we must call it after updating the output matrix
    121         //it allows:
    122         // -to save value in the logs
    123         // -to automatically call the next filter UpdateFrom method
    124         ProcessUpdate(output);
    125     }
     127    // ProcessUpdate is very important
     128    // we must call it after updating the output matrix
     129    // it allows:
     130    // -to save value in the logs
     131    // -to automatically call the next filter UpdateFrom method
     132    ProcessUpdate(output);
     133  }
    126134}
    127 }// end namespace sensor
    128 }// end namespace flair
     135} // end namespace sensor
     136} // end namespace flair
Note: See TracChangeset for help on using the changeset viewer.