Skip to content

Commit

Permalink
create dedicated modules namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
cameron-goddard committed Jan 18, 2024
1 parent 5e352ae commit 1a464f3
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 46 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 28 additions & 28 deletions src/core/flight_mode.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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() {
Expand Down
12 changes: 12 additions & 0 deletions src/core/modules.cpp
Original file line number Diff line number Diff line change
@@ -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;
};
23 changes: 23 additions & 0 deletions src/core/modules.hpp
Original file line number Diff line number Diff line change
@@ -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
6 changes: 0 additions & 6 deletions src/core/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ namespace state {
double pressure = -1;
double altitude = -1;

BMP388 altimeter(I2C_PORT);
} // namespace altimeter
namespace gps {
bool init = false;
Expand All @@ -51,32 +50,27 @@ namespace state {
float gyro_y = -1;
float 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;

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
12 changes: 0 additions & 12 deletions src/core/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
#include "flight_mode.hpp"
#include <stdint.h>

#include "bmp388.hpp"
#include "bno055.hpp"
#include "lis3dh.hpp"
#include "si7021.hpp"

#include "../rfm/rfm.hpp"
#include "../sd/sd.hpp"

namespace state {
Expand Down Expand Up @@ -40,7 +34,6 @@ namespace state {
extern double pressure;
extern double altitude;

extern BMP388 altimeter;
} // namespace altimeter
namespace gps {
extern bool init;
Expand All @@ -58,32 +51,27 @@ namespace state {
extern float gyro_y;
extern float 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 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

Expand Down

0 comments on commit 1a464f3

Please sign in to comment.