Open Lighting Architecture  0.9.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SPIDevice.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  * SPIDevice.h
17  * The SPI Device class
18  * Copyright (C) 2013 Simon Newton
19  */
20 
21 #ifndef PLUGINS_SPI_SPIDEVICE_H_
22 #define PLUGINS_SPI_SPIDEVICE_H_
23 
24 #include <memory>
25 #include <string>
26 #include <vector>
27 
28 #include "olad/Device.h"
29 #include "ola/io/SelectServer.h"
30 #include "ola/rdm/UIDAllocator.h"
31 #include "ola/rdm/UID.h"
32 #include "plugins/spi/SPIBackend.h"
33 #include "plugins/spi/SPIWriter.h"
34 
35 namespace ola {
36 namespace plugin {
37 namespace spi {
38 
39 
40 class SPIDevice: public ola::Device {
41  public:
42  SPIDevice(class SPIPlugin *owner,
43  class Preferences *preferences,
44  class PluginAdaptor *plugin_adaptor,
45  const std::string &spi_device,
46  ola::rdm::UIDAllocator *uid_allocator);
47 
48  std::string DeviceId() const;
49 
50  bool AllowMultiPortPatching() const { return true; }
51 
52  protected:
53  bool StartHook();
54  void PrePortStop();
55 
56  private:
57  typedef std::vector<class SPIOutputPort*> SPIPorts;
58 
59  std::auto_ptr<SPIWriterInterface> m_writer;
60  std::auto_ptr<SPIBackendInterface> m_backend;
61  class Preferences *m_preferences;
62  class PluginAdaptor *m_plugin_adaptor;
63  SPIPorts m_spi_ports;
64  std::string m_spi_device_name;
65 
66  // Per device options
67  std::string SPIBackendKey() const;
68  std::string SPISpeedKey() const;
69  std::string SPICEKey() const;
70  std::string PortCountKey() const;
71  std::string SyncPortKey() const;
72  std::string GPIOPinKey() const;
73 
74  // Per port options
75  std::string DeviceLabelKey(uint8_t port) const;
76  std::string PersonalityKey(uint8_t port) const;
77  std::string PixelCountKey(uint8_t port) const;
78  std::string StartAddressKey(uint8_t port) const;
79  std::string GetPortKey(const std::string &suffix, uint8_t port) const;
80 
81  void SetDefaults();
82  void PopulateHardwareBackendOptions(HardwareBackend::Options *options);
83  void PopulateSoftwareBackendOptions(SoftwareBackend::Options *options);
84  void PopulateWriterOptions(SPIWriter::Options *options);
85 
86  static const char SPI_DEVICE_NAME[];
87  static const char HARDWARE_BACKEND[];
88  static const char SOFTWARE_BACKEND[];
89  static const uint8_t MAX_GPIO_PIN = 25;
90 };
91 } // namespace spi
92 } // namespace plugin
93 } // namespace ola
94 #endif // PLUGINS_SPI_SPIDEVICE_H_