Open Lighting Architecture  0.10.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
JaRuleWidget.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  * JaRuleWidget.h
17  * A Ja Rule widget.
18  * Copyright (C) 2015 Simon Newton
19  */
20 
21 #ifndef LIBS_USB_JARULEWIDGET_H_
22 #define LIBS_USB_JARULEWIDGET_H_
23 
24 #include <libusb.h>
25 #include <stdint.h>
26 
27 #include <ola/io/ByteString.h>
28 #include <ola/rdm/UID.h>
29 #include <ola/thread/ExecutorInterface.h>
30 
31 #include <string>
32 #include <vector>
33 
34 #include "libs/usb/LibUsbAdaptor.h"
35 #include "libs/usb/JaRuleConstants.h"
36 #include "libs/usb/Types.h"
37 
38 namespace ola {
39 namespace usb {
40 
57 class JaRuleWidget {
58  public:
66  AsyncronousLibUsbAdaptor *adaptor,
67  libusb_device *usb_device);
68 
72  ~JaRuleWidget();
73 
79  bool Init();
80 
85  USBDeviceID GetDeviceId() const;
86 
94  void CancelAll(uint8_t port_id);
95 
103  uint8_t PortCount() const;
104 
110  ola::rdm::UID GetUID() const;
111 
117  std::string ManufacturerString() const;
118 
124  std::string ProductString() const;
125 
132  class JaRulePortHandle* ClaimPort(uint8_t port_index);
133 
139  void ReleasePort(uint8_t port_index);
140 
153  void SendCommand(uint8_t port_index, CommandClass command,
154  const uint8_t *data, unsigned int size,
155  CommandCompleteCallback *callback);
156 
157  private:
158  typedef std::vector<class JaRuleWidgetPort*> PortHandles;
159 
160  ola::thread::ExecutorInterface *m_executor;
161  LibUsbAdaptor *m_adaptor;
162  libusb_device *m_device;
163  libusb_device_handle *m_usb_handle;
164  ola::rdm::UID m_uid; // The UID of the device, or 0000:00000000 if unset
165  std::string m_manufacturer;
166  std::string m_product;
167  PortHandles m_ports; // The list of port handles.
168 
169  bool InternalInit();
170 
171  static const uint8_t SUBCLASS_VALUE = 0xff;
172  static const uint8_t PROTOCOL_VALUE = 0xff;
173 
175 };
176 } // namespace usb
177 } // namespace ola
178 #endif // LIBS_USB_JARULEWIDGET_H_
uint8_t PortCount() const
The number of ports on the widget.
Definition: JaRuleWidget.cpp:111
class JaRulePortHandle * ClaimPort(uint8_t port_index)
Claim a handle to a port.
Definition: JaRuleWidget.cpp:127
bool Init()
Initialize the Ja Rule widget.
Definition: JaRuleWidget.cpp:87
void SendCommand(uint8_t port_index, CommandClass command, const uint8_t *data, unsigned int size, CommandCompleteCallback *callback)
The low level API to send a command to the widget.
Definition: JaRuleWidget.cpp:141
std::string ProductString() const
Get the product string.
Definition: JaRuleWidget.cpp:123
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Creates dummy copy constructor and assignment operator declarations.
Definition: Macro.h:44
void CancelAll(uint8_t port_id)
Cancel all queued and inflight commands.
Definition: JaRuleWidget.cpp:103
Definition: Types.h:30
Represents a DMX/RDM port on a Ja Rule device.
Definition: JaRulePortHandle.h:41
CommandClass
The Ja Rule command set.
Definition: JaRuleConstants.h:101
A RDM unique identifier (UID).
A Ja Rule hardware device (widget).
Definition: JaRuleWidget.h:57
Defer execution of a callback.
Definition: ExecutorInterface.h:35
The base class for all 4 argument callbacks.
Definition: Callback.h:3811
JaRuleWidget(ola::thread::ExecutorInterface *executor, AsyncronousLibUsbAdaptor *adaptor, libusb_device *usb_device)
Create a new Ja Rule widget.
Definition: JaRuleWidget.cpp:66
A LibUsbAdaptor for use with Asyncronous widgets.
Definition: LibUsbAdaptor.h:563
std::string ManufacturerString() const
Get the manufacturer string.
Definition: JaRuleWidget.cpp:119
USBDeviceID GetDeviceId() const
The device ID of this widget.
Definition: JaRuleWidget.cpp:99
~JaRuleWidget()
Destructor.
Definition: JaRuleWidget.cpp:77
void ReleasePort(uint8_t port_index)
Release a handle to a port.
Definition: JaRuleWidget.cpp:134
Represents a RDM UID.
Definition: UID.h:57
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
ola::rdm::UID GetUID() const
The UID of the widget.
Definition: JaRuleWidget.cpp:115
Wraps calls to libusb so we can test the code.
Definition: LibUsbAdaptor.h:36