Skip to content

Commit

Permalink
Merge branch 'master' into inverter_error_checking
Browse files Browse the repository at this point in the history
  • Loading branch information
RCMast3r committed Feb 5, 2024
2 parents 9347fb5 + d7231a4 commit 1a550d1
Show file tree
Hide file tree
Showing 4 changed files with 1,667 additions and 71 deletions.
11 changes: 9 additions & 2 deletions lib/interfaces/include/DashboardInterface.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef __DASHBOARDINTERFACE_H__
#define __DASHBOARDINTERFACE_H__

#include "MessageQueueDefine.h"
#include "FlexCAN_T4.h"
#include "ht_can.h"

enum DialMode_e
Expand Down Expand Up @@ -72,12 +74,17 @@ class DashboardInterface
private:

DashComponentInterface_s _data;
CANBufferType *msg_queue_;

public:
Dashboard(){};

Dashboard(CANBufferType *msg_output_queue)
{
msg_queue_ = msg_output_queue;
};

void read(const CAN_message_t &can_msg);
CAN_message_t write();
void write();

DialMode_e getDialMode();

Expand Down
9 changes: 9 additions & 0 deletions lib/interfaces/include/MessageQueueDefine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef MESAGE_QUEUE_DEFINE_H
#define MESAGE_QUEUE_DEFINE_H

#include "FlexCAN_T4.h"

constexpr std::size_t CANBufferSize = 16;
using CANBufferType = CircularBuffer<uint8_t, CANBufferSize>;

#endif
139 changes: 70 additions & 69 deletions lib/interfaces/src/DashboardInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,73 +1,74 @@
// #include "DashboardInterface.h"
#include "DashboardInterface.h"

// void DashboardInterface::read(const CAN_message_t &can_msg)
// {
void DashboardInterface::read(const CAN_message_t &can_msg)
{

// DASHBOARD_STATE_t msg;
// Unpack_DASHBOARD_STATE_ht_can(&msg, can_msg.buf, NULL);
DASHBOARD_STATE_t msg;
Unpack_DASHBOARD_STATE_ht_can(&msg, can_msg.buf, NULL);

// _data.dial_mode = static_cast<DialMode_e>(msg.dial_state);
_data.dial_mode = static_cast<DialMode_e>(msg.dial_state);

// _data.ssok = msg.ssok_above_threshold
// _data.shutdown = msg.shutdown_h_above_threshold;

// _data.button.start = msg.start_btn;
// _data.button.mark = msg.mark_btn;
// _data.button.mode = msg.mode_btn;
// _data.button.mc_cycle = msg.mc_cycle_btn;
// _data.button.launch_ctrl = msg.launch_ctrl_btn;
// _data.button.torque_mode = msg.torque_mode_btn;
// _data.button.led_dimmer = msg.led_dimmer_btn;

// _data.buzzer_state = msg.drive_buzzer;

// }

// CAN_message_t DashboardInterface::write()
// {

// DASHBOARD_MCU_STATE_t msg;
// msg.drive_buzzer = _data.buzzer_cmd;

// // TODO: use logic as to not write data for LEDs that have not changed
// msg.bots_led = _data.LED[DashLED_e::BOTS_LED];
// msg.launch_control_led = _data.LED[DashLED_e::LAUNCH_CONTROL_LED];
// msg.mode_led = _data.LED[DashLED_e::MODE_LED];
// msg.mech_brake_led = _data.LED[DashLED_e::MECH_BRAKE_LED];
// msg.cockpit_brb_led = _data.LED[DashLED_e::COCKPIT_BRB_LED];
// msg.inertia_led = _data.LED[DashLED_e::INERTIA_LED];
// msg.glv_led = _data.LED[DashLED_e::GLV_LED];
// msg.crit_charge_led = _data.LED[DashLED_e::CRIT_CHARGE_LED];
// msg.start_led = _data.LED[DashLED_e::START_LED];
// msg.mc_error_led = _data.LED[DashLED_e::MC_ERROR_LED];
// msg.imd_led = _data.LED[DashLED_e::IMD_LED];
// msg.ams_led = _data.LED[DashLED_e::AMS_LED];

// CAN_message_t can_msg;
// can_msg.id = Pack_DASHBOARD_MCU_STATE_ht_can(&msg, can_msg.buf, &can_msg.len, NULL);

// return can_msg;

// }

// //figure out how to set enumed led colors or send (0,255 value)
// void DashboardInterface::setLED(DashLED_e led, LEDColors_e color)
// {
// _data.LED[static_cast<int>(led)] = static_cast<int> color;
// }

// DialMode_e DashboardInterface::getDialMode() {return _data.dial_mode;}

// bool DashboardInterface::startButtonPressed() {return _data.button.start;}
// bool DashboardInterface::specialButtonPressed() {return _data.button.mark;}
// bool DashboardInterface::torqueButtonPressed() {return _data.button.mode;}
// bool DashboardInterface::inverterResetButtonPressed() {return _data.button.mc_cycle;}
// bool DashboardInterface::launchControlButtonPressed() {return _data.button.launch_ctrl;}
// bool DashboardInterface::torqueLoadingButtonPressed() {return _data.button.torque_mode;}
// bool DashboardInterface::nightModeButtonPressed() {return _data.button.led_dimmer;}

// bool DashboardInterface::safetySystemOK() {return _data.ssok;}
// bool DashboardInterface::shutdownHAboveThreshold() {return _data.shutdown;}

// void DashboardInterface::soundBuzzer(bool state) {_data.buzzer_cmd = state;}
// bool DashboardInterface::checkBuzzer() {return _data.buzzer_state;}
_data.ssok = msg.ssok_above_threshold
_data.shutdown = msg.shutdown_h_above_threshold;

_data.button.start = msg.start_btn;
_data.button.mark = msg.mark_btn;
_data.button.mode = msg.mode_btn;
_data.button.mc_cycle = msg.mc_cycle_btn;
_data.button.launch_ctrl = msg.launch_ctrl_btn;
_data.button.torque_mode = msg.torque_mode_btn;
_data.button.led_dimmer = msg.led_dimmer_btn;

_data.buzzer_state = msg.drive_buzzer;

}

