-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencoder.cpp
More file actions
65 lines (53 loc) · 1.84 KB
/
Copy pathencoder.cpp
File metadata and controls
65 lines (53 loc) · 1.84 KB
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
// SPDX-License-Identifier: LGPL-2.1-only
//
// libpisoundmicro - a utility library for Pisound Micro I/O expander capabilities.
// Copyright (c) 2017-2025 Vilniaus Blokas UAB, https://blokas.io/
//
// This file is part of libpisoundmicro.
//
// libpisoundmicro is free software: you can redistribute it and/or modify it under the terms of the
// GNU Lesser General Public License as published by the Free Software Foundation, version 2.1 of the License.
//
// libpisoundmicro is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
// for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with libpisoundmicro. If not, see <https://www.gnu.org/licenses/>.
#include "include/pisound-micro.h"
#include <fcntl.h>
#include <errno.h>
namespace upisnd
{
Encoder Encoder::setup(ElementName name, upisnd_pin_t pin_a, upisnd_pin_pull_e pull_a, upisnd_pin_t pin_b, upisnd_pin_pull_e pull_b)
{
return Encoder(upisnd_setup_encoder(name, pin_a, pull_a, pin_b, pull_b), false);
}
int Encoder::get() const
{
ValueFd fd = openValueFd(O_RDONLY | O_CLOEXEC);
int result = fd.read();
if (errno != 0)
return -errno;
return result;
}
int Encoder::getOpts(upisnd_encoder_opts_t &opts) const
{
return upisnd_element_encoder_get_opts(ref(), &opts);
}
int Encoder::setOpts(const upisnd_encoder_opts_t &opts)
{
return upisnd_element_encoder_set_opts(ref(), &opts);
}
upisnd_pin_t Encoder::getPinB() const
{
return upisnd_element_encoder_get_pin_b(ref());
}
upisnd_pin_pull_e Encoder::getPinPull() const
{
return upisnd_element_gpio_get_pull(ref());
}
upisnd_pin_pull_e Encoder::getPinBPull() const
{
return upisnd_element_encoder_get_pin_b_pull(ref());
}
} // namespace upisnd