00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 #include <wx/stattext.h>
00034 #include <wx/statline.h>
00035 #include <wx/checkbox.h>
00036 
00037 
00038 #include "proximity_sensor_dashboard/user_interface.h"
00039 #include "proximity_sensor_dashboard/skin.h"
00040 
00041 #include <math.h>
00042 #include <iostream>
00043 
00044 
00045 
00046 
00047 
00048 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size): wxFrame( NULL, -1, title, pos, size )
00049 {
00050   
00051   timer_ = new wxTimer(this, skin_id::ID_TIMER);
00052   timer_->Start(250);
00053   Connect(skin_id::ID_TIMER, wxEVT_TIMER, wxTimerEventHandler(MyFrame::gridUpdate), NULL, this);
00054   
00055   
00056   menubar = new wxMenuBar;
00057   file = new wxMenu;
00058   file->Append(skin_id::ID_About, wxT("&About..."));
00059   file->AppendSeparator();
00060   file->Append(wxID_EXIT, wxT("&Quit"));
00061   menubar->Append(file, wxT("&File"));
00062   SetMenuBar(menubar);
00063   
00064   Connect(skin_id::ID_About, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnAbout));
00065   Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnQuit));
00066 
00067   wxBoxSizer* v_sizer = new wxBoxSizer( wxVERTICAL ); 
00068   views = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP); 
00069   expert_panel = new wxPanel(views, wxID_ANY); 
00070   basic_panel = new wxPanel(views, wxID_ANY); 
00071   
00072   
00073   wxStaticText *headline = new wxStaticText(expert_panel, wxID_ANY, title,wxPoint(15,15));
00074   
00075   wxFont headline_font = headline->GetFont(); 
00076   headline_font.SetWeight(wxBOLD);
00077   headline_font.SetPointSize(15);
00078   headline->SetFont(headline_font);
00079   
00080   
00081   
00082   
00083   
00084   const wxString col_title_[18] = { wxT("Adr"),
00085                                     wxT("Stat"),
00086                                     wxT("X"),
00087                                     wxT("Ini"),
00088                                     wxT("Limit"),
00089                                     wxT("U1"),
00090                                     wxT("U2"),
00091                                     wxT("U3"),
00092                                     wxT("Dyn"),
00093                                     wxT(""),
00094                                     wxT("SE-NR."),
00095                                     wxT(""),
00096                                     wxT("A"),
00097                                     wxT("B"),
00098                                     wxT("C"),
00099                                     wxT("D"),
00100                                     wxT("E") };
00101   grid = new wxGrid(expert_panel, wxID_ANY, wxPoint(30,85), wxSize(699, 770));
00102   grid->CreateGrid(skind_def::max_sensor_number, 16);
00103   
00104   grid->SetColLabelSize(30);
00105   grid->SetRowLabelSize(50);
00106   
00107   wxColour label_background_colour;
00108   label_background_colour = grid->GetLabelBackgroundColour();
00109   
00110   for(int i = 0; i < skind_def::max_sensor_number ; i++)
00111   {
00112     grid->SetRowSize(i, 20);
00113     grid->SetCellBackgroundColour(i, 8, label_background_colour);
00114     grid->SetCellBackgroundColour(i, 10, label_background_colour);
00115     grid->SetCellBackgroundColour(i, 9, *wxWHITE);
00116     for(int j = 0; j < 16; j++)
00117     {
00118       grid->SetCellAlignment(i, j, wxALIGN_CENTRE, wxALIGN_CENTRE);
00119     }
00120   }
00121   
00122   for(int j = 0; j < 8 ; j++)
00123   {
00124     grid->SetColSize(j, 50);
00125   }
00126   
00127   grid->SetColSize(8, 25);
00128   grid->SetColSize(9, 80);
00129   grid->SetColSize(10, 25);
00130   
00131   for(int i = 11 ; i < 16 ; i++)
00132   {
00133     grid->SetColSize(i, 20);
00134   }
00135   
00136   
00137   for(int k = 0; k < 16; k++)
00138   {
00139     grid->SetColLabelValue((k),col_title_[k+1]);
00140   }
00141   
00142   
00143   for(int i = 0; i < skin_dat_.u8sensor_number_ ; i++)
00144   {
00145     grid->SetCellValue(i,9,wxString::Format(wxT("%i"),i+1));
00146     grid->SetCellTextColour(i,9,wxColour(255,255,0));
00147   }
00148   
00149   
00150   grid->EnableEditing(false);
00151   grid->EnableDragRowSize(false);
00152   grid->EnableDragColSize(false);
00153   
00154   
00155   grid->SetScrollLineY(20);
00156   
00157   
00158   wxPoint first_cell_point;
00159   first_cell_point = grid->GetPosition();
00160   wxSize first_cell_size;
00161   first_cell_size.Set(grid->GetRowLabelSize(), grid->GetColLabelSize());
00162   wxColour background_colour = grid->GetLabelBackgroundColour();
00163   
00164   wxPanel *cover_first_cell = new wxPanel(expert_panel, wxID_ANY, first_cell_point, first_cell_size, wxSUNKEN_BORDER);
00165   cover_first_cell->SetBackgroundColour(background_colour);
00166   
00167   wxStaticText *first_cell_text = new wxStaticText(cover_first_cell, wxID_ANY, col_title_[0],wxPoint(10, 5), wxDefaultSize);
00168   
00169   wxFont grid_label_font = grid->GetLabelFont();
00170   first_cell_text->SetFont(grid_label_font);
00171   
00172   
00173   wxPanel *cover_col8 = new wxPanel(expert_panel, wxID_ANY, wxPoint(479, first_cell_point.y+28), wxSize(grid->GetColSize(8)+1,grid->GetRowSize(0)*38 + 10 - 28), wxSUNKEN_BORDER);
00174   cover_col8->SetBackgroundColour(background_colour);
00175   
00176   
00177   wxPanel *cover_col10 = new wxPanel(expert_panel, wxID_ANY, wxPoint(479 + grid->GetColSize(8) + grid->GetColSize(9), first_cell_point.y+28), wxSize(grid->GetColSize(8)+1,grid->GetRowSize(0)*38 + 10 - 28), wxSUNKEN_BORDER);
00178   cover_col10->SetBackgroundColour(background_colour);
00179   
00180   
00181   wxPanel *textlabel_x_col_bar = new wxPanel(expert_panel, wxID_ANY, wxPoint(479 + grid->GetColSize(8),first_cell_point.y - grid->GetColLabelSize()), wxSize(grid->GetColSize(9) + 1, grid->GetColLabelSize()), wxSUNKEN_BORDER);
00182   textlabel_x_col_bar->SetBackgroundColour(background_colour);
00183   
00184   wxStaticText *text_x_col_bar = new wxStaticText(textlabel_x_col_bar, wxID_ANY, wxT("X Col.Bar"),wxPoint(3, 5), wxDefaultSize);
00185   
00186   text_x_col_bar->SetFont(grid_label_font);
00187   
00188   
00189   wxPanel *textlabel_errorbar = new wxPanel(expert_panel, wxID_ANY, wxPoint(479 + grid->GetColSize(8) + grid->GetColSize(9)+ grid->GetColSize(10),first_cell_point.y - grid->GetColLabelSize()), wxSize(grid->GetColSize(11)*5 + 1, grid->GetColLabelSize()), wxSUNKEN_BORDER);
00190   textlabel_errorbar->SetBackgroundColour(background_colour);
00191   
00192   wxStaticText *text_errorbar = new wxStaticText(textlabel_errorbar, wxID_ANY, wxT("ErrorBar"),wxPoint(16, 5), wxDefaultSize);
00193   
00194   text_errorbar->SetFont(grid_label_font);
00195   
00196   
00197   wxCheckBox *cb_hex_dec = new wxCheckBox(expert_panel, skin_id::ID_HEX, wxT("Hex"), wxPoint(100,55), wxDefaultSize);
00198   Connect(skin_id::ID_HEX, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(MyFrame::OnCheck));
00199   cb_hex_dec->SetValue(false);
00200   bhex_ = cb_hex_dec->GetValue();
00201   
00202   
00203   wxStaticText *text_status = new wxStaticText(expert_panel, wxID_ANY, wxT("Status:"),wxPoint(200, 57), wxDefaultSize);
00204   text_status->SetFont(grid_label_font);
00205   
00206   text_go_nogo = new wxStaticText(expert_panel, wxID_ANY, wxT(""),wxPoint(270, 57), wxDefaultSize, wxALIGN_CENTRE);
00207   text_err_noerr = new wxStaticText(expert_panel, wxID_ANY, wxT(""),wxPoint(320, 57), wxDefaultSize, wxALIGN_CENTRE);
00208   
00209   
00210   
00211   
00212   for(int k = 0; k < skind_def::max_sensor_number; k++)
00213   {
00214     if(bhex_)
00215     {
00216       grid->SetRowLabelValue(k,hexadezimal(skin_dat_.u8readadr_lo_+256*skin_dat_.u8readadr_hi_+skind_def::anz_byte_per_sensor*k));
00217     }
00218     else
00219     {
00220       grid->SetRowLabelValue(k, wxString::Format(wxT("%i"),(skin_dat_.u8readadr_lo_+256*skin_dat_.u8readadr_hi_+skind_def::anz_byte_per_sensor*k)));
00221     }
00222   }
00223   
00224 
00225 
00226 
00227   
00228   wxBoxSizer* layout_v1 = new wxBoxSizer( wxVERTICAL );
00229   wxBoxSizer* layout_h1 = new wxBoxSizer( wxHORIZONTAL );  
00230   wxStaticText* basic_text = new wxStaticText(basic_panel, wxID_ANY, wxT("Welcome to the Basic Dashboard"));
00231   basic_text->SetFont(headline_font);
00232   
00233   basic_data = new wxGrid(basic_panel, wxID_ANY);
00234   basic_data->CreateGrid(skind_def::max_sensor_number, 3);
00235 
00236   
00237   
00238   for( int i = 0; i < skind_def::max_sensor_number; i++ )
00239   {
00240     basic_data->SetRowSize(i, 20);
00241     for(int j = 0; j < 3; j++)
00242     {
00243       basic_data->SetCellAlignment(i, j, wxALIGN_CENTRE, wxALIGN_CENTRE);
00244     }
00245   }
00246   basic_data->SetColSize(0, 80);
00247   basic_data->SetColSize(1, 80);
00248   basic_data->SetColSize(2, 80);
00249   basic_data->SetColLabelValue( 0, wxT("Sensor") );
00250   basic_data->SetColLabelValue( 1, wxT("Value") );
00251   basic_data->SetColLabelValue( 2, wxT("Visual") );
00252 
00253 
00254   
00255   basic_data->SetScrollLineY(20);
00256 
00257   
00258   basic_data->EnableEditing(false);
00259   basic_data->EnableDragRowSize(false);
00260   basic_data->EnableDragColSize(false);
00261   
00262   layout_v1->Add(basic_text, 0, wxEXPAND);
00263   layout_v1->Add(basic_data, 1, wxEXPAND);
00264 
00265   layout_h1->Add(layout_v1, 1, wxEXPAND);
00266 
00267   layout_v1->SetSizeHints(basic_panel);
00268   layout_h1->SetSizeHints(basic_panel);
00269   basic_panel->SetSizer(layout_h1);
00270   
00271   
00272   
00273   views->AddPage(basic_panel, wxT("Basic"));  
00274   views->AddPage(expert_panel, wxT("Expert")); 
00275   
00276   v_sizer->Add(views, 1, wxEXPAND);
00277   SetSizer(v_sizer);
00278 
00279 
00280   
00281   publish_data_2_gui();
00282     
00283 }
00284 
00285 
00286 void MyFrame::gridUpdate(wxTimerEvent& evt)
00287 {
00288   ros::spinOnce();
00289   ROS_DEBUG("Update results grid.");
00290   publish_data_2_gui();
00291   
00292   if (!ros::ok())
00293   {
00294     Close();
00295   }
00296 }
00297 
00298 
00299 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
00300 {
00301   Close(true);
00302 }
00303 
00304 
00305 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
00306 {
00307   wxMessageBox( wxT(".....      text  text  text     ....."), wxT("Proximity Sensor Dashboard from Bosch RTC"), wxICON_INFORMATION, this );
00308 }
00309 
00310 
00311 void MyFrame::OnCheck(wxCommandEvent& event)
00312 {
00313   if(bhex_)
00314   {
00315     bhex_ = false;
00316   }
00317   else
00318   {
00319     bhex_ = true;
00320   }
00321 }
00322 
00323 
00324 wxString MyFrame::hexadezimal(uint32_t conv_value)
00325 {
00326   const wxString ziffern[16] = { wxT("0"),
00327                                  wxT("1"),
00328                                  wxT("2"),
00329                                  wxT("3"),
00330                                  wxT("4"),
00331                                  wxT("5"),
00332                                  wxT("6"),
00333                                  wxT("7"),
00334                                  wxT("8"),
00335                                  wxT("9"),
00336                                  wxT("A"),
00337                                  wxT("B"),
00338                                  wxT("C"),
00339                                  wxT("D"),
00340                                  wxT("E"),
00341                                  wxT("F") };
00342   int i = 0;
00343   wxString ts;
00344   
00345   ts = wxT("");
00346   for(i = 3 ; i >= 0 ; i--)
00347   {
00348     ts = ts + ziffern[((conv_value >> (4*i)) & (15))]; 
00349   }
00350   return ts;
00351 }
00352 
00353 
00354 void MyFrame::publish_data_2_gui()
00355 {
00356   ROS_DEBUG("Publishing data to GUI.");
00357   
00358   
00359   if(skin_dat_.bsens_num_changed == true)
00360   {
00361     grid->ClearGrid();
00362     basic_data->ClearGrid();
00363     skin_dat_.bsens_num_changed = false;
00364     
00365     
00366     for(int i = 0; i < skind_def::max_sensor_number ; i++)
00367     {
00368       grid->SetCellValue(i,9,wxString::Format(wxT("%i"),i+1));
00369       grid->SetCellTextColour(i,9,wxColour(255,255,0));
00370 
00371       basic_data->SetCellValue( i, 0, wxString::Format(wxT("%i"), i+1) );
00372     }
00373 
00374     
00375     for(int k = skin_dat_.u8sensor_number_; k < skind_def::max_sensor_number; k++)
00376     {
00377       grid->SetCellBackgroundColour(k, 9, *wxWHITE);
00378       grid->SetCellBackgroundColour(k, 11, *wxWHITE);
00379       grid->SetCellBackgroundColour(k, 12, *wxWHITE);
00380       grid->SetCellBackgroundColour(k, 13, *wxWHITE);
00381       grid->SetCellBackgroundColour(k, 14, *wxWHITE);
00382       grid->SetCellBackgroundColour(k, 15, *wxWHITE);
00383     }
00384   }
00385   
00386 
00387 
00388   
00389   
00390   
00391   
00392   
00393   
00394   
00395   
00396   
00397   ros::Time dcurrent_time = ros::Time::now();
00398   if( ( dcurrent_time > (skin_dat_.dtime_subscription_ + ros::Duration((ceil(float(skin_dat_.u8sensor_number_) / 32.0) -1 ) * 0.1 + 0.3))) )
00399   {
00400     skin_dat_.initialize_sensor_data();
00401     
00402     text_go_nogo->SetLabel(wxT(""));
00403     text_err_noerr->SetLabel(wxT(""));
00404   }
00405   else
00406   {
00407     
00408     if(skin_dat_.bstatus_go_ == true)
00409     {
00410       text_go_nogo->SetLabel(wxT("Go"));
00411       text_go_nogo->SetForegroundColour(*wxGREEN);
00412     }
00413     else
00414     {
00415       text_go_nogo->SetLabel(wxT("NoGo"));
00416       text_go_nogo->SetForegroundColour(*wxRED);
00417     }
00418     
00419     if(skin_dat_.bstatus_err_ == false)
00420     {
00421       text_err_noerr->SetLabel(wxT("NoErr"));
00422       text_err_noerr->SetForegroundColour(*wxGREEN);
00423     }
00424     else
00425     {
00426       text_err_noerr->SetLabel(wxT("Err"));
00427       text_err_noerr->SetForegroundColour(*wxRED);
00428     }
00429   }
00430   
00431   
00432   for(int l = 0; l < skind_def::max_sensor_number; l++)
00433   {
00434     if(bhex_)
00435     {
00436       grid->SetRowLabelValue(l,hexadezimal(skin_dat_.u8readadr_lo_+256*skin_dat_.u8readadr_hi_+skind_def::anz_byte_per_sensor*l));
00437     }
00438     else
00439     {
00440       grid->SetRowLabelValue(l, wxString::Format(wxT("%i"),(skin_dat_.u8readadr_lo_+256*skin_dat_.u8readadr_hi_+skind_def::anz_byte_per_sensor*l)));
00441     }
00442   }
00443   
00444   for(int k = 0; k < skin_dat_.u8sensor_number_; k++)
00445   {
00446     
00447     for(int j = 0; j < 8; j++)
00448     {
00449       
00450       if(bhex_)
00451       {
00452         grid->SetCellValue(k,j,hexadezimal(skin_dat_.u8asensor_data_[k][j]));
00453       }
00454       else
00455       {
00456         grid->SetCellValue(k,j,wxString::Format(wxT("%i"),skin_dat_.u8asensor_data_[k][j]));
00457       }
00458 
00459     }
00460     basic_data->SetCellValue( k, 1, wxString::Format(wxT("%i"), skin_dat_.u8asensor_data_[k][1] - skin_dat_.u8asensor_data_[k][2]) );
00461     
00462     
00464     
00466     
00467     
00468     
00469     
00470     
00471     
00472     
00473     
00474     
00475     
00476     
00477     
00478     
00479     
00480     
00481     
00482     
00483     
00484     berrcond_[0] = ( (skin_dat_.u8asensor_data_[k][5]) > 32 );
00485     berrcond_[1] = ( (skin_dat_.u8asensor_data_[k][6]) < 16 );
00486     berrcond_[2] = ( ((skin_dat_.u8asensor_data_[k][6]) - (skin_dat_.u8asensor_data_[k][4])) < 16 );
00487     berrcond_[3] = ( ((skin_dat_.u8asensor_data_[k][0]) & 16) > 0 );    
00488     berrcond_[4] = ( ((skin_dat_.u8asensor_data_[k][0]) & 32) > 0 );    
00489     
00490     wxColour errcol;
00491     
00492     for(int i = 0; i < 5; i++)
00493     {
00494       errcol = *wxWHITE;
00495       if((skin_dat_.u8sensor_number_ > 0) & (skin_dat_.u8sensor_number_ <= skind_def::max_sensor_number))
00496       {
00497         if( ((skin_dat_.u8asensor_data_[k][0]) & 1) == 1)
00498         {
00499           if(berrcond_[i])
00500           {
00501             errcol = *wxRED;
00502           }
00503           else
00504           {
00505             errcol = *wxGREEN;
00506           }
00507         }
00508         grid->SetCellBackgroundColour(k, i + 11, errcol);
00509       }
00510     }
00511     
00512     
00513     
00514     
00515     
00516     
00518     
00520     
00521     float tr;
00522     wxColour statcol;
00523     
00524     if( skin_dat_.u8asensor_data_[k][3] != 0 )
00525     {
00526       tr = float ( (skin_dat_.u8asensor_data_[k][1]) - (skin_dat_.u8asensor_data_[k][2]) ) / float (skin_dat_.u8asensor_data_[k][3]); 
00527     }
00528     else
00529     {
00530       tr = 2;
00531     }
00532     
00533     
00534     if(tr > 0)
00535     {
00536       if(tr > 1)
00537       {
00538         tr = 1;
00539       }
00540       statcol.Set(int (tr * 255)*65536);
00541       grid->SetCellBackgroundColour(k, 9, statcol);
00542       basic_data->SetCellBackgroundColour(k, 2, statcol);
00543     }
00544     else
00545     {
00546       tr = -tr;
00547       if(tr > 1)
00548       {
00549         tr = 1;
00550       }
00551       statcol.Set(int (tr * 255));
00552       grid->SetCellBackgroundColour(k, 9, statcol);
00553       basic_data->SetCellBackgroundColour(k, 2, statcol);
00554     }
00555   }
00556   
00557   grid->ForceRefresh();
00558   basic_data->ForceRefresh();
00559 }
00560 
00561 
00562 
00563 
00564 
00565 
00566 
00567