upload device uploads code in editor

pull/3/head
Clyne 4 years ago
parent 02ef389567
commit dccf7ed52d

@ -0,0 +1,91 @@
#include "wxmain.hpp"
#include <wx/filename.h>
void MainFrame::prepareEditor()
{
m_text_editor->SetLexer(wxSTC_LEX_CPP);
m_text_editor->SetMarginWidth(0, 30);
m_text_editor->SetMarginType(0, wxSTC_MARGIN_NUMBER);
wxFont::AddPrivateFont("./Hack-Regular.ttf");
m_text_editor->StyleSetFaceName(wxSTC_STYLE_DEFAULT, "Hack");
m_text_editor->StyleClearAll();
m_text_editor->SetTabWidth(4);
m_text_editor->StyleSetForeground(wxSTC_STYLE_LINENUMBER, wxColor(75, 75, 75));
m_text_editor->StyleSetBackground(wxSTC_STYLE_LINENUMBER, wxColor(220, 220, 220));
m_text_editor->StyleSetForeground(wxSTC_C_STRING, wxColour(150,0,0));
m_text_editor->StyleSetForeground(wxSTC_C_PREPROCESSOR, wxColour(165,105,0));
m_text_editor->StyleSetForeground(wxSTC_C_IDENTIFIER, wxColour(40,0,60));
m_text_editor->StyleSetForeground(wxSTC_C_NUMBER, wxColour(0,150,0));
m_text_editor->StyleSetForeground(wxSTC_C_CHARACTER, wxColour(150,0,0));
m_text_editor->StyleSetForeground(wxSTC_C_WORD, wxColour(0,0,150));
m_text_editor->StyleSetForeground(wxSTC_C_WORD2, wxColour(0,150,0));
m_text_editor->StyleSetForeground(wxSTC_C_COMMENT, wxColour(150,150,150));
m_text_editor->StyleSetForeground(wxSTC_C_COMMENTLINE, wxColour(150,150,150));
m_text_editor->StyleSetForeground(wxSTC_C_COMMENTDOC, wxColour(150,150,150));
m_text_editor->StyleSetForeground(wxSTC_C_COMMENTDOCKEYWORD, wxColour(0,0,200));
m_text_editor->StyleSetForeground(wxSTC_C_COMMENTDOCKEYWORDERROR, wxColour(0,0,200));
m_text_editor->StyleSetBold(wxSTC_C_WORD, true);
m_text_editor->StyleSetBold(wxSTC_C_WORD2, true);
m_text_editor->StyleSetBold(wxSTC_C_COMMENTDOCKEYWORD, true);
// a sample list of keywords, I haven't included them all to keep it short...
m_text_editor->SetKeyWords(0,
wxT("return for while do break continue if else goto"));
m_text_editor->SetKeyWords(1,
wxT("void char short int long float double unsigned signed "
"volatile static const constexpr constinit consteval "
"virtual final noexcept public private protected"));
m_text_editor->SetText("void process_data(adcsample_t *samples, unsigned int size)\n{\n\t\n}\n");
}
static const char *makefile_text = R"make(
all:
@arm-none-eabi-g++ -x c++ -mcpu=cortex-m4 -mthumb -Os --specs=nosys.specs -nostartfiles -fPIE -c $0 -o $0.o
@arm-none-eabi-ld -shared -n -N -z max-page-size=512 -Ttext-segment=0 \
$0.o -o $0.so
@arm-none-eabi-strip -s -S --strip-unneeded $0.so
@arm-none-eabi-objcopy --remove-section .dynsym \
--remove-section .dynstr \
--remove-section .dynamic \
--remove-section .hash \
--remove-section .ARM.exidx \
--remove-section .ARM.attributes \
--remove-section .comment \
$0.so
)make";
static const char *file_header = R"cpp(
#include <cstdint>
using adcsample_t = uint16_t;
__attribute__((section(".process_data"))) void process_data(adcsample_t *samples, unsigned int size);
// End stmdspgui header code
)cpp";
wxString MainFrame::compileEditorCode()
{
auto file_text = wxString(file_header) + m_text_editor->GetText();
auto file_name = wxFileName::CreateTempFileName("stmdspgui");
wxFile file (file_name, wxFile::write);
file.Write(file_text);
file.Close();
wxFile makefile (file_name + "make", wxFile::write);
wxString make_text (makefile_text);
make_text.Replace("$0", file_name);
makefile.Write(make_text);
makefile.Close();
wxString make_command = wxString("make -C ") + file_name.BeforeLast('/') +
" -f " + file_name + "make";
if (system(make_command.ToAscii()) == 0)
return file_name + ".so";
else
return "";
}

