encoder.cpp
Go to the documentation of this file.
00001 #include "phidgets_api/encoder.h"
00002 
00003 #include <cassert>
00004 
00005 namespace phidgets
00006 {
00007 
00008 Encoder::Encoder():
00009   Phidget(),
00010   encoder_handle_(0)
00011 {
00012   // create the handle
00013   CPhidgetEncoder_create(&encoder_handle_);
00014 
00015   // pass handle to base class
00016   Phidget::init((CPhidgetHandle)encoder_handle_);
00017 
00018   // register base class callbacks
00019   Phidget::registerHandlers();
00020 
00021   // register encoder data callbacks
00022   CPhidgetEncoder_set_OnInputChange_Handler(encoder_handle_, InputChangeHandler, this);
00023   CPhidgetEncoder_set_OnPositionChange_Handler(encoder_handle_, PositionChangeHandler, this);
00024   CPhidgetEncoder_set_OnIndex_Handler(encoder_handle_, IndexHandler, this);
00025 }
00026 
00027 int Encoder::getInputCount()
00028 {
00029   int count;
00030   int ret = CPhidgetEncoder_getInputCount(encoder_handle_, &count);
00031 
00032   assert(ret == EPHIDGET_OK);
00033 
00034   return count;
00035 }
00036 
00037 bool Encoder::getInputState(int index)
00038 {
00039   int state;
00040   int ret = CPhidgetEncoder_getInputState(encoder_handle_, index, &state);
00041 
00042   assert(ret == EPHIDGET_OK);
00043 
00044   return state == PTRUE;
00045 }
00046 
00047 int Encoder::getEncoderCount()
00048 {
00049   int count;
00050   int ret = CPhidgetEncoder_getEncoderCount(encoder_handle_, &count);
00051 
00052   assert(ret == EPHIDGET_OK);
00053 
00054   return count;
00055 }
00056 
00057 int Encoder::getPosition(int index)
00058 {
00059   int position;
00060   int ret = CPhidgetEncoder_getPosition(encoder_handle_, index, &position);
00061 
00062   assert(ret == EPHIDGET_OK);
00063 
00064   return position;
00065 }
00066 
00067 void Encoder::setPosition(int index, int position)
00068 {
00069   int ret = CPhidgetEncoder_setPosition(encoder_handle_, index, position);
00070 
00071   assert(ret == EPHIDGET_OK);
00072 }
00073 
00074 int Encoder::getIndexPosition(int index)
00075 {
00076   int position;
00077   int ret = CPhidgetEncoder_getIndexPosition(encoder_handle_, index, &position);
00078 
00079   // Encoder does not support indexing or index has not occured
00080   if (ret == EPHIDGET_UNKNOWNVAL) return 0;
00081 
00082   assert(ret == EPHIDGET_OK);
00083 
00084   return position;
00085 }
00086 
00087 bool Encoder::getEnabled(int index)
00088 {
00089   int enabled;
00090   int ret = CPhidgetEncoder_getEnabled(encoder_handle_, index, &enabled);
00091 
00092   assert(ret == EPHIDGET_OK);
00093 
00094   return enabled == PTRUE;
00095 }
00096 
00097 void Encoder::setEnabled(int index, bool enabled)
00098 {
00099   int ret = CPhidgetEncoder_setEnabled(encoder_handle_, index, enabled ? PTRUE : PFALSE);
00100 
00101   assert(ret == EPHIDGET_OK);
00102 }
00103 
00104 int Encoder::InputChangeHandler(CPhidgetEncoderHandle phid, void *userPtr, int index, int inputState)
00105 {
00106   ((Encoder*)userPtr)->inputChangeHandler(index, inputState);
00107 }
00108 
00109 int Encoder::PositionChangeHandler(CPhidgetEncoderHandle phid, void *userPtr, int index, int time, int positionChange)
00110 {
00111   ((Encoder*)userPtr)->positionChangeHandler(index, time, positionChange);
00112 }
00113 
00114 int Encoder::IndexHandler(CPhidgetEncoderHandle phid, void *userPtr, int index, int indexPosition)
00115 {
00116   ((Encoder*)userPtr)->indexHandler(index, indexPosition);
00117 }
00118 
00119 void Encoder::inputChangeHandler(int index, int inputState)
00120 {
00121   // This method can be overridden in a concrete subclass (e.g., ROS wrapper)
00122 }
00123 
00124 void Encoder::positionChangeHandler(int index, int time, int positionChange)
00125 {
00126   // This method can be overridden in a concrete subclass (e.g., ROS wrapper)
00127 }
00128 
00129 void Encoder::indexHandler(int index, int indexPosition)
00130 {
00131   // This method can be overridden in a concrete subclass (e.g., ROS wrapper)
00132 }
00133 
00134 
00135 } //namespace phidgets
00136 


phidgets_api
Author(s): Tully Foote, Ivan Dryanovski
autogenerated on Wed Aug 16 2017 02:50:15