diff --git a/lib/interfaces/include/MCUInterface.h b/lib/interfaces/include/MCUInterface.h index d042ece3b..e53110c5b 100644 --- a/lib/interfaces/include/MCUInterface.h +++ b/lib/interfaces/include/MCUInterface.h @@ -9,17 +9,18 @@ #include "PedalsSystem.h" #include "SharedDataTypes.h" -const int DEFAULT_BMS_OK_READ = 17; // SHDN_D_READ -const int DEFAULT_BMS_SENSE_PIN = 16; // BMS_OK_SENSE -const int DEFAULT_IMD_OK_READ = 10; // SHDN_C_READ -const int DEFAULT_IMD_SENSE_PIN = 18; // OKHS_SENSE -const int DEFAULT_BSPD_OK_READ = 39; // SHDN_E_READ -const int DEFAULT_SOFTWARE_OK_READ = 25; // SHDN_F_READ Watchdog Combined -const int DEFAULT_BOTS_OK_READ = 24; // SHDN_B_READ -const int DEFAULT_BRB_OK_READ = 26; // SHDN_G_READ -const int DEFAULT_BRAKE_LIGHT_CTRL = 6; -const int DEFAULT_INVERTER_ENABLE = 9; -const int DEFAULT_INVERTER_24V_ENABLE = 7; +const int DEFAULT_BMS_OK_READ = 17; // SHDN_D_READ +const int DEFAULT_BMS_SENSE_PIN = 16; // BMS_OK_SENSE +const int DEFAULT_IMD_OK_READ = 10; // SHDN_C_READ +const int DEFAULT_IMD_SENSE_PIN = 18; // OKHS_SENSE +const int DEFAULT_BSPD_OK_READ = 39; // SHDN_E_READ +const int DEFAULT_SOFTWARE_OK_READ = 25; // SHDN_F_READ Watchdog Combined +const int DEFAULT_BOTS_OK_READ = 24; // SHDN_B_READ +const int DEFAULT_BRB_OK_READ = 26; // SHDN_G_READ +const int DEFAULT_BRAKE_LIGHT_CTRL = 6; +const int DEFAULT_INVERTER_ENABLE = 9; +const int DEFAULT_INVERTER_24V_ENABLE = 7; +const int DEFAULT_BRAKE_PRESSURE_SENSOR_READ = 27; // Read pin for brake pressure sensor. /// @brief specifically designed so that Walker would be happy struct MainECUHardwareReadPins @@ -36,10 +37,12 @@ struct MainECUHardwareReadPins // inverter enable pins int pin_inv_en; int pin_inv_24V_en; + int pin_brake_pressure_sensor_read; }; static const MainECUHardwareReadPins DEFAULT_PINS = {DEFAULT_BMS_OK_READ,DEFAULT_IMD_OK_READ, DEFAULT_BSPD_OK_READ, DEFAULT_SOFTWARE_OK_READ, - DEFAULT_BOTS_OK_READ, DEFAULT_BRB_OK_READ, DEFAULT_BRAKE_LIGHT_CTRL, DEFAULT_INVERTER_ENABLE, DEFAULT_INVERTER_24V_ENABLE}; + DEFAULT_BOTS_OK_READ, DEFAULT_BRB_OK_READ, DEFAULT_BRAKE_LIGHT_CTRL, DEFAULT_INVERTER_ENABLE, + DEFAULT_INVERTER_24V_ENABLE, DEFAULT_BRAKE_PRESSURE_SENSOR_READ}; class MCUInterface { @@ -115,6 +118,7 @@ class MCUInterface // Interfaces void update_mcu_status_CAN_ams(bool is_critical); void update_mcu_status_CAN_dashboard(bool is_active); + void update_brake_pressure_CAN(); /* Enqueue MCU_status CAN */ void enqueue_CAN_mcu_status(); diff --git a/lib/interfaces/src/MCUInterface.cpp b/lib/interfaces/src/MCUInterface.cpp index b66b356c1..dabb3bc37 100644 --- a/lib/interfaces/src/MCUInterface.cpp +++ b/lib/interfaces/src/MCUInterface.cpp @@ -182,6 +182,19 @@ void MCUInterface::update_mcu_status_CAN_pedals(const PedalsSystemData_s &pedals mcu_status_.no_brake_implausibility = !pedals.brakeImplausible; mcu_status_.no_accel_or_brake_implausibility = !(pedals.brakeAndAccelPressedImplausibility); } +void MCUInterface::update_brake_pressure_CAN() +{ + BRAKE_PRESSURE_SENSOR_t brake_sensor_msg; + brake_sensor_msg.brake_sensor_analog_read = analogRead(pins_.pin_brake_pressure_sensor_read); + + CAN_message_t msg; + + msg.id = Pack_BRAKE_PRESSURE_SENSOR_hytech(&brake_sensor_msg, msg.buf, &msg.len, (uint8_t*) &msg.flags.extended); + + uint8_t buf[sizeof(CAN_message_t)] = {}; + memmove(buf, &msg, sizeof(CAN_message_t)); + msg_queue_->push_back(buf, sizeof(CAN_message_t)); +} void MCUInterface::tick(int fsm_state, bool inv_has_error, @@ -209,6 +222,7 @@ void MCUInterface::tick(int fsm_state, // External Interfaces update_mcu_status_CAN_ams(pack_charge_is_critical); update_mcu_status_CAN_dashboard(button_is_pressed); + update_brake_pressure_CAN(); // Internal values update_mcu_status_CAN(); // Push into buffer diff --git a/platformio.ini b/platformio.ini index a9474fcd6..7ff412f6f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -58,7 +58,7 @@ lib_deps = https://github.com/tonton81/FlexCAN_T4 https://github.com/ssilverman/QNEthernet#v0.26.0 https://github.com/RCMast3r/hytech_can#testing_new_inv_ids - https://github.com/hytech-racing/HT_CAN/releases/download/125/can_lib.tar.gz + https://github.com/hytech-racing/HT_CAN/releases/download/127/can_lib.tar.gz [env:test_can_on_teensy] lib_ignore = @@ -81,7 +81,7 @@ lib_deps = https://github.com/hytech-racing/shared_firmware_interfaces.git#feature/thermistor-template https://github.com/hytech-racing/shared_firmware_systems.git#af96a63 https://github.com/RCMast3r/spi_libs#2214fee - https://github.com/hytech-racing/HT_CAN/releases/download/108/can_lib.tar.gz + https://github.com/hytech-racing/HT_CAN/releases/download/127/can_lib.tar.gz git+ssh://git@github.com/hytech-racing/CASE_lib.git#v49