Open Lighting Architecture  Latest Git
SPIDMXWidget.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  * SPIDMXWidget.h
17  * This is a wrapper around the required SPIDEV calls.
18  * Copyright (C) 2017 Florian Edelmann
19  */
20 
21 #ifndef PLUGINS_SPIDMX_SPIDMXWIDGET_H_
22 #define PLUGINS_SPIDMX_SPIDMXWIDGET_H_
23 
24 #include <linux/spi/spidev.h>
25 #include <string>
26 #include <vector>
27 
28 #include "ola/base/Macro.h"
29 #include "ola/DmxBuffer.h"
30 
31 namespace ola {
32 namespace plugin {
33 namespace spidmx {
34 
38 class SPIDMXWidget {
39  public:
44  explicit SPIDMXWidget(const std::string &path);
45 
47  ~SPIDMXWidget();
48 
50  std::string Name() const { return m_path; }
51  std::string Description() const { return m_path; }
52 
54  bool Open();
55 
57  bool Close();
58 
60  bool IsOpen() const;
61 
66  bool ReadWrite(uint8_t *tx_buf, uint8_t *rx_buf, uint32_t blocklength);
67 
69  bool SetupOutput();
70 
71  private:
72  const std::string m_path;
73 
78  int m_fd;
79 
81  static const int NOT_OPEN = -2;
82 
84  static const int FAILED_OPEN = -1;
85 
87  static const uint32_t SPI_SPEED = 2000000;
88 
90  static const uint16_t SPI_DELAY = 0;
91 
93  static const uint8_t SPI_BITS_PER_WORD = 8;
94 
96  static const uint8_t SPI_CS_CHANGE = 0;
97 
99  static const uint16_t SPI_PAD = 0;
100 
102  static const uint8_t SPI_MODE = SPI_MODE_0;
103 
104  DISALLOW_COPY_AND_ASSIGN(SPIDMXWidget);
105 };
106 
107 } // namespace spidmx
108 } // namespace plugin
109 } // namespace ola
110 #endif // PLUGINS_SPIDMX_SPIDMXWIDGET_H_
bool IsOpen() const
Definition: SPIDMXWidget.cpp:88
Definition: SPIDMXWidget.h:38
SPIDMXWidget(const std::string &path)
Definition: SPIDMXWidget.cpp:49
bool Close()
Definition: SPIDMXWidget.cpp:73
A class used to hold a single universe of DMX data.
bool ReadWrite(uint8_t *tx_buf, uint8_t *rx_buf, uint32_t blocklength)
Definition: SPIDMXWidget.cpp:98
~SPIDMXWidget()
Definition: SPIDMXWidget.cpp:54
Helper macros.
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
bool Open()
Definition: SPIDMXWidget.cpp:61
std::string Name() const
Definition: SPIDMXWidget.h:50
bool SetupOutput()
Definition: SPIDMXWidget.cpp:125