Open Lighting Architecture  Latest Git
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 <memory>
25 #include "ola/DmxBuffer.h"
26 #include "ola/rdm/UID.h"
27 #include "ola/rdm/UIDSet.h"
30 #include "plugins/usbpro/BaseUsbProWidget.h"
31 
32 namespace ola {
33 namespace plugin {
34 namespace usbpro {
35 
36 
37 /*
38  * A Arduino Widget implementation. We separate the Widget from the
39  * implementation so we can leverage the QueueingRDMController.
40  */
43  public:
45  uint16_t esta_id,
46  uint32_t serial);
48 
49  void Stop();
50 
52  ola::rdm::RDMCallback *on_complete);
53 
55  GetUidSet(callback);
56  }
57 
59  GetUidSet(callback);
60  }
61 
62  private:
63  uint8_t m_transaction_id;
64  ola::rdm::UID m_uid;
65  std::auto_ptr<const ola::rdm::RDMRequest> m_pending_request;
66  ola::rdm::RDMCallback *m_rdm_request_callback;
67 
68  void HandleMessage(uint8_t label,
69  const uint8_t *data,
70  unsigned int length);
71  void HandleRDMResponse(const uint8_t *data, unsigned int length);
72  void GetUidSet(ola::rdm::RDMDiscoveryCallback *callback);
73 
74  static const uint8_t RDM_REQUEST_LABEL;
75 
76  // the first byte is the response code
77  static const uint8_t RESPONSE_OK;
78  static const uint8_t RESPONSE_WAS_BROADCAST;
79  static const uint8_t RESPONSE_FAILED;
80  static const uint8_t RESPONSE_FAILED_CHECKSUM;
81  static const uint8_t RESPONSE_INVALID_DESTINATION;
82  static const uint8_t RESPONSE_INVALID_COMMAND;
83 };
84 
85 
86 /*
87  * A Arduino Widget. This mostly just wraps the implementation.
88  */
91  public:
93  uint16_t esta_id,
94  uint32_t serial,
95  unsigned int queue_size = 20);
96  ~ArduinoWidget();
97 
98  void Stop() { m_impl->Stop(); }
99 
100  bool SendDMX(const DmxBuffer &buffer) {
101  return m_impl->SendDMX(buffer);
102  }
103 
105  ola::rdm::RDMCallback *on_complete) {
106  m_controller->SendRDMRequest(request, on_complete);
107  }
108 
110  m_impl->RunFullDiscovery(callback);
111  }
112 
114  m_impl->RunIncrementalDiscovery(callback);
115  }
116 
117  ola::io::ConnectedDescriptor *GetDescriptor() const {
118  return m_impl->GetDescriptor();
119  }
120 
121  private:
122  // we need to control the order of construction & destruction here so these
123  // are pointers.
124  ArduinoWidgetImpl *m_impl;
126 };
127 } // namespace usbpro
128 } // namespace plugin
129 } // namespace ola
130 #endif // PLUGINS_USBPRO_ARDUINOWIDGET_H_
Definitions and Interfaces to implement an RDMController that sends a single message at a time...
void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Start an incremental discovery operation.
Definition: ArduinoWidget.h:113
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition: Descriptor.h:282
void SendRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *on_complete)
Definition: ArduinoWidget.cpp:100
void SendRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *on_complete)
Send a RDM command.
Definition: ArduinoWidget.h:104
The interface that can send RDM commands, as well as perform discovery operations.
Definition: RDMControllerInterface.h:104
RDM Commands that represent requests (GET, SET or DISCOVER).
Definition: RDMCommand.h:234
Used to hold a single universe of DMX data.
Definition: DmxBuffer.h:49
A RDM unique identifier (UID).
Definition: BaseUsbProWidget.h:40
A set of UIDs.
A class used to hold a single universe of DMX data.
void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Start an incremental discovery operation.
Definition: ArduinoWidget.h:58
~ArduinoWidgetImpl()
Definition: ArduinoWidget.cpp:78
An RDM Controller that queues messages and only sends a single message at a time. ...
Definition: SerialWidgetInterface.h:38
Definition: ArduinoWidget.h:89
The base class for all 1 argument callbacks.
Definition: Callback.h:982
void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Start a full discovery operation.
Definition: ArduinoWidget.h:109
Definition: QueueingRDMController.h:88
void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Start a full discovery operation.
Definition: ArduinoWidget.h:54
Represents a RDM UID.
Definition: UID.h:57
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Definition: ArduinoWidget.h:41
void Stop()
Definition: ArduinoWidget.cpp:87