diff --git a/include/newDisplay.h b/include/newDisplay.h index 6c7158e..fdc9424 100644 --- a/include/newDisplay.h +++ b/include/newDisplay.h @@ -48,6 +48,9 @@ class HTX_Display void draw_popup(String title); void send_display_buffer(SPI_HandleTypeDef *hspi); void display_min_cell(float min_cell_voltage); + void display_all_temps(veh_vec temps); + void display_max_temps(int inverter_temp, int motor_temp); + uint8_t current_page = 0; private: diff --git a/lib/interfaces/include/VCRInterface.h b/lib/interfaces/include/VCRInterface.h index f2f474e..5dae543 100644 --- a/lib/interfaces/include/VCRInterface.h +++ b/lib/interfaces/include/VCRInterface.h @@ -15,6 +15,18 @@ struct MotorMechanics_s float actual_speed; //rpm }; +struct Temperature_s +{ + veh_vec inverter_temps; + veh_vec motor_temps; +}; + +struct InverterStatus_s +{ + veh_vec error; + veh_vec dc_bus_voltage; + veh_vec error_id; +}; class VCRInterface { @@ -24,15 +36,26 @@ class VCRInterface bool is_in_pedals_calibration_state() {return _is_in_pedals_calibration_state;} void receive_inv_dynamics(const CAN_message_t &can_msg, unsigned long curr_millis); - MotorMechanics_s get_curr_wheel_data() {return _wheel_data;} void receive_vehicle_state(const CAN_message_t &can_msg); - VehicleState_e get_curr_car_state() {return _vehicle_state_value;} bool get_drivebrain_in_control() {return _is_db_in_ctrl;} + + void receive_inverter_status_1(const CAN_message_t &can_msg); + void receive_inverter_status_2(const CAN_message_t &can_msg); + void receive_inverter_status_3(const CAN_message_t &can_msg); + void receive_inverter_status_4(const CAN_message_t &can_msg); + + void receive_inverter_temperature_1(const CAN_message_t &can_msg); + void receive_inverter_temperature_2(const CAN_message_t &can_msg); + void receive_inverter_temperature_3(const CAN_message_t &can_msg); + void receive_inverter_temperature_4(const CAN_message_t &can_msg); + int get_inverter_max_temp() {return std::max({_temps.inverter_temps.FL, _temps.inverter_temps.FR, _temps.inverter_temps.RL, _temps.inverter_temps.RR});} + int get_motor_max_temp() {return std::max({_temps.motor_temps.FL, _temps.motor_temps.FR, _temps.motor_temps.RL, _temps.motor_temps.RR});} + private: TorqueLimit_e _torque_limit = TorqueLimit_e::TCMUX_LOW_TORQUE; bool _is_in_pedals_calibration_state = false; @@ -40,6 +63,8 @@ class VCRInterface VehicleState_e _vehicle_state_value; DrivetrainState_e _drivetrain_state_value; bool _is_db_in_ctrl; + InverterStatus_s _inverter_status; + Temperature_s _temps; }; diff --git a/lib/interfaces/src/DashCANInterfaceImpl.cpp b/lib/interfaces/src/DashCANInterfaceImpl.cpp index b615e3e..b263649 100644 --- a/lib/interfaces/src/DashCANInterfaceImpl.cpp +++ b/lib/interfaces/src/DashCANInterfaceImpl.cpp @@ -5,11 +5,6 @@ void DashCAN::dash_read_switch(CANInterfaces &interfaces, const CAN_message_t &msg, unsigned long millis) { switch (msg.id) { - // case DASHBOARD_BUZZER_CONTROL_CANID: - // { - // interfaces.vcr_interface.receive_dash_control_data(_msg); - // break; - // } case BMS_VOLTAGES_CANID: { interfaces.acu_interface.receive_acu_voltages(msg); @@ -40,7 +35,46 @@ void DashCAN::dash_read_switch(CANInterfaces &interfaces, const CAN_message_t &m interfaces.vcf_interface.receive_dashboard_message(msg, millis); break; } - + case INV1_STATUS_CANID: + { + interfaces.vcr_interface.receive_inverter_status_1(msg); + break; + } + case INV2_STATUS_CANID: + { + interfaces.vcr_interface.receive_inverter_status_2(msg); + break; + } + case INV3_STATUS_CANID: + { + interfaces.vcr_interface.receive_inverter_status_3(msg); + break; + } + case INV4_STATUS_CANID: + { + interfaces.vcr_interface.receive_inverter_status_4(msg); + break; + } + case INV1_TEMPS_CANID: + { + interfaces.vcr_interface.receive_inverter_temperature_1(msg); + break; + } + case INV2_TEMPS_CANID: + { + interfaces.vcr_interface.receive_inverter_temperature_2(msg); + break; + } + case INV3_TEMPS_CANID: + { + interfaces.vcr_interface.receive_inverter_temperature_3(msg); + break; + } + case INV4_TEMPS_CANID: + { + interfaces.vcr_interface.receive_inverter_temperature_4(msg); + break; + } default: break; } diff --git a/lib/interfaces/src/VCRInterface.cpp b/lib/interfaces/src/VCRInterface.cpp index 882c4c5..b82107f 100644 --- a/lib/interfaces/src/VCRInterface.cpp +++ b/lib/interfaces/src/VCRInterface.cpp @@ -21,4 +21,69 @@ void VCRInterface::receive_vehicle_state(const CAN_message_t &can_msg) _vehicle_state_value = static_cast(unpacked_msg.vehicle_state); _drivetrain_state_value = static_cast(unpacked_msg.drivetrain_state); _is_db_in_ctrl = unpacked_msg.drivebrain_in_control; +} + +void VCRInterface::receive_inverter_status_1(const CAN_message_t &can_msg) +{ + INV1_STATUS_t unpacked_msg; + Unpack_INV1_STATUS_hytech(&unpacked_msg, can_msg.buf, can_msg.len); //NOLINT + _inverter_status.error.FL = unpacked_msg.error; + _inverter_status.dc_bus_voltage.FL = unpacked_msg.dc_bus_voltage; +} + +void VCRInterface::receive_inverter_status_2(const CAN_message_t &can_msg) +{ + INV2_STATUS_t unpacked_msg; + Unpack_INV2_STATUS_hytech(&unpacked_msg, can_msg.buf, can_msg.len); //NOLINT + _inverter_status.error.FR = unpacked_msg.error; + _inverter_status.dc_bus_voltage.FR = unpacked_msg.dc_bus_voltage; + +} + +void VCRInterface::receive_inverter_status_3(const CAN_message_t &can_msg) +{ + INV3_STATUS_t unpacked_msg; + Unpack_INV3_STATUS_hytech(&unpacked_msg, can_msg.buf, can_msg.len); //NOLINT + _inverter_status.error.RL = unpacked_msg.error; + _inverter_status.dc_bus_voltage.RL = unpacked_msg.dc_bus_voltage; +} + +void VCRInterface::receive_inverter_status_4(const CAN_message_t &can_msg) +{ + INV4_STATUS_t unpacked_msg; + Unpack_INV4_STATUS_hytech(&unpacked_msg, can_msg.buf, can_msg.len); //NOLINT + _inverter_status.error.RR = unpacked_msg.error; + _inverter_status.dc_bus_voltage.RR = unpacked_msg.dc_bus_voltage; +} + +void VCRInterface::receive_inverter_temperature_1(const CAN_message_t &can_msg) +{ + INV1_TEMPS_t unpacked_msg; + Unpack_INV1_TEMPS_hytech(&unpacked_msg, can_msg.buf, can_msg.len); //NOLINT + _temps.motor_temps.FL = HYTECH_motor_temp_ro_fromS(unpacked_msg.motor_temp_ro); + _temps.inverter_temps.FL = HYTECH_inverter_temp_ro_fromS(unpacked_msg.inverter_temp_ro); +} + +void VCRInterface::receive_inverter_temperature_2(const CAN_message_t &can_msg) +{ + INV2_TEMPS_t unpacked_msg; + Unpack_INV2_TEMPS_hytech(&unpacked_msg, can_msg.buf, can_msg.len); //NOLINT + _temps.motor_temps.FR = HYTECH_motor_temp_ro_fromS(unpacked_msg.motor_temp_ro); + _temps.inverter_temps.FR = HYTECH_inverter_temp_ro_fromS(unpacked_msg.inverter_temp_ro); +} + +void VCRInterface::receive_inverter_temperature_3(const CAN_message_t &can_msg) +{ + INV3_TEMPS_t unpacked_msg; + Unpack_INV3_TEMPS_hytech(&unpacked_msg, can_msg.buf, can_msg.len); //NOLINT + _temps.motor_temps.RL = HYTECH_motor_temp_ro_fromS(unpacked_msg.motor_temp_ro); + _temps.inverter_temps.RL = HYTECH_inverter_temp_ro_fromS(unpacked_msg.inverter_temp_ro); +} + +void VCRInterface::receive_inverter_temperature_4(const CAN_message_t &can_msg) +{ + INV4_TEMPS_t unpacked_msg; + Unpack_INV4_TEMPS_hytech(&unpacked_msg, can_msg.buf, can_msg.len); //NOLINT + _temps.motor_temps.RR = HYTECH_motor_temp_ro_fromS(unpacked_msg.motor_temp_ro); + _temps.inverter_temps.RR = HYTECH_inverter_temp_ro_fromS(unpacked_msg.inverter_temp_ro); } \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 84cba68..ba27d15 100644 --- a/platformio.ini +++ b/platformio.ini @@ -68,14 +68,14 @@ build_src_filter = build_flags = -std=c++17 -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC - -D USBCON + #-D USBCON -D USBD_VID=0x0483 -D USBD_PID=0x0003 -D USE_HAL_DRIVER -D HAL_PCD_MODULE_ENABLED -D HAL_FDCAN_MODULE_ENABLED - -D USBCON - -D USBD_USE_CDC + #-D USBCON + #-D USBD_USE_CDC -D HSE_VALUE=25000000 check_src_filters = + diff --git a/src/Dash_Tasks.cpp b/src/Dash_Tasks.cpp index 9ea6bd1..40baaa3 100644 --- a/src/Dash_Tasks.cpp +++ b/src/Dash_Tasks.cpp @@ -6,11 +6,13 @@ #define SHARP_CS PB4 #define SHARP_CLK PB10 #define SHARP_MOSI PB15 + +veh_vec fake_temps = {30, 32, 28, 31}; HT_TASK::TaskResponse init_heartbeat(const unsigned long& sys_micros, const HT_TASK::TaskInfo& task_info) { - SerialUSB.begin(115200); + //SerialUSB.begin(115200); // Create Interfaces ACUInterfaceInstance::create(); @@ -58,10 +60,13 @@ HT_TASK::TaskResponse screen_refresh(const unsigned long& sys_micros, const HT_T HTXDisplayInstance::instance().draw_background(); HTXDisplayInstance::instance().invert_display(VCFInterfaceInstance::instance().is_mech_brake_pressed()); HTXDisplayInstance::instance().draw_vertical_pedal_bar(VCFInterfaceInstance::instance().get_curr_data().stamped_pedals.pedals_data.brake_percent * 100, 17); + HTXDisplayInstance::instance().draw_vertical_pedal_bar(VCFInterfaceInstance::instance().get_curr_data().stamped_pedals.pedals_data.accel_percent * 100, 46); + HTXDisplayInstance::instance().draw_battery_bar((ACUInterfaceInstance::instance().get_curr_data().pack_voltage - 460) / 70 * 100.0 + 1); HTXDisplayInstance::instance().draw_icons(1, VCRInterfaceInstance::instance().get_curr_car_state(), VCRInterfaceInstance::instance().get_drivebrain_in_control()); HTXDisplayInstance::instance().display_mode(VCFInterfaceInstance::instance().get_control_mode()); HTXDisplayInstance::instance().display_min_cell(ACUInterfaceInstance::instance().get_curr_data().min_cell_voltage); + HTXDisplayInstance::instance().display_max_temps(VCRInterfaceInstance::instance().get_inverter_max_temp(), VCRInterfaceInstance::instance().get_motor_max_temp()); //HTXDisplayInstance::instance().display_speeds(VCRInterfaceInstance::instance().get_curr_wheel_data().actual_speed); if (ACUInterfaceInstance::instance().get_curr_data().imd_ok == false || ACUInterfaceInstance::instance().get_curr_data().bms_ok == false) diff --git a/src/main.cpp b/src/main.cpp index 569aee6..ffcb3a4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -62,7 +62,7 @@ void setup() { void loop() { scheduler.run(); - Serial.println(ACUInterfaceInstance::instance().get_curr_data().pack_voltage); - Serial.println(VCFInterfaceInstance::instance().get_curr_data().stamped_pedals.pedals_data.brake_percent); + //Serial.println(ACUInterfaceInstance::instance().get_curr_data().pack_voltage); + //Serial.println(VCFInterfaceInstance::instance().get_curr_data().stamped_pedals.pedals_data.brake_percent); } diff --git a/src/newDisplay.cpp b/src/newDisplay.cpp index 241f9de..35decb7 100644 --- a/src/newDisplay.cpp +++ b/src/newDisplay.cpp @@ -18,7 +18,9 @@ void HTX_Display::draw_background() { _display.clearDisplayBuffer(); _display.fillRect(0, 0, 320, 240, _white); - _display.drawBitmap(0, 0, epd_bitmap_hytech_dashboard, 320, 240, _black); + _display.fillRect(15, 33, 22, 179, _black); + _display.fillRect(44, 33, 22, 179, _black); + //_display.drawBitmap(0, 0, epd_bitmap_hytech_dashboard, 320, 240, _black); _display.fillRect(320 - 40, 30, 40, 200, _white); //_display.fillRect(283, 36, 305 - 283, 210 - 36, _black); _display.fillRect(283 - 3, (36 + 210 - 36) / 2 + 15, 25, 7, _white); @@ -136,16 +138,53 @@ void HTX_Display::display_mode(int mode) void HTX_Display::display_min_cell(float min_cell_voltage) { - _display.setFont(&FreeSans12pt7b); + _display.setFont(&FreeSans9pt7b); _display.setTextSize(1); _display.setTextColor(_black); - _display.setCursor(220, 100); + _display.setCursor(230, 100); + _display.print("CEL:"); + _display.setCursor(270, 100); // SerialUSB.println(mph); _display.print(min_cell_voltage); } + + +void HTX_Display::display_max_temps(int inverter_temp, int motor_temp) +{ + _display.setFont(&FreeSans9pt7b); + _display.setTextSize(1); + _display.setTextColor(_black); + _display.setCursor(235, 130); + _display.print("TEMPS"); + _display.setCursor(230, 150); + _display.print("INV:"); + _display.setCursor(265, 150); + _display.print(inverter_temp); + _display.setCursor(230, 170); + _display.print("MTR:"); + _display.setCursor(275, 170); + _display.print(motor_temp); +} + +void HTX_Display::display_all_temps(veh_vec temps) +{ + _display.setFont(&FreeSans9pt7b); + _display.setTextSize(1); + _display.setTextColor(_black); + + _display.setCursor(220, 120); + _display.print(temps.FL); + _display.setCursor(250, 120); + _display.print(temps.FR); + _display.setCursor(220, 140); + _display.print(temps.RL); + _display.setCursor(250, 140); + _display.print(temps.RR); +} + void HTX_Display::draw_icons(uint8_t vn_status, VehicleState_e car_state, bool db_in_ctrl) {