encoder.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019, Open Source Robotics Foundation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef PHIDGETS_API_ENCODER_H
31 #define PHIDGETS_API_ENCODER_H
32 
33 #include <functional>
34 
35 #include <libphidget22/phidget22.h>
36 
37 #include "phidgets_api/phidget22.h"
38 
39 namespace phidgets {
40 
41 class Encoder final
42 {
43  public:
45 
46  explicit Encoder(
47  int32_t serial_number, int hub_port, bool is_hub_port_device,
48  int channel,
49  std::function<void(int, int, double, int)> position_change_handler);
50 
51  ~Encoder();
52 
55  int64_t getPosition() const;
56 
61  void setPosition(int64_t position) const;
62 
67  int64_t getIndexPosition() const;
68 
71  bool getEnabled() const;
72 
77  void setEnabled(bool enabled) const;
78 
79  Phidget_EncoderIOMode getIOMode() const;
80  void setIOMode(Phidget_EncoderIOMode io_mode) const;
81 
82  uint32_t getDataInterval() const;
83  void setDataInterval(uint32_t data_interval_ms) const;
84 
85  void positionChangeHandler(int position_change, double time,
86  int index_triggered);
87 
88  private:
89  int channel_;
90  std::function<void(int, int, double, int)> position_change_handler_;
91  PhidgetEncoderHandle encoder_handle_;
92 
93  static void PositionChangeHandler(PhidgetEncoderHandle phid, void *ctx,
94  int position_change, double time_change,
95  int index_triggered);
96 };
97 
98 } // namespace phidgets
99 
100 #endif // PHIDGETS_API_ENCODER_H
phidgets
Definition: accelerometer.h:39
phidgets::Encoder::getDataInterval
uint32_t getDataInterval() const
Definition: encoder.cpp:166
phidgets::Encoder::setEnabled
void setEnabled(bool enabled) const
Set the powered state of an encoder. If an encoder is not enabled, it will not be given power,...
Definition: encoder.cpp:130
phidgets::Encoder::channel_
int channel_
Definition: encoder.h:89
phidgets::Encoder::encoder_handle_
PhidgetEncoderHandle encoder_handle_
Definition: encoder.h:91
phidgets::Encoder::getPosition
int64_t getPosition() const
Reads the current position of an encoder.
Definition: encoder.cpp:72
phidgets::Encoder::setIOMode
void setIOMode(Phidget_EncoderIOMode io_mode) const
Definition: encoder.cpp:155
phidgets::Encoder::getEnabled
bool getEnabled() const
Checks if an encoder is powered on and receiving events.
Definition: encoder.cpp:115
phidgets::Encoder::~Encoder
~Encoder()
Definition: encoder.cpp:66
phidgets::Encoder::PositionChangeHandler
static void PositionChangeHandler(PhidgetEncoderHandle phid, void *ctx, int position_change, double time_change, int index_triggered)
Definition: encoder.cpp:200
phidgets::Encoder::setPosition
void setPosition(int64_t position) const
Sets the offset of an encoder such that current position is the specified value.
Definition: encoder.cpp:87
phidget22.h
phidgets::Encoder::setDataInterval
void setDataInterval(uint32_t data_interval_ms) const
Definition: encoder.cpp:181
phidgets::Encoder::position_change_handler_
std::function< void(int, int, double, int)> position_change_handler_
Definition: encoder.h:90
phidgets::Encoder::Encoder
Encoder(int32_t serial_number, int hub_port, bool is_hub_port_device, int channel, std::function< void(int, int, double, int)> position_change_handler)
Definition: encoder.cpp:39
phidgets::Encoder::getIndexPosition
int64_t getIndexPosition() const
Gets the position of an encoder the last time an index pulse occured. An index pulse in this context ...
Definition: encoder.cpp:99
phidgets::Encoder
Definition: encoder.h:41
PHIDGET22_NO_COPY_NO_MOVE_NO_ASSIGN
#define PHIDGET22_NO_COPY_NO_MOVE_NO_ASSIGN(Classname)
Definition: phidget22.h:38
phidgets::Encoder::positionChangeHandler
void positionChangeHandler(int position_change, double time, int index_triggered)
Definition: encoder.cpp:194
phidgets::Encoder::getIOMode
Phidget_EncoderIOMode getIOMode() const
Definition: encoder.cpp:142


phidgets_api
Author(s): Tully Foote, Ivan Dryanovski
autogenerated on Sun May 11 2025 02:20:27