VEXcode IQ C++ Unofficial documentation for version 3.0.4.1
Loading...
Searching...
No Matches
vex_brain.h
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* */
3/* Copyright (c) Innovation First 2017, All rights reserved. */
4/* */
5/* Module: vex_brain.h */
6/* Author: James Pearman */
7/* Created: 8 July 2017 */
8/* */
9/* Revisions: */
10/* V1.00 TBD - Initial release */
11/* */
12/*----------------------------------------------------------------------------*/
13
14#ifndef VEX_BRAIN_CLASS_H
15#define VEX_BRAIN_CLASS_H
16
17#include "vex_timer.h"
18
19/*-----------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace vex {
25 class brain {
26 private:
27 static int32_t _index;
28
29 public:
34 ~brain();
35
36 private:
37 enum class tEventType {
38 EVENT_UP_PRESSED = 1,
39 EVENT_UP_RELEASED = 2,
40 EVENT_DOWN_PRESSED = 4,
41 EVENT_DOWN_RELEASED = 8,
42 EVENT_CHECK_PRESSED = 16,
43 EVENT_CHECK_RELEASED = 32
44 };
45
46 public:
50 class button {
51 private:
52 uint8_t _id;
53
54 public:
55 button() : _id( -1 ) {};
56 button( const int id ) : _id( id ) {};
57 ~button() {};
58
63 void pressed( void (* callback)(void) );
68 void released( void (* callback)(void) );
73 bool pressing( void );
74 };
75
80 button &buttonLeft = buttonUp;
85 button &buttonRight = buttonDown;
90
94 class lcd {
95 private:
96 int16_t _row;
97 int16_t _maxrows;
98 int16_t _rowheight;
99
100 int16_t _col;
101 int16_t _maxcols;
102
103 int32_t _penWidth;
104
105 char _textStr[32];
106
107 bool _fg_color;
108 bool _bg_color;
109 bool _transparent;
110 bool _aspect_compensation;
111
112 int _origin_x;
113 int _origin_y;
114
115 int32_t rowToPixel( int32_t row );
116 int32_t colToPixel( int32_t col );
117 int32_t scaley( int32_t y );
118
119 public:
120 lcd();
121 ~lcd() {};
122
128 void setCursor( int32_t row, int32_t col );
129
134 void setPenWidth( uint32_t width );
135
141 void setOrigin( int32_t x, int32_t y );
142
147 void setAspectCompensation( bool value );
148
153 int32_t column();
154
159 int32_t row();
160
166 void setPenColor( colorType color );
167
173 void setFillColor( colorType color );
174
180 void print( const char *format, ... );
181 void print( char *format, ... );
182
192 void printAt( int32_t x, int32_t y, const char *format, ... );
193
197 void clearScreen( void );
198
203 void clearLine( int number );
204
208 void clearLine( void );
209
214 void newLine( void );
215
221 void drawPixel( int x, int y );
222
230 void drawLine( int x1, int y1, int x2, int y2 );
231
239 void drawRectangle( int x, int y, int width, int height );
240
249 void drawRectangle( int x, int y, int width, int height, colorType color );
250
251
259 void invertRectangle( int x, int y, int width, int height );
260
267 void drawCircle( int x, int y, int radius );
268
276 void drawCircle( int x, int y, int radius, colorType color );
277
284 void invertCircle( int x, int y, int radius );
285 };
286
291
297 double timer( timeUnits units );
298
303
309 void setTimer( double value, timeUnits units );
310
315
319 class battery {
320 public:
321 battery() {};
322 ~battery() {};
323
329 uint16_t capacity( percentUnits units = percentUnits::pct );
330
336 double voltage( voltageUnits units = voltageUnits::volt );
337 };
338
339 battery Battery;
340
341 // we need to avoid using printf or std::cout
342 // as it uses too much memory
346 class terminal {
347 public:
348 terminal() {};
349 ~terminal() {};
350
354 void print( const char *fmt, ... );
355 };
356
357 terminal Terminal;
358
362 void playSound( soundType sound );
366 void playNote( int32_t octave, int32_t note );
370 void playNote( int32_t octave, int32_t note, int32_t ms );
374 void soundOff( void );
379 };
380};
381
382#endif // VEX_BRAIN_CLASS_H
Use the battery class to see information about the battery.
Definition vex_brain.h:319
double voltage(voltageUnits units=voltageUnits::volt)
Gets the battery voltage.
uint16_t capacity(percentUnits units=percentUnits::pct)
Gets the battery capacity.
Use the button class to get values from the brain's buttons.
Definition vex_brain.h:50
bool pressing(void)
Sets the function to be called when the button is released.
void pressed(void(*callback)(void))
Sets the function to be called when the button is pressed.
void released(void(*callback)(void))
Sets the function to be called when the button is released.
Use this class to write or draw to the brain's LCD screen.
Definition vex_brain.h:94
void drawCircle(int x, int y, int radius, colorType color)
Draws a circle using the specified points and attributes set in the parameters. Fills the circle with...
void setAspectCompensation(bool value)
compensate for non square pixels when drawing
void setFillColor(colorType color)
Sets the default fill color for any subsequent draw command.
void drawRectangle(int x, int y, int width, int height)
Draws a rectangle using the specified points and attributes set in the parameters....
void invertCircle(int x, int y, int radius)
Inverts a circular area of the screen using the specified points and attributes set in the parameters...
void printAt(int32_t x, int32_t y, const char *format,...)
Prints a number, string, or Boolean at an x, y cursor location.
void clearScreen(void)
Clears the whole Screen to white.
void setOrigin(int32_t x, int32_t y)
Sets the origin of the screen to the parameters defined in the function.
void setPenColor(colorType color)
Sets the color of the pen to a specified color.
void setCursor(int32_t row, int32_t col)
Sets the cursor to the row and column number set in the parameters.
void drawRectangle(int x, int y, int width, int height, colorType color)
Draws a rectangle using the specified points and attributes set in the parameters....
void newLine(void)
Clears the rest of the line from where the cursor is located and then moves the cursor to the beginni...
void invertRectangle(int x, int y, int width, int height)
Inverts a rectangular area of the screen using the specified points and attributes set in the paramet...
int32_t row()
An integer that tracks the current cursor position's row, starting at 1.
void print(const char *format,...)
Prints a number, string, or Boolean.
void drawCircle(int x, int y, int radius)
Draws a circle using the specified points and attributes set in the parameters. Fills the circle with...
void clearLine(void)
Clears the rest of the line from where the cursor is located.
void clearLine(int number)
Clears the specified line.
void drawLine(int x1, int y1, int x2, int y2)
Draws a line connecting the two specified points in the parameters.
int32_t column()
An integer that tracks the current cursor position's column, starting at 1.
void drawPixel(int x, int y)
Draws a single pixel to the screen in the specified x and y location.
void setPenWidth(uint32_t width)
Sets the pen's width.
Use the terminal class to send text to the brain USB port.
Definition vex_brain.h:346
void print(const char *fmt,...)
print on the vexcode terminal
button buttonCheck
A button that represents the Check button on the brain.
Definition vex_brain.h:89
void setTimer(double value, timeUnits units)
Sets the timer to a value and time unit.
brain()
Creates a new brain object.
vex::timer Timer
Use the Timer class to obtain the system time.
Definition vex_brain.h:314
lcd Screen
Use the Screen class to write or draw to the screen.
Definition vex_brain.h:290
void playNote(int32_t octave, int32_t note, int32_t ms)
play a note in the given octave on the brain and wait for the given time before returning
void resetTimer()
Resets the timer to zero.
button buttonDown
A button that represents the Down/Right button on the brain.
Definition vex_brain.h:84
double timer(timeUnits units)
Gets the value of the timer in the units specified.
button buttonUp
A button that represents the Up/Left button on the brain.
Definition vex_brain.h:79
void soundOff(void)
turn sound off on the brain
void programStop()
request that vexos stop the running program. The program will stop after approximately 500mS.
void playNote(int32_t octave, int32_t note)
play a note in the given octave on the brain
void playSound(soundType sound)
play one of the predefined sounds on the brain
Use the timer class to create timers for your program.
Definition vex_timer.h:27
Bumper switch device class
Definition vex_brain.h:24
IQ timer class header.