Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
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
31namespace ola {
32namespace plugin {
33namespace 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
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 GPIODriver(const GPIODriver &) = delete;
131 const GPIODriver &operator=(const GPIODriver &) = delete;
132};
133} // namespace gpio
134} // namespace plugin
135} // namespace ola
136#endif // PLUGINS_GPIO_GPIODRIVER_H_
A class used to hold a single universe of DMX data.
Helper macros.
Used to hold a single universe of DMX data.
Definition DmxBuffer.h:49
Uses data in a DMXBuffer to drive GPIO pins.
Definition GPIODriver.h:38
GPIODriver(const Options &options)
Create a new GPIODriver.
Definition GPIODriver.cpp:49
std::vector< uint16_t > PinList() const
Get a list of the GPIO pins controlled by this driver.
Definition GPIODriver.h:89
~GPIODriver()
Destructor.
Definition GPIODriver.cpp:55
bool Init()
Initialize the GPIODriver.
Definition GPIODriver.cpp:66
void * Run()
The entry point for the new thread.
Definition GPIODriver.cpp:85
bool SendDmx(const DmxBuffer &dmx)
Set the values of the GPIO pins from the data in the DMXBuffer.
Definition GPIODriver.cpp:74
Definition Mutex.h:83
Definition Mutex.h:41
Definition Thread.h:52
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
The Options.
Definition GPIODriver.h:43
std::vector< uint16_t > gpio_pins
A list of I/O pins to map to slots.
Definition GPIODriver.h:50
uint16_t start_address
The DMX512 start address of the first pin.
Definition GPIODriver.h:55
uint8_t turn_off
The value below which a pin will be turned off.
Definition GPIODriver.h:65
uint8_t turn_on
The value above which a pin will be turned on.
Definition GPIODriver.h:60