Arduino Filters master
Filter library for Arduino
ExtendedIOElement.cpp
Go to the documentation of this file.
2AH_DIAGNOSTIC_WERROR() // Enable errors on warnings
3
4#include "ExtendedIOElement.hpp"
5#include <AH/Error/Error.hpp>
6#include <AH/STL/type_traits> // is_unsigned
7
9
11 : length(length), start(offset), end(offset + length) {
12 if (end < start)
13 FATAL_ERROR(F("ExtIO ran out of pin numbers. "
14 "Dynamically creating new ExtendedIOElements is not "
15 "recommended."),
16 0x00FF);
17 offset = end;
18}
19
21 ExtendedIOElement::applyToAll(&ExtendedIOElement::begin);
22}
23
25 ExtendedIOElement::applyToAll(&ExtendedIOElement::updateBufferedOutputs);
26}
27
29 ExtendedIOElement::applyToAll(&ExtendedIOElement::updateBufferedInputs);
30}
31
33 if (p >= length) {
34 static_assert(std::is_unsigned<pin_t>::value,
35 "Error: pin_t should be an unsigned integer type");
36 ERROR(F("Error: the pin number (")
37 << p
38 << F(") is greater than the number of pins of this "
39 "ExtendedIOElement (")
40 << length << ')',
41 0x4567);
42 return end - 1; // LCOV_EXCL_LINE
43 }
44 return p + start;
45}
46
48
50
52
54
56 return updatables;
57}
58
59pin_t ExtendedIOElement::offset = NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS;
60
62
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:36
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:35
pin_t getStart() const
Get the smallest global extended IO pin number that belongs to this extended IO element.
virtual void updateBufferedInputs()=0
Read the physical state into the input buffers.
virtual void updateBufferedOutputs()=0
Write the internal state to the physical outputs.
pin_t pin(pin_t pin) const
Get the extended IO pin number of a given physical pin of this extended IO element.
pin_t getLength() const
Get the number of pins this IO element has.
pin_t operator[](pin_t pin) const
Get the extended IO pin number of a given physical pin of this extended IO element.
virtual void begin()=0
Initialize the extended IO element.
ExtendedIOElement(pin_t length)
Create an ExtendedIOElement with the given number of pins.
static DoublyLinkedList< ExtendedIOElement > & getAll()
Get the list of all Extended IO elements.
static void updateAllBufferedOutputs()
Write the internal states to the physical outputs for all extended IO elements.
pin_t getEnd() const
Get the largest global extended IO pin number that belongs to this extended IO element.
static void beginAll()
Initialize all extended IO elements.
static void updateAllBufferedInputs()
Read the physical state into the input buffers for all extended IO elements.
static DoublyLinkedList< ExtendedIOElement > updatables
Definition: Updatable.hpp:156
#define FATAL_ERROR(msg, errc)
Print the error message and error code, and stop the execution.
Definition: Error.hpp:60
#define ERROR(msg, errc)
Print the error message and error code, and stop the execution if FATAL_ERRORS are enabled.
Definition: Error.hpp:42