|
|
@ -5,12 +5,10 @@
|
|
|
|
#include <wx/menu.h>
|
|
|
|
#include <wx/menu.h>
|
|
|
|
#include <wx/msgdlg.h>
|
|
|
|
#include <wx/msgdlg.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
|
|
|
|
#include <wx/statusbr.h>
|
|
|
|
|
|
|
|
|
|
|
|
enum Id {
|
|
|
|
enum Id {
|
|
|
|
Single = 1,
|
|
|
|
MeasureTimer = 1,
|
|
|
|
ConnectDevice,
|
|
|
|
|
|
|
|
UploadFilter,
|
|
|
|
|
|
|
|
RenderTimer,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MFileNew,
|
|
|
|
MFileNew,
|
|
|
|
MFileOpen,
|
|
|
|
MFileOpen,
|
|
|
@ -27,6 +25,10 @@ enum Id {
|
|
|
|
|
|
|
|
|
|
|
|
MainFrame::MainFrame() : wxFrame(nullptr, -1, "stmdspgui", wxPoint(50, 50), wxSize(640, 800))
|
|
|
|
MainFrame::MainFrame() : wxFrame(nullptr, -1, "stmdspgui", wxPoint(50, 50), wxSize(640, 800))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
m_status_bar = new wxStatusBar(this);
|
|
|
|
|
|
|
|
m_status_bar->SetStatusText("Ready.");
|
|
|
|
|
|
|
|
SetStatusBar(m_status_bar);
|
|
|
|
|
|
|
|
|
|
|
|
auto menubar = new wxMenuBar;
|
|
|
|
auto menubar = new wxMenuBar;
|
|
|
|
auto menuFile = new wxMenu;
|
|
|
|
auto menuFile = new wxMenu;
|
|
|
|
Bind(wxEVT_MENU, &MainFrame::onFileNew, this, Id::MFileNew, wxID_ANY,
|
|
|
|
Bind(wxEVT_MENU, &MainFrame::onFileNew, this, Id::MFileNew, wxID_ANY,
|
|
|
@ -46,9 +48,7 @@ MainFrame::MainFrame() : wxFrame(nullptr, -1, "stmdspgui", wxPoint(50, 50), wxSi
|
|
|
|
menuRun->AppendSeparator();
|
|
|
|
menuRun->AppendSeparator();
|
|
|
|
Bind(wxEVT_MENU, &MainFrame::onRunStart, this, Id::MRunStart, wxID_ANY,
|
|
|
|
Bind(wxEVT_MENU, &MainFrame::onRunStart, this, Id::MRunStart, wxID_ANY,
|
|
|
|
menuRun->Append(MRunStart, "&Start"));
|
|
|
|
menuRun->Append(MRunStart, "&Start"));
|
|
|
|
m_run_measure = menuRun->AppendCheckItem(MRunMeasure, "&Measure code speed");
|
|
|
|
m_run_measure = menuRun->AppendCheckItem(MRunMeasure, "&Measure code time");
|
|
|
|
m_run_measure_value = menuRun->Append(wxID_ANY, "Last time:");
|
|
|
|
|
|
|
|
m_run_measure_value->Enable(false);
|
|
|
|
|
|
|
|
menuRun->AppendSeparator();
|
|
|
|
menuRun->AppendSeparator();
|
|
|
|
Bind(wxEVT_MENU, &MainFrame::onRunCompile, this, Id::MRunCompile, wxID_ANY,
|
|
|
|
Bind(wxEVT_MENU, &MainFrame::onRunCompile, this, Id::MRunCompile, wxID_ANY,
|
|
|
|
menuRun->Append(MRunCompile, "&Compile code"));
|
|
|
|
menuRun->Append(MRunCompile, "&Compile code"));
|
|
|
@ -67,56 +67,20 @@ MainFrame::MainFrame() : wxFrame(nullptr, -1, "stmdspgui", wxPoint(50, 50), wxSi
|
|
|
|
prepareEditor();
|
|
|
|
prepareEditor();
|
|
|
|
window->Add(m_text_editor, 1, wxEXPAND | wxALL, 10);
|
|
|
|
window->Add(m_text_editor, 1, wxEXPAND | wxALL, 10);
|
|
|
|
|
|
|
|
|
|
|
|
//m_signal_area = new wxControl(this, wxID_ANY, wxDefaultPosition, wxSize(600, 200));
|
|
|
|
|
|
|
|
//window->Add(m_signal_area, 1, wxEXPAND | wxALL, 10);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SetSizerAndFit(window);
|
|
|
|
SetSizerAndFit(window);
|
|
|
|
|
|
|
|
|
|
|
|
//m_render_timer = new wxTimer(this, Id::RenderTimer);
|
|
|
|
m_measure_timer = new wxTimer(this, Id::MeasureTimer);
|
|
|
|
|
|
|
|
Bind(wxEVT_TIMER, &MainFrame::onMeasureTimer, this, Id::MeasureTimer);
|
|
|
|
//Bind(wxEVT_PAINT, &MainFrame::onPaint, this, wxID_ANY);
|
|
|
|
|
|
|
|
//Bind(wxEVT_TIMER, &MainFrame::onRenderTimer, this, Id::RenderTimer);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainFrame::onPaint([[maybe_unused]] wxPaintEvent& pe)
|
|
|
|
void MainFrame::onMeasureTimer([[maybe_unused]] wxTimerEvent&)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto *dc = new wxClientDC(this);
|
|
|
|
if (m_status_bar && m_device) {
|
|
|
|
auto region = m_signal_area->GetRect();
|
|
|
|
m_status_bar->SetStatusText(wxString::Format(wxT("Execution time: %u cycles"),
|
|
|
|
dc->SetClippingRegion(region);
|
|
|
|
m_device->continuous_start_get_measurement()));
|
|
|
|
|
|
|
|
|
|
|
|
dc->SetBrush(*wxBLACK_BRUSH); dc->SetPen(*wxBLACK_PEN);
|
|
|
|
|
|
|
|
dc->DrawRectangle(region);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_device_samples.size() > 0) {
|
|
|
|
|
|
|
|
dc->SetPen(*wxRED_PEN);
|
|
|
|
|
|
|
|
auto points = new wxPoint[m_device_samples.size()];
|
|
|
|
|
|
|
|
const float spacing = static_cast<float>(region.GetWidth()) / m_device_samples.size();
|
|
|
|
|
|
|
|
float x = 0;
|
|
|
|
|
|
|
|
for (auto ptr = points; auto sample : m_device_samples) {
|
|
|
|
|
|
|
|
*ptr++ = wxPoint {
|
|
|
|
|
|
|
|
static_cast<int>(x),
|
|
|
|
|
|
|
|
region.GetHeight() - sample * region.GetHeight() / 4096
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
x += spacing;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
dc->DrawLines(m_device_samples.size(), points, region.GetX(), region.GetY());
|
|
|
|
|
|
|
|
delete[] points;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainFrame::onRenderTimer([[maybe_unused]] wxTimerEvent& te)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
updateDrawing();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MainFrame::updateDrawing()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (m_device_samples = m_device_samples_future.get(); m_device_samples.size() > 0)
|
|
|
|
|
|
|
|
this->RefreshRect(m_signal_area->GetRect());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requestSamples();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MainFrame::prepareEditor()
|
|
|
|
void MainFrame::prepareEditor()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_text_editor->SetLexer(wxSTC_LEX_CPP);
|
|
|
|
m_text_editor->SetLexer(wxSTC_LEX_CPP);
|
|
|
@ -146,7 +110,7 @@ void MainFrame::prepareEditor()
|
|
|
|
|
|
|
|
|
|
|
|
// a sample list of keywords, I haven't included them all to keep it short...
|
|
|
|
// a sample list of keywords, I haven't included them all to keep it short...
|
|
|
|
m_text_editor->SetKeyWords(0,
|
|
|
|
m_text_editor->SetKeyWords(0,
|
|
|
|
wxT("return for while do break continue if else goto"));
|
|
|
|
wxT("return for while do break continue if else goto asm"));
|
|
|
|
m_text_editor->SetKeyWords(1,
|
|
|
|
m_text_editor->SetKeyWords(1,
|
|
|
|
wxT("void char short int long auto float double unsigned signed "
|
|
|
|
wxT("void char short int long auto float double unsigned signed "
|
|
|
|
"volatile static const constexpr constinit consteval "
|
|
|
|
"volatile static const constexpr constinit consteval "
|
|
|
@ -205,10 +169,13 @@ wxString MainFrame::compileEditorCode()
|
|
|
|
|
|
|
|
|
|
|
|
wxString make_command = wxString("make -C ") + temp_file_name.BeforeLast('/') +
|
|
|
|
wxString make_command = wxString("make -C ") + temp_file_name.BeforeLast('/') +
|
|
|
|
" -f " + temp_file_name + "make";
|
|
|
|
" -f " + temp_file_name + "make";
|
|
|
|
if (system(make_command.ToAscii()) == 0)
|
|
|
|
if (system(make_command.ToAscii()) == 0) {
|
|
|
|
|
|
|
|
m_status_bar->SetStatusText("Compilation succeeded.");
|
|
|
|
return temp_file_name + ".o";
|
|
|
|
return temp_file_name + ".o";
|
|
|
|
else
|
|
|
|
} else {
|
|
|
|
|
|
|
|
m_status_bar->SetStatusText("Compilation failed.");
|
|
|
|
return "";
|
|
|
|
return "";
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainFrame::onFileNew([[maybe_unused]] wxCommandEvent&)
|
|
|
|
void MainFrame::onFileNew([[maybe_unused]] wxCommandEvent&)
|
|
|
@ -221,6 +188,7 @@ R"cpp(adcsample_t *process_data(adcsample_t *samples, unsigned int size)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)cpp");
|
|
|
|
)cpp");
|
|
|
|
m_text_editor->DiscardEdits();
|
|
|
|
m_text_editor->DiscardEdits();
|
|
|
|
|
|
|
|
m_status_bar->SetStatusText("Ready.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainFrame::onFileOpen([[maybe_unused]] wxCommandEvent&)
|
|
|
|
void MainFrame::onFileOpen([[maybe_unused]] wxCommandEvent&)
|
|
|
@ -237,6 +205,7 @@ void MainFrame::onFileOpen([[maybe_unused]] wxCommandEvent&)
|
|
|
|
m_open_file_path = openDialog.GetPath();
|
|
|
|
m_open_file_path = openDialog.GetPath();
|
|
|
|
m_text_editor->SetText(buffer);
|
|
|
|
m_text_editor->SetText(buffer);
|
|
|
|
m_text_editor->DiscardEdits();
|
|
|
|
m_text_editor->DiscardEdits();
|
|
|
|
|
|
|
|
m_status_bar->SetStatusText("Ready.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete[] buffer;
|
|
|
|
delete[] buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -253,8 +222,13 @@ void MainFrame::onFileSave(wxCommandEvent& ce)
|
|
|
|
file.Write(m_text_editor->GetText());
|
|
|
|
file.Write(m_text_editor->GetText());
|
|
|
|
file.Close();
|
|
|
|
file.Close();
|
|
|
|
m_text_editor->DiscardEdits();
|
|
|
|
m_text_editor->DiscardEdits();
|
|
|
|
|
|
|
|
m_status_bar->SetStatusText("Saved.");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
m_status_bar->SetStatusText("Save failed: couldn't open file.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
m_status_bar->SetStatusText("No modifications to save.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -271,8 +245,13 @@ void MainFrame::onFileSaveAs([[maybe_unused]] wxCommandEvent& ce)
|
|
|
|
file.Close();
|
|
|
|
file.Close();
|
|
|
|
m_text_editor->DiscardEdits();
|
|
|
|
m_text_editor->DiscardEdits();
|
|
|
|
m_open_file_path = saveDialog.GetPath();
|
|
|
|
m_open_file_path = saveDialog.GetPath();
|
|
|
|
|
|
|
|
m_status_bar->SetStatusText("Saved.");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
m_status_bar->SetStatusText("Save failed: couldn't open file.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
m_status_bar->SetStatusText("No modifications to save.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -291,16 +270,21 @@ void MainFrame::onRunConnect(wxCommandEvent& ce)
|
|
|
|
m_device = new stmdsp::device(devices.front());
|
|
|
|
m_device = new stmdsp::device(devices.front());
|
|
|
|
if (m_device->connected()) {
|
|
|
|
if (m_device->connected()) {
|
|
|
|
menuItem->SetItemLabel("&Disconnect");
|
|
|
|
menuItem->SetItemLabel("&Disconnect");
|
|
|
|
|
|
|
|
m_status_bar->SetStatusText("Connected.");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
delete m_device;
|
|
|
|
delete m_device;
|
|
|
|
m_device = nullptr;
|
|
|
|
m_device = nullptr;
|
|
|
|
menuItem->SetItemLabel("&Connect");
|
|
|
|
menuItem->SetItemLabel("&Connect");
|
|
|
|
|
|
|
|
m_status_bar->SetStatusText("Failed to connect.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
m_status_bar->SetStatusText("No devices found.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
delete m_device;
|
|
|
|
delete m_device;
|
|
|
|
m_device = nullptr;
|
|
|
|
m_device = nullptr;
|
|
|
|
menuItem->SetItemLabel("&Connect");
|
|
|
|
menuItem->SetItemLabel("&Connect");
|
|
|
|
|
|
|
|
m_status_bar->SetStatusText("Disconnected.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -308,30 +292,28 @@ void MainFrame::onRunStart(wxCommandEvent& ce)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto menuItem = dynamic_cast<wxMenuItem *>(ce.GetEventUserData());
|
|
|
|
auto menuItem = dynamic_cast<wxMenuItem *>(ce.GetEventUserData());
|
|
|
|
|
|
|
|
|
|
|
|
if (!m_render_timer->IsRunning()) {
|
|
|
|
if (!m_is_running) {
|
|
|
|
if (m_device != nullptr && m_device->connected()) {
|
|
|
|
if (m_device != nullptr && m_device->connected()) {
|
|
|
|
if (m_run_measure && m_run_measure->IsChecked())
|
|
|
|
if (m_run_measure && m_run_measure->IsChecked()) {
|
|
|
|
m_device->continuous_start_measure();
|
|
|
|
m_device->continuous_start_measure();
|
|
|
|
else
|
|
|
|
m_measure_timer->StartOnce(1000);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
m_device->continuous_start();
|
|
|
|
m_device->continuous_start();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
m_device_samples_future = std::async(std::launch::async,
|
|
|
|
|
|
|
|
[]() { return decltype(m_device_samples)(); });
|
|
|
|
|
|
|
|
m_render_timer->Start(1000);
|
|
|
|
|
|
|
|
menuItem->SetItemLabel("&Stop");
|
|
|
|
menuItem->SetItemLabel("&Stop");
|
|
|
|
|
|
|
|
m_status_bar->SetStatusText("Running.");
|
|
|
|
|
|
|
|
m_is_running = true;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
wxMessageBox("No device connected!", "Run", wxICON_WARNING);
|
|
|
|
wxMessageBox("No device connected!", "Run", wxICON_WARNING);
|
|
|
|
|
|
|
|
m_status_bar->SetStatusText("Please connect.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
m_render_timer->Stop();
|
|
|
|
|
|
|
|
m_device->continuous_stop();
|
|
|
|
m_device->continuous_stop();
|
|
|
|
|
|
|
|
|
|
|
|
menuItem->SetItemLabel("&Start");
|
|
|
|
menuItem->SetItemLabel("&Start");
|
|
|
|
if (m_run_measure && m_run_measure_value) {
|
|
|
|
m_status_bar->SetStatusText("Ready.");
|
|
|
|
m_run_measure_value->SetItemLabel(
|
|
|
|
m_is_running = false;
|
|
|
|
m_run_measure->IsChecked() ? wxString::Format(wxT("Last time: %u"),m_device->continuous_start_get_measurement())
|
|
|
|
|
|
|
|
: "Last time: --");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -349,22 +331,24 @@ void MainFrame::onRunUpload([[maybe_unused]] wxCommandEvent&)
|
|
|
|
if (m_device != nullptr && m_device->connected()) {
|
|
|
|
if (m_device != nullptr && m_device->connected()) {
|
|
|
|
file_stream.ReadAll(buffer, size);
|
|
|
|
file_stream.ReadAll(buffer, size);
|
|
|
|
m_device->upload_filter(buffer, size);
|
|
|
|
m_device->upload_filter(buffer, size);
|
|
|
|
|
|
|
|
m_status_bar->SetStatusText("Code uploaded.");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
wxMessageBox("No device connected!", "Run", wxICON_WARNING);
|
|
|
|
wxMessageBox("No device connected!", "Run", wxICON_WARNING);
|
|
|
|
|
|
|
|
m_status_bar->SetStatusText("Please connect.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
m_status_bar->SetStatusText("Couldn't load compiled code.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainFrame::onRunUnload([[maybe_unused]] wxCommandEvent&)
|
|
|
|
void MainFrame::onRunUnload([[maybe_unused]] wxCommandEvent&)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (m_device != nullptr && m_device->connected())
|
|
|
|
if (m_device != nullptr && m_device->connected()) {
|
|
|
|
m_device->unload_filter();
|
|
|
|
m_device->unload_filter();
|
|
|
|
}
|
|
|
|
m_status_bar->SetStatusText("Unloaded code.");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
void MainFrame::requestSamples()
|
|
|
|
m_status_bar->SetStatusText("No device connected.");
|
|
|
|
{
|
|
|
|
}
|
|
|
|
m_device_samples_future = std::async(std::launch::async,
|
|
|
|
|
|
|
|
[this]() { return m_device->continuous_read(); });
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|