Open Lighting Architecture  0.9.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ArduinoWidget.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  * ArduinoWidget.h
17  * The Arduino RGB Mixer widget.
18  * Copyright (C) 2011 Simon Newton
19  */
20 
21 #ifndef PLUGINS_USBPRO_ARDUINOWIDGET_H_
22 #define PLUGINS_USBPRO_ARDUINOWIDGET_H_
23 
24 #include "ola/DmxBuffer.h"
25 #include "ola/rdm/UID.h"
26 #include "ola/rdm/UIDSet.h"
29 #include "plugins/usbpro/BaseUsbProWidget.h"
30 
31 namespace ola {
32 namespace plugin {
33 namespace usbpro {
34 
35 
36 /*
37  * A Arduino Widget implementation. We separate the Widget from the
38  * implementation so we can leverage the QueueingRDMController.
39  */
42  public:
44  uint16_t esta_id,
45  uint32_t serial);
47 
48  void Stop();
49 
50  void SendRDMRequest(const ola::rdm::RDMRequest *request,
51  ola::rdm::RDMCallback *on_complete);
52 
54  GetUidSet(callback);
55  }
56 
57  void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback) {
58  GetUidSet(callback);
59  }
60 
61  private:
62  uint8_t m_transaction_id;
63  ola::rdm::UID m_uid;
64  const ola::rdm::RDMRequest *m_pending_request;
65  ola::rdm::RDMCallback *m_rdm_request_callback;
66 
67  void HandleMessage(uint8_t label,
68  const uint8_t *data,
69  unsigned int length);
70  void HandleRDMResponse(const uint8_t *data, unsigned int length);
71  void GetUidSet(ola::rdm::RDMDiscoveryCallback *callback);
72 
73  static const uint8_t RDM_REQUEST_LABEL;
74 
75  // the first byte is the response code
76  static const uint8_t RESPONSE_OK;
77  static const uint8_t RESPONSE_WAS_BROADCAST;
78  static const uint8_t RESPONSE_FAILED;
79  static const uint8_t RESPONSE_FAILED_CHECKSUM;
80  static const uint8_t RESONSE_INVALID_DESTINATION;
81  static const uint8_t RESPONSE_INVALID_COMMAND;
82 };
83 
84 
85 /*
86  * A Arduino Widget. This mostly just wraps the implementation.
87  */
90  public:
92  uint16_t esta_id,
93  uint32_t serial,
94  unsigned int queue_size = 20);
95  ~ArduinoWidget();
96 
97  void Stop() { m_impl->Stop(); }
98 
99  bool SendDMX(const DmxBuffer &buffer) {
100  return m_impl->SendDMX(buffer);
101  }
102 
104  ola::rdm::RDMCallback *on_complete) {
105  m_controller->SendRDMRequest(request, on_complete);
106  }
107 
109  m_impl->RunFullDiscovery(callback);
110  }
111 
112  void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback) {
113  m_impl->RunIncrementalDiscovery(callback);
114  }
115 
116  ola::io::ConnectedDescriptor *GetDescriptor() const {
117  return m_impl->GetDescriptor();
118  }
119 
120  private:
121  // we need to control the order of construction & destruction here so these
122  // are pointers.
123  ArduinoWidgetImpl *m_impl;
125 };
126 } // namespace usbpro
127 } // namespace plugin
128 } // namespace ola
129 #endif // PLUGINS_USBPRO_ARDUINOWIDGET_H_