Add Port menu to GUI
This commit is contained in:
parent
1a666bdd3b
commit
fb9576c8c0
4 changed files with 385 additions and 8 deletions
85
gui.cpp
85
gui.cpp
|
|
@ -3,14 +3,15 @@
|
|||
|
||||
|
||||
|
||||
|
||||
wxMenu *port_menu;
|
||||
wxString port_name;
|
||||
|
||||
|
||||
wxBEGIN_EVENT_TABLE(MyCanvas, wxGLCanvas)
|
||||
EVT_SIZE(MyCanvas::OnSize)
|
||||
EVT_PAINT(MyCanvas::OnPaint)
|
||||
//EVT_CHAR(MyCanvas::OnChar)
|
||||
//EVT_MOUSE_EVENTS(MyCanvas::OnMouseEvent)
|
||||
EVT_SIZE(MyCanvas::OnSize)
|
||||
EVT_PAINT(MyCanvas::OnPaint)
|
||||
//EVT_CHAR(MyCanvas::OnChar)
|
||||
//EVT_MOUSE_EVENTS(MyCanvas::OnMouseEvent)
|
||||
wxEND_EVENT_TABLE()
|
||||
|
||||
MyCanvas::MyCanvas(wxWindow *parent, wxWindowID id, int* gl_attrib)
|
||||
|
|
@ -60,6 +61,9 @@ BEGIN_EVENT_TABLE(MyFrame,wxFrame)
|
|||
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
|
||||
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
|
||||
EVT_TIMER(ID_TIMER, MyFrame::OnTimer)
|
||||
EVT_MENU_RANGE(9000, 9999, MyFrame::OnPort)
|
||||
EVT_MENU_OPEN(MyMenu::OnShowPortList)
|
||||
EVT_MENU_HIGHLIGHT(-1, MyMenu::OnHighlight)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
|
||||
|
|
@ -75,6 +79,11 @@ MyFrame::MyFrame(wxWindow *parent, wxWindowID id, const wxString &title,
|
|||
menu = new wxMenu;
|
||||
menu->Append(wxID_EXIT, wxT("Quit"));
|
||||
menuBar->Append(menu, wxT("&File"));
|
||||
|
||||
menu = new wxMenu;
|
||||
menuBar->Append(menu, "Port");
|
||||
port_menu = menu;
|
||||
|
||||
menu = new wxMenu;
|
||||
//item = new wxMenuItem(menu, ID_ABOUT, "About");
|
||||
menu->Append(wxID_ABOUT, wxT("About"));
|
||||
|
|
@ -105,7 +114,8 @@ MyFrame::MyFrame(wxWindow *parent, wxWindowID id, const wxString &title,
|
|||
Raise();
|
||||
|
||||
m_canvas->InitGL();
|
||||
open_port(PORT);
|
||||
raw_data_reset();
|
||||
//open_port(PORT);
|
||||
m_timer = new wxTimer(this, ID_TIMER);
|
||||
m_timer->Start(40, wxTIMER_CONTINUOUS);
|
||||
}
|
||||
|
|
@ -117,6 +127,21 @@ void MyFrame::OnTimer(wxTimerEvent &event)
|
|||
m_canvas->Refresh();
|
||||
}
|
||||
|
||||
|
||||
void MyFrame::OnPort(wxCommandEvent &event)
|
||||
{
|
||||
int id = event.GetId();
|
||||
wxString name = port_menu->FindItem(id)->GetItemLabelText();
|
||||
|
||||
close_port();
|
||||
//printf("OnPort, id = %d, name = %s\n", id, (const char *)name);
|
||||
port_name = name;
|
||||
if (id == 9000) return;
|
||||
raw_data_reset();
|
||||
open_port((const char *)name);
|
||||
}
|
||||
|
||||
|
||||
void MyFrame::OnAbout(wxCommandEvent &event)
|
||||
{
|
||||
wxMessageDialog dialog(this,
|
||||
|
|
@ -137,7 +162,49 @@ MyFrame::~MyFrame(void)
|
|||
|
||||
|
||||
/*****************************************************************************/
|
||||
// Port Menu
|
||||
|
||||
MyMenu::MyMenu(const wxString& title, long style) : wxMenu(title, style)
|
||||
{
|
||||
}
|
||||
|
||||
void MyMenu::OnShowPortList(wxMenuEvent &event)
|
||||
{
|
||||
wxMenu *menu;
|
||||
int any=0;
|
||||
int num;
|
||||
|
||||
menu = event.GetMenu();
|
||||
//printf("OnShowPortList, %s\n", (const char *)menu->GetTitle());
|
||||
if (menu != port_menu) return;
|
||||
|
||||
wxMenuItemList old_items = menu->GetMenuItems();
|
||||
num = old_items.GetCount();
|
||||
for (int i = old_items.GetCount() - 1; i >= 0; i--) {
|
||||
menu->Delete(old_items[i]);
|
||||
}
|
||||
menu->AppendRadioItem(9000, " (none)");
|
||||
wxArrayString list = serial_port_list();
|
||||
num = list.GetCount();
|
||||
for (int i=0; i < num; i++) {
|
||||
//printf("%d: port %s\n", i, (const char *)list[i]);
|
||||
menu->AppendRadioItem(9001 + i, list[i]);
|
||||
if (port_name.IsSameAs(list[i])) {
|
||||
menu->Check(9001 + i, true);
|
||||
any = 1;
|
||||
}
|
||||
}
|
||||
if (!any) menu->Check(9000, true);
|
||||
}
|
||||
|
||||
void MyMenu::OnHighlight(wxMenuEvent &event)
|
||||
{
|
||||
//printf("OnHighlight\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
IMPLEMENT_APP(MyApp)
|
||||
|
||||
|
|
@ -152,7 +219,7 @@ bool MyApp::OnInit()
|
|||
|
||||
wxPoint pos(100, 100);
|
||||
|
||||
MyFrame *frame = new MyFrame(NULL, -1, wxT("IMU Read"), pos, wxSize(1160,660),
|
||||
MyFrame *frame = new MyFrame(NULL, -1, wxT("IMU Read"), pos, wxSize(1120,760),
|
||||
wxDEFAULT_FRAME_STYLE & ~(wxMAXIMIZE_BOX | wxRESIZE_BORDER));
|
||||
frame->Show( true );
|
||||
return true;
|
||||
|
|
@ -162,3 +229,7 @@ int MyApp::OnExit()
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue