diff --git a/BrainATUMtome/BrainATUMtome.pro b/BrainATUMtome/BrainATUMtome.pro index 4fcf917..53ddb8e 100644 --- a/BrainATUMtome/BrainATUMtome.pro +++ b/BrainATUMtome/BrainATUMtome.pro @@ -27,11 +27,13 @@ CONFIG += c++11 SOURCES += \ main.cpp \ mainwindow.cpp \ - eventlog.cpp + eventlog.cpp \ + epos.cpp HEADERS += \ mainwindow.h \ - eventlog.h + eventlog.h \ + epos.h FORMS += \ mainwindow.ui diff --git a/BrainATUMtome/epos.cpp b/BrainATUMtome/epos.cpp new file mode 100644 index 0000000..74676e6 --- /dev/null +++ b/BrainATUMtome/epos.cpp @@ -0,0 +1,28 @@ +#include "epos.h" + +Epos::Epos(QObject *parent) : QObject(parent) +{ + +} + + +void Epos::on_uirequest_velocity(int motorid, int velocity) +{ + QString textMotor = (motorid == MOTORID_LOWER) ? "lower" : "upper"; + QString textState = "off"; + if (velocity > 0) { + textState = "is on, direction ccw, velocity " + QString::number(abs(velocity)); + } + else if (velocity < 0) { + textState = "is on, direction cw, velocity " + QString::number(abs(velocity)); + } + + emit log(EventLogType::Notify, "EPOS :: " + textMotor + " motor " + textState); +} + + +void Epos::on_uirequest_tension(bool state) +{ + QString textState = (state) ? "on" : "off"; + emit log(EventLogType::Notify, "EPOS :: tension motor is " + textState); +} diff --git a/BrainATUMtome/epos.h b/BrainATUMtome/epos.h new file mode 100644 index 0000000..d0b3822 --- /dev/null +++ b/BrainATUMtome/epos.h @@ -0,0 +1,26 @@ +#ifndef EPOS_H +#define EPOS_H + +#include + +#include "eventlog.h" + +class Epos : public QObject +{ + Q_OBJECT +public: + explicit Epos(QObject *parent = nullptr); + +private: + const int MOTORID_LOWER = 0; + const int MOTORID_UPPER = 1; + +public slots: + void on_uirequest_velocity(int motorid, int velocity); + void on_uirequest_tension(bool state); + +signals: + void log(EventLogType type, const QString &message); +}; + +#endif // EPOS_H diff --git a/BrainATUMtome/mainwindow.cpp b/BrainATUMtome/mainwindow.cpp index 84742c1..3d36b46 100644 --- a/BrainATUMtome/mainwindow.cpp +++ b/BrainATUMtome/mainwindow.cpp @@ -4,8 +4,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), - m_epos_velocity_lower(0), - m_epos_velocity_upper(0), + m_driverEpos(nullptr), + m_epos_direction_lower(0), + m_epos_direction_upper(0), m_microtome_cuttingSpeed(0), m_microtome_returnSpeed(0), m_microtome_feedStep(0), @@ -14,11 +15,7 @@ MainWindow::MainWindow(QWidget *parent) : { ui->setupUi(this); - connect(ui->radioButton_epos_lower_off, &QRadioButton::toggled, this, &MainWindow::on_eposLowerToggled); - connect(ui->radioButton_epos_lower_ccw, &QRadioButton::toggled, this, &MainWindow::on_eposLowerToggled); - connect(ui->radioButton_epos_lower_cw, &QRadioButton::toggled, this, &MainWindow::on_eposLowerToggled); - - + configure_epos(); } MainWindow::~MainWindow() @@ -27,29 +24,164 @@ MainWindow::~MainWindow() } -void MainWindow::on_eposLowerToggled(bool checked) +void MainWindow::configure_epos() +{ + m_driverEpos = new Epos(this); + connect(m_driverEpos, &Epos::log, ui->widget_board, &EventLog::on_log); + connect(this, &MainWindow::uirequest_epos_velocity, m_driverEpos, &Epos::on_uirequest_velocity); + connect(this, &MainWindow::uirequest_epos_tension, m_driverEpos, &Epos::on_uirequest_tension); + + connect(ui->radioButton_epos_lower_off, &QRadioButton::toggled, this, &MainWindow::on_radioButtonsEposLowerToggled); + connect(ui->radioButton_epos_lower_ccw, &QRadioButton::toggled, this, &MainWindow::on_radioButtonsEposLowerToggled); + connect(ui->radioButton_epos_lower_cw, &QRadioButton::toggled, this, &MainWindow::on_radioButtonsEposLowerToggled); + + connect(ui->radioButton_epos_upper_off, &QRadioButton::toggled, this, &MainWindow::on_radioButtonsEposUpperToggled); + connect(ui->radioButton_epos_upper_ccw, &QRadioButton::toggled, this, &MainWindow::on_radioButtonsEposUpperToggled); + connect(ui->radioButton_epos_upper_cw, &QRadioButton::toggled, this, &MainWindow::on_radioButtonsEposUpperToggled); + + connect(ui->radioButton_epos_tension_off, &QRadioButton::toggled, this, &MainWindow::on_radioButtonsEposTensionToggled); + connect(ui->radioButton_epos_tension_on, &QRadioButton::toggled, this, &MainWindow::on_radioButtonsEposTensionToggled); + + connect(ui->radioButton_epos_sync_off, &QRadioButton::toggled, this, &MainWindow::on_radioButtonsEposSyncToggled); + connect(ui->radioButton_epos_sync_on, &QRadioButton::toggled, this, &MainWindow::on_radioButtonsEposSyncToggled); +} + + +void MainWindow::on_radioButtonsEposLowerToggled(bool checked) { if (!checked) return; - emit ui->spinBox_epos_lower_velocity->editingFinished(); - if (ui->radioButton_epos_lower_off->isChecked()) { - ui->widget_board->on_log(EventLogType::Notify, "LOWER OFF"); - m_epos_velocity_lower = 0; + + m_epos_direction_lower = 0; + } else if (ui->radioButton_epos_lower_ccw->isChecked()) { - ui->widget_board->on_log(EventLogType::Notify, "LOWER CCW"); + + m_epos_direction_lower = 1; + } else if (ui->radioButton_epos_lower_cw->isChecked()) { - ui->widget_board->on_log(EventLogType::Notify, "LOWER CW"); - m_epos_velocity_lower = -m_epos_velocity_lower; + + m_epos_direction_lower = -1; + } - ui->widget_board->on_log(EventLogType::Respond, "EPOS :: velocity lower " + QString::number(m_epos_velocity_lower)); + emit ui->spinBox_epos_lower_velocity->editingFinished(); } + void MainWindow::on_spinBox_epos_lower_velocity_editingFinished() { - m_epos_velocity_lower = ui->spinBox_epos_lower_velocity->value(); + int velocity_value = ui->spinBox_epos_lower_velocity->value() * m_epos_direction_lower; + emit uirequest_epos_velocity(0, velocity_value); + + if (ui->radioButton_epos_sync_on->isChecked()) { + ui->spinBox_epos_upper_velocity->setValue(ui->spinBox_epos_lower_velocity->value()); + emit uirequest_epos_velocity(1, velocity_value); + } +} + + +void MainWindow::on_radioButtonsEposUpperToggled(bool checked) +{ + if (!checked) + return; + + if (ui->radioButton_epos_upper_off->isChecked()) { + + m_epos_direction_upper = 0; + + } + else if (ui->radioButton_epos_upper_ccw->isChecked()) { + + m_epos_direction_upper = 1; + + } + else if (ui->radioButton_epos_upper_cw->isChecked()) { + + m_epos_direction_upper = -1; + + } + + emit ui->spinBox_epos_upper_velocity->editingFinished(); +} + + + +void MainWindow::on_spinBox_epos_upper_velocity_editingFinished() +{ + int velocity_value = ui->spinBox_epos_upper_velocity->value() * m_epos_direction_upper; + emit uirequest_epos_velocity(1, velocity_value); + + if (ui->radioButton_epos_sync_on->isChecked()) { + ui->spinBox_epos_lower_velocity->setValue(ui->spinBox_epos_upper_velocity->value()); + emit uirequest_epos_velocity(0, velocity_value); + } +} + + +void MainWindow::on_radioButtonsEposTensionToggled(bool checked) +{ + if (!checked) + return; + + if (ui->radioButton_epos_tension_off->isChecked()) { + emit uirequest_epos_tension(false); + } + else if (ui->radioButton_epos_tension_on->isChecked()) { + emit uirequest_epos_tension(true); + } +} + + +void MainWindow::on_radioButtonsEposSyncToggled(bool checked) +{ + if (!checked) + return; + + if (ui->radioButton_epos_sync_off->isChecked()) { + + ui->widget_board->on_log(EventLogType::Notify, "EPOS :: sync mode is off"); + + // switch off motors + ui->radioButton_epos_lower_off->setChecked(true); + ui->radioButton_epos_upper_off->setChecked(true); + ui->radioButton_epos_tension_off->setChecked(true); + + // enable async mode + enable_epos_radioButtons(true); + } + else if (ui->radioButton_epos_sync_on->isChecked()) { + + ui->widget_board->on_log(EventLogType::Notify, "EPOS :: sync mode is on"); + + int velocity_min = qMin(ui->spinBox_epos_lower_velocity->value(), ui->spinBox_epos_upper_velocity->value()); + ui->spinBox_epos_lower_velocity->setValue(velocity_min); + ui->spinBox_epos_upper_velocity->setValue(velocity_min); + + // switch on motors + ui->radioButton_epos_lower_cw->setChecked(true); + ui->radioButton_epos_upper_cw->setChecked(true); + ui->radioButton_epos_tension_on->setChecked(true); + + // enable sync mode + enable_epos_radioButtons(false); + } +} + + +void MainWindow::enable_epos_radioButtons(bool state) +{ + ui->radioButton_epos_lower_off->setEnabled(state); + ui->radioButton_epos_lower_ccw->setEnabled(state); + ui->radioButton_epos_lower_cw->setEnabled(state); + + ui->radioButton_epos_upper_off->setEnabled(state); + ui->radioButton_epos_upper_ccw->setEnabled(state); + ui->radioButton_epos_upper_cw->setEnabled(state); + + ui->radioButton_epos_tension_off->setEnabled(state); + ui->radioButton_epos_tension_on->setEnabled(state); } diff --git a/BrainATUMtome/mainwindow.h b/BrainATUMtome/mainwindow.h index 1f82b0d..dc56d78 100644 --- a/BrainATUMtome/mainwindow.h +++ b/BrainATUMtome/mainwindow.h @@ -5,6 +5,7 @@ #include #include "eventlog.h" +#include "epos.h" namespace Ui { class MainWindow; @@ -20,18 +21,27 @@ class MainWindow : public QMainWindow private: Ui::MainWindow *ui; - int m_epos_velocity_lower; - int m_epos_velocity_upper; + + Epos *m_driverEpos; + + int m_epos_direction_lower; + int m_epos_direction_upper; int m_microtome_cuttingSpeed; int m_microtome_returnSpeed; int m_microtome_feedStep; int m_microtome_sections; int m_microtome_advanceRemaining; -private slots: - void on_eposLowerToggled(bool checked); + void configure_epos(); + void enable_epos_radioButtons(bool state); +private slots: + void on_radioButtonsEposLowerToggled(bool checked); + void on_radioButtonsEposUpperToggled(bool checked); + void on_radioButtonsEposTensionToggled(bool checked); + void on_radioButtonsEposSyncToggled(bool checked); void on_spinBox_epos_lower_velocity_editingFinished(); + void on_spinBox_epos_upper_velocity_editingFinished(); signals: void uirequest_epos_velocity(int motorid, int velocity);