Control Surface
main
MIDI Control Surface library for Arduino
Toggle main menu visibility
Loading...
Searching...
No Matches
src
AH
Hardware
ExtendedInputOutput
ExtendedIOElement.cpp
Go to the documentation of this file.
1
#include "
ExtendedIOElement.hpp
"
2
#include <
AH/Error/Error.hpp
>
3
#include <AH/STL/type_traits>
// is_unsigned
4
5
BEGIN_AH_NAMESPACE
6
7
ExtendedIOElement::ExtendedIOElement
(
pin_int_t
length
)
8
:
length
(
length
),
start
(
offset
),
end
(
offset
+
length
) {
9
if
(
end
>
NO_PIN
)
10
FATAL_ERROR
(F(
"ExtIO ran out of pin numbers. "
11
"Dynamically creating new ExtendedIOElements is not "
12
"recommended."
),
13
0x00FF);
14
offset
=
end
;
15
}
16
17
void
ExtendedIOElement::beginAll
() {
18
ExtendedIOElement::applyToAll(&
ExtendedIOElement::begin
);
19
}
20
21
void
ExtendedIOElement::updateAllBufferedOutputs
() {
22
ExtendedIOElement::applyToAll(&
ExtendedIOElement::updateBufferedOutputs
);
23
}
24
25
void
ExtendedIOElement::updateAllBufferedInputs
() {
26
ExtendedIOElement::applyToAll(&
ExtendedIOElement::updateBufferedInputs
);
27
}
28
29
pin_t
ExtendedIOElement::pin
(
pin_int_t
p)
const
{
30
if
(p >=
length
) {
31
static_assert
(!std::is_integral<pin_t>::value ||
32
std::is_unsigned<pin_t>::value,
33
"Error: pin_t should be an unsigned integer type"
);
34
ERROR
(F(
"Error: the pin number ("
)
35
<< p
36
<< F(
") is greater than the number of pins of this "
37
"ExtendedIOElement ("
)
38
<<
length
<<
')'
,
39
0x4567);
40
return
end
- 1;
// LCOV_EXCL_LINE
41
}
42
return
p +
start
;
43
}
44
45
pin_t
ExtendedIOElement::operator[]
(
pin_int_t
p)
const
{
return
pin
(p); }
46
47
pin_int_t
ExtendedIOElement::getLength
()
const
{
return
length
; }
48
49
pin_t
ExtendedIOElement::getEnd
()
const
{
return
end
; }
50
51
pin_t
ExtendedIOElement::getStart
()
const
{
return
start
; }
52
53
DoublyLinkedList<ExtendedIOElement>
&
ExtendedIOElement::getAll
() {
54
return
updatables
;
55
}
56
57
pin_t
ExtendedIOElement::offset
= NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS;
58
59
END_AH_NAMESPACE
END_AH_NAMESPACE
#define END_AH_NAMESPACE
Definition
AH/Settings/NamespaceSettings.hpp:14
BEGIN_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
Definition
AH/Settings/NamespaceSettings.hpp:11
Error.hpp
ERROR
#define ERROR(msg, errc)
Definition
Error.hpp:19
ExtendedIOElement.hpp
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:51
AH::ExtendedIOElement::updateBufferedInputs
virtual void updateBufferedInputs()=0
Read the physical state into the input buffers.
AH::ExtendedIOElement::updateBufferedOutputs
virtual void updateBufferedOutputs()=0
Write the internal state to the physical outputs.
AH::ExtendedIOElement::ExtendedIOElement
ExtendedIOElement(pin_int_t length)
Create an ExtendedIOElement with the given number of pins.
Definition
ExtendedIOElement.cpp:7
AH::ExtendedIOElement::getLength
pin_int_t getLength() const
Get the number of pins this IO element has.
Definition
ExtendedIOElement.cpp:47
AH::ExtendedIOElement::end
const pin_t end
Definition
ExtendedIOElement.hpp:266
AH::ExtendedIOElement::length
const pin_int_t length
Definition
ExtendedIOElement.hpp:264
AH::ExtendedIOElement::start
const pin_t start
Definition
ExtendedIOElement.hpp:265
AH::ExtendedIOElement::offset
static pin_t offset
Definition
ExtendedIOElement.hpp:267
AH::ExtendedIOElement::begin
virtual void begin()=0
Initialize the extended IO element.
AH::ExtendedIOElement::getAll
static DoublyLinkedList< ExtendedIOElement > & getAll()
Get the list of all Extended IO elements.
Definition
ExtendedIOElement.cpp:53
AH::ExtendedIOElement::updateAllBufferedOutputs
static void updateAllBufferedOutputs()
Write the internal states to the physical outputs for all extended IO elements.
Definition
ExtendedIOElement.cpp:21
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:49
AH::ExtendedIOElement::beginAll
static void beginAll()
Initialize all extended IO elements.
Definition
ExtendedIOElement.cpp:17
AH::ExtendedIOElement::operator[]
pin_t operator[](pin_int_t pin) const
Get the extended IO pin number of a given physical pin of this extended IO element.
Definition
ExtendedIOElement.cpp:45
AH::ExtendedIOElement::pin
pin_t pin(pin_int_t pin) const
Get the extended IO pin number of a given physical pin of this extended IO element.
Definition
ExtendedIOElement.cpp:29
AH::ExtendedIOElement::updateAllBufferedInputs
static void updateAllBufferedInputs()
Read the physical state into the input buffers for all extended IO elements.
Definition
ExtendedIOElement.cpp:25
AH::UpdatableCRTP< ExtendedIOElement >::updatables
static DoublyLinkedList< ExtendedIOElement > updatables
Definition
Updatable.hpp:152
DoublyLinkedList
A class for doubly linked lists.
Definition
LinkedList.hpp:21
FATAL_ERROR
#define FATAL_ERROR(msg, errc)
Print the error message and error code, and stop the execution.
Definition
Error.hpp:57
AH::NO_PIN
constexpr pin_t NO_PIN
A special pin number that indicates an unused or invalid pin.
Definition
Hardware-Types.hpp:96
AH::pin_int_t
uint_fast16_t pin_int_t
Integer type used internally to store the index of (extended) GPIO pins.
Definition
Hardware-Types.hpp:19
AH::ExtIO::pin_t
Type for storing pin numbers of Extended Input/Output elements.
Definition
Hardware-Types.hpp:25
Generated by
1.17.0