This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
ExtendedIOElement.cpp
Go to the documentation of this file.
1 #include "ExtendedIOElement.hpp"
2 #include <Arduino.h>
3 #include <Helpers/Error.hpp>
4 #include <Helpers/Helpers.hpp>
5 
7 
9  : length(length), start(offset), end(offset + length) {
10  if (end < start)
11  FATAL_ERROR(F("ExtIO ran out of pin numbers. "
12  "Dynamically creating new ExtendedIOElements is not "
13  "recommended."),
14  0x00FF);
15  offset = end;
16  elements.append(this);
17 }
18 
20 
22  for (ExtendedIOElement &e : elements)
23  e.begin();
24 }
25 
27  if (p >= length) {
28  static_assert(is_unsigned<pin_t>::value,
29  "Error: pin_t should be an unsigned integer type");
30  ERROR(F("Error: the pin number (")
31  << p
32  << F(") is greater than the number of pins of this "
33  "ExtendedIOElement (")
34  << length << ')',
35  0x4567);
36  return end - 1;
37  }
38  return p + start;
39 }
40 
42 
44 
45 pin_t ExtendedIOElement::getEnd() const { return end; }
46 
48 
50  return elements;
51 }
52 
54 
55 pin_t ExtendedIOElement::offset = NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS;
56 
ExtendedIOElement.hpp
ExtendedIOElement::length
const pin_t length
Definition: ExtendedIOElement.hpp:189
ERROR
#define ERROR(x, e)
Definition: Error.hpp:27
Error.hpp
ExtendedIOElement::end
const pin_t end
Definition: ExtendedIOElement.hpp:191
pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Def.hpp:17
DoublyLinkedList::append
void append(Node *node)
Append a node to a linked list.
Definition: LinkedList.hpp:113
ExtendedIOElement::~ExtendedIOElement
virtual ~ExtendedIOElement()
Definition: ExtendedIOElement.cpp:19
ExtendedIOElement::getStart
pin_t getStart() const
Get the smallest global extended IO pin number that belongs to this extended IO element.
Definition: ExtendedIOElement.cpp:47
DoublyLinkedList::remove
void remove(Node *node)
Remove a node from the linked list.
Definition: LinkedList.hpp:196
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:41
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
ExtendedIOElement::getLength
pin_t getLength() const
Get the number of pins this IO element has.
Definition: ExtendedIOElement.cpp:43
ExtendedIOElement::offset
static pin_t offset
Definition: ExtendedIOElement.hpp:192
is_unsigned
A utility class to check whether a given type is unsigned.
Definition: Helpers.hpp:12
ExtendedIOElement::getEnd
pin_t getEnd() const
Get the largest global extended IO pin number that belongs to this extended IO element.
Definition: ExtendedIOElement.cpp:45
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:26
ExtendedIOElement::getAll
static DoublyLinkedList< ExtendedIOElement > & getAll()
Get the list of all Extended IO elements.
Definition: ExtendedIOElement.cpp:49
ExtendedIOElement::start
const pin_t start
Definition: ExtendedIOElement.hpp:190
ExtendedIOElement
An abstract base class for Extended Input/Output elements.
Definition: ExtendedIOElement.hpp:59
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
FATAL_ERROR
#define FATAL_ERROR(x, e)
Definition: Error.hpp:35
Helpers.hpp
DoublyLinkedList< ExtendedIOElement >
ExtendedIOElement::elements
static DoublyLinkedList< ExtendedIOElement > elements
Definition: ExtendedIOElement.hpp:194
ExtendedIOElement::ExtendedIOElement
ExtendedIOElement(pin_t length)
Create an ExtendedIOElement with the given number of pins.
Definition: ExtendedIOElement.cpp:8
ExtendedIOElement::beginAll
static void beginAll()
Initialize all extended IO elements.
Definition: ExtendedIOElement.cpp:21
MIDI_Notes::F
constexpr int8_t F
Definition: Notes.hpp:23