DUDS
Distributed Update of Data from Something
SysFsPort.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2017 Jeff Jackowski
9  */
11 #include <fstream>
12 
13 // !@?!#?!#?
14 // It was bad enough to find an MS header had "#define interface struct".
15 // I was hoping such things wouldn't be here, but I was wrong.
16 #undef linux
17 
18 namespace duds { namespace hardware { namespace interface {
19 
20 class PinConfiguration;
21 
22 namespace linux {
23 
46  class FsPin {
52  std::fstream direction;
57  std::fstream value;
62  unsigned int fsid;
69  bool reqoutval;
76  bool curoutval;
83  bool isoutput;
84  public:
104  void open(DigitalPinConfig &conf, DigitalPinCap &cap, unsigned int pin);
108  bool read();
125  void write(bool state);
136  void setDirection(bool output);
137  };
138  typedef std::vector<FsPin> FsPinVector;
143  FsPinVector fspins;
144 public:
145  /* *
146  * Make a SysFsPort object without pins.
147  */
148  //SysFsPort() { }
161  SysFsPort(const std::vector<unsigned int> &ids, unsigned int firstid);
170  static std::shared_ptr<SysFsPort> makeConfiguredPort(
171  PinConfiguration &pc,
172  const std::string &name = "default"
173  );
174  /* *
175  * Make a SysFsPort object with the given pins.
176  * @param ids The key is the pin ID from the filesystem. The value is
177  * the global ID that will be used by this port.
178  */
179  //SysFsPort(const std::map<unsigned int, unsigned int> &ids);
180  #ifdef HAVE_LIBBOOST_FILESYSTEM
181  // find the pins
182  //SysFsPort();
183  #endif
184  virtual ~SysFsPort();
185 
186  // virtual functions required by Digitalport
187 protected:
188  virtual void configurePort(
189  unsigned int localPinId,
190  const DigitalPinConfig &cfg,
192  );
193  virtual bool inputImpl(unsigned int gid, DigitalPinAccessBase::PortData *);
194  virtual void outputImpl(
195  unsigned int lid,
196  bool state,
198  );
199 public:
204  virtual bool simultaneousOperations() const;
205 };
206 
207 } } } } // namespaces
208 
void write(bool state)
Changes the output value of the pin.
Definition: SysFsPort.cpp:238
Defines the configuration for a digital general purpose I/O pin.
std::fstream direction
The file used to control the I/O direction of the pin.
Definition: SysFsPort.hpp:52
bool isoutput
True when the pin is configured as an output.
Definition: SysFsPort.hpp:83
void open(DigitalPinConfig &conf, DigitalPinCap &cap, unsigned int pin)
Opens the value and direction files for the pin.
Definition: SysFsPort.cpp:116
A type for holding arbitrary port-specific data within a DigitalPinAccess or DigitalPinSetAccess obje...
virtual void configurePort(unsigned int localPinId, const DigitalPinConfig &cfg, DigitalPinAccessBase::PortData *)
Changes the hardware configuration for a single pin.
Definition: SysFsPort.cpp:77
bool read()
Reads from the value file of the pin and returns the result.
Definition: SysFsPort.cpp:226
FsPinVector fspins
Internal pin objects for each pin that will be made available through this port object.
Definition: SysFsPort.hpp:143
Parses configuration data for DigitalPort, DigitalPin, DigitalPinSet, ChipSelectManager, and ChipSelect objects.
A GPIO implementation using the Linux kernel&#39;s userspace interface in syfs.
Definition: SysFsPort.hpp:45
bool curoutval
The current output value for the pin.
Definition: SysFsPort.hpp:76
void output(unsigned int gid, bool state, DigitalPinAccessBase::PortData *pdata)
Does error checking in advance of calling outputImpl(unsigned int, bool) to change the output of the ...
bool reqoutval
The requested output value for the pin.
Definition: SysFsPort.hpp:69
virtual bool simultaneousOperations() const
The sysfs interface does not support simultaneous operations; returns false.
Definition: SysFsPort.cpp:73
virtual void outputImpl(unsigned int lid, bool state, DigitalPinAccessBase::PortData *)
Changes the output state of the given pin.
Definition: SysFsPort.cpp:105
std::fstream value
The file used to query the pin&#39;s input state and change the pins output state.
Definition: SysFsPort.hpp:57
Defines the capabilites of a digital general purpose I/O pin.
void setDirection(bool output)
Changes the pin&#39;s direction between input and output.
Definition: SysFsPort.cpp:204
static std::shared_ptr< SysFsPort > makeConfiguredPort(PinConfiguration &pc, const std::string &name="default")
Make a SysFsPort object according to the given configuration, and attach to the configuration.
Definition: SysFsPort.cpp:40
A partial DigitalPort implementation for ports where the configuration of each pin is independent of ...
virtual bool inputImpl(unsigned int gid, DigitalPinAccessBase::PortData *)
Reads input from the given pin.
Definition: SysFsPort.cpp:97
unsigned int fsid
The GPIO&#39;s ID number from the filesystem.
Definition: SysFsPort.hpp:62
SysFsPort(const std::vector< unsigned int > &ids, unsigned int firstid)
Make a SysFsPort object with the given pins.
Definition: SysFsPort.cpp:19