Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added handle_mode() #10

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/utils.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
#ifndef OBC_UTILS_HPP
#define OBC_UTILS_HPP

#include <Arduino.h>

#include <type_traits>

namespace utl {

enum class Logger { Debug, Flight };

enum class Modes { Idle, Measurements, Experiment, Uplink };

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Czym różni się Measurements od Experiment? Chyba czuje, różnice, ale czy to oznacza, że gdy odpalimy eksperyment to nie wykonujemy pomiarów z samego obc? (w sensie, czy mode Measurements pokrywa się jakoś z Experiment zadaniami).

Ogólnie to szczegół, przy takiej implementacji chyba łatwo będzie zedytować te stany/zdefiniować nowe. O to chodziło.


template <typename Enum>
constexpr auto to_underlying(Enum e)
{
return static_cast<std::underlying_type_t<Enum>>(e);
}

void handle_mode(Modes mode);
void handle_idle();
void handle_measurements();
void handle_experiment();
void handle_uplink();

} // namespace utl

#endif
17 changes: 8 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

#include "accelerometer.hpp"
#include "barometer.hpp"
#include "devices.hpp"
#include "gps.hpp"
#include "logger.hpp"
#include "utils.hpp"

HardwareSerial Serial2{PA3, PA2};
auto current_mode = utl::Modes::Idle;

HardwareSerial Serial2{PA3, PA2};
Adafruit_GPS gps{&Serial2};
MMA8452Q accelerometer;
BMP280 bmp;

void setup()
{
// put your setup code here, to run once:
}
void setup() { obc::init(); }

void loop()
{
// put your main code here, to run repeatedly:
}
void loop() { utl::handle_mode(current_mode); }
29 changes: 29 additions & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "utils.hpp"

namespace utl {

void handle_mode(Modes mode)
{
switch (mode) {
case Modes::Idle:
return handle_idle();
case Modes::Measurements:
return handle_measurements();
case Modes::Experiment:
return handle_experiment();
case Modes::Uplink:
return handle_uplink();
default:
break;
}
}

void handle_idle() {}

void handle_measurements() {}

void handle_experiment() {}

void handle_uplink() {}

} // namespace utl