2016-02-16 17:19:44 -08:00
|
|
|
#include "gui.h"
|
|
|
|
|
#include "imuread.h"
|
|
|
|
|
|
2016-02-18 01:31:30 -08:00
|
|
|
|
|
|
|
|
|
2016-03-15 15:32:15 -07:00
|
|
|
wxMenu *port_menu;
|
2016-03-15 16:04:11 -07:00
|
|
|
wxMenu *sendcal_menu;
|
2016-03-15 15:32:15 -07:00
|
|
|
wxString port_name;
|
2016-02-18 01:31:30 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
wxBEGIN_EVENT_TABLE(MyCanvas, wxGLCanvas)
|
2016-03-15 15:32:15 -07:00
|
|
|
EVT_SIZE(MyCanvas::OnSize)
|
|
|
|
|
EVT_PAINT(MyCanvas::OnPaint)
|
|
|
|
|
//EVT_CHAR(MyCanvas::OnChar)
|
|
|
|
|
//EVT_MOUSE_EVENTS(MyCanvas::OnMouseEvent)
|
2016-02-18 01:31:30 -08:00
|
|
|
wxEND_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
MyCanvas::MyCanvas(wxWindow *parent, wxWindowID id, int* gl_attrib)
|
|
|
|
|
: wxGLCanvas(parent, id, gl_attrib)
|
|
|
|
|
{
|
|
|
|
|
//m_xrot = 0;
|
|
|
|
|
//m_yrot = 0;
|
|
|
|
|
//m_numverts = 0;
|
|
|
|
|
// Explicitly create a new rendering context instance for this canvas.
|
|
|
|
|
m_glRC = new wxGLContext(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MyCanvas::~MyCanvas()
|
|
|
|
|
{
|
|
|
|
|
delete m_glRC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MyCanvas::OnSize(wxSizeEvent& event)
|
|
|
|
|
{
|
|
|
|
|
//printf("OnSize\n");
|
|
|
|
|
if (!IsShownOnScreen()) return;
|
|
|
|
|
SetCurrent(*m_glRC);
|
|
|
|
|
resize_callback(event.GetSize().x, event.GetSize().y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MyCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) )
|
|
|
|
|
{
|
|
|
|
|
//printf("OnPaint\n");
|
|
|
|
|
wxPaintDC dc(this);
|
|
|
|
|
SetCurrent(*m_glRC);
|
|
|
|
|
display_callback();
|
|
|
|
|
SwapBuffers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MyCanvas::InitGL()
|
|
|
|
|
{
|
|
|
|
|
//printf("Init\n");
|
|
|
|
|
SetCurrent(*m_glRC);
|
|
|
|
|
visualize_init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-21 20:27:36 -08:00
|
|
|
/*****************************************************************************/
|
2016-02-18 01:31:30 -08:00
|
|
|
|
2016-02-16 17:19:44 -08:00
|
|
|
BEGIN_EVENT_TABLE(MyFrame,wxFrame)
|
|
|
|
|
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
|
|
|
|
|
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
|
2016-03-15 16:04:11 -07:00
|
|
|
EVT_MENU(ID_SENDCAL, MyFrame::OnSendCal)
|
2016-02-18 01:31:30 -08:00
|
|
|
EVT_TIMER(ID_TIMER, MyFrame::OnTimer)
|
2016-03-15 15:32:15 -07:00
|
|
|
EVT_MENU_RANGE(9000, 9999, MyFrame::OnPort)
|
|
|
|
|
EVT_MENU_OPEN(MyMenu::OnShowPortList)
|
|
|
|
|
EVT_MENU_HIGHLIGHT(-1, MyMenu::OnHighlight)
|
2016-02-16 17:19:44 -08:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MyFrame::MyFrame(wxWindow *parent, wxWindowID id, const wxString &title,
|
|
|
|
|
const wxPoint &position, const wxSize& size, long style) :
|
|
|
|
|
wxFrame( parent, id, title, position, size, style )
|
|
|
|
|
{
|
2016-02-18 01:31:30 -08:00
|
|
|
wxMenuBar *menuBar;
|
|
|
|
|
wxMenu *menu;
|
2016-02-19 17:05:16 -08:00
|
|
|
//wxMenuItem *item;
|
2016-02-18 01:31:30 -08:00
|
|
|
|
|
|
|
|
menuBar = new wxMenuBar;
|
|
|
|
|
menu = new wxMenu;
|
2016-03-15 16:04:11 -07:00
|
|
|
menu->Append(ID_SENDCAL, wxT("Send Calibration"));
|
|
|
|
|
sendcal_menu = menu;
|
|
|
|
|
sendcal_menu->Enable(ID_SENDCAL, false);
|
2016-02-18 01:31:30 -08:00
|
|
|
menu->Append(wxID_EXIT, wxT("Quit"));
|
|
|
|
|
menuBar->Append(menu, wxT("&File"));
|
2016-03-15 15:32:15 -07:00
|
|
|
|
|
|
|
|
menu = new wxMenu;
|
|
|
|
|
menuBar->Append(menu, "Port");
|
|
|
|
|
port_menu = menu;
|
|
|
|
|
|
2016-02-18 01:31:30 -08:00
|
|
|
menu = new wxMenu;
|
|
|
|
|
//item = new wxMenuItem(menu, ID_ABOUT, "About");
|
|
|
|
|
menu->Append(wxID_ABOUT, wxT("About"));
|
|
|
|
|
menuBar->Append(menu, wxT("&Help"));
|
|
|
|
|
SetMenuBar(menuBar);
|
|
|
|
|
|
2016-02-21 20:27:36 -08:00
|
|
|
wxBoxSizer *topsizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
|
wxBoxSizer *leftsizer = new wxStaticBoxSizer(wxVERTICAL, this, "Communication");
|
|
|
|
|
wxBoxSizer *middlesizer = new wxStaticBoxSizer(wxVERTICAL, this, "Magnetometer");
|
|
|
|
|
wxBoxSizer *rightsizer = new wxStaticBoxSizer(wxVERTICAL, this, "Gyroscope");
|
|
|
|
|
|
|
|
|
|
topsizer->Add(leftsizer, 0, wxALL, 5);
|
|
|
|
|
topsizer->Add(middlesizer, 1, wxALL | wxEXPAND, 5);
|
|
|
|
|
topsizer->Add(rightsizer, 0, wxALL, 5);
|
|
|
|
|
|
2016-02-18 01:31:30 -08:00
|
|
|
int gl_attrib[20] =
|
|
|
|
|
{ WX_GL_RGBA, WX_GL_MIN_RED, 1, WX_GL_MIN_GREEN, 1,
|
|
|
|
|
WX_GL_MIN_BLUE, 1, WX_GL_DEPTH_SIZE, 1,
|
|
|
|
|
WX_GL_DOUBLEBUFFER,
|
2016-02-19 17:05:16 -08:00
|
|
|
0};
|
2016-02-18 01:31:30 -08:00
|
|
|
m_canvas = new MyCanvas(this, wxID_ANY, gl_attrib);
|
2016-02-21 20:27:36 -08:00
|
|
|
m_canvas->SetMinSize(wxSize(340,340));
|
|
|
|
|
|
|
|
|
|
middlesizer->Add(m_canvas, 1, wxEXPAND | wxALL, 10);
|
|
|
|
|
topsizer->SetSizeHints(this);
|
|
|
|
|
SetSizerAndFit(topsizer);
|
2016-02-18 01:31:30 -08:00
|
|
|
Show(true);
|
|
|
|
|
Raise();
|
|
|
|
|
|
2016-02-21 20:27:36 -08:00
|
|
|
m_canvas->InitGL();
|
2016-03-15 15:32:15 -07:00
|
|
|
raw_data_reset();
|
|
|
|
|
//open_port(PORT);
|
2016-02-18 01:31:30 -08:00
|
|
|
m_timer = new wxTimer(this, ID_TIMER);
|
|
|
|
|
m_timer->Start(40, wxTIMER_CONTINUOUS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MyFrame::OnTimer(wxTimerEvent &event)
|
|
|
|
|
{
|
|
|
|
|
//printf("OnTimer\n");
|
2016-03-15 16:04:11 -07:00
|
|
|
if (port_is_open()) {
|
|
|
|
|
read_serial_data();
|
|
|
|
|
m_canvas->Refresh();
|
|
|
|
|
if (magcal.FitError < 6.0f) {
|
|
|
|
|
sendcal_menu->Enable(ID_SENDCAL, true);
|
|
|
|
|
} else if (magcal.FitError > 7.0f) {
|
|
|
|
|
sendcal_menu->Enable(ID_SENDCAL, false);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
sendcal_menu->Enable(ID_SENDCAL, false);
|
|
|
|
|
}
|
2016-02-16 17:19:44 -08:00
|
|
|
}
|
|
|
|
|
|
2016-03-15 16:04:11 -07:00
|
|
|
void MyFrame::OnSendCal(wxCommandEvent &event)
|
|
|
|
|
{
|
|
|
|
|
printf("OnSendCal\n");
|
|
|
|
|
printf("Magnetic Calibration: (%.1f%% fit error)\n", magcal.FitError);
|
|
|
|
|
printf(" %7.2f %6.3f %6.3f %6.3f\n",
|
|
|
|
|
magcal.V[0], magcal.invW[0][0], magcal.invW[0][1], magcal.invW[0][2]);
|
|
|
|
|
printf(" %7.2f %6.3f %6.3f %6.3f\n",
|
|
|
|
|
magcal.V[1], magcal.invW[1][0], magcal.invW[1][1], magcal.invW[1][2]);
|
|
|
|
|
printf(" %7.2f %6.3f %6.3f %6.3f\n",
|
|
|
|
|
magcal.V[2], magcal.invW[2][0], magcal.invW[2][1], magcal.invW[2][2]);
|
|
|
|
|
send_calibration();
|
|
|
|
|
}
|
2016-03-15 15:32:15 -07:00
|
|
|
|
|
|
|
|
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);
|
2016-03-15 16:04:11 -07:00
|
|
|
sendcal_menu->Enable(ID_SENDCAL, false);
|
2016-03-15 15:32:15 -07:00
|
|
|
port_name = name;
|
|
|
|
|
if (id == 9000) return;
|
|
|
|
|
raw_data_reset();
|
|
|
|
|
open_port((const char *)name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-02-16 17:19:44 -08:00
|
|
|
void MyFrame::OnAbout(wxCommandEvent &event)
|
|
|
|
|
{
|
|
|
|
|
wxMessageDialog dialog(this,
|
|
|
|
|
"IMU Read\n\n\nCopyright 2016, PJRC.COM, LLC.",
|
|
|
|
|
"About IMUREAD", wxOK|wxICON_INFORMATION);
|
|
|
|
|
dialog.ShowModal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MyFrame::OnQuit( wxCommandEvent &event )
|
|
|
|
|
{
|
|
|
|
|
Close(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MyFrame::~MyFrame(void)
|
|
|
|
|
{
|
2016-02-18 01:31:30 -08:00
|
|
|
close_port();
|
2016-02-16 17:19:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-02-21 20:27:36 -08:00
|
|
|
/*****************************************************************************/
|
2016-03-15 15:32:15 -07:00
|
|
|
// Port Menu
|
2016-02-16 17:19:44 -08:00
|
|
|
|
2016-03-15 15:32:15 -07:00
|
|
|
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();
|
2016-03-15 16:04:11 -07:00
|
|
|
bool isopen = port_is_open();
|
2016-03-15 15:32:15 -07:00
|
|
|
for (int i=0; i < num; i++) {
|
|
|
|
|
//printf("%d: port %s\n", i, (const char *)list[i]);
|
|
|
|
|
menu->AppendRadioItem(9001 + i, list[i]);
|
2016-03-15 16:04:11 -07:00
|
|
|
if (isopen && port_name.IsSameAs(list[i])) {
|
2016-03-15 15:32:15 -07:00
|
|
|
menu->Check(9001 + i, true);
|
|
|
|
|
any = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!any) menu->Check(9000, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MyMenu::OnHighlight(wxMenuEvent &event)
|
|
|
|
|
{
|
|
|
|
|
//printf("OnHighlight\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2016-02-16 17:19:44 -08:00
|
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
|
|
|
|
|
MyApp::MyApp()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
|
{
|
|
|
|
|
// make sure we exit properly on macosx
|
|
|
|
|
SetExitOnFrameDelete(true);
|
|
|
|
|
|
|
|
|
|
wxPoint pos(100, 100);
|
|
|
|
|
|
2016-03-15 15:32:15 -07:00
|
|
|
MyFrame *frame = new MyFrame(NULL, -1, wxT("IMU Read"), pos, wxSize(1120,760),
|
2016-02-16 17:19:44 -08:00
|
|
|
wxDEFAULT_FRAME_STYLE & ~(wxMAXIMIZE_BOX | wxRESIZE_BORDER));
|
|
|
|
|
frame->Show( true );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int MyApp::OnExit()
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-03-15 15:32:15 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|