MCU
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
DashboardInterface Class Reference

#include <DashboardInterface.h>

Collaboration diagram for DashboardInterface:
Collaboration graph

Public Member Functions

 DashboardInterface (CANBufferType *msg_output_queue)
 
void read (const CAN_message_t &can_msg)
 
CAN_message_t write ()
 
void tick10 (MCUInterface *mcu, int car_state, bool buzzer, bool drivetrain_error, TorqueLimit_e torque, float min_cell_voltage, AnalogConversion_s glv_voltage, int launch_state, ControllerMode_e dial_mode)
 
ControllerMode_e getDialMode ()
 
TorqueLimit_e getTorqueLimitMode ()
 
bool safetySystemOK ()
 
bool startButtonPressed ()
 
bool specialButtonPressed ()
 
bool torqueModeButtonPressed ()
 
bool inverterResetButtonPressed ()
 
bool launchControlButtonPressed ()
 
bool torqueLoadingButtonPressed ()
 
bool nightModeButtonPressed ()
 
bool leftShifterButtonPressed ()
 
bool rightShifterButtonPressed ()
 
bool shutdownHAboveThreshold ()
 
void soundBuzzer (bool s)
 
bool checkBuzzer ()
 
void setLED (DashLED_e led, LEDColors_e color)
 
ControllerMode_e getDialMode ()
 
TorqueLimit_e getTorqueLimitMode ()
 
bool startButtonPressed ()
 
bool checkBuzzer ()
 

Public Attributes

bool buzzer = false
 
bool start_button_status_
 

Private Member Functions

void update_torque_mode_ (bool button_pressed)
 

Private Attributes

CANBufferTypemsg_queue_
 
DashComponentInterface_s _data
 
bool prev_button_pressed_state_
 

Detailed Description

Definition at line 82 of file DashboardInterface.h.

Constructor & Destructor Documentation

◆ DashboardInterface()

DashboardInterface::DashboardInterface ( CANBufferType msg_output_queue)
inline

Constructor for new DashboardInterface, All that it is inited with is the pointer to the telem circular buffer that is used to write new messages

Parameters
msg_output_queuePointer to the telem CAN circular buffer

Definition at line 99 of file DashboardInterface.h.

100 {
101 _data.torque_limit_mode = TorqueLimit_e::TCMUX_FULL_TORQUE;
103 msg_queue_ = msg_output_queue;
104 };
DashComponentInterface_s _data
CANBufferType * msg_queue_

Member Function Documentation

◆ checkBuzzer() [1/2]

bool DashboardInterface::checkBuzzer ( )

Definition at line 160 of file DashboardInterface.cpp.

◆ checkBuzzer() [2/2]

bool DashboardInterface::checkBuzzer ( )
inline

Definition at line 41 of file DashboardInterface.h.

41{ return buzzer; };

◆ getDialMode() [1/2]

ControllerMode_e DashboardInterface::getDialMode ( )

getter for the dashboard's current dial position (drive profile)

Returns
returns a ControllerMode_e enum with the current dial position

Definition at line 145 of file DashboardInterface.cpp.

145{ return _data.dial_mode; }

◆ getDialMode() [2/2]

ControllerMode_e DashboardInterface::getDialMode ( )
inline

Definition at line 38 of file DashboardInterface.h.

38{return {};}

◆ getTorqueLimitMode() [1/2]

TorqueLimit_e DashboardInterface::getTorqueLimitMode ( )

Definition at line 146 of file DashboardInterface.cpp.

146{return _data.torque_limit_mode; }

◆ getTorqueLimitMode() [2/2]

TorqueLimit_e DashboardInterface::getTorqueLimitMode ( )
inline

Definition at line 39 of file DashboardInterface.h.

39{return {};}

◆ inverterResetButtonPressed()

bool DashboardInterface::inverterResetButtonPressed ( )

Definition at line 150 of file DashboardInterface.cpp.

