Go to the documentation of this file.
32 #include <libphidget22/phidget22.h>
40 int32_t serial_number,
int hub_port,
bool is_hub_port_device,
int channel,
41 std::function<
void(
int,
int,
double,
int)> position_change_handler)
42 : channel_(channel), position_change_handler_(position_change_handler)
46 if (ret != EPHIDGET_OK)
53 hub_port, is_hub_port_device, channel);
55 ret = PhidgetEncoder_setOnPositionChangeHandler(
57 if (ret != EPHIDGET_OK)
60 "Failed to set change handler for Encoder channel " +
61 std::to_string(channel),
68 PhidgetHandle handle =
reinterpret_cast<PhidgetHandle
>(
encoder_handle_);
75 PhidgetReturnCode ret =
77 if (ret != EPHIDGET_OK)
79 throw Phidget22Error(
"Failed to get position for Encoder channel " +
89 PhidgetReturnCode ret =
91 if (ret != EPHIDGET_OK)
93 throw Phidget22Error(
"Failed to set position for Encoder channel " +
102 PhidgetReturnCode ret =
104 if (ret != EPHIDGET_OK)
107 "Failed to get index position for Encoder channel " +
118 PhidgetReturnCode ret =
120 if (ret != EPHIDGET_OK)
122 throw Phidget22Error(
"Failed to get enabled for Encoder channel " +
127 return enabled == PTRUE;
132 PhidgetReturnCode ret =
134 if (ret != EPHIDGET_OK)
136 throw Phidget22Error(
"Failed to set enabled for Encoder channel " +
144 Phidget_EncoderIOMode io_mode;
145 PhidgetReturnCode ret = PhidgetEncoder_getIOMode(
encoder_handle_, &io_mode);
146 if (ret != EPHIDGET_OK)
148 throw Phidget22Error(
"Failed to get IO Mode for Encoder channel " +
157 PhidgetReturnCode ret = PhidgetEncoder_setIOMode(
encoder_handle_, io_mode);
158 if (ret != EPHIDGET_OK)
160 throw Phidget22Error(
"Failed to set IO Mode for Encoder channel " +
168 uint32_t data_interval_ms;
169 PhidgetReturnCode ret =
171 if (ret != EPHIDGET_OK)
174 "Failed to get data interval for Encoder channel " +
178 return data_interval_ms;
183 PhidgetReturnCode ret =
185 if (ret != EPHIDGET_OK)
188 "Failed to set data interval for Encoder channel " +
201 int position_change,
double time,
205 ->positionChangeHandler(position_change, time, index_triggered);
uint32_t getDataInterval() const
void setEnabled(bool enabled) const
Set the powered state of an encoder. If an encoder is not enabled, it will not be given power,...
PhidgetEncoderHandle encoder_handle_
int64_t getPosition() const
Reads the current position of an encoder.
void setIOMode(Phidget_EncoderIOMode io_mode) const
bool getEnabled() const
Checks if an encoder is powered on and receiving events.
void openWaitForAttachment(PhidgetHandle handle, int32_t serial_number, int hub_port, bool is_hub_port_device, int channel)
static void PositionChangeHandler(PhidgetEncoderHandle phid, void *ctx, int position_change, double time_change, int index_triggered)
void closeAndDelete(PhidgetHandle *handle) noexcept
void setPosition(int64_t position) const
Sets the offset of an encoder such that current position is the specified value.
void setDataInterval(uint32_t data_interval_ms) const
std::function< void(int, int, double, int)> position_change_handler_
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)
int64_t getIndexPosition() const
Gets the position of an encoder the last time an index pulse occured. An index pulse in this context ...
void positionChangeHandler(int position_change, double time, int index_triggered)
Phidget_EncoderIOMode getIOMode() const
phidgets_api
Author(s): Tully Foote, Ivan Dryanovski
autogenerated on Sun May 11 2025 02:20:27