Implement AMI, more communication with STM etc
It's late and I forgot to commit
This commit is contained in:
27
include/AMI.h
Normal file
27
include/AMI.h
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "AppState.h"
|
||||
#include "View.h"
|
||||
#include "widgets.h"
|
||||
|
||||
#include <SDL2/SDL_render.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
class AMI final : public View {
|
||||
public:
|
||||
AMI(SDL_Renderer* renderer);
|
||||
~AMI();
|
||||
|
||||
void draw(const AppState& state) override;
|
||||
|
||||
private:
|
||||
TTF_Font* font_medium;
|
||||
TTF_Font* font_large;
|
||||
|
||||
std::unique_ptr<TextWidget> header;
|
||||
std::unordered_map<Mission, std::unique_ptr<TextWidget>> missions;
|
||||
};
|
||||
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "AMI.h"
|
||||
#include "AppState.h"
|
||||
#include "MissionSelect.h"
|
||||
#include "defines.h"
|
||||
@ -14,6 +15,13 @@ public:
|
||||
~SDLManager();
|
||||
};
|
||||
|
||||
#ifndef NDEBUG
|
||||
class KeyboardHandler {
|
||||
public:
|
||||
void handle_keyup(const SDL_Event& ev, AppState& state);
|
||||
};
|
||||
#endif // !NDEBUG
|
||||
|
||||
class App {
|
||||
public:
|
||||
App();
|
||||
@ -35,9 +43,14 @@ private:
|
||||
|
||||
std::unique_ptr<AppState> state;
|
||||
std::unique_ptr<MissionSelect> mission_select;
|
||||
std::unique_ptr<AMI> ami;
|
||||
|
||||
bool running;
|
||||
|
||||
SDL_Window* window;
|
||||
SDL_Renderer* renderer;
|
||||
|
||||
#ifndef NDEBUG
|
||||
KeyboardHandler keyboard_handler;
|
||||
#endif // !NDEBUG
|
||||
};
|
||||
@ -11,6 +11,17 @@ constexpr int I2C_POLL_COMMAND = 0x00;
|
||||
|
||||
enum class AppView { MISSION_SELECT, AMI, DRIVER, TESTING };
|
||||
std::ostream& operator<<(std::ostream& os, AppView view);
|
||||
enum class Mission {
|
||||
NONE,
|
||||
ACCELERATION,
|
||||
SKIDPAD,
|
||||
AUTOCROSS,
|
||||
TRACKDRIVE,
|
||||
EBS_TEST,
|
||||
INSPECTION,
|
||||
MANUAL
|
||||
};
|
||||
std::ostream& operator<<(std::ostream& os, Mission mission);
|
||||
|
||||
class AppState {
|
||||
public:
|
||||
@ -19,11 +30,21 @@ public:
|
||||
|
||||
void poll();
|
||||
|
||||
AppView get_view();
|
||||
AppView get_view() const;
|
||||
Mission get_mission() const;
|
||||
|
||||
private:
|
||||
void unmarshal_mission_select(uint8_t* data);
|
||||
|
||||
// This is optional so that we can still run the code on a PC without I2C
|
||||
std::optional<int> i2c_dev_file;
|
||||
|
||||
AppView view;
|
||||
};
|
||||
Mission mission;
|
||||
|
||||
#ifndef NDEBUG
|
||||
friend class KeyboardHandler;
|
||||
#endif // !NDEBUG
|
||||
};
|
||||
|
||||
extern AppState app_state;
|
||||
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "AppState.h"
|
||||
#include "View.h"
|
||||
#include "events.h"
|
||||
#include "widgets.h"
|
||||
@ -15,8 +16,7 @@ public:
|
||||
MissionSelect(SDL_Renderer* renderer);
|
||||
~MissionSelect();
|
||||
|
||||
void draw() override;
|
||||
void handle_events(std::queue<Event>& events) override;
|
||||
void draw(const AppState& state) override;
|
||||
|
||||
private:
|
||||
TTF_Font* avenir;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "AppState.h"
|
||||
#include "events.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
@ -11,8 +12,7 @@ public:
|
||||
View(SDL_Renderer* renderer);
|
||||
virtual ~View();
|
||||
|
||||
virtual void draw() = 0;
|
||||
virtual void handle_events(std::queue<Event>& events) = 0;
|
||||
virtual void draw(const AppState& state) = 0;
|
||||
|
||||
protected:
|
||||
SDL_Renderer* renderer;
|
||||
|
||||
@ -3,17 +3,30 @@
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
|
||||
#include <fmt/ostream.h>
|
||||
|
||||
#include <optional>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
enum class Alignment { LEFT, RIGHT, CENTER };
|
||||
enum class Alignment {
|
||||
START,
|
||||
END,
|
||||
CENTER,
|
||||
LEFT = START,
|
||||
TOP = START,
|
||||
RIGHT = END,
|
||||
BOTTOM = END
|
||||
};
|
||||
std::ostream& operator<<(std::ostream& os, Alignment align);
|
||||
struct PositionInfo {
|
||||
PositionInfo();
|
||||
|
||||
int x;
|
||||
int y;
|
||||
Alignment align;
|
||||
Alignment align_h;
|
||||
Alignment align_v;
|
||||
};
|
||||
|
||||
class Widget {
|
||||
@ -24,7 +37,7 @@ public:
|
||||
virtual void set_width(int width, bool preserve_aspect_ratio = true);
|
||||
virtual void set_height(int height, bool preserve_aspect_ratio = true);
|
||||
virtual void set_position(int x, int y);
|
||||
virtual void set_alignment(Alignment align);
|
||||
virtual void set_alignment(Alignment align_h, Alignment align_v);
|
||||
|
||||
int get_width();
|
||||
int get_height();
|
||||
@ -87,6 +100,7 @@ public:
|
||||
|
||||
void select_next();
|
||||
void select_prev();
|
||||
void select(size_t n);
|
||||
size_t get_selection();
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user