@ -29,6 +29,7 @@ class MainFrame : public wxFrame
bool m_is_rendering = false;
wxTimer *m_render_timer = nullptr;
wxComboBox *m_device_combo = nullptr;
wxStyledTextCtrl *m_text_editor = nullptr;
const wxRect m_clipping_region = {20, 500, 600, 360};
@ -36,47 +37,18 @@ class MainFrame : public wxFrame
std::future<std::vector<stmdsp::adcsample_t>> m_device_samples_future;
std::vector<stmdsp::adcsample_t> m_device_samples;
void prepareEditor();
wxString compileEditorCode();
public:
MainFrame() : wxFrame(nullptr, -1, "Hello world", wxPoint(50, 50), wxSize(640, 880))
{
new wxStaticText(this, Id::Welcome, "Welcome to the GUI.", wxPoint(20, 20));
new wxButton(this, Id::Single, "Single", wxPoint(20, 60));
new wxButton(this, Id::UploadFilter, "Upload Filter", wxPoint(120, 60));
auto stc = new wxStyledTextCtrl(this, wxID_ANY, wxPoint(20, 100), wxSize(600, 400));
stc->SetLexer(wxSTC_LEX_CPP);
stc->SetMarginWidth(0, 30);
stc->SetMarginType(0, wxSTC_MARGIN_NUMBER);
wxFont::AddPrivateFont("./Hack-Regular.ttf");
stc->StyleSetFaceName(wxSTC_STYLE_DEFAULT, "Hack");
stc->StyleClearAll();
stc->SetTabWidth(4);
stc->StyleSetForeground(wxSTC_STYLE_LINENUMBER, wxColor(75, 75, 75));
stc->StyleSetBackground(wxSTC_STYLE_LINENUMBER, wxColor(220, 220, 220));
stc->StyleSetForeground (wxSTC_C_STRING, wxColour(150,0,0));
stc->StyleSetForeground (wxSTC_C_PREPROCESSOR, wxColour(165,105,0));
stc->StyleSetForeground (wxSTC_C_IDENTIFIER, wxColour(40,0,60));
stc->StyleSetForeground (wxSTC_C_NUMBER, wxColour(0,150,0));
stc->StyleSetForeground (wxSTC_C_CHARACTER, wxColour(150,0,0));
stc->StyleSetForeground (wxSTC_C_WORD, wxColour(0,0,150));
stc->StyleSetForeground (wxSTC_C_WORD2, wxColour(0,150,0));
stc->StyleSetForeground (wxSTC_C_COMMENT, wxColour(150,150,150));
stc->StyleSetForeground (wxSTC_C_COMMENTLINE, wxColour(150,150,150));
stc->StyleSetForeground (wxSTC_C_COMMENTDOC, wxColour(150,150,150));
stc->StyleSetForeground (wxSTC_C_COMMENTDOCKEYWORD, wxColour(0,0,200));
stc->StyleSetForeground (wxSTC_C_COMMENTDOCKEYWORDERROR, wxColour(0,0,200));
stc->StyleSetBold(wxSTC_C_WORD, true);
stc->StyleSetBold(wxSTC_C_WORD2, true);
stc->StyleSetBold(wxSTC_C_COMMENTDOCKEYWORD, true);
// a sample list of keywords, I haven't included them all to keep it short...
stc->SetKeyWords(0,
wxT("return for while do break continue if else goto"));
stc->SetKeyWords(1,
wxT("void char short int long float double unsigned signed "
"volatile static const constexpr constinit consteval "
"virtual final noexcept public private protected"));
m_text_editor = new wxStyledTextCtrl(this, wxID_ANY, wxPoint(20, 100), wxSize(600, 400));
prepareEditor();
m_device_combo = new wxComboBox(this, Id::SelectDevice, "", wxPoint(470, 20), wxSize(150, 30));
m_device_combo->SetEditable(false);
@ -150,10 +122,11 @@ public:
}
void onUploadPressed(wxCommandEvent& ce) {
wxFileDialog dialog (this, "Select filter to upload", "", "", "*.so",
wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (dialog.ShowModal() != wxID_CANCEL) {
if (wxFileInputStream file_stream (dialog.GetPath()); file_stream.IsOk()) {
//wxFileDialog dialog (this, "Select filter to upload", "", "", "*.so",
// wxFD_OPEN | wxFD_FILE_MUST_EXIST);
//if (dialog.ShowModal() != wxID_CANCEL) {
if (auto file = compileEditorCode(); !file.IsEmpty()) {
if (wxFileInputStream file_stream (/*dialog.GetPath()*/file); file_stream.IsOk()) {
auto size = file_stream.GetSize();
auto buffer = new unsigned char[size];
auto device = new stmdsp::device(m_device_combo->GetStringSelection().ToStdString());

Loading…
Cancel
Save