Open Lighting Architecture  0.9.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GenericUsbProWidget.h
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15  *
16  * GenericUsbProWidget.h
17  * This class implements a generic Usb Pro style widget, which can send and
18  * receive DMX as well and get/set widget parameters.
19  * Copyright (C) 2011 Simon Newton
20  */
21 
22 #ifndef PLUGINS_USBPRO_GENERICUSBPROWIDGET_H_
23 #define PLUGINS_USBPRO_GENERICUSBPROWIDGET_H_
24 
25 #include <deque>
26 #include <string>
27 #include "ola/Callback.h"
28 #include "ola/DmxBuffer.h"
29 #include "ola/thread/SchedulerInterface.h"
30 #include "plugins/usbpro/BaseUsbProWidget.h"
31 
32 namespace ola {
33 namespace plugin {
34 namespace usbpro {
35 
36 typedef struct {
37  uint8_t firmware;
38  uint8_t firmware_high;
39  uint8_t break_time;
40  uint8_t mab_time;
41  uint8_t rate;
43 
46 
47 
48 /*
49  * An Generic DMX USB PRO Widget. This just handles the base functionality,
50  * other features like RDM, multi-universe support etc. can be layered on top
51  * of this.
52  */
54  public:
57 
58  void SetDMXCallback(ola::Callback0<void> *callback);
59  void GenericStop();
60 
61  virtual bool SendDMX(const DmxBuffer &buffer);
62  bool ChangeToReceiveMode(bool change_only);
63  const DmxBuffer &FetchDMX() const;
64 
65  void GetParameters(usb_pro_params_callback *callback);
66  bool SetParameters(uint8_t break_time,
67  uint8_t mab_time,
68  uint8_t rate);
69 
70  static const uint8_t RECEIVED_DMX_LABEL = 5;
71 
72  protected:
73  // child classes can intercept this.
74  virtual void HandleMessage(uint8_t label,
75  const uint8_t *data,
76  unsigned int length);
77  void HandleDMX(const uint8_t *data, unsigned int length);
78 
79  private:
80  bool m_active;
81  DmxBuffer m_input_buffer;
82  ola::Callback0<void> *m_dmx_callback;
83  std::deque<usb_pro_params_callback*> m_outstanding_param_callbacks;
84 
85  void HandleParameters(const uint8_t *data, unsigned int length);
86  void HandleDMXDiff(const uint8_t *data, unsigned int length);
87 
88  static const uint8_t REPROGRAM_FIRMWARE_LABEL = 2;
89  static const uint8_t PARAMETERS_LABEL = 3;
90  static const uint8_t SET_PARAMETERS_LABEL = 4;
91  static const uint8_t DMX_RX_MODE_LABEL = 8;
92  static const uint8_t DMX_CHANGED_LABEL = 9;
93 };
94 } // namespace usbpro
95 } // namespace plugin
96 } // namespace ola
97 #endif // PLUGINS_USBPRO_GENERICUSBPROWIDGET_H_