summaryrefslogtreecommitdiff
path: root/src/sensor/sensor.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sensor/sensor.hpp')
-rw-r--r--src/sensor/sensor.hpp87
1 files changed, 46 insertions, 41 deletions
diff --git a/src/sensor/sensor.hpp b/src/sensor/sensor.hpp
index c982fac..3e56627 100644
--- a/src/sensor/sensor.hpp
+++ b/src/sensor/sensor.hpp
@@ -1,16 +1,17 @@
-#ifndef SENSOR_HPP
-#define SENSOR_HPP
+#pragma once
-#include "../utils/serial.hpp"
-#include "../utils/time.hpp"
+#include "utils/serial.hpp"
+#include "utils/time.hpp"
-#include "Wire.h"
#include <Arduino.h>
+#include <Wire.h>
-#define SENSOR_WAKEUP 0x00
+constexpr uint8_t SENSOR_WAKEUP = 0x00U;
-#define RAW_TO_DPS_FACTOR (1.0 / 131.0)
-#define RAW_TO_G_FACTOR (1.0 / 16384.0)
+constexpr float RAW_TO_DPS_FACTOR = 1.0 / 131.0;
+constexpr float RAW_TO_G_FACTOR = 1.0 / 16384.0;
+
+constexpr unsigned int ONE_EIGHTY = 180;
enum class SensorStatus
{
@@ -35,7 +36,7 @@ public:
* @param sout A serial output stream
* @param throttle_time A minumum time between sensor reads for the sensor to throttle
*/
- Sensor(uint8_t address, TwoWire *wire, SerialStream sout, unsigned int throttle_time);
+ Sensor(uint8_t address, TwoWire wire, SerialStream sout, unsigned int throttle_time);
/**
* Initializes communication with the sensor.
@@ -50,11 +51,6 @@ public:
bool isConnected();
/**
- * Resets the sensor.
- */
- void reset();
-
- /**
* Reads from the sensor.
*
* @returns Whether or not it succeeded.
@@ -81,52 +77,52 @@ public:
/**
* Returns the current X axis acceleration in g:s (g-force).
*/
- float getAccelX();
+ double getAccelX();
/**
* Returns the current Y axis acceleration in g:s (g-force).
*/
- float getAccelY();
+ double getAccelY();
/**
* Returns the current Z axis acceleration in g:s (g-force).
*/
- float getAccelZ();
+ double getAccelZ();
/**
* Returns the current X angle.
*/
- float getAngleX();
+ double getAngleX();
/**
* Returns the current Y angle.
*/
- float getAngleY();
+ double getAngleY();
/**
* Returns the current X axis in degrees/s.
*/
- float getGyroX();
+ double getGyroX();
/**
* Returns the current Y axis in degrees/s.
*/
- float getGyroY();
+ double getGyroY();
/**
* Returns the current Z axis in degrees/s.
*/
- float getGyroZ();
+ double getGyroZ();
/**
* Returns the current pitch angle.
*/
- float getPitch();
+ double getPitch();
/**
* Returns the current roll angle.
*/
- float getRoll();
+ double getRoll();
/**
* Sets the value of a key in the sensor's register.
@@ -150,16 +146,18 @@ public:
SensorStatus getStatus();
// Accelerometer calibration values
- float accel_cal_x;
- float accel_cal_y;
- float accel_cal_z;
+ double accel_cal_x = 0.0F;
+ double accel_cal_y = 0.0F;
+ double accel_cal_z = 0.0F;
// Gyroscope calibration values
- float gyro_cal_x;
- float gyro_cal_y;
- float gyro_cal_z;
+ double gyro_cal_x = 0.0F;
+ double gyro_cal_y = 0.0F;
+ double gyro_cal_z = 0.0F;
private:
+ TwoWire _wire;
+
uint8_t _address;
bool _throttle_enabled;
@@ -169,25 +167,32 @@ private:
SensorStatus _status;
- uint8_t _accel_sensitivity;
+ uint8_t _accel_sensitivity = 0U;
float _accel_to_g_force;
- float _accel_raw_x, _accel_raw_y, _accel_raw_z;
- float _accel_x, _accel_y;
+ double _accel_raw_x = 0;
+ double _accel_raw_y = 0;
+ double _accel_raw_z = 0;
- uint8_t _gyro_sensitivity;
+ double _accel_x = 0;
+ double _accel_y = 0;
+
+ uint8_t _gyro_sensitivity = 0U;
float _ang_rate_to_dps;
- float _gyro_raw_x, _gyro_raw_y, _gyro_raw_z;
- float _gyro_x, _gyro_y, _gyro_z;
+ double _gyro_raw_x = 0;
+ double _gyro_raw_y = 0;
+ double _gyro_raw_z = 0;
- float _pitch, _roll, _yaw;
+ double _gyro_x = 0;
+ double _gyro_y = 0;
+ double _gyro_z = 0;
- int16_t _readHighLow();
+ double _pitch = 0;
+ double _roll = 0;
+ double _yaw = 0;
- TwoWire *_wire;
+ int16_t _readHighLow();
SerialStream _sout;
};
-
-#endif