2023-04-03 09:59:18 -04:00
|
|
|
/*
|
|
|
|
qwidget.h
|
|
|
|
|
|
|
|
Copyright (c) 2023 Kevin Matz (kevin.matz@gmail.com)
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2023-04-03 16:46:06 -04:00
|
|
|
#include <QFlags>
|
2023-04-03 09:59:18 -04:00
|
|
|
#include <QObject>
|
2023-04-03 16:45:32 -04:00
|
|
|
#include <QSerialPort>
|
|
|
|
#include <QSerialPortInfo>
|
2023-04-03 09:59:18 -04:00
|
|
|
#include <widget.h>
|
|
|
|
|
2023-04-05 07:53:22 -04:00
|
|
|
using ENTTEC::Pro::FIRMWARE_TYPE;
|
|
|
|
using ENTTEC::Pro::MESSAGE_LABEL;
|
|
|
|
using ENTTEC::Pro::DMX_RX_MODE;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The DmxWidget class
|
|
|
|
*/
|
2023-04-03 09:59:18 -04:00
|
|
|
class DmxWidget
|
|
|
|
: public QObject
|
|
|
|
, public ENTTEC::Widget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit DmxWidget(QObject *parent = nullptr);
|
2023-04-03 16:45:32 -04:00
|
|
|
virtual ~DmxWidget();
|
2023-04-03 09:59:18 -04:00
|
|
|
|
2023-04-05 08:10:59 -04:00
|
|
|
virtual void open() override;
|
|
|
|
virtual void close() override;
|
2023-04-03 16:45:32 -04:00
|
|
|
|
|
|
|
void setPort(const QSerialPortInfo &port) { port_->setPort(port); emit portNameChanged(); }
|
|
|
|
void setPortName(const QString &name) { port_->setPortName(name); emit portNameChanged(); }
|
2023-04-09 20:18:16 -04:00
|
|
|
QString portName() const { return port_->portName(); }
|
|
|
|
QSerialPortInfo portInfo() const { return QSerialPortInfo(*port_); }
|
2023-04-03 16:45:32 -04:00
|
|
|
|
2023-04-05 07:53:22 -04:00
|
|
|
Q_ENUM(FIRMWARE_TYPE)
|
|
|
|
Q_ENUM(MESSAGE_LABEL)
|
|
|
|
Q_ENUM(DMX_RX_MODE)
|
2023-04-03 16:46:06 -04:00
|
|
|
Q_DECLARE_FLAGS(RxErrors, ENTTEC::Pro::RX_ERROR)
|
2023-04-03 16:45:32 -04:00
|
|
|
Q_PROPERTY(bool isConnected READ isConnected NOTIFY connectedChanged)
|
|
|
|
Q_PROPERTY(QString portName READ portName NOTIFY portNameChanged)
|
2023-04-03 16:46:06 -04:00
|
|
|
|
2023-04-09 19:42:21 -04:00
|
|
|
static QList<std::shared_ptr<DmxWidget>> availableWidgets();
|
2023-04-05 12:42:18 -04:00
|
|
|
|
2023-04-03 09:59:18 -04:00
|
|
|
signals:
|
2023-04-03 16:45:32 -04:00
|
|
|
void connectedChanged(bool);
|
|
|
|
void portNameChanged();
|
2023-04-06 20:07:52 -04:00
|
|
|
void serialDataRead();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void sendMessage(std::shared_ptr<ENTTEC::Pro::MessageData>) const override;
|
2023-04-03 09:59:18 -04:00
|
|
|
|
2023-04-03 16:45:32 -04:00
|
|
|
private:
|
|
|
|
QSerialPort *port_;
|
2023-04-06 20:07:52 -04:00
|
|
|
QByteArray message_rx_buffer_;
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void parseMessageBuffer();
|
2023-04-03 09:59:18 -04:00
|
|
|
};
|
2023-04-03 16:46:06 -04:00
|
|
|
|
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(DmxWidget::RxErrors)
|