◆ launchControlButtonPressed()

bool DashboardInterface::launchControlButtonPressed ( )

Definition at line 151 of file DashboardInterface.cpp.

151{ return _data.button.launch_ctrl; }

◆ leftShifterButtonPressed()

bool DashboardInterface::leftShifterButtonPressed ( )

Definition at line 153 of file DashboardInterface.cpp.

153{ return _data.button.left_shifter; }

◆ nightModeButtonPressed()

bool DashboardInterface::nightModeButtonPressed ( )

Definition at line 152 of file DashboardInterface.cpp.

152{ return _data.button.led_dimmer; }

◆ read()

void DashboardInterface::read ( const CAN_message_t &  can_msg)

read function will take in a reference to a new CAN message, unpack it, and will store all of the information into the DashComponentInterface for later access

Parameters
can_msgis the reference to a new CAN message CAN_message_t

Definition at line 3 of file DashboardInterface.cpp.

4{
5
6 DASHBOARD_STATE_t dash_state;
7 Unpack_DASHBOARD_STATE_hytech(&dash_state, can_msg.buf, can_msg.len);
8
9 _data.dial_mode = static_cast<ControllerMode_e>(dash_state.dial_state);
10
11 _data.ssok = dash_state.ssok_above_threshold;
12 _data.shutdown = dash_state.shutdown_h_above_threshold;
13
14 _data.button.start = dash_state.start_button;
15 _data.button.mark = dash_state.mark_button;
16 _data.button.mode = dash_state.mode_button;
17 _data.button.mc_cycle = dash_state.motor_controller_cycle_button;
18 _data.button.launch_ctrl = dash_state.launch_ctrl_button;
19 _data.button.torque_mode = dash_state.torque_mode_button;
20 _data.button.led_dimmer = dash_state.led_dimmer_button;
21 _data.button.left_shifter = dash_state.left_shifter_button;
22 _data.button.right_shifter = dash_state.right_shifter_button;
23
24 _data.buzzer_state = dash_state.drive_buzzer;
25
27}
ControllerMode_e
void update_torque_mode_(bool button_pressed)

◆ rightShifterButtonPressed()

bool DashboardInterface::rightShifterButtonPressed ( )

Definition at line 154 of file DashboardInterface.cpp.

154{ return _data.button.right_shifter; }

◆ safetySystemOK()

bool DashboardInterface::safetySystemOK ( )

Definition at line 156 of file DashboardInterface.cpp.

156{ return _data.ssok; }

◆ setLED()

void DashboardInterface::setLED ( DashLED_e  led,
LEDColors_e  color 
)

setter for the dash LEDs

Parameters
ledDashLED_e enum that corresponds to the LED's value in the LED array
colorLEDColors_e enum that corresponds to the color/state of the set LED

Definition at line 78 of file DashboardInterface.cpp.

79{
80
81 _data.LED[static_cast<uint8_t>(led)] = static_cast<uint8_t>(color);
82}

◆ shutdownHAboveThreshold()

bool DashboardInterface::shutdownHAboveThreshold ( )

Definition at line 157 of file DashboardInterface.cpp.

157{ return _data.shutdown; }

◆ soundBuzzer()

void DashboardInterface::soundBuzzer ( bool  s)

Definition at line 159 of file DashboardInterface.cpp.

◆ specialButtonPressed()

bool DashboardInterface::specialButtonPressed ( )

Definition at line 148 of file DashboardInterface.cpp.

148{ return _data.button.mark; }

◆ startButtonPressed() [1/2]

bool DashboardInterface::startButtonPressed ( )

Definition at line 147 of file DashboardInterface.cpp.

147{ return _data.button.start; }

◆ startButtonPressed() [2/2]

bool DashboardInterface::startButtonPressed ( )
inline

Definition at line 40 of file DashboardInterface.h.

◆ tick10()

