Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions projects/dashboard/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ canGen:
- name: veh
node: DASH
dbcFile: "../veh.dbc"
- name: pt
node: DASH
dbcFile: "../pt.dbc"
2 changes: 0 additions & 2 deletions projects/dashboard/include/Display.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "StartingMotors.hpp"
#include "generated/can/veh_bus.hpp"
#include "generated/can/veh_messages.hpp"

class Display {
public:
using State = generated::can::TxDashStatus::State_t;
Expand All @@ -28,7 +27,6 @@ class Display {
Button enter;
Button scroll;
generated::can::VehBus& veh_bus;

Profile selected_profile = Profile::Default;

void Start();
Expand Down
131 changes: 112 additions & 19 deletions projects/dashboard/include/DriveModeMenu.hpp
Original file line number Diff line number Diff line change
@@ -1,47 +1,140 @@
#pragma once

#include "Screen.hpp"
#include "etl/circular_buffer.h"
#include "etl/vector.h"
#include "lvgl.h"

class Speedometer {
// ── HV current arc ───────────────────────────────────────────────────────────
class HVCurrentArc {
public:
static constexpr uint32_t kUpdateRateHz = 100;
static constexpr uint32_t kAvgWindowSamples = kUpdateRateHz;
static constexpr float kHVCurrentMax = 500.0f;
static constexpr float kArcResolution = 10.0f;

void Draw(lv_obj_t* parent);
void PushSample(float hv_current);

private:
lv_obj_t* arc_{nullptr};
lv_obj_t* label_{nullptr};
etl::circular_buffer<float, kAvgWindowSamples> buf_;

float ComputeAverage() const;
void Update();
};

// ── HV / LV voltage ──────────────────────────────────────────────────────────
class HVVoltageDisplay {
public:
void Draw(lv_obj_t* parent);
void SetVoltage(float hv_voltage);

private:
lv_obj_t* label_{nullptr};
};

class LVVoltageDisplay {
public:
void Draw(lv_obj_t* parent, lv_align_t align, lv_coord_t x, lv_coord_t y);
void SetSpeed(float speed);
void Draw(lv_obj_t* parent);
void SetVoltage(float lv_voltage);

private:
const float kArcMaxSpeed = 120;
const float kArcSpeedResolution = 10;
lv_obj_t* label_{nullptr};
};

lv_obj_t* arc;
lv_obj_t* label;
// ── LV current (text) ────────────────────────────────────────────────────────
class LVCurrentDisplay {
public:
void Draw(lv_obj_t* parent);
void SetCurrent(float current);

private:
lv_obj_t* label_{nullptr};
};

// ── SOC ──────────────────────────────────────────────────────────────────────
class Battery {
public:
void Draw(lv_obj_t* parent, lv_align_t align, lv_coord_t x, lv_coord_t y);
void SetPercent(float volt);
void Draw(lv_obj_t* parent);
void SetSOC(float soc);

private:
const int kVoltMax = 600.f;
const int kVoltMin = 250.f; // display this as "empty"
lv_obj_t* bar_{nullptr};
lv_obj_t* label_{nullptr};
};

// ── Temperature card ─────────────────────────────────────────────────────────
class TempCard {
public:
void Draw(lv_obj_t* parent, const char* title, lv_color_t color);
void SetTemps(float min, float max);

lv_obj_t* label;
private:
lv_obj_t* container_{nullptr};
lv_obj_t* min_label_{nullptr};
lv_obj_t* max_label_{nullptr};
};

class DriveModeMenu : public Screen {
// ── CAN indicator ────────────────────────────────────────────────────────────
class CANIndicator {
public:
DriveModeMenu(Display* display);
void Draw(lv_obj_t* parent, const char* label);
void SetActive(bool active);

private:
lv_obj_t* dot_{nullptr};
lv_obj_t* label_{nullptr};
};

// ── FC status ────────────────────────────────────────────────────────────────
class FCStatusMessage {
public:
void Draw(lv_obj_t* parent);
void SetStatus(const char* status);

private:
lv_obj_t* label_{nullptr};
};

// ── Speedometer (compact) ────────────────────────────────────────────────────
class Speedometer {
public:
static constexpr float kSpeedMax = 140.0f; // km/h, FSAE-realistic ceiling

void Draw(lv_obj_t* parent);
void SetSpeed(float speed_kph);

private:
lv_obj_t* arc_{nullptr};
lv_obj_t* value_label_{nullptr};
};

// ── Screen ───────────────────────────────────────────────────────────────────
class DriveModeMenu : public Screen {
public:
explicit DriveModeMenu(Display* display);
void CreateGUI() override;
void Update() override;

private:
HVCurrentArc hv_arc_;
HVVoltageDisplay hv_voltage_;
LVVoltageDisplay lv_voltage_;
LVCurrentDisplay lv_current_;
Battery battery_;
Speedometer speedometer_;

// Demo: cycling warnings
uint32_t last_warning_time_;
TempCard battery_temp_;
TempCard motor_temp_;
TempCard inverter_temp_;

CANIndicator veh_can_;

FCStatusMessage fc_status_;
Speedometer speedo_;

uint32_t last_warning_time_{0};
etl::vector<int, 10> active_warning_ids_;
int warning_cycle_index_;
};
int warning_cycle_index_{0};
};
1 change: 1 addition & 0 deletions projects/dashboard/include/Screen.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "StatusBar.hpp"
#include "generated/can/veh_bus.hpp"
#include "generated/can/veh_messages.hpp"
#include "lvgl.h"

Expand Down
1 change: 1 addition & 0 deletions projects/dashboard/include/StartingHV.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ class StartingHV : public Screen {
void Update() override;

private:
lv_obj_t* title_label;
lv_obj_t* progress_bar_;
};
1 change: 1 addition & 0 deletions projects/dashboard/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ platform_packages = platformio/toolchain-gccarmnoneeabi@^1.140201.0
framework = stm32cube
board = disco_f469ni
upload_protocol = stlink
debug_tool = stlink

lib_deps =
${common.lib_deps}
Expand Down
1 change: 0 additions & 1 deletion projects/dashboard/src/AcknowledgeConfig.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "AcknowledgeConfig.hpp"

#include "Display.hpp"
#include "generated/can/veh_bus.hpp"
#include "lvgl.h"

AcknowledgeConfig::AcknowledgeConfig(Display* display) : Screen(display) {}
Expand Down
3 changes: 2 additions & 1 deletion projects/dashboard/src/ConfirmMenu.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ConfirmMenu.hpp"

#include "Display.hpp"
#include "generated/can/veh_bus.hpp"

ConfirmMenu::ConfirmMenu(Display* display) : Screen(display) {}

Expand Down Expand Up @@ -32,4 +33,4 @@ void ConfirmMenu::Update() {
} else if (display_->scroll.PosEdge()) {
lv_roller_set_selected(roller, !sel, LV_ANIM_ON);
}
}
}
4 changes: 3 additions & 1 deletion projects/dashboard/src/Display.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "Display.hpp"

#include "generated/can/pt_bus.hpp"
#include "generated/can/veh_bus.hpp"
Display::Display(Button& enter, Button& scroll, generated::can::VehBus& veh)
: enter(enter),
scroll(scroll),
veh_bus(veh),
screen_(&profile_select),
screen_(&profile_select), //! Useful: drive_mode profile_select
profile_select(this),
confirm_menu(this),
acknowledge_config(this),
Expand Down
Loading
Loading