Make new GUI stuff (mostly) work
This commit is contained in:
parent
1a6a6f48ee
commit
a3a4b7e504
3 changed files with 79 additions and 51 deletions
99
gui.cpp
99
gui.cpp
|
|
@ -62,11 +62,10 @@ BEGIN_EVENT_TABLE(MyFrame,wxFrame)
|
|||
EVT_BUTTON(ID_CLEAR_BUTTON, MyFrame::OnClear)
|
||||
EVT_BUTTON(ID_SENDCAL_BUTTON, MyFrame::OnSendCal)
|
||||
EVT_TIMER(ID_TIMER, MyFrame::OnTimer)
|
||||
EVT_MENU_RANGE(9000, 9999, MyFrame::OnPort)
|
||||
EVT_MENU_RANGE(9000, 9999, MyFrame::OnPortMenu)
|
||||
EVT_MENU_OPEN(MyFrame::OnShowMenu)
|
||||
EVT_ACTIVATE(MyFrame::OnActivate)
|
||||
//EVT_LEFT_DOWN(MyFrame::OnMouse)
|
||||
EVT_CHOICE(ID_PORTLIST, MyFrame::OnSelect)
|
||||
EVT_COMBOBOX(ID_PORTLIST, MyFrame::OnPortList)
|
||||
EVT_COMBOBOX_DROPDOWN(ID_PORTLIST, MyFrame::OnShowPortList)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
|
||||
|
|
@ -107,17 +106,15 @@ MyFrame::MyFrame(wxWindow *parent, wxWindowID id, const wxString &title,
|
|||
topsizer->Add(middlesizer, 1, wxALL | wxEXPAND, 5);
|
||||
topsizer->Add(rightsizer, 0, wxALL | wxEXPAND | wxALIGN_TOP, 5);
|
||||
|
||||
|
||||
vsizer = new wxBoxSizer(wxVERTICAL);
|
||||
leftsizer->Add(vsizer, 0, wxALL, 8);
|
||||
text = new wxStaticText(this, wxID_ANY, "Port");
|
||||
vsizer->Add(text, 0, wxTOP|wxBOTTOM, 4);
|
||||
m_port_list = new wxChoice(this, ID_PORTLIST);
|
||||
m_port_list = new wxComboBox(this, ID_PORTLIST, "",
|
||||
wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY);
|
||||
m_port_list->Append("(none)");
|
||||
m_port_list->Append(SAMPLE_PORT_NAME); // never seen, only for initial size
|
||||
m_port_list->SetSelection(0);
|
||||
//m_port_list->Connect((wxEventType)wxEVT_LEFT_DOWN, &MyFrame::OnMouse);
|
||||
//m_port_list->Connect(wxEVT_LEFT_DOWN, &(MyFrame::OnMouse));
|
||||
//m_port_list->Bind(wxEVT_LEFT_DOWN, &(MyFrame::OnMouse));
|
||||
vsizer->Add(m_port_list, 1, wxEXPAND, 0);
|
||||
|
||||
vsizer->AddSpacer(8);
|
||||
|
|
@ -248,8 +245,10 @@ void MyFrame::OnTimer(wxTimerEvent &event)
|
|||
fiterror = quality_spherical_fit_error();
|
||||
if (gaps < 15.0f && variance < 4.5f && wobble < 4.0f && fiterror < 5.0f) {
|
||||
m_sendcal_menu->Enable(ID_SENDCAL_MENU, true);
|
||||
m_button_sendcal->Enable(true);
|
||||
} else if (gaps > 20.0f && variance > 5.0f && wobble > 5.0f && fiterror > 6.0f) {
|
||||
m_sendcal_menu->Enable(ID_SENDCAL_MENU, false);
|
||||
m_button_sendcal->Enable(false);
|
||||
}
|
||||
snprintf(buf, sizeof(buf), "%.1f%%", quality_surface_gap_error());
|
||||
m_err_coverage->SetLabelText(buf);
|
||||
|
|
@ -280,18 +279,28 @@ void MyFrame::OnTimer(wxTimerEvent &event)
|
|||
m_gyro[i]->SetLabelText(buf);
|
||||
}
|
||||
} else {
|
||||
m_sendcal_menu->Enable(ID_SENDCAL_MENU, false);
|
||||
if (!port_name.IsEmpty()) {
|
||||
//printf("port has closed, updating stuff\n");
|
||||
m_sendcal_menu->Enable(ID_SENDCAL_MENU, false);
|
||||
m_button_clear->Enable(false);
|
||||
m_button_sendcal->Enable(false);
|
||||
m_port_list->Clear();
|
||||
m_port_list->Append("(none)");
|
||||
m_port_list->SetSelection(0);
|
||||
port_name = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MyFrame::OnClear(wxCommandEvent &event)
|
||||
{
|
||||
printf("OnClear\n");
|
||||
//printf("OnClear\n");
|
||||
raw_data_reset();
|
||||
}
|
||||
|
||||
void MyFrame::OnSendCal(wxCommandEvent &event)
|
||||
{
|
||||
printf("OnSendCal\n");
|
||||
/*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]);
|
||||
|
|
@ -299,68 +308,80 @@ void MyFrame::OnSendCal(wxCommandEvent &event)
|
|||
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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MyFrame::OnShowMenu(wxMenuEvent &event)
|
||||
{
|
||||
wxMenu *menu;
|
||||
int any=0;
|
||||
int num;
|
||||
|
||||
menu = event.GetMenu();
|
||||
printf("OnShow Port Menu, %s\n", (const char *)menu->GetTitle());
|
||||
wxMenu *menu = event.GetMenu();
|
||||
if (menu != m_port_menu) return;
|
||||
//printf("OnShow Port Menu, %s\n", (const char *)menu->GetTitle());
|
||||
while (menu->GetMenuItemCount() > 0) {
|
||||
menu->Delete(menu->GetMenuItems()[0]);
|
||||
}
|
||||
menu->AppendRadioItem(9000, " (none)");
|
||||
wxArrayString list = serial_port_list();
|
||||
num = list.GetCount();
|
||||
bool isopen = port_is_open();
|
||||
if (!isopen) menu->Check(9000, true);
|
||||
wxArrayString list = serial_port_list();
|
||||
int 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 (isopen && port_name.IsSameAs(list[i])) {
|
||||
menu->Check(9001 + i, true);
|
||||
any = 1;
|
||||
}
|
||||
}
|
||||
if (!any) menu->Check(9000, true);
|
||||
menu->UpdateUI();
|
||||
}
|
||||
|
||||
void MyFrame::OnActivate(wxActivateEvent& event)
|
||||
void MyFrame::OnShowPortList(wxCommandEvent& event)
|
||||
{
|
||||
if (!event.GetActive()) return;
|
||||
printf("OnActivate, %s\n", "??");
|
||||
//printf("OnShowPortList\n");
|
||||
m_port_list->Clear();
|
||||
m_port_list->Append("(none)");
|
||||
wxArrayString list = serial_port_list();
|
||||
int num = list.GetCount();
|
||||
for (int i=0; i < num; i++) {
|
||||
m_port_list->Append(list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void MyFrame::OnMouse(wxMouseEvent& event)
|
||||
{
|
||||
printf("OnMouse\n");
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void MyFrame::OnSelect(wxCommandEvent& event)
|
||||
{
|
||||
printf("OnSelect, %s\n", "??");
|
||||
}
|
||||
|
||||
void MyFrame::OnPort(wxCommandEvent &event)
|
||||
void MyFrame::OnPortMenu(wxCommandEvent &event)
|
||||
{
|
||||
int id = event.GetId();
|
||||
wxString name = m_port_menu->FindItem(id)->GetItemLabelText();
|
||||
|
||||
close_port();
|
||||
printf("OnPort, id = %d, name = %s\n", id, (const char *)name);
|
||||
m_sendcal_menu->Enable(ID_SENDCAL_MENU, false);
|
||||
//printf("OnPortMenu, id = %d, name = %s\n", id, (const char *)name);
|
||||
port_name = name;
|
||||
m_port_list->Clear();
|
||||
m_port_list->Append(port_name);
|
||||
m_port_list->SetSelection(0);
|
||||
if (id == 9000) return;
|
||||
raw_data_reset();
|
||||
open_port((const char *)name);
|
||||
m_button_clear->Enable(true);
|
||||
}
|
||||
|
||||
void MyFrame::OnPortList(wxCommandEvent& event)
|
||||
{
|
||||
int selected = m_port_list->GetSelection();
|
||||
if (selected == wxNOT_FOUND) return;
|
||||
wxString name = m_port_list->GetString(selected);
|
||||
//printf("OnPortList, %s\n", (const char *)name);
|
||||
close_port();
|
||||
port_name = name;
|
||||
if (name == "(none)") return;
|
||||
raw_data_reset();
|
||||
open_port((const char *)name);
|
||||
m_button_clear->Enable(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void MyFrame::OnAbout(wxCommandEvent &event)
|
||||
{
|
||||
|
|
|
|||
27
gui.h
27
gui.h
|
|
@ -63,10 +63,6 @@ public:
|
|||
const wxSize &size = wxDefaultSize,
|
||||
long style = wxDEFAULT_FRAME_STYLE);
|
||||
~MyFrame(void);
|
||||
void InitGL();
|
||||
void OnPort(wxCommandEvent &event);
|
||||
void OnSendCal(wxCommandEvent &event);
|
||||
void OnClear(wxCommandEvent &event);
|
||||
private:
|
||||
wxStaticText *m_err_coverage;
|
||||
wxStaticText *m_err_variance;
|
||||
|
|
@ -84,15 +80,17 @@ private:
|
|||
wxButton *m_button_clear;
|
||||
wxButton *m_button_sendcal;
|
||||
wxMenu *m_port_menu;
|
||||
wxChoice *m_port_list;
|
||||
wxComboBox *m_port_list;
|
||||
wxMenu *m_sendcal_menu;
|
||||
void OnSendCal(wxCommandEvent &event);
|
||||
void OnClear(wxCommandEvent &event);
|
||||
void OnShowMenu(wxMenuEvent &event);
|
||||
void OnActivate(wxActivateEvent &event);
|
||||
void OnMouse(wxMouseEvent &event);
|
||||
void OnAbout(wxCommandEvent &event);
|
||||
void OnSelect(wxCommandEvent& event);
|
||||
void OnQuit(wxCommandEvent &event);
|
||||
void OnShowPortList(wxCommandEvent &event);
|
||||
void OnPortList(wxCommandEvent& event);
|
||||
void OnPortMenu(wxCommandEvent &event);
|
||||
void OnTimer(wxTimerEvent &event);
|
||||
void OnAbout(wxCommandEvent &event);
|
||||
void OnQuit(wxCommandEvent &event);
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
|
|
@ -110,5 +108,14 @@ private:
|
|||
// portlist.cpp
|
||||
wxArrayString serial_port_list();
|
||||
|
||||
// sample port name, for initial sizing of left panel
|
||||
#if defined(LINUX)
|
||||
#define SAMPLE_PORT_NAME "/dev/ttyACM5."
|
||||
#elif defined(WINDOWS)
|
||||
#define SAMPLE_PORT_NAME "COM22:."
|
||||
#elif defined(MACOSX)
|
||||
#define SAMPLE_PORT_NAME "/dev/cu.usbmodem2457891..."
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ static int packet_magnetic_cal(const unsigned char *data)
|
|||
magcal.BpFast[1][n] = y;
|
||||
magcal.BpFast[2][n] = z;
|
||||
magcal.valid[n] = 1;
|
||||
printf("mag cal, n=%3d: %5d %5d %5d\n", n, x, y, z);
|
||||
//printf("mag cal, n=%3d: %5d %5d %5d\n", n, x, y, z);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -340,7 +340,7 @@ static int ascii_parse(const unsigned char *data, int len)
|
|||
}
|
||||
return ret;
|
||||
fail:
|
||||
printf("ascii FAIL\n");
|
||||
//printf("ascii FAIL\n");
|
||||
ascii_state = ASCII_STATE_WORD;
|
||||
ascii_raw_data_count = 0;
|
||||
ascii_num = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue