This commit is contained in:
Julian 2024-07-23 15:13:22 +02:00
parent 5fb5d271b1
commit 10aa474124
3 changed files with 148 additions and 145 deletions

View File

@ -5,8 +5,10 @@
/** /**
* Decrements the given value if it is above the minimum allowed value * Decrements the given value if it is above the minimum allowed value
*/ */
#define DEC_IF_ABOVE(param_val, min_val, decr_amt) ((param_val) = ((param_val) - (decr_amt) ) > (min_val) ? ((param_val) - (decr_amt)) : (min_val)) // TODO these functions take into account that the parameters are unsigned, it's definitely better to have them
#define INC_IF_BELOW(param_val, max_val, incr_amt) ((param_val) = ((param_val) + (incr_amt)) < (max_val) ? ((param_val) + (incr_amt)) : (max_val)) // signed but would need to be tested with the autobox
#define DEC_IF_ABOVE(param_val, min_val, decr_amt) ((param_val) = (((int)(param_val) - (int)(decr_amt)) > (int)(min_val)) ? ((param_val) - (decr_amt)) : (min_val))
#define INC_IF_BELOW(param_val, max_val, incr_amt) ((param_val) = (((param_val) + (incr_amt)) < (max_val)) ? ((param_val) + (incr_amt)) : (max_val))
Params params = {0}; Params params = {0};

View File

@ -13,7 +13,7 @@
#include "leds.h" #include "leds.h"
#define DRS_BUTTON_IDX (6) #define DRS_BUTTON_IDX (6)
#define DRS_PRESS_WAIT_CYCLES (10) #define DRS_PRESS_WAIT_CYCLES (1000)
static int drs_press_buf_cycles = 0; static int drs_press_buf_cycles = 0;
void ui_thread_entry(ULONG _) { void ui_thread_entry(ULONG _) {

View File

@ -1,16 +1,14 @@
#include "vehicle.h" #include "vehicle.h"
#include "main.h"
#include "ui.h"
#include "vehicle_state.h"
#include "can-halal.h" #include "can-halal.h"
#include "main.h"
#include "stm32h7xx.h" #include "stm32h7xx.h"
#include "stm32h7xx_hal.h" #include "stm32h7xx_hal.h"
#include "stm32h7xx_hal_fdcan.h" #include "stm32h7xx_hal_fdcan.h"
#include "stm32h7xx_hal_gpio.h" #include "stm32h7xx_hal_gpio.h"
#include "tx_api.h" #include "tx_api.h"
#include "ui.h"
#include "vehicle_state.h"
#define CAN_ID_AMS_SLAVE_PANIC 0x9 #define CAN_ID_AMS_SLAVE_PANIC 0x9
#define CAN_ID_AMS_STATUS 0xA #define CAN_ID_AMS_STATUS 0xA
@ -98,7 +96,8 @@ void vehicle_broadcast_param(ParamType param, int32_t value) {
void vehicle_broadcast_buttons(GPIO_PinState *button_states) { void vehicle_broadcast_buttons(GPIO_PinState *button_states) {
uint8_t data = (button_states[0] << 2) | (button_states[1] << 0) | uint8_t data = (button_states[0] << 2) | (button_states[1] << 0) |
(button_states[2] << 1) | (button_states[3] << 3); (button_states[2] << 1) | (button_states[3] << 3) |
(button_states[6] << 4);
ftcan_transmit(CAN_ID_STW_BUTTONS, &data, 1); ftcan_transmit(CAN_ID_STW_BUTTONS, &data, 1);
} }
@ -228,12 +227,14 @@ void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
break; break;
case CAN_ID_ABX_PARAM_CONFIRMED: case CAN_ID_ABX_PARAM_CONFIRMED:
vehicle_state.last_param_confirmed = data[0]; vehicle_state.last_param_confirmed = data[0];
tx_event_flags_set(&gui_update_events, GUI_UPDATE_PARAM_CONFIRMED, TX_OR); tx_event_flags_set(&gui_update_events, GUI_UPDATE_PARAM_CONFIRMED,
TX_OR);
break; break;
case CAN_ID_SHUNT_CURRENT: { case CAN_ID_SHUNT_CURRENT: {
// The first two bytes of shunt result messages are metadata // The first two bytes of shunt result messages are metadata
const uint8_t *result_ptr = &data[2]; const uint8_t *result_ptr = &data[2];
vehicle_state.ts_current = ftcan_unmarshal_signed(&result_ptr, 4) * 1e-3; vehicle_state.ts_current =
ftcan_unmarshal_signed(&result_ptr, 4) * 1e-3;
break; break;
} }
case CAN_ID_SHUNT_VOLTAGE1: { case CAN_ID_SHUNT_VOLTAGE1: {