VEXcode IQ C++ Unofficial documentation for version 3.0.4.1
Loading...
Searching...
No Matches
vex_device.h
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* */
3/* Copyright (c) Innovation First 2017, All rights reserved. */
4/* */
5/* Module: vex_device.h */
6/* Author: James Pearman */
7/* Created: 21 Nov 2016 */
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/*-----------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22/*-----------------------------------------------------------------------------*/
24/*-----------------------------------------------------------------------------*/
25namespace vex {
26 class device {
27 private:
28 int32_t _lastpolltime;
29 int16_t _pollinterval;
30
31 protected:
32 int16_t _index;
33 void setPollInterval( int32_t value );
34 bool pollValid( bool bSave );
35
36 public:
37 device();
38 device( int32_t index );
39 ~device();
40
41 IQ_DeviceType type();
42 int32_t index();
43 void init( int32_t index );
44 virtual bool installed();
45 virtual int32_t value();
46
47 int32_t readDigitalPin();
48 int32_t readAnalogPin();
49 };
50};
51
52/*-----------------------------------------------------------------------------*/
54/*-----------------------------------------------------------------------------*/
55// This version of safearray now returns element 0 for out of bounds access
56// The only place we actually use this on IQ is in vision class
57// need to save memory !
58namespace vex {
59 template <class T, int len> class safearray {
60 private:
61 int length;
62
63 protected:
64 T arr[len];
65
66 public:
67 safearray(){ length = len;
68 };
69 ~safearray(){};
70
71 T &operator[]( int i );
72 int getLength() { return length; };
73 };
74
75 template <class T, int len> T &safearray<T, len>::operator[](int i)
76 {
77 // bounds check the array index
78 if( i < 0 || i > (length-1) ) {
79 return( arr[0] );
80 }
81 else {
82 return( arr[i] );
83 }
84 }
85};
86
87/*-----------------------------------------------------------------------------*/
89/*-----------------------------------------------------------------------------*/
90namespace vex {
93 class devices {
94 private:
95 //safearray<device, IQ_MAX_DEVICE_PORTS> data;
96
97 public:
98 devices();
99 ~devices();
100
101 //device &operator[]( int i ) {
102 // return( data[i] );
103 //}
109 IQ_DeviceType type( int32_t index );
110
115 int32_t number();
116
123 };
124};
125
126#endif // VEX_DEVICE_CLASS_H
Use the device class to get information about all of the vex devices plugged into the IQ.
Definition vex_device.h:93
int32_t numberOf(IQ_DeviceType type)
Gets the number of specified devices that are plugged into the V5.
IQ_DeviceType type(int32_t index)
Get the V5 device type plugged into a specific port.
int32_t number()
Gets the number of VEX devices that are plugged in.
IQ_DeviceType
IQ Device type definitions
Definition iq_apitypes.h:35
Bumper switch device class
Definition vex_brain.h:24