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/src/core/flight_mode.cpp b/src/core/flight_mode.cpp index 18b333b..c7db97e 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 "state.hpp" +#include "modules.hpp" void FlightMode::execute() { float 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(); + state::therm::temp = modules::therm.read_temperature(); + state::therm::humidity = modules::therm.read_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/modules.cpp b/src/core/modules.cpp new file mode 100644 index 0000000..c9a8989 --- /dev/null +++ b/src/core/modules.cpp @@ -0,0 +1,12 @@ +#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; +}; \ No newline at end of file diff --git a/src/core/modules.hpp b/src/core/modules.hpp new file mode 100644 index 0000000..8db71cb --- /dev/null +++ b/src/core/modules.hpp @@ -0,0 +1,23 @@ +#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; +}; + +#endif \ No newline at end of file diff --git a/src/core/state.cpp b/src/core/state.cpp index 6100afb..d538b9d 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; @@ -51,7 +50,6 @@ namespace state { float gyro_y = -1; float gyro_z = -1; - BNO055 imu(I2C_PORT); } // namespace imu namespace accel { bool init = false; @@ -59,24 +57,20 @@ namespace state { float accel_y = -1; float accel_z = -1; - LIS3DH accel(I2C_PORT); } // namespace accel namespace therm { bool init = false; float temp = -1; float 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..86b0950 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; @@ -58,7 +51,6 @@ namespace state { extern float gyro_y; extern float gyro_z; - extern BNO055 imu; } // namespace imu namespace accel { extern bool init; @@ -66,24 +58,20 @@ namespace state { extern float accel_y; extern float accel_z; - extern LIS3DH accel; } // namespace accel namespace therm { extern bool init; extern float temp; extern float 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