DUDS
Distributed Update of Data from Something
DigitalPinSetAccess.cpp
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 
12 namespace duds { namespace hardware { namespace interface {
13 
15  unsigned int total = (unsigned int)pinvec.size() + len;
16  if (total > pinvec.capacity()) {
17  pinvec.reserve(total);
18  }
19 }
20 
23 ) noexcept {
24  // lose access to pin
25  retire();
26  // update the port object of the old object
27  if (old.havePins()) {
28  old.port()->updateAccess(old, this);
29  }
30  // take the old object's data
32  pinvec = std::move(old.pinvec);
33  return *this;
34 }
35 
36 void DigitalPinSetAccess::retire() noexcept {
37  if (havePins()) {
38  port()->updateAccess(*this, nullptr);
39  pinvec.clear();
40  reset();
41  }
42 }
43 
44 std::vector<unsigned int> DigitalPinSetAccess::subset(
45  const std::vector<unsigned int> &pos
46 ) const {
47  std::vector<unsigned int> pins;
48  pins.reserve(pos.size());
49  std::vector<unsigned int>::const_iterator iter = pos.cbegin();
50  for (; iter != pos.cend(); ++iter) {
51  if ((*iter != -1) && (*iter >= pinvec.size())) {
53  PinErrorId(globalId(*iter))
54  );
55  }
56  pins.push_back(pinvec[*iter]);
57  }
58  return pins;
59 }
60 
62  std::vector<DigitalPinConfig> c(pinvec.size(), conf);
64 }
65 
66 void DigitalPinSetAccess::output(bool state) const {
67  std::vector<bool> s(pinvec.size(), state);
68  port()->output(pinvec, s, &portdata);
69 }
70 
71 } } }
Provides access to multiple pins on a DigitalPort.
DigitalPort * port() const
Returns a pointer to the port that controls the pin(s) that are operated through this object...
Defines the configuration for a digital general purpose I/O pin.
std::vector< unsigned int > subset(const std::vector< unsigned int > &pos) const
Produces a vector with port local pin IDs that are a subset of the pins in this access object...
DigitalPinConfig modifyConfig(unsigned int globalPinId, const DigitalPinConfig &cfg, DigitalPinAccessBase::PortData *pdata)
Modifies the configuration of a single pin with an independent configuration.
move_impl move(unsigned int c, unsigned int r)
Display stream manipulator that moves the display cursor to the given location.
A pin required for the operation does not exist or is unavailable to the process. ...
Definition: PinErrors.hpp:70
DigitalPinConfig modifyConfig(unsigned int pos, const DigitalPinConfig &conf) const
Modifies the configuration of a pin.
DigitalPinSetAccess & operator=(DigitalPinSetAccess &&old) noexcept
A move assignment.
void reset()
Loses the pointer to the DigitalPort rendering the access object useless.
boost::error_info< struct Info_PinId, unsigned int > PinErrorId
The pin global ID involved in the error.
Definition: PinErrors.hpp:97
PortData portdata
Port specific information.
DigitalPinAccessBase & operator=(DigitalPinAccessBase &&old) noexcept
Allows moving access objects.
void reserveAdditional(unsigned int len)
Reserves additional space in pins so that upcoming pushes onto the vector will not cause multiple mem...
void updateAccess(const DigitalPinAccess &oldAcc, DigitalPinAccess *newAcc)
Transfers or relinquishes access to pins.
bool havePins() const
Returns true if this object has been given any pins to access.
void output(unsigned int pos, bool state) const
Changes the output state of a pin.
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 ...
unsigned int globalId(unsigned int pos) const
Returns the global pin ID of the pin at the given position inside this set of pins.
std::vector< unsigned int > pinvec
The port local pin IDs this object may use.
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
Definition: Errors.hpp:48