Add Send Calibration to GUI
This commit is contained in:
parent
fb9576c8c0
commit
38d5d30656
4 changed files with 48 additions and 5 deletions
34
gui.cpp
34
gui.cpp
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
|
||||
wxMenu *port_menu;
|
||||
wxMenu *sendcal_menu;
|
||||
wxString port_name;
|
||||
|
||||
|
||||
|
|
@ -60,6 +61,7 @@ void MyCanvas::InitGL()
|
|||
BEGIN_EVENT_TABLE(MyFrame,wxFrame)
|
||||
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
|
||||
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
|
||||
EVT_MENU(ID_SENDCAL, MyFrame::OnSendCal)
|
||||
EVT_TIMER(ID_TIMER, MyFrame::OnTimer)
|
||||
EVT_MENU_RANGE(9000, 9999, MyFrame::OnPort)
|
||||
EVT_MENU_OPEN(MyMenu::OnShowPortList)
|
||||
|
|
@ -77,6 +79,9 @@ MyFrame::MyFrame(wxWindow *parent, wxWindowID id, const wxString &title,
|
|||
|
||||
menuBar = new wxMenuBar;
|
||||
menu = new wxMenu;
|
||||
menu->Append(ID_SENDCAL, wxT("Send Calibration"));
|
||||
sendcal_menu = menu;
|
||||
sendcal_menu->Enable(ID_SENDCAL, false);
|
||||
menu->Append(wxID_EXIT, wxT("Quit"));
|
||||
menuBar->Append(menu, wxT("&File"));
|
||||
|
||||
|
|
@ -123,10 +128,31 @@ MyFrame::MyFrame(wxWindow *parent, wxWindowID id, const wxString &title,
|
|||
void MyFrame::OnTimer(wxTimerEvent &event)
|
||||
{
|
||||
//printf("OnTimer\n");
|
||||
read_serial_data();
|
||||
m_canvas->Refresh();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void MyFrame::OnPort(wxCommandEvent &event)
|
||||
{
|
||||
|
|
@ -135,6 +161,7 @@ void MyFrame::OnPort(wxCommandEvent &event)
|
|||
|
||||
close_port();
|
||||
//printf("OnPort, id = %d, name = %s\n", id, (const char *)name);
|
||||
sendcal_menu->Enable(ID_SENDCAL, false);
|
||||
port_name = name;
|
||||
if (id == 9000) return;
|
||||
raw_data_reset();
|
||||
|
|
@ -186,10 +213,11 @@ void MyMenu::OnShowPortList(wxMenuEvent &event)
|
|||
menu->AppendRadioItem(9000, " (none)");
|
||||
wxArrayString list = serial_port_list();
|
||||
num = list.GetCount();
|
||||
bool isopen = port_is_open();
|
||||
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])) {
|
||||
if (isopen && port_name.IsSameAs(list[i])) {
|
||||
menu->Check(9001 + i, true);
|
||||
any = 1;
|
||||
}
|
||||
|
|
|
|||
2
gui.h
2
gui.h
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
|
||||
#define ID_TIMER 10000
|
||||
#define ID_SENDCAL 10001
|
||||
|
||||
|
||||
class MyCanvas : public wxGLCanvas
|
||||
|
|
@ -62,6 +63,7 @@ public:
|
|||
~MyFrame(void);
|
||||
void InitGL();
|
||||
void OnPort(wxCommandEvent &event);
|
||||
void OnSendCal(wxCommandEvent &event);
|
||||
private:
|
||||
MyCanvas *m_canvas;
|
||||
wxTimer *m_timer;
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ typedef struct {
|
|||
} Quaternion_t;
|
||||
extern Quaternion_t current_orientation;
|
||||
|
||||
extern int port_is_open(void);
|
||||
extern int open_port(const char *name);
|
||||
extern int read_serial_data(void);
|
||||
extern int write_serial_data(const void *ptr, int len);
|
||||
|
|
|
|||
16
serialdata.c
16
serialdata.c
|
|
@ -245,6 +245,12 @@ static void newdata(const unsigned char *data, int len)
|
|||
|
||||
static int portfd=-1;
|
||||
|
||||
int port_is_open(void)
|
||||
{
|
||||
if (portfd > 0) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int open_port(const char *name)
|
||||
{
|
||||
struct termios termsettings;
|
||||
|
|
@ -279,7 +285,7 @@ int read_serial_data(void)
|
|||
if (n > 0 && n <= sizeof(buf)) {
|
||||
newdata(buf, n);
|
||||
nodata_count = 0;
|
||||
//return n;
|
||||
return n;
|
||||
} else if (n == 0) {
|
||||
if (++nodata_count > 6) {
|
||||
close_port();
|
||||
|
|
@ -339,7 +345,13 @@ void close_port(void)
|
|||
|
||||
#elif defined(WINDOWS)
|
||||
|
||||
static HANDLE port_handle;
|
||||
static HANDLE port_handle=INVALID_HANDLE_VALUE;
|
||||
|
||||
int port_is_open(void)
|
||||
{
|
||||
if (port_handle == INVALID_HANDLE_VALUE) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int open_port(const char *name)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue