Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
emit color with log message
Browse files Browse the repository at this point in the history
  • Loading branch information
MPIBR-tushevg committed Jan 6, 2019
1 parent 3512e50 commit 0b72578
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 49 deletions.
8 changes: 4 additions & 4 deletions BrainATUMtome/epos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void Epos::open(int motorid,
return;
}

emit log(EventLogType::Notify, "Epos :: device is open on port " + QString(portName));
emit log(Qt::black, "Epos :: device is open on port " + QString(portName));

setVelocityMode(keyHandle);
}
Expand Down Expand Up @@ -209,7 +209,7 @@ void Epos::throwError(const QString &errorMessage)
//std::copy(errorInfo, "failed to read error information", errorInfoSize);
}

emit log(EventLogType::Warn, "EPOS :: Error, " + errorMessage + "\n" + QString(errorInfo) + ", errorCode: " + QString::number(m_errorCode, 16));
emit log(Qt::red, "EPOS :: Error, " + errorMessage + "\n" + QString(errorInfo) + ", errorCode: " + QString::number(m_errorCode, 16));

// led indicator
setLedGreen(FALSE);
Expand All @@ -228,7 +228,7 @@ void Epos::on_uirequest_velocity(int motorid, int velocity)
textState = "is on, direction cw, velocity " + QString::number(abs(velocity));
}

emit log(EventLogType::Notify, "EPOS :: " + textMotor + " motor " + textState);
emit log(Qt::black, "EPOS :: " + textMotor + " motor " + textState);

// activate/deactivate runing state
BOOL runningState = (velocity == 0) ? FALSE : TRUE;
Expand All @@ -248,6 +248,6 @@ void Epos::on_uirequest_velocity(int motorid, int velocity)
void Epos::on_uirequest_tension(bool state)
{
QString textState = (state) ? "on" : "off";
emit log(EventLogType::Notify, "EPOS :: tension motor is " + textState);
emit log(Qt::black, "EPOS :: tension motor is " + textState);
setTension(state);
}
3 changes: 1 addition & 2 deletions BrainATUMtome/epos.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <QObject>

#include "Definitions.h"
#include "eventlog.h"

class Epos : public QObject
{
Expand Down Expand Up @@ -49,7 +48,7 @@ public slots:
void on_uirequest_tension(bool state);

signals:
void log(EventLogType type, const QString &message);
void log(const Qt::GlobalColor &color, const QString &message);
};

#endif // EPOS_H
14 changes: 2 additions & 12 deletions BrainATUMtome/eventlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,10 @@ void EventLog::addMessageToBoard(const QString &message, QBrush brush)
}


void EventLog::on_log(EventLogType type, const QString &message)
void EventLog::on_log(const Qt::GlobalColor &color, const QString &message)
{
QBrush brush = QBrush(Qt::SolidPattern);

if (type == EventLogType::Notify) {
brush.setColor(Qt::black);
}
else if (type == EventLogType::Respond) {
brush.setColor(Qt::gray);
}
else if (type == EventLogType::Warn) {
brush.setColor(Qt::red);
}

brush.setColor(color);

QString logMessage = message;
if (m_useTimestamp) {
Expand Down
5 changes: 1 addition & 4 deletions BrainATUMtome/eventlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

#include <QDebug>


enum class EventLogType {Notify, Respond, Warn};

class EventLog : public QPlainTextEdit
{
Q_OBJECT
Expand All @@ -25,7 +22,7 @@ class EventLog : public QPlainTextEdit
void addMessageToBoard(const QString &message, QBrush brush);

public slots:
void on_log(EventLogType type, const QString &message);
void on_log(const Qt::GlobalColor &color, const QString &message);
};

#endif // EVENTLOG_H
8 changes: 4 additions & 4 deletions BrainATUMtome/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ MainWindow::MainWindow(QWidget *parent) :
// open settings
QString fileIni = "/Users/tushevg/Desktop/BrainATUMtome/config/settings.ini";
if (!(QFileInfo::exists(fileIni) && QFileInfo(fileIni).isFile()))
ui->widget_board->on_log(EventLogType::Warn, "MainWindow :: provided INI file " + fileIni + " is not valid.");
ui->widget_board->on_log(Qt::red, "MainWindow :: provided INI file " + fileIni + " is not valid.");
m_settings = new QSettings(fileIni, QSettings::IniFormat);

configure_epos();
Expand All @@ -41,7 +41,7 @@ MainWindow::~MainWindow()
void MainWindow::configure_epos()
{
if (m_settings->value("epos/deviceName").isNull()) {
ui->widget_board->on_log(EventLogType::Warn, "Settings :: failed to parse Epos settings in configuration file " + m_settings->fileName());
ui->widget_board->on_log(Qt::red, "Settings :: failed to parse Epos settings in configuration file " + m_settings->fileName());
return;
}
QString portLower = m_settings->value("epos/portLower", "USB0").toString();
Expand Down Expand Up @@ -92,7 +92,7 @@ void MainWindow::configure_epos()
void MainWindow::configure_microtome()
{
if (m_settings->value("microtome/deviceName").isNull()) {
ui->widget_board->on_log(EventLogType::Warn, "Settings :: failed to parse microtome settings in configuration file " + m_settings->fileName());
ui->widget_board->on_log(Qt::red, "Settings :: failed to parse microtome settings in configuration file " + m_settings->fileName());
return;
}

Expand All @@ -115,7 +115,7 @@ void MainWindow::configure_microtome()
void MainWindow::configure_syringe()
{
if (m_settings->value("syringe/deviceName").isNull()) {
ui->widget_board->on_log(EventLogType::Warn, "Settings :: failed to parse syringe settings in configuration file " + m_settings->fileName());
ui->widget_board->on_log(Qt::red, "Settings :: failed to parse syringe settings in configuration file " + m_settings->fileName());
return;
}

Expand Down
1 change: 0 additions & 1 deletion BrainATUMtome/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <QSettings>
#include <QDebug>

#include "eventlog.h"
#include "epos.h"
#include "microtome.h"
#include "syringe.h"
Expand Down
12 changes: 6 additions & 6 deletions BrainATUMtome/microtome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ void Microtome::open(const QString &portName, int baudRate)
{
m_serialPort = new SerialPort(this);
connect(m_serialPort, &SerialPort::log,
[this](EventLogType type, const QString &message) {
emit log(type, "Microtome :: " + message);
[this](const Qt::GlobalColor &color, const QString &message) {
emit log(color, "Microtome :: " + message);
}
);
m_serialPort->open(portName, baudRate);
Expand All @@ -43,7 +43,7 @@ void Microtome::on_uirequest_cuttingMotor(bool state)

// start cutting motor
m_cutter_requestStop = false;
emit log(EventLogType::Notify, "Microtome :: cutting motor is on");
emit log(Qt::black, "Microtome :: cutting motor is on");
command = SerialPackage::pack(ADDRESS_COMMAND_CUTTER) +
SerialPackage::pack(CUTTER_MOTOR) +
SerialPackage::pack(STATUS_SET);
Expand All @@ -55,7 +55,7 @@ void Microtome::on_uirequest_cuttingMotor(bool state)

void Microtome::on_uirequest_cuttingSpeed(int cuttingSpeed)
{
emit log(EventLogType::Notify, "Microtome :: cutting speed is " + QString::number(cuttingSpeed));
emit log(Qt::black, "Microtome :: cutting speed is " + QString::number(cuttingSpeed));

// 1 digit = 10 um/sec
quint16 valueCuttingSpeed = static_cast<quint16>(cuttingSpeed / 10);
Expand All @@ -70,7 +70,7 @@ void Microtome::on_uirequest_cuttingSpeed(int cuttingSpeed)

void Microtome::on_uirequest_returnSpeed(int returnSpeed)
{
emit log(EventLogType::Notify, "Microtome :: return speed is " + QString::number(returnSpeed));
emit log(Qt::black, "Microtome :: return speed is " + QString::number(returnSpeed));

// 1 digit = 10 um/sec
quint16 valueReturnSpeed = static_cast<quint16>(returnSpeed / 10);
Expand All @@ -85,7 +85,7 @@ void Microtome::on_uirequest_returnSpeed(int returnSpeed)

void Microtome::on_uirequest_feedStep(int feedStep)
{
emit log(EventLogType::Notify, "Microtome :: feed step is " + QString::number(feedStep));
emit log(Qt::black, "Microtome :: feed step is " + QString::number(feedStep));

// 1 digit == 1 nm
quint16 valueFeedStep = static_cast<quint16>(feedStep);
Expand Down
3 changes: 1 addition & 2 deletions BrainATUMtome/microtome.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <QObject>

#include "eventlog.h"
#include "serialport.h"
#include "serialpackage.h"

Expand Down Expand Up @@ -53,7 +52,7 @@ public slots:
void on_uirequest_feedStep(int feedStep);

signals:
void log(EventLogType type, const QString &message);
void log(const Qt::GlobalColor &color, const QString &message);
void schedule(const QByteArray &message);

};
Expand Down
12 changes: 6 additions & 6 deletions BrainATUMtome/serialport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SerialPort::SerialPort(QObject *parent) : QObject(parent),
// configure callbacks
connect(m_serialPort, &QSerialPort::readyRead, this, &SerialPort::on_bufferRead);
connect(stateSender, &QState::entered, this, &SerialPort::on_bufferWrite);
connect(m_timerRespond, &QTimer::timeout, [this](){emit log(EventLogType::Warn, "SerialPort :: respond timeout.");});
connect(m_timerRespond, &QTimer::timeout, [this](){emit log(Qt::red, "SerialPort :: respond timeout.");});


//connect(stateListener, &QState::entered, [this](){emit log(EventLogType::Notify, "SerialPort ::Dispatcher::Listener");});
Expand Down Expand Up @@ -62,11 +62,11 @@ void SerialPort::open(const QString &portName, qint32 baudRate)
m_serialPort->open(QIODevice::ReadWrite);
if (!m_serialPort->isOpen())
{
emit log(EventLogType::Warn, "SerialPort :: failed to open serial port " + m_serialPort->portName());
emit log(Qt::red, "SerialPort :: failed to open serial port " + m_serialPort->portName());
return;
}

emit log(EventLogType::Notify,
emit log(Qt::black,
"SerialPort :: device opened @ port=" + m_serialPort->portName() + ", baudRate=" + QString::number(m_serialPort->baudRate()));

// configure respond timer
Expand Down Expand Up @@ -126,16 +126,16 @@ void SerialPort::on_bufferWrite()
// check transfer
if (bytesWritten == -1)
{
emit log(EventLogType::Warn, "SerialPort :: failed to write data to serial port.");
emit log(Qt::red, "SerialPort :: failed to write data to serial port.");
}
else if (bytesWritten != packageBuffer.size())
{
emit log(EventLogType::Warn, "SerialPort :: serial port sent a truncated message.");
emit log(Qt::red, "SerialPort :: serial port sent a truncated message.");
}
else
{
m_timerRespond->start();
emit log(EventLogType::Respond, "SerialPort :: message " + QString::fromUtf8(packageBuffer));
emit log(Qt::gray, "SerialPort :: message " + QString::fromUtf8(packageBuffer));
emit sent();
}
}
4 changes: 1 addition & 3 deletions BrainATUMtome/serialport.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include <QTimer>
#include <QQueue>

#include "eventlog.h"

class SerialPort : public QObject
{
Q_OBJECT
Expand Down Expand Up @@ -36,7 +34,7 @@ private slots:
void on_bufferWrite();

signals:
void log(EventLogType type, const QString &message);
void log(const Qt::GlobalColor &color, const QString &message);

void schedule();
void sent();
Expand Down
8 changes: 4 additions & 4 deletions BrainATUMtome/syringe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ void Syringe::open(const QString &portName, int baudRate)
{
m_serialPort = new SerialPort(this);
connect(m_serialPort, &SerialPort::log,
[this](EventLogType type, const QString &message) {
emit log(type, "Syringe :: " + message);
[this](const Qt::GlobalColor &color, const QString &message) {
emit log(color, "Syringe :: " + message);
}
);
m_serialPort->open(portName, baudRate);
}

void Syringe::on_uirequest_pump()
{
emit log(EventLogType::Notify, "Syringe :: pump");
emit log(Qt::black, "Syringe :: pump");
}


void Syringe::on_uirequest_auto(bool state)
{
QString textState = (state) ? "on" : "off";
emit log(EventLogType::Notify, "Syringe :: auto pumping is " + textState);
emit log(Qt::black, "Syringe :: auto pumping is " + textState);
m_auto = state;
}
2 changes: 1 addition & 1 deletion BrainATUMtome/syringe.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Syringe : public QObject
SerialPort *m_serialPort;

signals:
void log(EventLogType type, const QString &message);
void log(const Qt::GlobalColor &color, const QString &message);

public slots:
void on_uirequest_pump();
Expand Down

0 comments on commit 0b72578

Please sign in to comment.