Open Lighting Architecture: plugins/usbpro/ArduinoWidget.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
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"
28#include "ola/rdm/RDMControllerInterface.h"
29#include "ola/rdm/QueueingRDMController.h"
30#include "plugins/usbpro/BaseUsbProWidget.h"
31
32namespace ola {
33namespace plugin {
34namespace usbpro {
35
36
37/*
38 * A Arduino Widget implementation. We separate the Widget from the
39 * implementation so we can leverage the QueueingRDMController.
40 */
41 class ArduinoWidgetImpl: public BaseUsbProWidget,
42 public ola::rdm::DiscoverableRDMControllerInterface {
43 public:
44 ArduinoWidgetImpl(ola::io::ConnectedDescriptor *descriptor,
45 uint16_t esta_id,
46 uint32_t serial);
47 ~ArduinoWidgetImpl();
48
49 void Stop();
50
51 void SendRDMRequest(ola::rdm::RDMRequest *request,
52 ola::rdm::RDMCallback *on_complete);
53
54 void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback) {
55 GetUidSet(callback);
56 }
57
58 void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback) {
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 */
89 class ArduinoWidget: public SerialWidgetInterface,
90 public ola::rdm::DiscoverableRDMControllerInterface {
91 public:
92 ArduinoWidget(ola::io::ConnectedDescriptor *descriptor,
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
104 void SendRDMRequest(ola::rdm::RDMRequest *request,
105 ola::rdm::RDMCallback *on_complete) {
106 m_controller->SendRDMRequest(request, on_complete);
107 }
108
109 void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback) {
110 m_impl->RunFullDiscovery(callback);
111 }
112
113 void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback) {
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;
125 ola::rdm::DiscoverableQueueingRDMController *m_controller;
126};
127} // namespace usbpro
128} // namespace plugin
129} // namespace ola
130#endif // PLUGINS_USBPRO_ARDUINOWIDGET_H_
DmxBuffer.h
A class used to hold a single universe of DMX data.
QueueingRDMController.h
An RDM Controller that queues messages and only sends a single message at a time.
RDMControllerInterface.h
Definitions and Interfaces to implement an RDMController that sends a single message at a time.
UID.h
A RDM unique identifier (UID).
UIDSet.h
A set of UIDs.
ola::DmxBuffer
Used to hold a single universe of DMX data.
Definition DmxBuffer.h:49
ola::io::ConnectedDescriptor
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition Descriptor.h:283
ola::plugin::usbpro::ArduinoWidget::SendRDMRequest
void SendRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *on_complete)
Send a RDM command.
Definition ArduinoWidget.h:104
ola::plugin::usbpro::ArduinoWidget::ArduinoWidget
ArduinoWidget(ola::io::ConnectedDescriptor *descriptor, uint16_t esta_id, uint32_t serial, unsigned int queue_size=20)
Definition ArduinoWidget.cpp:231
ola::plugin::usbpro::ArduinoWidget::RunIncrementalDiscovery
void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Start an incremental discovery operation.
Definition ArduinoWidget.h:113
ola::plugin::usbpro::ArduinoWidget::RunFullDiscovery
void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Start a full discovery operation.
Definition ArduinoWidget.h:109
ola::plugin::usbpro::ArduinoWidgetImpl::RunFullDiscovery
void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Start a full discovery operation.
Definition ArduinoWidget.h:54
ola::plugin::usbpro::ArduinoWidgetImpl::SendRDMRequest
void SendRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *on_complete)
Definition ArduinoWidget.cpp:100
ola::plugin::usbpro::ArduinoWidgetImpl::~ArduinoWidgetImpl
~ArduinoWidgetImpl()
Definition ArduinoWidget.cpp:78
ola::plugin::usbpro::ArduinoWidgetImpl::Stop
void Stop()
Definition ArduinoWidget.cpp:87
ola::plugin::usbpro::ArduinoWidgetImpl::RunIncrementalDiscovery
void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Start an incremental discovery operation.
Definition ArduinoWidget.h:58
ola::rdm::DiscoverableQueueingRDMController
Definition QueueingRDMController.h:88
ola::rdm::DiscoverableRDMControllerInterface
The interface that can send RDM commands, as well as perform discovery operations.
Definition RDMControllerInterface.h:104
ola::rdm::RDMRequest
RDM Commands that represent requests (GET, SET or DISCOVER).
Definition RDMCommand.h:234
ola::rdm::UID
Represents a RDM UID.
Definition UID.h:57
ola::plugin::usbpro
Code for Enttec USB Pro devices and others using the same protocol.
ola::plugin
Code for supported devices and protocols.
ola::rdm::RDMCallback
ola::BaseCallback1< void, RDMReply * > RDMCallback
The callback run when a RDM request completes.
Definition RDMControllerInterface.h:52
ola::rdm::RDMDiscoveryCallback
ola::BaseCallback1< void, const ola::rdm::UIDSet & > RDMDiscoveryCallback
The callback run when a discovery operation completes.
Definition RDMControllerInterface.h:68
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44