/* widget.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 "pro.h" #include #include #include #include #include #include #include namespace ENTTEC { /** * @brief The Widget class * * Operates on either the USB Host side (computer) or USB Device side (DMX USB Pro impersonator). */ class Widget : public DMX::Universe { public: explicit Widget(); virtual ~Widget(); virtual void init(); //!< USB Device start virtual void halt(); //!< USB Device stop virtual void open(); //!< USB Host start virtual void close(); //!< USB Host stop /** * @brief isConnected * @return */ bool isConnected() const { return usb_mode != USBunknown; } /** * @brief featureDMX * @return */ bool featureDMX() const { return firmware_version >> 8 == Pro::FwDMX || featureRDM(); } /** * @brief featureRDM * @return */ bool featureRDM() const { return firmware_version >> 8 == Pro::FwRDM; } virtual void setModeController(); virtual void setModeBridge(Pro::DMX_RX_MODE = Pro::RxNotifyAlways); uint32_t serialNumber() const; uint16_t firmwareVersion() const; double txBreakTime() const; double setTxBreakTime(double); void setTxBreakIntervals(uint8_t); double txMabTime() const; double setTxMabTime(double); void setTxMabIntervals(uint8_t); uint8_t txRate() const; void setTxRate(uint8_t); const std::vector &userData() const; void setUserData(std::vector); void getParameters(size_t user_length = 0); void setParameters(size_t user_length = 0) const; void getSerialNumber(); bool writeFirmware(const uint8_t *, const size_t); /// @brief The OperatingMode enum enum OperatingMode { USBunknown, USBhost, USBdevice }; static std::shared_ptr MessageDataFactory(Pro::MESSAGE_LABEL, OperatingMode); protected: void routeRxMessage(std::shared_ptr); // USB Host operations virtual void sendMessage(std::shared_ptr) const; virtual void rebootBootloader(); void sendDmx(bool trimmed = true) const; void sendRDMdata(const std::vector &) const; void sendRDMdiscovery(const std::vector &) const; void receiveRDM(const std::vector &); /** * @brief writeFwPage * @return * * Reimpliment in super class to process the page. Base implimentation is to return false. */ virtual bool writeFwPage(uint8_t*) { return false; } uint32_t serial_number; //!< BCD serial number uint16_t firmware_version; //!< Firmware version number uint8_t tx_break_intervals; //!< DMX_BREAK_INTERVAL count of the DMX BREAK uint8_t tx_mab_intervals; //!< DMX_MAB_INTERVAL count of the DMX MARK AFTER BREAK uint8_t tx_rate; //!< DMX packet transmit Rate std::vector user_configuration; //!< User defined configuration data. OperatingMode usb_mode; //!< The side of the USB the widget is acting on. bool reply_serial; //!< receiving a serialnumber will set to true private: void rxMsgHello(); void rxMsgReprogramFirmware(); void rxMsgProgramFlashPageRequest(std::shared_ptr); void rxMsgProgramFlashPageReply(std::shared_ptr); void rxMsgGetWidgetParametersRequest(std::shared_ptr); void rxMsgGetWidgetParametersReply(std::shared_ptr); void rxMsgSetWidgetParametersRequest(std::shared_ptr); void rxMsgRecievedDmxPacket(std::shared_ptr); void rxMsgOutputOnlySendDMX(std::shared_ptr); void rxMsgSendRDMData(std::shared_ptr); void rxMsgRecieveDMXOnChange(std::shared_ptr); void rxMsgRecievedDMXChanged(std::shared_ptr); void rxMsgGetWidgetSerialRequest(); void rxMsgGetWidgetSerialReply(std::shared_ptr); void rxMsgSendRDMDiscovery(std::shared_ptr); Pro::DMX_RX_MODE rx_update_mode_; mutable std::mutex mtx_metadata_; std::shared_ptr token_data_changed_; std::shared_ptr token_rdm_receive_; std::shared_ptr token_rdm_send_; RDM::Controller *rdm_controller_; RDM::Responder *rdm_responder_; void rdm_configure_responder_(); }; } // namespace ENTTEC