/* 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 #include #include #include #include #include using ENTTEC::Pro::FIRMWARE_TYPE; using ENTTEC::Pro::MESSAGE_LABEL; using ENTTEC::Pro::DMX_RX_MODE; /** * @brief The DmxWidget class */ class DmxWidget : public QObject , public ENTTEC::Widget { Q_OBJECT public: explicit DmxWidget(QObject *parent = nullptr); virtual ~DmxWidget(); virtual void open() override; virtual void close() override; void setPort(const QSerialPortInfo &port) { port_->setPort(port); emit portNameChanged(); } void setPortName(const QString &name) { port_->setPortName(name); emit portNameChanged(); } QString portName() const { return port_->portName(); } QSerialPortInfo portInfo() const { return QSerialPortInfo(*port_); } Q_ENUM(FIRMWARE_TYPE) Q_ENUM(MESSAGE_LABEL) Q_ENUM(DMX_RX_MODE) Q_DECLARE_FLAGS(RxErrors, ENTTEC::Pro::RX_ERROR) Q_PROPERTY(bool isConnected READ isConnected NOTIFY connectedChanged) Q_PROPERTY(QString portName READ portName NOTIFY portNameChanged) static QList> availableWidgets(); signals: void connectedChanged(bool); void portNameChanged(); void serialDataRead(); protected: virtual void sendMessage(std::shared_ptr) const override; private: QSerialPort *port_; QByteArray message_rx_buffer_; private slots: void parseMessageBuffer(); void serialErrorOccured(QSerialPort::SerialPortError); }; Q_DECLARE_OPERATORS_FOR_FLAGS(DmxWidget::RxErrors)