VEXcode IQ C++ Unofficial documentation for version 3.0.4.1
Loading...
Searching...
No Matches
vex_generic.h
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* */
3/* Copyright (c) Innovation First 2019, All rights reserved. */
4/* */
5/* Module: vex_generic.h */
6/* Author: James Pearman */
7/* Created: 6 June 2019 */
8/* */
9/* Revisions: */
10/* V1.00 TBD - Initial release */
11/* */
12/*----------------------------------------------------------------------------*/
13
14#ifndef VEX_GENERIC_CLASS_H
15#define VEX_GENERIC_CLASS_H
16
17/*-----------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22/*-----------------------------------------------------------------------------*/
24/*-----------------------------------------------------------------------------*/
25namespace vex {
26 class generic : public device {
27 public:
32 generic( int32_t index );
33 ~generic();
34
35 bool installed();
36
37 /*--------------------------------------------------------------------*/
38 //
39 // The following methods are for communication with generic devices
40 // that conform to the IQ sensor reference spec and have been enumerated
41 // by vexos as either generic or user sensors.
42 //
43 /*--------------------------------------------------------------------*/
44
49 int32_t version();
54 int32_t vendorId();
59 int32_t productId();
60
66 int32_t readByte( uint8_t reg );
73 int32_t writeByte( uint8_t reg, uint8_t value );
74
81 int32_t readWord( uint8_t reg, bool bLittleEndian = false );
89 int32_t writeWord( uint8_t reg, uint16_t value, bool bLittleEndian = false );
90
98 bool readReg( uint8_t reg, uint8_t *pBytes, uint8_t nLength );
106 bool writeReg( uint8_t reg, uint8_t *pBytes, uint8_t nLength );
107
108 typedef enum _i2cRegType {
109 // All sensors have these registers
110 kRegAsciiVersion = 0x00, // 8 bytes
111 kRegAsciiVendor = 0x08, // 8 bytes
112 kRegAsciiDeviceId = 0x10, // 8 bytes
113
114 kRegUserVendorId = 0x18, // user sensor specific
115 kRegUserProductId = 0x19, // user sensor specific
116
117 kRegFirmwareVersion = 0x20,
118 kRegDeviceType = 0x21,
119 kRegDeviceId = 0x22,
120 kRegDeviceStatus = 0x23
121 } i2cRegType;
122
123 /*--------------------------------------------------------------------*/
124 //
125 // The following methods are for communication with generic devices
126 // that do not conform to the IQ sensor reference spec and have an I2C
127 // address that does not conflict with other sensors on the same bus.
128 // If the addressed device is not present, or gives an error during
129 // use, the IQ may abort with an "I2C error" message in the same way
130 // as when an IQ sensor is disconnected.
131 // raw sensors should not use I2C addresses that may be assigned to IQ
132 // devices if sharing the bus with them.
133 // (8 bit addresses)
134 // 0x60
135 // 0x20, 0x22, 0x24
136 /*--------------------------------------------------------------------*/
137
145 bool readRaw( uint8_t addr, uint8_t *pBytes, uint8_t nLength );
153 bool writeRaw( uint8_t addr, uint8_t *pBytes, uint8_t nLength );
154
163 private:
164 };
165};
166
167#endif // VEX_GENERIC_CLASS_H
int32_t writeWord(uint8_t reg, uint16_t value, bool bLittleEndian=false)
Write 1 word (2 bytes) to the generic sensor.
int32_t productId()
Gets the product id of the generic sensor.
int32_t readWord(uint8_t reg, bool bLittleEndian=false)
Read 1 word (2 bytes) from the generic sensor.
void writeRawWait()
Wait for raw write to complete usually this is not needed, writeRaw will block when called waiting fo...
int32_t version()
Gets the firmware version of the generic sensor.
int32_t readByte(uint8_t reg)
Read 1 byte from the generic sensor.
bool readReg(uint8_t reg, uint8_t *pBytes, uint8_t nLength)
Read bytes from the generic sensor.
bool writeRaw(uint8_t addr, uint8_t *pBytes, uint8_t nLength)
Write bytes to the device.
int32_t vendorId()
Gets the vendor id of the generic sensor.
int32_t writeByte(uint8_t reg, uint8_t value)
Write 1 byte to the generic sensor.
bool writeReg(uint8_t reg, uint8_t *pBytes, uint8_t nLength)
Write bytes to the generic sensor.
bool readRaw(uint8_t addr, uint8_t *pBytes, uint8_t nLength)
Read bytes from the device.
Bumper switch device class
Definition vex_brain.h:24