clean up gui states

pull/3/head
Clyne 4 years ago
parent 4f59610a00
commit 22a0cd0c82

@ -139,14 +139,18 @@ namespace stmdsp
} }
void device::siggen_start() { void device::siggen_start() {
if (connected()) if (connected()) {
m_is_siggening = true;
m_serial.write("W"); m_serial.write("W");
} }
}
void device::siggen_stop() { void device::siggen_stop() {
if (connected()) if (connected()) {
m_is_siggening = false;
m_serial.write("w"); m_serial.write("w");
} }
}
void device::upload_filter(unsigned char *buffer, size_t size) { void device::upload_filter(unsigned char *buffer, size_t size) {
if (connected()) { if (connected()) {

@ -67,6 +67,7 @@ namespace stmdsp
void siggen_upload(dacsample_t *buffer, unsigned int size); void siggen_upload(dacsample_t *buffer, unsigned int size);
void siggen_start(); void siggen_start();
void siggen_stop(); void siggen_stop();
bool is_siggening() const { return m_is_siggening; }
// buffer is ELF binary // buffer is ELF binary
void upload_filter(unsigned char *buffer, size_t size); void upload_filter(unsigned char *buffer, size_t size);
@ -75,6 +76,7 @@ namespace stmdsp
private: private:
serial::Serial m_serial; serial::Serial m_serial;
unsigned int m_buffer_size = SAMPLES_MAX; unsigned int m_buffer_size = SAMPLES_MAX;
bool m_is_siggening = false;
}; };
} }