void DashboardInterface::tick10 ( MCUInterface mcu,
int  car_state,
bool  buzzer,
bool  drivetrain_error,
TorqueLimit_e  torque,
float  min_cell_voltage,
AnalogConversion_s  glv_voltage,
int  launch_state,
ControllerMode_e  dial_mode 
)

Definition at line 84 of file DashboardInterface.cpp.

93{
94
95 // TODO unfuck this
96 _data.cur_dial_mode = dial_mode;
98
99 setLED(DashLED_e::AMS_LED, mcu->bms_ok_is_high() ? LEDColors_e::ON : LEDColors_e::RED);
100 setLED(DashLED_e::IMD_LED, mcu->imd_ok_is_high() ? LEDColors_e::ON : LEDColors_e::RED);
101 setLED(DashLED_e::BOTS_LED, mcu->get_bots_ok() ? LEDColors_e::ON : LEDColors_e::RED);
102 setLED(DashLED_e::START_LED, car_state == int(MCU_STATE::READY_TO_DRIVE) ? LEDColors_e::ON : LEDColors_e::RED);
103 setLED(DashLED_e::MC_ERROR_LED, !drivetrain_error ? LEDColors_e::ON : LEDColors_e::RED);
104 setLED(DashLED_e::COCKPIT_BRB_LED, mcu->brb_ok_is_high() ? LEDColors_e::ON : LEDColors_e::RED);
105
106 switch (launch_state)
107 {
108 case 1:
109 setLED(DashLED_e::LAUNCH_CONTROL_LED, LEDColors_e::RED);
110 break;
111 case 2:
112 setLED(DashLED_e::LAUNCH_CONTROL_LED, LEDColors_e::YELLOW);
113 break;
114 case 3:
115 setLED(DashLED_e::LAUNCH_CONTROL_LED, LEDColors_e::ON);
116 break;
117 default:
118 setLED(DashLED_e::LAUNCH_CONTROL_LED, LEDColors_e::OFF);
119 break;
120 }
121
122 switch (torque)
123 {
124 case TorqueLimit_e::TCMUX_LOW_TORQUE:
125 setLED(DashLED_e::MODE_LED, LEDColors_e::OFF);
126 break;
127 case TorqueLimit_e::TCMUX_MID_TORQUE:
128 setLED(DashLED_e::MODE_LED, LEDColors_e::YELLOW);
129 break;
130 case TorqueLimit_e::TCMUX_FULL_TORQUE:
131 setLED(DashLED_e::MODE_LED, LEDColors_e::ON);
132 break;
133 default:
134 setLED(DashLED_e::MODE_LED, LEDColors_e::RED);
135 break;
136 }
137
138 uint16_t scaled_cell_voltage = (uint16_t)map((uint32_t)(min_cell_voltage * 1000), 3300, 4200, 0, 255); // scale voltage
139 _data.LED[static_cast<int>(DashLED_e::CRIT_CHARGE_LED)] = std::max(0, std::min((int)scaled_cell_voltage, 255)); // clamp voltage
140 // _data.LED[DashLED_e::GLV_LED] = (uint8_t)map(glv_voltage.raw)
141
142 write();
143}
void setLED(DashLED_e led, LEDColors_e color)
bool brb_ok_is_high()
bool imd_ok_is_high()
bool get_bots_ok()
bool bms_ok_is_high()
ControllerMode_e cur_dial_mode

◆ torqueLoadingButtonPressed()

bool DashboardInterface::torqueLoadingButtonPressed ( )

◆ torqueModeButtonPressed()

bool DashboardInterface::torqueModeButtonPressed ( )

Definition at line 149 of file DashboardInterface.cpp.

149{ return _data.button.torque_mode; }

◆ update_torque_mode_()

void DashboardInterface::update_torque_mode_ ( bool  button_pressed)
private

Definition at line 30 of file DashboardInterface.cpp.