void DashboardInterface::write()
{

DASHBOARD_MCU_STATE_t msg;
msg.drive_buzzer = _data.buzzer_cmd;

// TODO: use logic as to not write data for LEDs that have not changed
msg.bots_led = _data.LED[DashLED_e::BOTS_LED];
msg.launch_control_led = _data.LED[DashLED_e::LAUNCH_CONTROL_LED];
msg.mode_led = _data.LED[DashLED_e::MODE_LED];
msg.mech_brake_led = _data.LED[DashLED_e::MECH_BRAKE_LED];
msg.cockpit_brb_led = _data.LED[DashLED_e::COCKPIT_BRB_LED];
msg.inertia_led = _data.LED[DashLED_e::INERTIA_LED];
msg.glv_led = _data.LED[DashLED_e::GLV_LED];
msg.crit_charge_led = _data.LED[DashLED_e::CRIT_CHARGE_LED];
msg.start_led = _data.LED[DashLED_e::START_LED];
msg.mc_error_led = _data.LED[DashLED_e::MC_ERROR_LED];
msg.imd_led = _data.LED[DashLED_e::IMD_LED];
msg.ams_led = _data.LED[DashLED_e::AMS_LED];

CAN_message_t can_msg;
can_msg.id = Pack_DASHBOARD_MCU_STATE_ht_can(&msg, can_msg.buf, &can_msg.len, NULL);

msg_queue_->push_back(can_msg, sizeof(CAN_message_t));

}

//figure out how to set enumed led colors or send (0,255 value)
void DashboardInterface::setLED(DashLED_e led, LEDColors_e color)
{
_data.LED[static_cast<int>(led)] = static_cast<int> color;
}

DialMode_e DashboardInterface::getDialMode() {return _data.dial_mode;}

bool DashboardInterface::startButtonPressed() {return _data.button.start;}
bool DashboardInterface::specialButtonPressed() {return _data.button.mark;}
bool DashboardInterface::torqueButtonPressed() {return _data.button.mode;}
bool DashboardInterface::inverterResetButtonPressed() {return _data.button.mc_cycle;}
bool DashboardInterface::launchControlButtonPressed() {return _data.button.launch_ctrl;}
bool DashboardInterface::torqueLoadingButtonPressed() {return _data.button.torque_mode;}
bool DashboardInterface::nightModeButtonPressed() {return _data.button.led_dimmer;}

bool DashboardInterface::safetySystemOK() {return _data.ssok;}
bool DashboardInterface::shutdownHAboveThreshold() {return _data.shutdown;}

void DashboardInterface::soundBuzzer(bool state) {_data.buzzer_cmd = state;}
bool DashboardInterface::checkBuzzer() {return _data.buzzer_state;}

Loading

0 comments on commit 1a550d1

Please sign in to comment.