Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux work: uint32_t + GTK+ GUI #21

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
27 changes: 27 additions & 0 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: C/C++ CI

on:
push:
branches: [ linux ]
pull_request:
branches: [ linux ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Install gtkmm
run: sudo apt-get install libgtkmm-3.0-dev
- name: make
run: |
cd ArduinoFloppyReader/ArduinoFloppyReader
make all
- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: GTK GUI
path: ArduinoFloppyReader/ArduinoFloppyReader/GarduinoReaderWriter

5 changes: 5 additions & 0 deletions ArduinoFloppyReader/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ bld/
[Oo]bj/
[Ll]og/

ArduinoReaderWriter
GarduinoReaderWriter
*~
.vscode/

# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
Expand Down
608 changes: 608 additions & 0 deletions ArduinoFloppyReader/ArduinoFloppyReader/Garduino.glade

Large diffs are not rendered by default.

386 changes: 386 additions & 0 deletions ArduinoFloppyReader/ArduinoFloppyReader/GarduinoReaderWriter.cpp

Large diffs are not rendered by default.

154 changes: 154 additions & 0 deletions ArduinoFloppyReader/ArduinoFloppyReader/WarduinoReaderWriter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#include <wx/wx.h>
#include <iostream>
#include <thread>
#include <vector>
#include <string>
#include "../lib/ArduinoInterface.h"
#include "../lib/ADFWriter.h"

class WarduinoApp : public wxApp
{
public:
virtual bool OnInit();
};

class MyFrame : public wxFrame
{
public:
MyFrame();

private:
// wxTextCtrl *textctrl;
wxComboBox *portCombo;
wxButton *diagnosticsButton;
wxButton *readButton;
wxButton *writeButton;
void OnDiagnostics(wxCommandEvent &WXUNUSED(event));
void run_diagnostics(std::string serial);
void showStatus(bool isError, std::string status);
bool showQuestion(bool isQuestion, const std::string question);
};

enum
{
BUTTON_Diagnostics = wxID_HIGHEST + 1,
COMBO_Ports = BUTTON_Diagnostics + 1,
};

bool WarduinoApp::OnInit()
{
MyFrame *frame = new MyFrame();
frame->Show(true);
return true;
}
MyFrame::MyFrame()
: wxFrame(NULL, wxID_ANY, "Arduino Amiga Floppy Disk Reader and Writer", wxDefaultPosition, wxSize(600, 650))
{
CreateStatusBar();
SetStatusText("Welcome to wxWidgets!");

wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *hbox1 = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *hbox2 = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *hbox3 = new wxBoxSizer(wxHORIZONTAL);
wxStaticBox *frameDiag = new wxStaticBox(this, wxID_ANY, "Arduino Configuration", wxDefaultPosition, wxSize(600, 200));
wxStaticBox *frameCopy = new wxStaticBox(this, wxID_ANY, "Copy Disk to ADF or SCP File (read)", wxDefaultPosition, wxSize(600, 200));
wxStaticBox *frameWrite = new wxStaticBox(this, wxID_ANY, "Write ADF File to Disk (write)", wxDefaultPosition, wxSize(600, 200));

auto arduinoLabel = new wxStaticText(this, -1, "Arduino connected on");
frameDiag->SetSizer(hbox1);
frameCopy->SetSizer(hbox2);
frameWrite->SetSizer(hbox3);
hbox1->Add(arduinoLabel);
vbox->Add(frameDiag, 1);
vbox->Add(frameCopy, 1);
vbox->Add(frameWrite, 1);
auto saveLabel = new wxStaticText(this, -1, "Save to");
hbox2->Add(saveLabel);
auto writeLabel = new wxStaticText(this, -1, "ADF File");
hbox3->Add(writeLabel);
this->SetSizer(vbox);

portCombo = new wxComboBox(this, COMBO_Ports);
hbox1->Add(portCombo);
std::vector<std::wstring> portList;
ArduinoFloppyReader::ArduinoInterface::enumeratePorts(portList);
for (std::wstring port : portList)
{
const std::string portString(port.begin(), port.end());
portCombo->Append(portString);
}
if (portList.size() > 0) {
portCombo->SetSelection(0);
}
diagnosticsButton = new wxButton(frameDiag, BUTTON_Diagnostics, "Run Diagnostics");
Connect(BUTTON_Diagnostics, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(MyFrame::OnDiagnostics));
hbox1->Add(diagnosticsButton);
Centre();
Show(true);
}
void MyFrame::OnDiagnostics(wxCommandEvent &WXUNUSED(event))
{
auto serial = this->portCombo->GetValue();
run_diagnostics(serial.c_str().AsChar());
}

bool MyFrame::showQuestion(bool isQuestion, const std::string question)
{
long style = (wxOK | wxCANCEL);
if (isQuestion)
{
style = (wxYES | wxNO);
}

wxMessageDialog dial(NULL, question.c_str(), wxT("Question"), style | wxICON_QUESTION);
auto Answer = dial.ShowModal();
// Process user choice
bool isYes = false;
switch (Answer)
{
case (wxID_OK):
isYes = true;
break;
case (wxID_CANCEL):
std::cout << "Cancel clicked." << std::endl;
break;
case (wxID_YES):
std::cout << "Yes clicked." << std::endl;
isYes = true;
break;
case (wxID_NO):
std::cout << "No clicked." << std::endl;
break;
default:
std::cout << "Unexpected answer: " << Answer << std::endl;
break;
}
return isYes;
}

void MyFrame::showStatus(bool isError, std::string status)
{
std::string strLine;

if (isError)
strLine = "DIAGNOSTICS FAILED: ";
strLine += (status + "\n").c_str();
std::cerr << strLine;
auto statusBar = GetStatusBar();
statusBar->SetStatusText(strLine);
}

void MyFrame::run_diagnostics(std::string serial)
{
ArduinoFloppyReader::ADFWriter writer;
writer.runDiagnostics(
std::wstring(serial.begin(), serial.end()), [this, serial](bool isError, const std::string message) -> void
{ this->showStatus(isError, message); },
[this, serial](bool isQuestion, const std::string question) -> bool
{
return this->showQuestion(isQuestion, question);
});
}

wxIMPLEMENT_APP(WarduinoApp);
29 changes: 24 additions & 5 deletions ArduinoFloppyReader/ArduinoFloppyReader/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
CC = g++

# define any compile-time flags
CFLAGS = -Wall -std=c++14 -Wno-psabi -O3
CFLAGS = -Wall -std=c++14 -Wno-psabi -O0 -g
GCFLAGS = ${CFLAGS} $(shell pkg-config --cflags gtkmm-3.0)
WCFLAGS = ${CFLAGS} $(shell wx-config --cflags)

# define any directories containing header files other than /usr/include
#
Expand All @@ -19,14 +21,19 @@ INCLUDES = -I../lib
# if I wanted to include libraries not in /usr/lib I'd specify
# their path using -Lpath, something like:
LFLAGS = -L../lib
GLFLAGS = ${LFLAGS} $(shell pkg-config --libs gtkmm-3.0)
WLFLAGS = ${LFLAGS} $(shell wx-config --libs)

# define any libraries to link into executable:
# if I want to link in libraries (libx.so or libx.a) I use the -llibname
# option, something like (this will link in libmylib.so and libm.so:
LIBS =

# define the C source files
SRCS = Main.cpp ../lib/SerialIO.cpp ../lib/RotationExtractor.cpp ../lib/ArduinoInterface.cpp ../lib/ADFWriter.cpp
# define the C surce files
COMMON_SRC = ../lib/SerialIO.cpp ../lib/RotationExtractor.cpp ../lib/ArduinoInterface.cpp ../lib/ADFWriter.cpp
SRCS = Main.cpp ${COMMON_SRC}
GSRCS = GarduinoReaderWriter.cpp ${COMMON_SRC}
WSRCS = WarduinoReaderWriter.cpp ${COMMON_SRC}

# define the C object files
#
Expand All @@ -37,10 +44,16 @@ SRCS = Main.cpp ../lib/SerialIO.cpp ../lib/RotationExtractor.cpp ../lib/ArduinoI
# with the .o suffix
#
OBJS = $(SRCS:.c=.o)
GOBJS = $(GSRCS:.c=.o)
WOBJS = $(WSRCS:.c=.o)

# define the executable file
MAIN = ArduinoReaderWriter

#GUI
GARDUINO = GarduinoReaderWriter
WARDUINO = WarduinoReaderWriter

#
# The following part of the makefile is generic; it can be used to
# build any executable just by changing the definitions above and by
Expand All @@ -49,12 +62,18 @@ MAIN = ArduinoReaderWriter

.PHONY: depend clean

all: $(MAIN)
all: $(MAIN) $(GARDUINO) $(WARDUINO)
@echo ArduinoReaderWriter ready

$(MAIN): $(OBJS)
$(CC) $(CFLAGS) $(INCLUDES) -o $(MAIN) $(OBJS) $(LFLAGS) $(LIBS)

$(GARDUINO): $(GOBJS) makefile Garduino.glade
$(CC) $(GCFLAGS) $(INCLUDES) -o $(GARDUINO) $(GOBJS) $(GLFLAGS) $(LIBS)

$(WARDUINO): $(WOBJS) makefile
$(CC) $(WCFLAGS) $(INCLUDES) -o $(WARDUINO) $(WOBJS) $(WLFLAGS) $(LIBS)

# this is a suffix replacement rule for building .o's from .c's
# it uses automatic variables $<: the name of the prerequisite of
# the rule(a .c file) and $@: the name of the target of the rule (a .o file)
Expand All @@ -63,7 +82,7 @@ $(MAIN): $(OBJS)
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@

clean:
$(RM) *.o *~ $(MAIN)
$(RM) *.o *~ $(MAIN) ${GARDUINO}

depend: $(SRCS)
makedepend $(INCLUDES) $^
Expand Down
5 changes: 4 additions & 1 deletion ArduinoFloppyReader/ArduinoFloppyReader/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ This is a console application

It should build with Visual Studio 2019

It will also compile on some distros of Linux.
It will also compile on some distros of Linux.
To compile/run the GTK+ GUI (requires gtkmm-3.x):
make all; ./GarduinoReaderWriter


It has been tested on Raspberry Pi OS (Raspbian - Debian-based) and can be compiled using the provided makefile
Loading