diff --git a/CMakeLists.txt b/CMakeLists.txt index c821272..e787b63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ set(SOURCES src/core/fsw.cpp src/core/flight_mode.cpp src/core/state.cpp + src/core/modules.cpp src/rfm/rfm.cpp src/sd/sd.cpp src/sd/hw_config.c diff --git a/lib/BNO055-Pico b/lib/BNO055-Pico index 3529021..e5de77a 160000 --- a/lib/BNO055-Pico +++ b/lib/BNO055-Pico @@ -1 +1 @@ -Subproject commit 352902134aa759d96917a484f97a71e8e4bbbd54 +Subproject commit e5de77ad27468d33f0069807e061d70bc2bcd766 diff --git a/lib/LIS3DH-Pico b/lib/LIS3DH-Pico index f807684..17759e4 160000 --- a/lib/LIS3DH-Pico +++ b/lib/LIS3DH-Pico @@ -1 +1 @@ -Subproject commit f807684f56349877a8fe98ef8b236860a6ec9c3d +Subproject commit 17759e41cde3f8bd77edf25b05c20e681dd961e4 diff --git a/lib/Si7021-Pico b/lib/Si7021-Pico index 28185fa..10c2337 160000 --- a/lib/Si7021-Pico +++ b/lib/Si7021-Pico @@ -1 +1 @@ -Subproject commit 28185fa7a1e0882a50740e076c031cb1f1494f96 +Subproject commit 10c23370054f430d3e984f6864fd7ee5e29a5158 diff --git a/src/core/flight_mode.cpp b/src/core/flight_mode.cpp index 18b333b..66c4b19 100644 --- a/src/core/flight_mode.cpp +++ b/src/core/flight_mode.cpp @@ -1,41 +1,41 @@ #include "flight_mode.hpp" #include "../constants.hpp" #include "../pins.hpp" -#include "../sd/sd.hpp" #include "hardware/gpio.h" +#include "modules.hpp" #include "state.hpp" void FlightMode::execute() { - float x, y, z; + double x, y, z; - state::altimeter::altimeter.read_altitude(&state::altimeter::altitude, constants::altimeter::ref_pressure); - state::altimeter::altimeter.read_pressure(&state::altimeter::pressure); + modules::altimeter.read_altitude(&state::altimeter::altitude, constants::altimeter::ref_pressure); + modules::altimeter.read_pressure(&state::altimeter::pressure); - state::imu::imu.read_gyro(&x, &y, &z); + modules::imu.read_gyro(&x, &y, &z); state::imu::gyro_x = x; state::imu::gyro_y = y; state::imu::gyro_z = z; - state::imu::imu.read_mag(&x, &y, &z); + modules::imu.read_mag(&x, &y, &z); state::imu::mag_x = x; state::imu::mag_y = y; state::imu::mag_z = z; - state::accel::accel.read_accel(&x, &y, &z); + modules::accel.read_accel(&x, &y, &z); state::accel::accel_x = x; state::accel::accel_y = y; state::accel::accel_z = z; - state::therm::temp = state::therm::therm.read_temperature(); - state::therm::humidity = state::therm::therm.read_humidity(); + modules::therm.read_temperature(&state::therm::temp); + modules::therm.read_humidity(&state::therm::humidity); if (!state::flight::altitude_armed && state::altimeter::altitude > constants::flight::arming_altitude) { state::flight::altitude_armed = true; // TODO: Log event } - state::sd::sd.log(); - state::rfm::rfm.transmit(); + // modules::sd.log(); + // modules::rfm.transmit(); } // Startup Mode @@ -47,47 +47,47 @@ void StartupMode::execute() { // TODO: Log event } if (!state::altimeter::init) { - if (state::altimeter::altimeter.begin()) { + if (modules::altimeter.begin()) { state::altimeter::init = true; } else { // TODO: Log failure } } if (!state::imu::init) { - if (state::imu::imu.begin()) { + if (modules::imu.begin()) { state::imu::init = true; } else { // TODO: Log failure } } if (!state::accel::init) { - if (state::accel::accel.begin()) { + if (modules::accel.begin()) { state::accel::init = true; } else { // TODO: Log failure } } if (!state::therm::init) { - if (state::therm::therm.begin()) { + if (modules::therm.begin()) { state::therm::init = true; } else { // TODO: Log failure } } - if (!state::sd::init) { - if (state::sd::sd.begin()) { - state::sd::init = true; - } else { - // TODO: Log failure - } - } - if (!state::rfm::init) { - if (state::rfm::rfm.begin()) { - state::rfm::init = true; - } else { - // TODO: Log failure - } - } + // if (!state::sd::init) { + // if (modules::sd.begin()) { + // state::sd::init = true; + // } else { + // // TODO: Log failure + // } + // } + // if (!state::rfm::init) { + // if (modules::rfm.begin()) { + // state::rfm::init = true; + // } else { + // // TODO: Log failure + // } + // } } void StartupMode::transition() { diff --git a/src/core/flight_mode.hpp b/src/core/flight_mode.hpp index 065ae64..f85b684 100644 --- a/src/core/flight_mode.hpp +++ b/src/core/flight_mode.hpp @@ -1,5 +1,5 @@ -#ifndef FLIGHT_MODE_ -#define FLIGHT_MODE_ +#ifndef FLIGHT_MODE_HPP_ +#define FLIGHT_MODE_HPP_ #include @@ -63,4 +63,4 @@ class MainDeployedMode : public FlightMode { std::string name() { return "Main Deployed"; }; }; -#endif // FLIGHT_MODE_ \ No newline at end of file +#endif // FLIGHT_MODE_HPP_ \ No newline at end of file diff --git a/src/core/modules.cpp b/src/core/modules.cpp new file mode 100644 index 0000000..de834b3 --- /dev/null +++ b/src/core/modules.cpp @@ -0,0 +1,11 @@ +#include "modules.hpp" + +namespace modules { + BMP388 altimeter(I2C_PORT); + BNO055 imu(I2C_PORT); + LIS3DH accel(I2C_PORT); + Si7021 therm(I2C_PORT); + + SD sd; + RFM rfm; +}; // namespace modules \ No newline at end of file diff --git a/src/core/modules.hpp b/src/core/modules.hpp new file mode 100644 index 0000000..6481181 --- /dev/null +++ b/src/core/modules.hpp @@ -0,0 +1,22 @@ +#ifndef MODULES_HPP_ +#define MODULES_HPP_ + +#include "bmp388.hpp" +#include "bno055.hpp" +#include "lis3dh.hpp" +#include "si7021.hpp" + +#include "../rfm/rfm.hpp" +#include "../sd/sd.hpp" + +namespace modules { + extern BMP388 altimeter; + extern BNO055 imu; + extern LIS3DH accel; + extern Si7021 therm; + + extern SD sd; + extern RFM rfm; +}; // namespace modules + +#endif \ No newline at end of file diff --git a/src/core/state.cpp b/src/core/state.cpp index 6100afb..da08a6f 100644 --- a/src/core/state.cpp +++ b/src/core/state.cpp @@ -33,7 +33,6 @@ namespace state { double pressure = -1; double altitude = -1; - BMP388 altimeter(I2C_PORT); } // namespace altimeter namespace gps { bool init = false; @@ -44,39 +43,34 @@ namespace state { } // namespace gps namespace imu { bool init = false; - float mag_x = -1; - float mag_y = -1; - float mag_z = -1; - float gyro_x = -1; - float gyro_y = -1; - float gyro_z = -1; + double mag_x = -1; + double mag_y = -1; + double mag_z = -1; + double gyro_x = -1; + double gyro_y = -1; + double gyro_z = -1; - BNO055 imu(I2C_PORT); } // namespace imu namespace accel { bool init = false; - float accel_x = -1; - float accel_y = -1; - float accel_z = -1; + double accel_x = -1; + double accel_y = -1; + double accel_z = -1; - LIS3DH accel(I2C_PORT); } // namespace accel namespace therm { bool init = false; - float temp = -1; - float humidity = -1; + double temp = -1; + double humidity = -1; - Si7021 therm(I2C_PORT); } // namespace therm namespace sd { bool init = false; FIL file; - SD sd; } // namespace sd namespace rfm { bool init = false; - RFM rfm; } // namespace rfm }; // namespace state diff --git a/src/core/state.hpp b/src/core/state.hpp index 33c66b0..2774436 100644 --- a/src/core/state.hpp +++ b/src/core/state.hpp @@ -4,12 +4,6 @@ #include "flight_mode.hpp" #include -#include "bmp388.hpp" -#include "bno055.hpp" -#include "lis3dh.hpp" -#include "si7021.hpp" - -#include "../rfm/rfm.hpp" #include "../sd/sd.hpp" namespace state { @@ -40,7 +34,6 @@ namespace state { extern double pressure; extern double altitude; - extern BMP388 altimeter; } // namespace altimeter namespace gps { extern bool init; @@ -51,39 +44,34 @@ namespace state { } // namespace gps namespace imu { extern bool init; - extern float mag_x; - extern float mag_y; - extern float mag_z; - extern float gyro_x; - extern float gyro_y; - extern float gyro_z; + extern double mag_x; + extern double mag_y; + extern double mag_z; + extern double gyro_x; + extern double gyro_y; + extern double gyro_z; - extern BNO055 imu; } // namespace imu namespace accel { extern bool init; - extern float accel_x; - extern float accel_y; - extern float accel_z; + extern double accel_x; + extern double accel_y; + extern double accel_z; - extern LIS3DH accel; } // namespace accel namespace therm { extern bool init; - extern float temp; - extern float humidity; + extern double temp; + extern double humidity; - extern Si7021 therm; } // namespace therm namespace sd { extern bool init; - extern SD sd; } // namespace sd namespace rfm { extern bool init; - extern RFM rfm; } // namespace rfm }; // namespace state