forked from dimitry-ishenko-cpp/firmata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pins.hpp
80 lines (64 loc) · 2.14 KB
/
pins.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2017 Dimitry Ishenko
// Contact: dimitry (dot) ishenko (at) (gee) mail (dot) com
//
// Distributed under the GNU GPL license. See the LICENSE.md file for details.
////////////////////////////////////////////////////////////////////////////////
#ifndef FIRMATA_PINS_HPP
#define FIRMATA_PINS_HPP
////////////////////////////////////////////////////////////////////////////////
#include "firmata/pin.hpp"
#include "firmata/types.hpp"
#include <algorithm>
#include <utility>
#include <vector>
////////////////////////////////////////////////////////////////////////////////
namespace firmata
{
////////////////////////////////////////////////////////////////////////////////
// Collection of pins
//
class pins : private std::vector<pin>
{
using base = std::vector<pin>;
public:
////////////////////
pins() noexcept = default;
pins(const pin&) = delete;
pins(pins&&) noexcept = default;
pins& operator=(const pins&) = delete;
pins& operator=(pins&&) noexcept = default;
////////////////////
using base::begin;
using base::end;
using base::cbegin;
using base::cend;
using base::rbegin;
using base::rend;
using base::crbegin;
using base::crend;
// number of pins
auto count() const noexcept { return size(); }
// number of pins that support certain mode
auto count(mode n) const noexcept
{
return std::count_if(begin(), end(),
[&](auto& pin){ return pin.supports(n); }
);
}
////////////////////
// get pin
auto& get(pos n) { return at(n); }
const auto& get(pos n) const { return at(n); }
// get analog pin
auto& get(analog n) { return get(analog_in, n); }
auto const& get(analog n) const { return get(analog_in, n); }
// get pin that supports certain mode
firmata::pin& get(mode, pos);
const firmata::pin& get(mode, pos) const;
friend class client;
};
////////////////////////////////////////////////////////////////////////////////
}
////////////////////////////////////////////////////////////////////////////////
#endif