mehr channel

This commit is contained in:
Rene Hopf
2014-10-31 16:00:08 +01:00
parent d74f496f9c
commit 4db8f1cdd2
4 changed files with 46 additions and 20 deletions
+18 -14
View File
@@ -1,13 +1,16 @@
#include "basicdrawpane.hpp"
BasicDrawPane::BasicDrawPane(wxFrame* parent) : wxPanel(parent){
BasicDrawPane::BasicDrawPane(wxFrame* parent, int ch) : wxPanel(parent){
time = 0;
diff = 0;
Bind(wxEVT_PAINT, &BasicDrawPane::paintEvent, this);
xpos = 0;
data.push_back(std::vector<float>(0));
for (int i = 0; i<1024/2; i++) {
data[0].push_back(0);
channels = ch;
for (int i = 0; i<channels; i++) {
data.push_back(std::vector<float>());
for (int j = 0; j<1024/2; j++) {
data[i].push_back(0);
}
}
}
@@ -41,7 +44,7 @@ void BasicDrawPane::paintNow()
render(dc);
}
void BasicDrawPane::plotvalue(int value)
void BasicDrawPane::plotvalue(int value, int channel)
{
diff = wxGetUTCTimeMillis()-time;
time = wxGetUTCTimeMillis();
@@ -49,7 +52,7 @@ void BasicDrawPane::plotvalue(int value)
//data.at(xpos) += 0.1;
data[0].at(xpos) = (float)value/64;
xpos = (xpos+1)%data.size();
xpos = (xpos+1)%data[0].size();
Refresh();
//oder
//Update();
@@ -82,14 +85,15 @@ void BasicDrawPane::render(wxDC& dc)
x = 0;
y = h/2;
xstep = w/(data[0].size()-1);
for(auto point : data[0]){
xold = x;
yold = y;
y = h/2-point*h/2;
dc.DrawLine( xold-xstep, yold, x, y );
x += xstep;
for (int i = 0; i<channels; i++) {
xstep = w/(data[i].size()-1);
for(auto point : data[i]){
xold = x;
yold = y;
y = h/2-point*h/2;
dc.DrawLine( xold-xstep, yold, x, y );
x += xstep;
}
}
// Look at the wxDC docs to learn how to draw other stuff
}
+3 -2
View File
@@ -17,11 +17,12 @@
class BasicDrawPane : public wxPanel
{
public:
BasicDrawPane(wxFrame* parent);
BasicDrawPane(wxFrame* parent, int ch);
void paintEvent(wxPaintEvent & evt);
void paintNow();
void plotvalue(int);
void plotvalue(int,int);
void render(wxDC& dc);
int channels;
private:
wxLongLong time;
wxLongLong diff;
+23 -4
View File
@@ -18,7 +18,9 @@ MainFrame::MainFrame(const wxString& title) : wxFrame(NULL, wxID_ANY, title){
wxPanel *top = new wxPanel(mainsplitter, wxID_ANY);
wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *leiste = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *channelleiste = new wxBoxSizer(wxHORIZONTAL);
choose_port = new wxChoice (top, wxID_ANY);
connectbutton = new wxButton(top, wxID_ANY, wxT("&Connect"));
clear = new wxButton(top, wxID_ANY, wxT("Clear"));
refresh = new wxButton(top, wxID_ANY, wxT("&Refresh"));
@@ -37,9 +39,22 @@ MainFrame::MainFrame(const wxString& title) : wxFrame(NULL, wxID_ANY, title){
leiste->Add(uhu,0,wxALIGN_LEFT|wxALL,3);
leiste->Add(stmbl,0,wxALIGN_LEFT|wxALL,3);
topsizer->Add(leiste);
drawpanel = new BasicDrawPane((wxFrame*)top);
topsizer->Add(drawpanel, 1,wxEXPAND,0);
top->SetSizer(topsizer);
drawpanel = new BasicDrawPane((wxFrame*)top,4);
topsizer->Add(drawpanel, 1,wxEXPAND,0);
for(int i = 0;i<drawpanel->channels;i++){
channelchoice.push_back(new wxChoice (top, wxID_ANY));
channelchoice.back()->SetClientData(new int(i));
channelchoice.back()->Bind(wxEVT_CHOICE,&MainFrame::OnChannelChange, this, wxID_ANY);
channelchoice.back()->Append(wxT("-"));
channelchoice.back()->Append(wxT("1"));
channelchoice.back()->Append(wxT("2"));
channelchoice.back()->Append(wxT("3"));
channelleiste->Add(channelchoice.back(), 0,wxALIGN_LEFT|wxALL,3);
}
topsizer->Add(channelleiste);
top->SetSizer(topsizer);
//unten
wxPanel *bottom = new wxPanel(mainsplitter, wxID_ANY);
@@ -78,6 +93,10 @@ void MainFrame::OnKeyDown(wxKeyEvent& event){
}
}
void MainFrame::OnChannelChange(wxCommandEvent& event){
std::cout << *(int*)event.GetClientData() << "->" << event.GetSelection() << std::endl;
}
void MainFrame::OnIdle(wxIdleEvent& evt){
int ret;
if(connected){
@@ -87,7 +106,7 @@ void MainFrame::OnIdle(wxIdleEvent& evt){
//if(uhu->GetValue()){
for (int i=0; i<ret; i++) {
if ((buf[i]>>7)) {
drawpanel->plotvalue(((int)buf[i])+128/2);
drawpanel->plotvalue(((int)buf[i])+128/2,0);
}else{
text->AppendText(buf[i]);
}
+2
View File
@@ -30,11 +30,13 @@ private:
struct sp_port **ports;
struct sp_port *port;
wxChoice *choose_port;
std::vector<wxChoice *> channelchoice;
bool connected;
void OnConnect(wxCommandEvent& WXUNUSED(event));
void OnRefresh(wxCommandEvent& WXUNUSED(event));
void OnClear(wxCommandEvent& WXUNUSED(event));
void OnInput(wxCommandEvent& event);
void OnChannelChange(wxCommandEvent& event);
void OnKeyDown(wxKeyEvent& event);
void OnIdle(wxIdleEvent& evt);
void connect();