working demo driver view
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
|
||||
#include "AMI.h"
|
||||
#include "AppState.h"
|
||||
#include "DriverView.h"
|
||||
#include "MissionSelect.h"
|
||||
#include "defines.h"
|
||||
|
||||
@ -44,6 +45,7 @@ private:
|
||||
std::unique_ptr<AppState> state;
|
||||
std::unique_ptr<MissionSelect> mission_select;
|
||||
std::unique_ptr<AMI> ami;
|
||||
std::unique_ptr<DriverView> driver_view;
|
||||
|
||||
bool running;
|
||||
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "DemoDataSource.h"
|
||||
|
||||
#include <fmt/ostream.h>
|
||||
|
||||
#include <optional>
|
||||
@ -32,6 +34,7 @@ public:
|
||||
|
||||
AppView get_view() const;
|
||||
Mission get_mission() const;
|
||||
DemoDataSource get_data_source() const;
|
||||
|
||||
private:
|
||||
void unmarshal_mission_select(uint8_t* data);
|
||||
@ -42,6 +45,7 @@ private:
|
||||
|
||||
AppView view;
|
||||
Mission mission;
|
||||
DemoDataSource data_source;
|
||||
|
||||
#ifndef NDEBUG
|
||||
friend class KeyboardHandler;
|
||||
|
||||
34
include/BaseDataSource.h
Normal file
34
include/BaseDataSource.h
Normal file
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
class BaseDataSource {
|
||||
public:
|
||||
double get_speed(); // in km/h
|
||||
double get_brake_balance(); // 0.0 - 1.0
|
||||
double get_hv_voltage(); // in V
|
||||
double get_hv_voltage_ratio(); // 0.0 - 1.0
|
||||
double get_lv_voltage(); // in V
|
||||
double get_battery_temperature(); // in °C
|
||||
double get_throttle_ratio(); // 0.0 - 1.0
|
||||
double get_brake_pressure_front_bar(); // in bar
|
||||
double get_brake_pressure_rear_bar(); // in bar
|
||||
|
||||
bool brake_balance_change_is_recent(); // true if the last change was less
|
||||
// than 1 second ago
|
||||
|
||||
virtual void poll() = 0;
|
||||
|
||||
protected:
|
||||
void set_brake_balance(double value);
|
||||
|
||||
double speed;
|
||||
double brake_balance;
|
||||
double hv_voltage;
|
||||
double hv_voltage_ratio;
|
||||
double lv_voltage;
|
||||
double battery_temperature;
|
||||
double throttle_ratio;
|
||||
double brake_pressure_front_bar;
|
||||
double brake_pressure_rear_bar;
|
||||
|
||||
int time_of_last_brake_balance_change;
|
||||
};
|
||||
13
include/DemoDataSource.h
Normal file
13
include/DemoDataSource.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseDataSource.h"
|
||||
|
||||
class DemoDataSource final : public BaseDataSource {
|
||||
public:
|
||||
DemoDataSource();
|
||||
~DemoDataSource();
|
||||
|
||||
void poll() override;
|
||||
void bump_brake_balance_up();
|
||||
void bump_brake_balance_down();
|
||||
};
|
||||
30
include/DriverView.h
Normal file
30
include/DriverView.h
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include "View.h"
|
||||
#include "defines.h"
|
||||
#include "util.h"
|
||||
#include "widgets.h"
|
||||
|
||||
class DriverView final : public View {
|
||||
public:
|
||||
DriverView(SDL_Renderer* renderer);
|
||||
~DriverView();
|
||||
|
||||
void draw(const AppState& state) override;
|
||||
|
||||
private:
|
||||
TTF_Font* font_large;
|
||||
TTF_Font* font_detail;
|
||||
TTF_Font* font_tiny;
|
||||
TTF_Font* font_giant;
|
||||
TTF_Font* font_medium;
|
||||
std::unique_ptr<TextWidget> speed_widget;
|
||||
std::unique_ptr<TextWidget> speed_hint_widget;
|
||||
|
||||
std::unique_ptr<TextWidget> brake_balance_widget;
|
||||
std::unique_ptr<TextWidget> brake_balance_hint_widget;
|
||||
|
||||
std::unique_ptr<TextWidget> general_info_widget;
|
||||
|
||||
std::unique_ptr<TextWidget> focus_widget;
|
||||
std::unique_ptr<TextWidget> focus_hint_widget;
|
||||
};
|
||||
@ -79,12 +79,13 @@ public:
|
||||
~TextWidget();
|
||||
|
||||
void update_text(const std::string& new_text);
|
||||
void set_wrap_width(int width);
|
||||
|
||||
protected:
|
||||
TTF_Font* font;
|
||||
|
||||
std::string text;
|
||||
|
||||
int wrap_width = -1; // -1 means no wrapping (default behavior)
|
||||
SDL_Texture* generate_text(const std::string& text);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user