LCOV - code coverage report
Current view: top level - src/Hardware/ExtendedInputOutput - ExtendedIOElement.cpp (source / functions) Hit Total Coverage
Test: 19d2efc7037c2e176feca44750a12594c76f466f Lines: 21 24 87.5 %
Date: 2019-11-24 14:50:27 Functions: 7 10 70.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include "ExtendedIOElement.hpp"
       2             : #include <Arduino.h>
       3             : #include <Helpers/Error.hpp>
       4             : #include <Helpers/Helpers.hpp>
       5             : 
       6             : BEGIN_CS_NAMESPACE
       7             : 
       8          15 : ExtendedIOElement::ExtendedIOElement(pin_t length)
       9          30 :     : length(length), start(offset), end(offset + length) {
      10          15 :     if (end < start)
      11           1 :         FATAL_ERROR(F("ExtIO ran out of pin numbers. "
      12             :                       "Dynamically creating new ExtendedIOElements is not "
      13             :                       "recommended."),
      14             :                     0x00FF);
      15          14 :     offset = end;
      16          14 :     elements.append(this);
      17          16 : }
      18             : 
      19          14 : ExtendedIOElement::~ExtendedIOElement() { elements.remove(this); }
      20             : 
      21           6 : void ExtendedIOElement::beginAll() {
      22          12 :     for (ExtendedIOElement &e : elements)
      23           6 :         e.begin();
      24           6 : }
      25             : 
      26          24 : pin_t ExtendedIOElement::pin(pin_t p) const {
      27          24 :     if (p >= length) {
      28             :         static_assert(is_unsigned<pin_t>::value,
      29             :                       "Error: pin_t should be an unsigned integer type");
      30           2 :         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           0 :         return end - 1;
      37             :     }
      38          22 :     return p + start;
      39          24 : }
      40             : 
      41           0 : pin_t ExtendedIOElement::operator[](pin_t p) const { return pin(p); }
      42             : 
      43           0 : pin_t ExtendedIOElement::getLength() const { return length; }
      44             : 
      45          24 : pin_t ExtendedIOElement::getEnd() const { return end; }
      46             : 
      47          67 : pin_t ExtendedIOElement::getStart() const { return start; }
      48             : 
      49          20 : DoublyLinkedList<ExtendedIOElement> &ExtendedIOElement::getAll() {
      50          20 :     return elements;
      51             : }
      52             : 
      53             : DoublyLinkedList<ExtendedIOElement> ExtendedIOElement::elements;
      54             : 
      55             : pin_t ExtendedIOElement::offset = NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS;
      56             : 
      57             : END_CS_NAMESPACE

Generated by: LCOV version 1.14-5-g4ff2ed6