Anyway, i have a driver thats posting information to my GUI via fifos. Theres a constant stream of data from one fifo (indata) and occasional data gets sent back down the other(outdata) to the driver. The latest data needs to be shown in the GUI (its a series of angles) and is then either worked upon and returned in modified form and displayed or just displayed. My plan was to have a main GUI thread spawn a thread that waited for signals from the fifo (it has a signal option to warn when new data is available), read the fifo and then update the GUI with the new data as a constant loop. So i wanted to use PostEvent to instruct the GUI that theres new data to use and update display. Unfortunately I cant seem to figure out what the first parameter of postevent should be - i know its the event handler for the main window but how do i get it?
Any help appreciated, even if you want to suggest a complete re-think, im open to anything and rather desperate at the moment .... ooh err! Thanks for reading!
James
Heres my current code, its partially modified examples. It compiles as it is and runs but no event ever gets captured:
.c file:
Code: Select all
#include <wx>
#include <wx>
#include <wx>
#include <wx>
#include "gui.h"
#include </usr>
#include "signal.h"
#include "unistd.h"
#include "sys/types.h"
//#include "pthread.h"
int outputfifo = -1;
int inputfifo = -1;
int newdata[16];
DEFINE_EVENT_TYPE(wxEVT_MY_CUSTOM_COMMAND)
// it may also be convenient to define an event table macro for this event type
#define EVT_MY_CUSTOM_COMMAND(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_MY_CUSTOM_COMMAND, id, wxID_ANY, \
(wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxCommandEventFunction, &fn ), \
(wxObject *) NULL \
),
BEGIN_EVENT_TABLE( guiFrame, wxFrame )
EVT_MENU( Menu_File_Quit, guiFrame::OnQuit )
EVT_MENU( Menu_File_About, guiFrame::OnAbout )
EVT_MENU( Menu_1, guiFrame::Send1 )
EVT_MY_CUSTOM_COMMAND(wxID_ANY, guiFrame::OnProcessCustom)
END_EVENT_TABLE()
IMPLEMENT_APP(guiapp)
WorkerThread::ExitCode WorkerThread::Entry()
{
//Sleep(10);
wxCommandEvent event(wxEVT_MY_CUSTOM_COMMAND);
wxPostEvent(m_handler, event);
return (ExitCode) 0;
}
bool
guiapp::OnInit()
{
guiFrame *frame = new guiFrame( wxT( "Puma 560 Visual Slave" ), wxPoint(50,50), wxSize(450,340) );
frame->Show(TRUE);
SetTopWindow(frame);
inputfifo = open("/dev/rtf1", O_RDONLY);
read(inputfifo, newdata, 16);
WorkerThread *thread = new WorkerThread(this);
thread->Create();
thread->Run();
return TRUE;
}
guiFrame::guiFrame( const wxString& title, const wxPoint& pos, const wxSize& size )
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
{
wxMenu *menuFile = new wxMenu;
menuFile->Append( Menu_File_About, wxT( "&About..." ) );
menuFile->AppendSeparator();
menuFile->Append( Menu_File_Quit, wxT( "E&xit" ) );
menuFile->AppendSeparator();
menuFile->Append( Menu_1, wxT( "&1s"));
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append( menuFile, wxT( "&File" ) );
SetMenuBar( menuBar );
CreateStatusBar();
}
void
guiFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Close(TRUE);
}
void
guiFrame::Send1( wxCommandEvent& WXUNUSED( event ) )
{
SetStatusText( wxT( "Send Position" ));
/*outputfifo= open("/dev/rtf0", O_WRONLY);
if (outputfifo>-1){
write(outputfifo,"0000000000000000",16);
close(outputfifo);}else{wxMessageBox( wxT( "Comms failed" ),
wxT( "Slave Control" ), wxOK | wxICON_INFORMATION, this );}
*/
}
void
guiFrame::OnAbout( wxCommandEvent& WXUNUSED( event ) )
{
wxMessageBox( wxT( "Slave Visual Control" ),
wxT( "Slave Control" ), wxOK | wxICON_INFORMATION, this );
}
void
guiFrame::OnProcessCustom(wxCommandEvent& WXUNUSED(event))
{
wxLogMessage(_T("Got a custom event!"));
}
//EOF
Code: Select all
#ifndef _GUI_H_
#define _GUI_H_
/**
* @short Application Main Window
* @author root <coyoteboyuk>
* @version 0.1
*/
BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EVENT_TYPE(wxEVT_MY_CUSTOM_COMMAND, -1)
END_DECLARE_EVENT_TYPES()
class
guiapp : public wxApp
{
public:
virtual bool OnInit();
};
class
guiFrame : public wxFrame
{
public:
guiFrame( const wxString& title, const wxPoint& pos, const wxSize& pos );
void OnQuit( wxCommandEvent& event );
void OnAbout( wxCommandEvent& event );
void Send1( wxCommandEvent& event);
void OnProcessCustom( wxCommandEvent& event);
private:
DECLARE_EVENT_TABLE()
};
enum
{
Menu_File_Quit = 100,
Menu_File_About,
Menu_1
};
class WorkerThread : public wxThread
{
public:
WorkerThread(wxEvtHandler *handler) :
m_handler(handler) { }
protected:
virtual ExitCode Entry();
private:
wxEvtHandler *m_handler;
};
#endif // _GUI_H_
//EOF