Open Lighting Architecture  Latest Git
Widget.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  * Widget.h
17  * A generic USB Widget.
18  * Copyright (C) 2014 Simon Newton
19  */
20 
21 #ifndef PLUGINS_USBDMX_WIDGET_H_
22 #define PLUGINS_USBDMX_WIDGET_H_
23 
24 #include "libs/usb/LibUsbAdaptor.h"
25 #include "libs/usb/Types.h"
26 #include "ola/DmxBuffer.h"
27 
28 namespace ola {
29 namespace plugin {
30 namespace usbdmx {
31 
37  public:
38  virtual ~WidgetInterface() {}
39 
44  virtual bool Init() = 0;
45 
50  virtual ola::usb::USBDeviceID GetDeviceId() const = 0;
51 
57  virtual bool SendDMX(const DmxBuffer &buffer) = 0;
58 };
59 
66 class SimpleWidget : public WidgetInterface {
67  public:
74  libusb_device *usb_device)
75  : m_adaptor(adaptor),
76  m_usb_device(usb_device) {
77  }
78 
80  return m_adaptor->GetDeviceId(m_usb_device);
81  }
82 
83  protected:
84  ola::usb::LibUsbAdaptor* const m_adaptor;
85  libusb_device* const m_usb_device;
86 };
87 } // namespace usbdmx
88 } // namespace plugin
89 } // namespace ola
90 #endif // PLUGINS_USBDMX_WIDGET_H_
virtual bool SendDMX(const DmxBuffer &buffer)=0
Send DMX data from this widget.
Definition: Types.h:30
virtual bool Init()=0
Initialize the widget.
Used to hold a single universe of DMX data.
Definition: DmxBuffer.h:49
A class used to hold a single universe of DMX data.
A base simple widget class.
Definition: Widget.h:66
The interface for a simple widget that supports a single universe of DMX.
Definition: Widget.h:36
virtual ola::usb::USBDeviceID GetDeviceId() const =0
The device ID of this widget.
ola::usb::USBDeviceID GetDeviceId() const
The device ID of this widget.
Definition: Widget.h:79
SimpleWidget(ola::usb::LibUsbAdaptor *adaptor, libusb_device *usb_device)
Create a new SimpleWidget.
Definition: Widget.h:73
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Wraps calls to libusb so we can test the code.
Definition: LibUsbAdaptor.h:36