@ -101,7 +101,6 @@ enum Id {
MRunUpload, MRunUpload,
MRunUnload, MRunUnload,
MRunEditBSize, MRunEditBSize,
MRunEditSRate,
MRunGenUpload, MRunGenUpload,
MRunGenStart, MRunGenStart,
MCodeCompile, MCodeCompile,
@ -110,127 +109,156 @@ enum Id {
MainFrame::MainFrame() : wxFrame(nullptr, wxID_ANY, "stmdspgui", wxPoint(50, 50), wxSize(640, 800)) MainFrame::MainFrame() : wxFrame(nullptr, wxID_ANY, "stmdspgui", wxPoint(50, 50), wxSize(640, 800))
{ {
auto splitter = new wxSplitterWindow(this, wxID_ANY); // Main frame structure:
// Begin with a main splitter for the code and terminal panes
auto mainSplitter = new wxSplitterWindow(this, wxID_ANY);
auto panelCode = new wxPanel(mainSplitter, wxID_ANY);
auto panelOutput = new wxPanel(mainSplitter, wxID_ANY);
// Additional panel for the toolbar
auto panelToolbar = new wxPanel(this, wxID_ANY); auto panelToolbar = new wxPanel(this, wxID_ANY);
auto panelCode = new wxPanel(splitter, wxID_ANY); // Sizers for the controls
auto panelOutput = new wxPanel(splitter, wxID_ANY);
auto sizerToolbar = new wxBoxSizer(wxHORIZONTAL); auto sizerToolbar = new wxBoxSizer(wxHORIZONTAL);
auto sizerCode = new wxBoxSizer(wxVERTICAL); auto sizerCode = new wxBoxSizer(wxVERTICAL);
auto sizerOutput = new wxBoxSizer(wxVERTICAL); auto sizerOutput = new wxBoxSizer(wxVERTICAL);
auto sizerSplitter = new wxBoxSizer(wxVERTICAL); auto sizerMain = new wxBoxSizer(wxVERTICAL);
// Menu objects
auto menuFile = new wxMenu; auto menuFile = new wxMenu;
auto menuRun = new wxMenu; auto menuRun = new wxMenu;
auto menuCode = new wxMenu; auto menuCode = new wxMenu;
// Member initialization // Member initialization
m_status_bar = new wxStatusBar(this); m_status_bar = new wxStatusBar(this);
m_text_editor = new wxStyledTextCtrl(panelCode, wxID_ANY, wxDefaultPosition, wxSize(620, 440)); m_text_editor = new wxStyledTextCtrl(panelCode, wxID_ANY,
m_compile_output = new wxTextCtrl(panelOutput, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultPosition, wxSize(620, 440));
wxSize(620, 250), wxTE_READONLY | wxTE_MULTILINE | wxHSCROLL); m_compile_output = new wxTextCtrl(panelOutput, wxID_ANY,
wxEmptyString,
wxDefaultPosition, wxSize(620, 250),
wxTE_READONLY | wxTE_MULTILINE | wxHSCROLL);
m_measure_timer = new wxTimer(this, Id::MeasureTimer); m_measure_timer = new wxTimer(this, Id::MeasureTimer);
m_menu_bar = new wxMenuBar; m_menu_bar = new wxMenuBar;
m_rate_select = new wxComboBox(panelToolbar, wxID_ANY,
wxEmptyString,
wxDefaultPosition, wxDefaultSize,
srateValues.size(), srateValues.data(),
wxCB_READONLY);
m_status_bar->SetStatusText("Ready."); m_menu_bar->Append(menuFile, "&File");
SetStatusBar(m_status_bar); m_menu_bar->Append(menuRun, "&Run");
m_menu_bar->Append(menuCode, "&Code");
splitter->SetSashGravity(0.5); SetMenuBar(m_menu_bar);
splitter->SetMinimumPaneSize(20);
// Toolbar initialization
auto comp = new wxButton(panelToolbar, Id::MCodeCompile, "Compile"); auto comp = new wxButton(panelToolbar, Id::MCodeCompile, "Compile");
m_rate_select = new wxComboBox(panelToolbar, wxID_ANY,
wxEmptyString, wxDefaultPosition, wxDefaultSize,
srateValues.size(), srateValues.data(), wxCB_READONLY);
m_rate_select->Disable();
sizerToolbar->Add(comp, 0, wxLEFT, 4); sizerToolbar->Add(comp, 0, wxLEFT, 4);
sizerToolbar->Add(m_rate_select, 0, wxLEFT, 12); sizerToolbar->Add(m_rate_select, 0, wxLEFT, 12);
panelToolbar->SetSizer(sizerToolbar); panelToolbar->SetSizer(sizerToolbar);
Bind(wxEVT_BUTTON, &MainFrame::onRunCompile, this, Id::MCodeCompile, wxID_ANY, comp);
Bind(wxEVT_COMBOBOX, &MainFrame::onToolbarSampleRate, this, wxID_ANY, wxID_ANY, m_rate_select);
// Code panel init.
prepareEditor(); prepareEditor();
sizerCode->Add(panelToolbar, 0, wxTOP | wxBOTTOM, 4); sizerCode->Add(panelToolbar, 0, wxTOP | wxBOTTOM, 4);
sizerCode->Add(m_text_editor, 1, wxEXPAND, 0); sizerCode->Add(m_text_editor, 1, wxEXPAND, 0);
panelCode->SetSizer(sizerCode); panelCode->SetSizer(sizerCode);
// Output panel init.
m_compile_output->SetBackgroundColour(wxColour(0, 0, 0)); m_compile_output->SetBackgroundColour(wxColour(0, 0, 0));
m_compile_output->SetDefaultStyle(wxTextAttr(*wxWHITE, *wxBLACK, wxFont("Hack"))); m_compile_output->SetDefaultStyle(wxTextAttr(*wxWHITE, *wxBLACK, wxFont("Hack")));
sizerOutput->Add(m_compile_output, 1, wxEXPAND | wxALL, 0); sizerOutput->Add(m_compile_output, 1, wxEXPAND | wxALL, 0);
panelOutput->SetSizer(sizerOutput); panelOutput->SetSizer(sizerOutput);
splitter->SplitHorizontally(panelCode, panelOutput, 440); // Main splitter init.
mainSplitter->SetSashGravity(0.5);
mainSplitter->SetMinimumPaneSize(20);
mainSplitter->SplitHorizontally(panelCode, panelOutput, 440);
sizerMain->Add(mainSplitter, 1, wxEXPAND, 5);
sizerMain->SetSizeHints(this);
SetSizer(sizerMain);
sizerSplitter->Add(splitter, 1, wxEXPAND, 5); m_status_bar->SetStatusText("Ready.");
SetSizer(sizerSplitter); SetStatusBar(m_status_bar);
sizerSplitter->SetSizeHints(this);
// Binds:
// General
Bind(wxEVT_TIMER, &MainFrame::onMeasureTimer, this, Id::MeasureTimer); Bind(wxEVT_TIMER, &MainFrame::onMeasureTimer, this, Id::MeasureTimer);
Bind(wxEVT_CLOSE_WINDOW, &MainFrame::onCloseEvent, this, wxID_ANY);
Bind(wxEVT_MENU, &MainFrame::onFileNew, this, Id::MFileNew, wxID_ANY, // Toolbar actions
menuFile->Append(MFileNew, "&New")); Bind(wxEVT_BUTTON, &MainFrame::onRunCompile, this, Id::MCodeCompile, wxID_ANY, comp);
Bind(wxEVT_MENU, &MainFrame::onFileOpen, this, Id::MFileOpen, wxID_ANY, Bind(wxEVT_COMBOBOX, &MainFrame::onToolbarSampleRate, this, wxID_ANY, wxID_ANY, m_rate_select);
menuFile->Append(MFileOpen, "&Open"));
menuFile->Append(MFileOpenTemplate, "Open &Template", loadTemplates());
Bind(wxEVT_MENU, &MainFrame::onFileSave, this, Id::MFileSave, wxID_ANY, // File menu actions
menuFile->Append(MFileSave, "&Save")); Bind(wxEVT_MENU, &MainFrame::onFileNew, this, Id::MFileNew, wxID_ANY, menuFile->Append(MFileNew, "&New"));
Bind(wxEVT_MENU, &MainFrame::onFileSaveAs, this, Id::MFileSaveAs, wxID_ANY, Bind(wxEVT_MENU, &MainFrame::onFileOpen, this, Id::MFileOpen, wxID_ANY, menuFile->Append(MFileOpen, "&Open"));
menuFile->Append(MFileSaveAs, "Save &As")); menuFile->Append(MFileOpenTemplate, "Open &Template", loadTemplates());
Bind(wxEVT_MENU, &MainFrame::onFileSave, this, Id::MFileSave, wxID_ANY, menuFile->Append(MFileSave, "&Save"));
Bind(wxEVT_MENU, &MainFrame::onFileSaveAs, this, Id::MFileSaveAs, wxID_ANY, menuFile->Append(MFileSaveAs, "Save &As"));
menuFile->AppendSeparator(); menuFile->AppendSeparator();
Bind(wxEVT_MENU, &MainFrame::onFileQuit, this, Id::MFileQuit, wxID_ANY, Bind(wxEVT_MENU, &MainFrame::onFileQuit, this, Id::MFileQuit, wxID_ANY, menuFile->Append(MFileQuit, "&Quit"));
menuFile->Append(MFileQuit, "&Quit"));
Bind(wxEVT_MENU, &MainFrame::onRunConnect, this, Id::MRunConnect, wxID_ANY, // Run menu actions
menuRun->Append(MRunConnect, "&Connect")); Bind(wxEVT_MENU, &MainFrame::onRunConnect, this, Id::MRunConnect, wxID_ANY, menuRun->Append(MRunConnect, "&Connect"));
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 time"); m_run_measure = menuRun->AppendCheckItem(MRunMeasure, "&Measure code time");
Bind(wxEVT_MENU, &MainFrame::onRunLogResults, this, Id::MRunLogResults, wxID_ANY, Bind(wxEVT_MENU, &MainFrame::onRunLogResults, this, Id::MRunLogResults, wxID_ANY, menuRun->AppendCheckItem(MRunLogResults, "&Log results..."));
menuRun->AppendCheckItem(MRunLogResults, "&Log results..."));
menuRun->AppendSeparator(); menuRun->AppendSeparator();
Bind(wxEVT_MENU, &MainFrame::onRunUpload, this, Id::MRunUpload, wxID_ANY, Bind(wxEVT_MENU, &MainFrame::onRunUpload, this, Id::MRunUpload, wxID_ANY, menuRun->Append(MRunUpload, "&Upload code"));
menuRun->Append(MRunUpload, "&Upload code")); Bind(wxEVT_MENU, &MainFrame::onRunUnload, this, Id::MRunUnload, wxID_ANY, menuRun->Append(MRunUnload, "U&nload code"));
Bind(wxEVT_MENU, &MainFrame::onRunUnload, this, Id::MRunUnload, wxID_ANY, Bind(wxEVT_MENU, &MainFrame::onRunEditBSize, this, Id::MRunEditBSize, wxID_ANY, menuRun->Append(MRunEditBSize, "Set &buffer size..."));
menuRun->Append(MRunUnload, "U&nload code"));
Bind(wxEVT_MENU, &MainFrame::onRunEditBSize, this, Id::MRunEditBSize, wxID_ANY,
menuRun->Append(MRunEditBSize, "Set &buffer size..."));
menuRun->AppendSeparator(); menuRun->AppendSeparator();
Bind(wxEVT_MENU, &MainFrame::onRunGenUpload, this, Id::MRunGenUpload, wxID_ANY, Bind(wxEVT_MENU, &MainFrame::onRunGenUpload, this, Id::MRunGenUpload, wxID_ANY, menuRun->Append(MRunGenUpload, "&Load signal generator..."));
menuRun->Append(MRunGenUpload, "&Load signal generator...")); Bind(wxEVT_MENU, &MainFrame::onRunGenStart, this, Id::MRunGenStart, wxID_ANY, menuRun->AppendCheckItem(MRunGenStart, "Start &generator"));
Bind(wxEVT_MENU, &MainFrame::onRunGenStart, this, Id::MRunGenStart, wxID_ANY,
menuRun->AppendCheckItem(MRunGenStart, "Start &generator"));
Bind(wxEVT_MENU, &MainFrame::onRunCompile, this, Id::MCodeCompile, wxID_ANY,
menuCode->Append(MCodeCompile, "&Compile code"));
Bind(wxEVT_MENU, &MainFrame::onCodeDisassemble, this, Id::MCodeDisassemble, wxID_ANY,
menuCode->Append(MCodeDisassemble, "Show &Disassembly"));
Bind(wxEVT_CLOSE_WINDOW, &MainFrame::onCloseEvent, this, wxID_ANY); // Code menu actions
Bind(wxEVT_MENU, &MainFrame::onRunCompile, this, Id::MCodeCompile, wxID_ANY, menuCode->Append(MCodeCompile, "&Compile code"));
Bind(wxEVT_MENU, &MainFrame::onCodeDisassemble, this, Id::MCodeDisassemble, wxID_ANY, menuCode->Append(MCodeDisassemble, "Show &Disassembly"));
menuCode->AppendSeparator();
m_menu_bar->Append(menuFile, "&File"); updateMenuOptions();
m_menu_bar->Append(menuRun, "&Run");
m_menu_bar->Append(menuCode, "&Code");
SetMenuBar(m_menu_bar);
} }
// Closes the window
// Needs to clean things up
void MainFrame::onCloseEvent(wxCloseEvent& event) void MainFrame::onCloseEvent(wxCloseEvent& event)
{ {
SetMenuBar(nullptr); //SetMenuBar(nullptr);
m_menu_bar->Remove(2); //delete m_menu_bar->Remove(2);
m_menu_bar->Remove(1); //delete m_menu_bar->Remove(1);
m_menu_bar->Remove(0); //delete m_menu_bar->Remove(0);
delete m_menu_bar; //delete m_menu_bar;
delete m_measure_timer; //delete m_measure_timer;
//Unbind(wxEVT_TIMER, &MainFrame::onMeasureTimer, this, Id::MeasureTimer);
//Unbind(wxEVT_CLOSE_WINDOW, &MainFrame::onCloseEvent, this, wxID_ANY);
//Unbind(wxEVT_BUTTON, &MainFrame::onRunCompile, this, Id::MCodeCompile, wxID_ANY);
//Unbind(wxEVT_COMBOBOX, &MainFrame::onToolbarSampleRate, this, wxID_ANY, wxID_ANY);
//Unbind(wxEVT_MENU, &MainFrame::onFileNew, this, Id::MFileNew, wxID_ANY);
//Unbind(wxEVT_MENU, &MainFrame::onFileOpen, this, Id::MFileOpen, wxID_ANY);
////menuFile->Append(MFileOpenTemplate, "Open &Template", loadTemplates());
//Unbind(wxEVT_MENU, &MainFrame::onFileSave, this, Id::MFileSave, wxID_ANY);
//Unbind(wxEVT_MENU, &MainFrame::onFileSaveAs, this, Id::MFileSaveAs, wxID_ANY);
//Unbind(wxEVT_MENU, &MainFrame::onFileQuit, this, Id::MFileQuit, wxID_ANY);
//Unbind(wxEVT_MENU, &MainFrame::onRunConnect, this, Id::MRunConnect, wxID_ANY);
//Unbind(wxEVT_MENU, &MainFrame::onRunStart, this, Id::MRunStart, wxID_ANY);
//Unbind(wxEVT_MENU, &MainFrame::onRunLogResults, this, Id::MRunLogResults, wxID_ANY);
//Unbind(wxEVT_MENU, &MainFrame::onRunUpload, this, Id::MRunUpload, wxID_ANY);
//Unbind(wxEVT_MENU, &MainFrame::onRunUnload, this, Id::MRunUnload, wxID_ANY);
//Unbind(wxEVT_MENU, &MainFrame::onRunEditBSize, this, Id::MRunEditBSize, wxID_ANY);
//Unbind(wxEVT_MENU, &MainFrame::onRunGenUpload, this, Id::MRunGenUpload, wxID_ANY);
//Unbind(wxEVT_MENU, &MainFrame::onRunGenStart, this, Id::MRunGenStart, wxID_ANY);
//Unbind(wxEVT_MENU, &MainFrame::onRunCompile, this, Id::MCodeCompile, wxID_ANY);
//Unbind(wxEVT_MENU, &MainFrame::onCodeDisassemble, this, Id::MCodeDisassemble, wxID_ANY);
event.Skip(); event.Skip();
} }
void MainFrame::onMeasureTimer([[maybe_unused]] wxTimerEvent&) // Measure timer tick handler
// Only called while connected and running.
void MainFrame::onMeasureTimer(wxTimerEvent&)
{ {
if (m_conv_result_log != nullptr) { if (m_conv_result_log) {
// We're meant to log
if (auto samples = m_device->continuous_read(); samples.size() > 0) { if (auto samples = m_device->continuous_read(); samples.size() > 0) {
for (auto& s : samples) { for (auto& s : samples) {
auto str = std::to_string(s); auto str = std::to_string(s);
@ -239,7 +267,8 @@ void MainFrame::onMeasureTimer([[maybe_unused]] wxTimerEvent&)
} }
} }
if (m_wav_clip != nullptr) { if (m_wav_clip) {
// Stream out next WAV chunk
auto size = m_device->get_buffer_size(); auto size = m_device->get_buffer_size();
auto chunk = new stmdsp::adcsample_t[size]; auto chunk = new stmdsp::adcsample_t[size];
auto src = reinterpret_cast<uint16_t *>(m_wav_clip->next(size)); auto src = reinterpret_cast<uint16_t *>(m_wav_clip->next(size));
@ -249,7 +278,8 @@ void MainFrame::onMeasureTimer([[maybe_unused]] wxTimerEvent&)
delete[] chunk; delete[] chunk;
} }
if (m_status_bar && m_run_measure && m_run_measure->IsChecked()) { if (m_run_measure->IsChecked()) {
// Show execution time
m_status_bar->SetStatusText(wxString::Format(wxT("Execution time: %u cycles"), m_status_bar->SetStatusText(wxString::Format(wxT("Execution time: %u cycles"),
m_device->continuous_start_get_measurement())); m_device->continuous_start_get_measurement()));
} }
@ -300,7 +330,7 @@ wxString MainFrame::compileEditorCode()
wxFile file (m_temp_file_name, wxFile::write); wxFile file (m_temp_file_name, wxFile::write);
wxString file_text (file_header); wxString file_text (file_header);
file_text.Replace("$0", std::to_string(m_device != nullptr ? m_device->get_buffer_size() file_text.Replace("$0", std::to_string(m_device ? m_device->get_buffer_size()
: stmdsp::SAMPLES_MAX)); : stmdsp::SAMPLES_MAX));
file.Write(wxString(file_text) + m_text_editor->GetText()); file.Write(wxString(file_text) + m_text_editor->GetText());
file.Close(); file.Close();
@ -331,7 +361,7 @@ wxString MainFrame::compileEditorCode()
} }
} }
void MainFrame::onFileNew([[maybe_unused]] wxCommandEvent&) void MainFrame::onFileNew(wxCommandEvent&)
{ {
m_open_file_path = ""; m_open_file_path = "";
m_text_editor->SetText(file_content); m_text_editor->SetText(file_content);
@ -339,7 +369,7 @@ void MainFrame::onFileNew([[maybe_unused]] wxCommandEvent&)
m_status_bar->SetStatusText("Ready."); m_status_bar->SetStatusText("Ready.");
} }
void MainFrame::onFileOpen([[maybe_unused]] wxCommandEvent&) void MainFrame::onFileOpen(wxCommandEvent&)
{ {
wxFileDialog openDialog(this, "Open filter file", "", "", wxFileDialog openDialog(this, "Open filter file", "", "",
"C++ source file (*.cpp)|*.cpp", "C++ source file (*.cpp)|*.cpp",
@ -356,9 +386,15 @@ void MainFrame::onFileOpen([[maybe_unused]] wxCommandEvent&)
m_text_editor->DiscardEdits(); m_text_editor->DiscardEdits();
m_compile_output->ChangeValue(""); m_compile_output->ChangeValue("");
m_status_bar->SetStatusText("Ready."); m_status_bar->SetStatusText("Ready.");
} else {
m_status_bar->SetStatusText("Failed to read file contents.");
} }
delete[] buffer; delete[] buffer;
} else {
m_status_bar->SetStatusText("Failed to open file.");
} }
} else {
m_status_bar->SetStatusText("Ready.");
} }
} }
@ -375,8 +411,12 @@ void MainFrame::onFileOpenTemplate(wxCommandEvent& event)
m_text_editor->SetText(buffer); m_text_editor->SetText(buffer);
//m_text_editor->DiscardEdits(); //m_text_editor->DiscardEdits();
m_status_bar->SetStatusText("Ready."); m_status_bar->SetStatusText("Ready.");
} else {
m_status_bar->SetStatusText("Failed to read file contents.");
} }
delete[] buffer; delete[] buffer;
} else {
m_status_bar->SetStatusText("Ready.");
} }
} }
@ -401,7 +441,7 @@ void MainFrame::onFileSave(wxCommandEvent& ce)
} }
} }
void MainFrame::onFileSaveAs([[maybe_unused]] wxCommandEvent& ce) void MainFrame::onFileSaveAs(wxCommandEvent&)
{ {
if (m_text_editor->IsModified()) { if (m_text_editor->IsModified()) {
wxFileDialog saveDialog(this, "Save filter file", "", "", wxFileDialog saveDialog(this, "Save filter file", "", "",
@ -424,7 +464,7 @@ void MainFrame::onFileSaveAs([[maybe_unused]] wxCommandEvent& ce)
} }
} }
void MainFrame::onFileQuit([[maybe_unused]] wxCommandEvent&) void MainFrame::onFileQuit(wxCommandEvent&)
{ {
Close(true); Close(true);
} }
@ -433,15 +473,15 @@ void MainFrame::onRunConnect(wxCommandEvent& ce)
{ {
auto menuItem = dynamic_cast<wxMenuItem *>(ce.GetEventUserData()); auto menuItem = dynamic_cast<wxMenuItem *>(ce.GetEventUserData());
if (m_device == nullptr) { if (!m_device) {
stmdsp::scanner scanner; stmdsp::scanner scanner;
if (auto devices = scanner.scan(); devices.size() > 0) { if (auto devices = scanner.scan(); devices.size() > 0) {
m_device = new stmdsp::device(devices.front()); m_device = new stmdsp::device(devices.front());
if (m_device->connected()) { if (m_device->connected()) {
auto rate = m_device->get_sample_rate(); auto rate = m_device->get_sample_rate();
m_rate_select->SetSelection(rate); m_rate_select->SetSelection(rate);
m_rate_select->Enable();
updateMenuOptions();
menuItem->SetItemLabel("&Disconnect"); menuItem->SetItemLabel("&Disconnect");
m_status_bar->SetStatusText("Connected."); m_status_bar->SetStatusText("Connected.");
} else { } else {
@ -457,7 +497,7 @@ void MainFrame::onRunConnect(wxCommandEvent& ce)
} else { } else {
delete m_device; delete m_device;
m_device = nullptr; m_device = nullptr;
m_rate_select->Disable(); updateMenuOptions();
menuItem->SetItemLabel("&Connect"); menuItem->SetItemLabel("&Connect");
m_status_bar->SetStatusText("Disconnected."); m_status_bar->SetStatusText("Disconnected.");
} }
@ -468,26 +508,23 @@ void MainFrame::onRunStart(wxCommandEvent& ce)
auto menuItem = dynamic_cast<wxMenuItem *>(ce.GetEventUserData()); auto menuItem = dynamic_cast<wxMenuItem *>(ce.GetEventUserData());
if (!m_is_running) { if (!m_is_running) {
if (m_device != nullptr && m_device->connected()) { if (m_run_measure->IsChecked()) {
if (m_run_measure && m_run_measure->IsChecked()) {
m_device->continuous_start_measure(); m_device->continuous_start_measure();
m_measure_timer->StartOnce(1000); m_measure_timer->StartOnce(1000);
} else if (m_wav_clip != nullptr) { } else {
m_device->continuous_start(); if (m_device->is_siggening() && m_wav_clip) {
m_measure_timer->Start(m_device->get_buffer_size() * 500 / m_measure_timer->Start(m_device->get_buffer_size() * 500 /
srateNums[m_rate_select->GetSelection()]); srateNums[m_rate_select->GetSelection()]);
} else { } else if (m_conv_result_log) {
m_device->continuous_start();
m_measure_timer->Start(15); m_measure_timer->Start(15);
} }
m_device->continuous_start();
}
menuItem->SetItemLabel("&Stop"); menuItem->SetItemLabel("&Stop");
m_status_bar->SetStatusText("Running."); m_status_bar->SetStatusText("Running.");
m_is_running = true; m_is_running = true;
} else {
wxMessageBox("No device connected!", "Run", wxICON_WARNING);
m_status_bar->SetStatusText("Please connect.");
}
} else { } else {
m_device->continuous_stop(); m_device->continuous_stop();
m_measure_timer->Stop(); m_measure_timer->Stop();
@ -506,7 +543,7 @@ void MainFrame::onRunLogResults(wxCommandEvent& ce)
wxFD_SAVE | wxFD_OVERWRITE_PROMPT); wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal() != wxID_CANCEL) { if (dialog.ShowModal() != wxID_CANCEL) {
if (m_conv_result_log != nullptr) { if (m_conv_result_log) {
m_conv_result_log->Close(); m_conv_result_log->Close();
delete m_conv_result_log; delete m_conv_result_log;
m_conv_result_log = nullptr; m_conv_result_log = nullptr;
@ -516,16 +553,15 @@ void MainFrame::onRunLogResults(wxCommandEvent& ce)
} }
m_status_bar->SetStatusText("Ready."); m_status_bar->SetStatusText("Ready.");
} else if (m_conv_result_log != nullptr) { } else if (m_conv_result_log) {
m_conv_result_log->Close(); m_conv_result_log->Close();
delete m_conv_result_log; delete m_conv_result_log;
m_conv_result_log = nullptr; m_conv_result_log = nullptr;
} }
} }
void MainFrame::onRunEditBSize([[maybe_unused]] wxCommandEvent&) void MainFrame::onRunEditBSize(wxCommandEvent&)
{ {
if (m_device != nullptr && m_device->connected()) {
wxTextEntryDialog dialog (this, "Enter new buffer size (100-3000)", "Set Buffer Size"); wxTextEntryDialog dialog (this, "Enter new buffer size (100-3000)", "Set Buffer Size");
if (dialog.ShowModal() == wxID_OK) { if (dialog.ShowModal() == wxID_OK) {
if (wxString value = dialog.GetValue(); !value.IsEmpty()) { if (wxString value = dialog.GetValue(); !value.IsEmpty()) {
@ -544,27 +580,17 @@ void MainFrame::onRunEditBSize([[maybe_unused]] wxCommandEvent&)
} else { } else {
m_status_bar->SetStatusText("Ready."); m_status_bar->SetStatusText("Ready.");
} }
} else {
wxMessageBox("No device connected!", "Run", wxICON_WARNING);
m_status_bar->SetStatusText("Please connect.");
}
} }
void MainFrame::onToolbarSampleRate(wxCommandEvent& ce) void MainFrame::onToolbarSampleRate(wxCommandEvent& ce)
{ {
if (m_device != nullptr && m_device->connected()) {
auto combo = dynamic_cast<wxComboBox *>(ce.GetEventUserData()); auto combo = dynamic_cast<wxComboBox *>(ce.GetEventUserData());
m_device->set_sample_rate(combo->GetCurrentSelection()); m_device->set_sample_rate(combo->GetCurrentSelection());
m_status_bar->SetStatusText("Ready."); m_status_bar->SetStatusText("Ready.");
} else {
wxMessageBox("No device connected!", "Run", wxICON_WARNING);
m_status_bar->SetStatusText("Please connect.");
}
} }
void MainFrame::onRunGenUpload([[maybe_unused]] wxCommandEvent&) void MainFrame::onRunGenUpload(wxCommandEvent&)
{ {
if (m_device != nullptr && m_device->connected()) {
wxTextEntryDialog dialog (this, "Enter generator values below. Values must be whole numbers " wxTextEntryDialog dialog (this, "Enter generator values below. Values must be whole numbers "
"between zero and 4095.", "Enter Generator Values"); "between zero and 4095.", "Enter Generator Values");
if (dialog.ShowModal() == wxID_OK) { if (dialog.ShowModal() == wxID_OK) {
@ -613,16 +639,11 @@ void MainFrame::onRunGenUpload([[maybe_unused]] wxCommandEvent&)
} else { } else {
m_status_bar->SetStatusText("Ready."); m_status_bar->SetStatusText("Ready.");
} }
} else {
wxMessageBox("No device connected!", "Run", wxICON_WARNING);
m_status_bar->SetStatusText("Please connect.");
}
} }
void MainFrame::onRunGenStart(wxCommandEvent& ce) void MainFrame::onRunGenStart(wxCommandEvent& ce)
{ {
auto menuItem = dynamic_cast<wxMenuItem *>(ce.GetEventUserData()); auto menuItem = dynamic_cast<wxMenuItem *>(ce.GetEventUserData());
if (m_device != nullptr && m_device->connected()) {
if (menuItem->IsChecked()) { if (menuItem->IsChecked()) {
m_device->siggen_start(); m_device->siggen_start();
menuItem->SetItemLabel("Stop &generator"); menuItem->SetItemLabel("Stop &generator");
@ -630,51 +651,40 @@ void MainFrame::onRunGenStart(wxCommandEvent& ce)
m_device->siggen_stop(); m_device->siggen_stop();
menuItem->SetItemLabel("Start &generator"); menuItem->SetItemLabel("Start &generator");
} }
} else {
wxMessageBox("No device connected!", "Run", wxICON_WARNING);
m_status_bar->SetStatusText("Please connect.");
}
} }
void MainFrame::onRunUpload([[maybe_unused]] wxCommandEvent&) void MainFrame::onRunUpload(wxCommandEvent&)
{ {
if (auto file = compileEditorCode(); !file.IsEmpty()) { if (auto file = compileEditorCode(); !file.IsEmpty()) {
if (wxFileInputStream file_stream (file); file_stream.IsOk()) { if (wxFileInputStream file_stream (file); file_stream.IsOk()) {
auto size = file_stream.GetSize(); auto size = file_stream.GetSize();
auto buffer = new unsigned char[size]; auto buffer = new unsigned char[size];
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."); m_status_bar->SetStatusText("Code uploaded.");
} else {
wxMessageBox("No device connected!", "Run", wxICON_WARNING);
m_status_bar->SetStatusText("Please connect.");
}
} else { } else {
m_status_bar->SetStatusText("Couldn't load compiled code."); m_status_bar->SetStatusText("Couldn't load compiled code.");
} }
} }
} }
void MainFrame::onRunUnload([[maybe_unused]] wxCommandEvent&) void MainFrame::onRunUnload(wxCommandEvent&)
{ {
if (m_device != nullptr && m_device->connected()) {
m_device->unload_filter(); m_device->unload_filter();
m_status_bar->SetStatusText("Unloaded code."); m_status_bar->SetStatusText("Unloaded code.");
} else {
m_status_bar->SetStatusText("No device connected.");
}
} }
void MainFrame::onRunCompile([[maybe_unused]] wxCommandEvent&) void MainFrame::onRunCompile(wxCommandEvent&)
{ {
compileEditorCode(); compileEditorCode();
} }
void MainFrame::onCodeDisassemble([[maybe_unused]] wxCommandEvent&) void MainFrame::onCodeDisassemble(wxCommandEvent&)
{ {
if (!m_temp_file_name.IsEmpty()) {
auto output = m_temp_file_name + ".asm.log"; auto output = m_temp_file_name + ".asm.log";
wxString command = wxString("arm-none-eabi-objdump -d --no-show-raw-insn ") + m_temp_file_name + ".orig.o" wxString command = wxString("arm-none-eabi-objdump -d --no-show-raw-insn ") +
m_temp_file_name + ".orig.o" // +
" > " + output + " 2>&1"; " > " + output + " 2>&1";
if (system(command.ToAscii()) == 0) { if (system(command.ToAscii()) == 0) {
@ -683,7 +693,11 @@ void MainFrame::onCodeDisassemble([[maybe_unused]] wxCommandEvent&)
m_compile_output->GetNumberOfLines())); m_compile_output->GetNumberOfLines()));
} else { } else {
m_compile_output->ChangeValue(""); m_compile_output->ChangeValue("");
m_status_bar->SetStatusText("Failed to load disassembly (code compiled?)."); m_status_bar->SetStatusText("Failed to load disassembly.");
}
} else {
m_compile_output->ChangeValue("");
m_status_bar->SetStatusText("Need to compile code before analyzing.");
} }
} }
@ -705,3 +719,15 @@ wxMenu *MainFrame::loadTemplates()
return menu; return menu;
} }
void MainFrame::updateMenuOptions()
{
bool connected = m_device != nullptr;
m_menu_bar->Enable(MRunStart, connected);
m_menu_bar->Enable(MRunUpload, connected);
m_menu_bar->Enable(MRunUnload, connected);
m_menu_bar->Enable(MRunEditBSize, connected);
m_menu_bar->Enable(MRunGenUpload, connected);
m_menu_bar->Enable(MRunGenStart, connected);
m_rate_select->Enable(connected);
}

@ -61,7 +61,9 @@ public:
void onMeasureTimer(wxTimerEvent& te); void onMeasureTimer(wxTimerEvent& te);
private: private:
// Set to true if connected and running
bool m_is_running = false; bool m_is_running = false;
wxComboBox *m_device_combo = nullptr; wxComboBox *m_device_combo = nullptr;
wxStyledTextCtrl *m_text_editor = nullptr; wxStyledTextCtrl *m_text_editor = nullptr;
wxTextCtrl *m_compile_output = nullptr; wxTextCtrl *m_compile_output = nullptr;
@ -71,17 +73,30 @@ private:
wxStatusBar *m_status_bar = nullptr; wxStatusBar *m_status_bar = nullptr;
wxMenuBar *m_menu_bar = nullptr; wxMenuBar *m_menu_bar = nullptr;
wxComboBox *m_rate_select = nullptr; wxComboBox *m_rate_select = nullptr;
// File handle for logging output samples
// Not null when logging is enabled
wxFileOutputStream *m_conv_result_log = nullptr; wxFileOutputStream *m_conv_result_log = nullptr;
// File path of currently opened file
// Empty if new file
wxString m_open_file_path; wxString m_open_file_path;
// File path for temporary files (e.g. compiled ELF)
// Set by compile action
wxString m_temp_file_name; wxString m_temp_file_name;
// Device interface
// Not null if connected
stmdsp::device *m_device = nullptr; stmdsp::device *m_device = nullptr;
// WAV data for signal generator
// Not null when a WAV is loaded
wav::clip *m_wav_clip = nullptr; wav::clip *m_wav_clip = nullptr;
bool tryDevice(); bool tryDevice();
void prepareEditor(); void prepareEditor();
wxString compileEditorCode(); wxString compileEditorCode();
wxMenu *loadTemplates(); wxMenu *loadTemplates();
// Updates control availabilities based on device connection
void updateMenuOptions();
}; };
#endif // WXMAIN_HPP_ #endif // WXMAIN_HPP_

Loading…
Cancel
Save