36 #ifndef UM6_REGISTERS_H 37 #define UM6_REGISTERS_H 40 #include <machine/endian.h> 54 #define TO_RADIANS (M_PI / 180.0) 55 #define TO_DEGREES (180.0 / M_PI) 59 #define NUM_REGISTERS (DATA_REG_START_ADDRESS + DATA_ARRAY_SIZE) 67 #if __BYTE_ORDER == __LITTLE_ENDIAN 68 uint8_t*
d =
reinterpret_cast<uint8_t*
>(dest);
69 uint8_t*
s =
reinterpret_cast<uint8_t*
>(src);
70 for (uint8_t i = 0; i < count; i++)
72 d[i] = s[count - (i+1)];
76 #warning Big-endian implementation is untested. 77 memcpy(dest, src, count);
97 uint8_t register_width, uint8_t array_length)
98 :
index(register_index),
width(register_width),
122 template<
typename RegT>
126 Accessor(
Registers* registers, uint8_t register_index, uint8_t array_length = 0,
double scale_factor = 1.0)
127 :
Accessor_(registers, register_index, sizeof(RegT), array_length), scale_(scale_factor)
130 RegT
get(uint8_t field)
const 132 RegT* raw_ptr =
reinterpret_cast<RegT*
>(
raw());
140 return get(field) * scale_;
143 void set(uint8_t field, RegT value)
const 145 RegT* raw_ptr =
reinterpret_cast<RegT*
>(
raw());
151 set(field, value / scale_);
185 memset(raw_, 0,
sizeof(raw_));
190 gyro, accel, mag, euler,
quat;
200 cmd_set_accel_ref, cmd_set_mag_ref;
202 void write_raw(uint8_t register_index, std::string data)
204 if ((register_index - 1) + (data.length()/4 - 1) >=
NUM_REGISTERS)
206 throw std::range_error(
"Index and length write beyond boundaries of register array.");
208 memcpy(&raw_[register_index], data.c_str(), data.length());
218 #endif // UM6_REGISTERS_H
const Accessor< int16_t > quat
double get_scaled(uint16_t field) const
#define UM6_ACCEL_PROC_XY
const Accessor< float > mag_ref
void write_raw(uint8_t register_index, std::string data)
#define UM6_SET_ACCEL_REF
Copied directly from the UM6_config.h file, available online here: http://sourceforge.net/p/um6firmware/code/34/tree/trunk/UM6%20Firmware/UM6_config.h#l14.
Accessor(Registers *registers, uint8_t register_index, uint8_t array_length=0, double scale_factor=1.0)
#define UM6_ACCEL_BIAS_XY
void memcpy_network(void *dest, void *src, size_t count)
const Accessor< float > temperature
const Accessor< int16_t > mag_bias
void set_scaled(uint16_t field, double value) const
Accessor_(Registers *registers, uint8_t register_index, uint8_t register_width, uint8_t array_length)
const Accessor< uint32_t > cmd_zero_gyros
#define UM6_EULER_PHI_THETA
const Accessor< uint32_t > status
#define UM6_COMMUNICATION