Implement I2C communication with STM
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "AppState.h"
|
||||
#include "MissionSelect.h"
|
||||
#include "defines.h"
|
||||
|
||||
@ -7,8 +8,6 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
enum class AppView { MISSION_SELECT, AMI, DRIVER, TESTING };
|
||||
|
||||
class SDLManager {
|
||||
public:
|
||||
SDLManager();
|
||||
@ -24,6 +23,7 @@ public:
|
||||
|
||||
private:
|
||||
void init_sdl();
|
||||
void init_state();
|
||||
|
||||
void handle_events();
|
||||
void render();
|
||||
@ -33,10 +33,10 @@ private:
|
||||
// others and its destructor is called after the others.
|
||||
SDLManager sdl_manager;
|
||||
|
||||
std::unique_ptr<AppState> state;
|
||||
std::unique_ptr<MissionSelect> mission_select;
|
||||
|
||||
bool running;
|
||||
AppView view;
|
||||
|
||||
SDL_Window* window;
|
||||
SDL_Renderer* renderer;
|
||||
|
||||
29
include/AppState.h
Normal file
29
include/AppState.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <fmt/ostream.h>
|
||||
|
||||
#include <optional>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
constexpr int I2C_SLAVE_ADDR = 0x20;
|
||||
constexpr int I2C_POLL_COMMAND = 0x00;
|
||||
|
||||
enum class AppView { MISSION_SELECT, AMI, DRIVER, TESTING };
|
||||
std::ostream& operator<<(std::ostream& os, AppView view);
|
||||
|
||||
class AppState {
|
||||
public:
|
||||
AppState(const std::string& i2c_dev_path);
|
||||
~AppState();
|
||||
|
||||
void poll();
|
||||
|
||||
AppView get_view();
|
||||
|
||||
private:
|
||||
// This is optional so that we can still run the code on a PC without I2C
|
||||
std::optional<int> i2c_dev_file;
|
||||
|
||||
AppView view;
|
||||
};
|
||||
Reference in New Issue
Block a user