31{
32 // detect high-to-low transition
33 if (prev_button_pressed_state_ == true && button_pressed == false)
34 {
35
36 _data.torque_limit_mode = static_cast<TorqueLimit_e>((static_cast<int>(_data.torque_limit_mode) + 1) % (static_cast<int>(TorqueLimit_e::TCMUX_NUM_TORQUE_LIMITS)));
37 }
38 prev_button_pressed_state_ = button_pressed;
39}
TorqueLimit_e
Defines modes of torque limit to be processed in torque limit map for exact values.

◆ write()

CAN_message_t DashboardInterface::write ( )

Definition at line 41 of file DashboardInterface.cpp.

42{
43
44 DASHBOARD_MCU_STATE_t dash_mcu_state;
45 dash_mcu_state.drive_buzzer = _data.buzzer_cmd;
46
47 dash_mcu_state.dial_state = static_cast<uint8_t>(_data.cur_dial_mode);
48
49 // TODO: use logic as to not write data for LEDs that have not changed
50 dash_mcu_state.launch_control_led = _data.LED[static_cast<int>(DashLED_e::LAUNCH_CONTROL_LED)];
51 dash_mcu_state.mode_led = _data.LED[static_cast<int>(DashLED_e::MODE_LED)];
52 dash_mcu_state.mechanical_brake_led = _data.LED[static_cast<int>(DashLED_e::MECH_BRAKE_LED)];
53 dash_mcu_state.cockpit_brb_led = _data.LED[static_cast<int>(DashLED_e::COCKPIT_BRB_LED)];
54 dash_mcu_state.inertia_status_led = _data.LED[static_cast<int>(DashLED_e::INERTIA_LED)];
55 dash_mcu_state.start_status_led = _data.LED[static_cast<int>(DashLED_e::START_LED)];
56 dash_mcu_state.motor_controller_error_led = _data.LED[static_cast<int>(DashLED_e::MC_ERROR_LED)];
57
58 dash_mcu_state.bots_led = _data.LED[static_cast<int>(DashLED_e::BOTS_LED)];
59 dash_mcu_state.imd_led = _data.LED[static_cast<int>(DashLED_e::IMD_LED)];
60 dash_mcu_state.ams_led = _data.LED[static_cast<int>(DashLED_e::AMS_LED)];
61
62 dash_mcu_state.glv_led = _data.LED[static_cast<int>(DashLED_e::GLV_LED)];
63 dash_mcu_state.pack_charge_led = _data.LED[static_cast<int>(DashLED_e::CRIT_CHARGE_LED)];
64
65 CAN_message_t can_msg;
66 auto id = Pack_DASHBOARD_MCU_STATE_hytech(&dash_mcu_state, can_msg.buf, &can_msg.len, (uint8_t *)&can_msg.flags.extended);
67 can_msg.id = id;
68 // this circular buffer implementation requires that you push your data in a array buffer
69 // all this does is put the msg into a uint8_t buffer and pushes it onto the queue
70 uint8_t buf[sizeof(CAN_message_t)] = {};
71 memmove(buf, &can_msg, sizeof(CAN_message_t));
72 msg_queue_->push_back(buf, sizeof(CAN_message_t));
73
74 return can_msg;
75}

Member Data Documentation

◆ _data

DashComponentInterface_s DashboardInterface::_data
private

Definition at line 88 of file DashboardInterface.h.

◆ buzzer

bool DashboardInterface::buzzer = false

Definition at line 36 of file DashboardInterface.h.

◆ msg_queue_

CANBufferType* DashboardInterface::msg_queue_
private

Definition at line 86 of file DashboardInterface.h.

◆ prev_button_pressed_state_

bool DashboardInterface::prev_button_pressed_state_
private

Definition at line 89 of file DashboardInterface.h.

◆ start_button_status_

bool DashboardInterface::start_button_status_

Definition at line 37 of file DashboardInterface.h.


The documentation for this class was generated from the following files: