VEXcode Doxygen
vex_device.h
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) Innovation First 2017-2019, All rights reserved. */
4 /* */
5 /* Module: vex_device.h */
6 /* Author: James Pearman */
7 /* Created: 10 Oct 2017 */
8 /* */
9 /* Revisions: */
10 /* V1.00 TBD - Initial release */
11 /* */
12 /*----------------------------------------------------------------------------*/
13 
14 #ifndef VEX_DEVICE_CLASS_H
15 #define VEX_DEVICE_CLASS_H
16 
17 #include "v5_apiprivate.h"
18 
19 /*-----------------------------------------------------------------------------*//*---------------------------------------------------------------------------*/
23 
24 /*-----------------------------------------------------------------------------*/
26 /*-----------------------------------------------------------------------------*/
27 namespace vex {
30  class device {
31  private:
32  V5_DeviceT _ptr;
33 
34  protected:
35  int32_t _index;
36  int32_t _threadID;
37 
38  public:
39  device();
40  device( int32_t index );
41  virtual ~device();
42 
43  V5_DeviceType type();
44  int32_t index();
45  void init( int32_t index );
46  virtual bool installed();
47  virtual int32_t value();
48  uint32_t timestamp();
49  };
50 };
51 
52 /*-----------------------------------------------------------------------------*/
54 /*-----------------------------------------------------------------------------*/
55 
56 namespace vex {
57  template <class T, int len> class safearray {
58  private:
59  int length;
60 
61  protected:
62  T arr[len];
63  T outofbounds;
64 
65  public:
66  safearray(){ length = len; outofbounds = 0;
67  };
68  ~safearray(){};
69 
70  T &operator[]( int i );
71  int getLength() { return length; };
72  };
73 
74  template <class T, int len> T &safearray<T, len>::operator[](int i)
75  {
76  // bounds check the array index
77  if( i < 0 || i > (length-1) ) {
78  return( outofbounds );
79  }
80  else {
81  return( arr[i] );
82  }
83  }
84 };
85 
86 
87 /*-----------------------------------------------------------------------------*/
89 /*-----------------------------------------------------------------------------*/
90 //
91 // This class is never directly used except as a ptr to gyro or imu
92 //
93 namespace vex {
94  class guido {
95  public:
96  guido(){};
97  virtual ~guido(){};
98 
99  // pure virtual methods that must be implemented
100  virtual double angle( rotationUnits units = rotationUnits::deg ) = 0;
101  virtual double heading( rotationUnits units = rotationUnits::deg ) = 0;
102  virtual void calibrate( int32_t value ) = 0;
103  virtual bool isCalibrating(void) = 0;
104  virtual void setHeading( double value, rotationUnits units ) = 0;
105  virtual double rotation( rotationUnits units = rotationUnits::deg ) = 0;
106  virtual void setRotation( double value, rotationUnits units ) = 0;
107  };
108 };
109 
110 /*-----------------------------------------------------------------------------*/
112 /*-----------------------------------------------------------------------------*/
113 namespace vex {
116  class devices {
117  private:
119 
120  public:
121  devices();
122  ~devices();
123 
124  device &operator[]( int i ) {
125  return( data[i] );
126  }
135  V5_DeviceType type( int32_t index );
136 
144  int32_t number();
145 
153  int32_t numberOf( V5_DeviceType type );
154  };
155 };
156 
157 #endif // VEX_DEVICE_CLASS_H
vex::devices::numberOf
int32_t numberOf(V5_DeviceType type)
Gets the number of specified devices that are plugged into the V5.
vex::devices::type
V5_DeviceType type(int32_t index)
Get the V5 device type plugged into a specific port.
vex::rotation
Use the rotation class to control absolute encoder devices.
Definition: vex_rotation.h:26
vex::device
Use the device class to get information about a vex device plugged into the V5.
Definition: vex_device.h:30
vex
device class
Definition: vex_brain.h:26
vex::guido
Definition: vex_device.h:94
vex::devices
Use the device class to get information about all of the vex devices plugged into the V5.
Definition: vex_device.h:116
vex::safearray
Definition: vex_device.h:57
vex::rotationUnits
rotationUnits
The measurement units for rotation values.
Definition: vex_units.h:74
vex::devices::number
int32_t number()
Gets the number of VEX devices that are plugged in.
vex::rotationUnits::deg
A rotation unit that is measured in degrees.
V5_DeviceType
V5_DeviceType
V5 Device type definitions
Definition: v5_apitypes.h:99
v5_apiprivate.h
Header for V5 Internal API.