VEXcode IQ C++ Unofficial documentation for version 3.0.4.1
Loading...
Searching...
No Matches
vex_controller.h
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* */
3/* Copyright (c) Innovation First 2017, All rights reserved. */
4/* */
5/* Module: vex_controller.h */
6/* Author: James Pearman */
7/* Created: 10 July 2017 */
8/* */
9/* Revisions: */
10/* V1.00 TBD - Initial release */
11/* */
12/*----------------------------------------------------------------------------*/
13
14#ifndef VEX_CONTROLLER_CLASS_H
15#define VEX_CONTROLLER_CLASS_H
16
17#include <functional>
18
19/*-----------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace vex {
25 class controller {
26 private:
27 int32_t _index;
28
29 protected:
30 int32_t _getIndex();
31
32 public:
38
39 private:
40 // bit masks for events
41 enum class tEventType {
42 EVENT_E_UP_PRESSED = 0,
43 EVENT_E_UP_RELEASED = 1,
44 EVENT_E_DN_PRESSED = 2,
45 EVENT_E_DN_RELEASED = 3,
46
47 EVENT_F_UP_PRESSED = 4,
48 EVENT_F_UP_RELEASED = 5,
49 EVENT_F_DN_PRESSED = 6,
50 EVENT_F_DN_RELEASED = 7,
51
52 EVENT_L_UP_PRESSED = 8,
53 EVENT_L_UP_RELEASED = 9,
54 EVENT_L_DN_PRESSED = 10,
55 EVENT_L_DN_RELEASED = 11,
56
57 EVENT_R_UP_PRESSED = 12,
58 EVENT_R_UP_RELEASED = 13,
59 EVENT_R_DN_PRESSED = 14,
60 EVENT_R_DN_RELEASED = 15,
61
62 EVENT_A_CHANGED = 16,
63 EVENT_B_CHANGED = 17,
64 EVENT_C_CHANGED = 18,
65 EVENT_D_CHANGED = 19
66 };
67
68 enum class tButtonType {
69 kButtonEUp = 0,
70 kButtonEDown,
71 kButtonFUp,
72 kButtonFDown,
73 kButtonLUp,
74 kButtonLDown,
75 kButtonRUp,
76 kButtonRDown,
77
78 // IQ2 compatibility
79 kButtonG,
80 kButtonH,
81
82 kButtonUndefined
83 };
84
85 public:
89 class button {
90 private:
91 tButtonType _id;
92 controller *_parent;
93
94 public:
95 button() : _id( tButtonType::kButtonUndefined ), _parent(NULL) {};
96 button( const tButtonType id, controller *parent ) : _id( id ), _parent(parent) {};
97 ~button() {};
98
103 void pressed( void (* callback)(void) ) const;
104
109 void released( void (* callback)(void) ) const;
110
115 bool pressing( void ) const;
116 };
117
118 const button ButtonEUp = button( tButtonType::kButtonEUp , this );
119 const button ButtonEDown = button( tButtonType::kButtonEDown, this );
120 const button ButtonFUp = button( tButtonType::kButtonFUp , this );
121 const button ButtonFDown = button( tButtonType::kButtonFDown, this );
122 const button ButtonLUp = button( tButtonType::kButtonLUp , this );
123 const button ButtonLDown = button( tButtonType::kButtonLDown, this );
124 const button ButtonRUp = button( tButtonType::kButtonRUp , this );
125 const button ButtonRDown = button( tButtonType::kButtonRDown, this );
126 const button ButtonL3 = button( tButtonType::kButtonG , this );
127 const button ButtonR3 = button( tButtonType::kButtonH , this );
128
129 private:
130 enum class tAxisType {
131 kAxisA = 0,
132 kAxisB,
133 kAxisC,
134 kAxisD,
135
136 kAxisUndefined
137 };
138
139 public:
143 class axis {
144 private:
145 tAxisType _id;
146 controller *_parent;
147
148 public:
149 axis() : _id( tAxisType::kAxisUndefined ), _parent(NULL) {};
150 axis( const tAxisType id, controller *parent ) : _id( id ), _parent(parent) {};
151 ~axis() {};
152
157 void changed( void (* callback)(void) ) const;
158
163 int32_t value( void ) const;
164
170 int32_t position( percentUnits units = percentUnits::pct ) const;
171 };
172
173 const axis AxisA = axis( tAxisType::kAxisA, this );
174 const axis AxisB = axis( tAxisType::kAxisB, this );
175 const axis AxisC = axis( tAxisType::kAxisC, this );
176 const axis AxisD = axis( tAxisType::kAxisD, this );
177 };
178};
179
180#endif // VEX_CONTROLLER_CLASS_H
Use the axis class to get values from one of the controller's joysticks.
void changed(void(*callback)(void)) const
Sets the function to be called when the joystick axis value changes.
int32_t position(percentUnits units=percentUnits::pct) const
Gets the position of the joystick axis on a scale from -100 to 100.
int32_t value(void) const
Gets the value of the joystick axis on a scale from -127 to 127.
Use the button class to get values from the controller's buttons.
bool pressing(void) const
Gets the status of a button.
void pressed(void(*callback)(void)) const
Sets the function to be called when the button is pressed.
void released(void(*callback)(void)) const
Sets the function to be called when the button is released.
controller()
Creates a new controller object.
Bumper switch device class
Definition vex_brain.h:24