Open Lighting Architecture  Latest Git
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GPIODriver.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  * GPIODriver.h
17  * Uses data in a DMXBuffer to drive GPIO pins.
18  * Copyright (C) 2014 Simon Newton
19  */
20 
21 #ifndef PLUGINS_GPIO_GPIODRIVER_H_
22 #define PLUGINS_GPIO_GPIODRIVER_H_
23 
24 #include <stdint.h>
25 #include <ola/DmxBuffer.h>
26 #include <ola/base/Macro.h>
27 #include <ola/thread/Thread.h>
28 
29 #include <vector>
30 
31 namespace ola {
32 namespace plugin {
33 namespace gpio {
34 
39  public:
43  struct Options {
44  public:
45  Options(): start_address(1), turn_on(128), turn_off(127) {}
46 
50  std::vector<uint16_t> gpio_pins;
51 
55  uint16_t start_address;
56 
60  uint8_t turn_on;
61 
65  uint8_t turn_off;
66  };
67 
72  explicit GPIODriver(const Options &options);
73 
77  ~GPIODriver();
78 
83  bool Init();
84 
89  std::vector<uint16_t> PinList() const { return m_options.gpio_pins; }
90 
96  bool SendDmx(const DmxBuffer &dmx);
97 
98  void *Run();
99 
100  private:
101  enum GPIOState {
102  ON,
103  OFF,
104  UNDEFINED,
105  };
106 
107  struct GPIOPin {
108  int fd;
109  GPIOState state;
110  bool last_value;
111  };
112 
113  typedef std::vector<GPIOPin> GPIOPins;
114 
115  const Options m_options;
116  GPIOPins m_gpio_pins;
117 
118  DmxBuffer m_buffer;
119  bool m_term; // GUARDED_BY(m_mutex);
120  bool m_dmx_changed; // GUARDED_BY(m_mutex);
121  ola::thread::Mutex m_mutex;
123 
124  bool SetupGPIO();
125  bool UpdateGPIOPins(const DmxBuffer &dmx);
126  void CloseGPIOFDs();
127 
128  static const char GPIO_BASE_DIR[];
129 
130  DISALLOW_COPY_AND_ASSIGN(GPIODriver);
131 };
132 } // namespace gpio
133 } // namespace plugin
134 } // namespace ola
135 #endif // PLUGINS_GPIO_GPIODRIVER_H_
~GPIODriver()
Destructor.
Definition: GPIODriver.cpp:55
std::vector< uint16_t > PinList() const
Get a list of the GPIO pins controlled by this driver.
Definition: GPIODriver.h:89
bool SendDmx(const DmxBuffer &dmx)
Set the values of the GPIO pins from the data in the DMXBuffer.
Definition: GPIODriver.cpp:74
uint16_t start_address
The DMX512 start address of the first pin.
Definition: GPIODriver.h:55
The Options.
Definition: GPIODriver.h:43
uint8_t turn_on
The value above which a pin will be turned on.
Definition: GPIODriver.h:60
Used to hold a single universe of DMX data.
Definition: DmxBuffer.h:49
bool Init()
Initialize the GPIODriver.
Definition: GPIODriver.cpp:66
std::vector< uint16_t > gpio_pins
A list of I/O pins to map to slots.
Definition: GPIODriver.h:50
A class used to hold a single universe of DMX data.
Definition: Thread.h:52
GPIODriver(const Options &options)
Create a new GPIODriver.
Definition: GPIODriver.cpp:49
void * Run()
The entry point for the new thread.
Definition: GPIODriver.cpp:85
Helper macros.
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
uint8_t turn_off
The value below which a pin will be turned off.
Definition: GPIODriver.h:65
Uses data in a DMXBuffer to drive GPIO pins.
Definition: GPIODriver.h:38
Definition: Mutex.h:41
Definition: Mutex.h:81