Control Surface  1.1.1
MIDI Control Surface library for Arduino
ExtendedIOElement.cpp
Go to the documentation of this file.
2 AH_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 
10 ExtendedIOElement::ExtendedIOElement(pin_t length)
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  elements.append(this);
19 }
20 
22 
24  for (ExtendedIOElement &e : elements)
25  e.begin();
26 }
27 
29  if (p >= length) {
30  static_assert(std::is_unsigned<pin_t>::value,
31  "Error: pin_t should be an unsigned integer type");
32  ERROR(F("Error: the pin number (")
33  << p
34  << F(") is greater than the number of pins of this "
35  "ExtendedIOElement (")
36  << length << ')',
37  0x4567);
38  return end - 1; // LCOV_EXCL_LINE
39  }
40  return p + start;
41 }
42 
44 
46 
47 pin_t ExtendedIOElement::getEnd() const { return end; }
48 
50 
52  return elements;
53 }
54 
56 
57 pin_t ExtendedIOElement::offset = NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS;
58 
60 
AH::ExtendedIOElement::end
const pin_t end
Definition: ExtendedIOElement.hpp:194
AH::ExtendedIOElement::offset
static pin_t offset
Definition: ExtendedIOElement.hpp:195
Warnings.hpp
AH::ExtendedIOElement::getEnd
pin_t getEnd() const
Get the largest global extended IO pin number that belongs to this extended IO element.
Definition: ExtendedIOElement.cpp:47
Error.hpp
AH::ExtendedIOElement::getAll
static DoublyLinkedList< ExtendedIOElement > & getAll()
Get the list of all Extended IO elements.
Definition: ExtendedIOElement.cpp:51
AH::pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Hardware-Types.hpp:17
AH::ExtendedIOElement::getLength
pin_t getLength() const
Get the number of pins this IO element has.
Definition: ExtendedIOElement.cpp:45
AH::ExtendedIOElement::~ExtendedIOElement
virtual ~ExtendedIOElement()
Definition: ExtendedIOElement.cpp:21
AH_DIAGNOSTIC_POP
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:17
AH::ExtendedIOElement::start
const pin_t start
Definition: ExtendedIOElement.hpp:193
AH::ExtendedIOElement
An abstract base class for Extended Input/Output elements.
Definition: ExtendedIOElement.hpp:62
FATAL_ERROR
#define FATAL_ERROR(msg, errc)
Print the error message and error code, and stop the execution.
Definition: Error.hpp:60
ERROR
#define ERROR(msg, errc)
Print the error message and error code, and stop the execution if FATAL_ERRORS are enabled.
Definition: Error.hpp:42
AH::ExtendedIOElement::getStart
pin_t getStart() const
Get the smallest global extended IO pin number that belongs to this extended IO element.
Definition: ExtendedIOElement.cpp:49
AH::ExtendedIOElement::beginAll
static void beginAll()
Initialize all extended IO elements.
Definition: ExtendedIOElement.cpp:23
AH::ExtendedIOElement::length
const pin_t length
Definition: ExtendedIOElement.hpp:192
AH::ExtendedIOElement::pin
pin_t pin(pin_t pin) const
Get the extended IO pin number of a given physical pin of this extended IO element.
Definition: ExtendedIOElement.cpp:28
AH::ExtendedIOElement::operator[]
pin_t operator[](pin_t pin) const
Get the extended IO pin number of a given physical pin of this extended IO element.
Definition: ExtendedIOElement.cpp:43
MIDI_Notes::F
constexpr int8_t F
Definition: Notes.hpp:23
DoublyLinkedList
A class for doubly linked lists.
Definition: LinkedList.hpp:27
AH_DIAGNOSTIC_WERROR
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:16
BEGIN_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
Definition: AH/Settings/NamespaceSettings.hpp:9
END_AH_NAMESPACE
#define END_AH_NAMESPACE
Definition: AH/Settings/NamespaceSettings.hpp:10
AH::ExtendedIOElement::elements
static DoublyLinkedList< ExtendedIOElement > elements
Definition: ExtendedIOElement.hpp:197