From 01ce0af940bd69c94a2fac8b65219262845cca98 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 14 Feb 2022 18:18:38 +0100 Subject: refactor: clean sewage --- src/calibration.hpp | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) (limited to 'src/calibration.hpp') diff --git a/src/calibration.hpp b/src/calibration.hpp index e66b6fc..e29602a 100644 --- a/src/calibration.hpp +++ b/src/calibration.hpp @@ -1,33 +1,32 @@ -#ifndef CALIBRATION_HPP -#define CALIBRATION_HPP +#pragma once #include "sensor/sensor.hpp" #include "utils/memory.hpp" #include "utils/serial.hpp" // Calibration precision -#define ACCEL_CAL_X_MAX 0.006 -#define ACCEL_CAL_X_MIN -0.006 +constexpr float ACCEL_CAL_X_MAX = 0.006; +constexpr float ACCEL_CAL_X_MIN = -0.006; -#define ACCEL_CAL_Y_MAX 0.006 -#define ACCEL_CAL_Y_MIN -0.006 +constexpr float ACCEL_CAL_Y_MAX = 0.006; +constexpr float ACCEL_CAL_Y_MIN = -0.006; -#define ACCEL_CAL_Z_MAX 0.006 -#define ACCEL_CAL_Z_MIN -0.006 +constexpr float ACCEL_CAL_Z_MAX = 0.006; +constexpr float ACCEL_CAL_Z_MIN = -0.006; -#define GYRO_CAL_X_MAX 0.06 -#define GYRO_CAL_X_MIN -0.06 +constexpr float GYRO_CAL_X_MAX = 0.06; +constexpr float GYRO_CAL_X_MIN = -0.06; -#define GYRO_CAL_Y_MAX 0.06 -#define GYRO_CAL_Y_MIN -0.06 +constexpr float GYRO_CAL_Y_MAX = 0.06; +constexpr float GYRO_CAL_Y_MIN = -0.06; -#define GYRO_CAL_Z_MAX 0.06 -#define GYRO_CAL_Z_MIN -0.06 +constexpr float GYRO_CAL_Z_MAX = 0.06; +constexpr float GYRO_CAL_Z_MIN = -0.06; -#define CALIBRATION_TIMEOUT 120000 // Milliseconds +constexpr uint32_t CALIBRATION_TIMEOUT = 120000; // Milliseconds -#define SENSOR_READ_CNT 20 -#define SENSOR_VAL_ADJUST 0.05 +constexpr unsigned int SENSOR_READ_CNT = 20; +constexpr float SENSOR_VAL_ADJUST = 0.05; /** * Sensor calibrator. @@ -41,7 +40,7 @@ public: * @param sensor A sensor to calibrate * @param sout A Serial output stream */ - SensorCalibrator(unique_ptr &sensor, SerialStream sout); + SensorCalibrator(UniquePtr &sensor, SerialStream sout); /** * Calibrates the sensor. @@ -60,17 +59,15 @@ private: void _adjustCalibration(); - unique_ptr &_sensor; + UniquePtr &_sensor; SerialStream _sout; - float _accel_x; - float _accel_y; - float _accel_z; + double _accel_x = 0; + double _accel_y = 0; + double _accel_z = 0; - float _gyro_x; - float _gyro_y; - float _gyro_z; + double _gyro_x = 0; + double _gyro_y = 0; + double _gyro_z = 0; }; - -#endif -- cgit v1.2.3-18-g5258