Compare commits
3 Commits
f0db650c30
...
afd4688c97
| Author | SHA1 | Date | |
|---|---|---|---|
| afd4688c97 | |||
| 4c2c277fef | |||
| 0076387f21 |
@ -21,6 +21,8 @@ void vehicle_thread_entry(ULONG hfdcan_addr);
|
||||
|
||||
void vehicle_broadcast_buttons(GPIO_PinState *button_states);
|
||||
|
||||
void vehicle_broadcast_wishlist();
|
||||
|
||||
#endif // SIMULATOR
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -7,6 +7,7 @@ extern "C" {
|
||||
|
||||
#include "params.h"
|
||||
#include "stw_defines.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define NUM_CONES 12
|
||||
@ -112,6 +113,7 @@ typedef struct {
|
||||
int sdc_closed;
|
||||
int pdu_sdc_active;
|
||||
int imd_ok;
|
||||
bool drs_active;
|
||||
int sdcl_state[3];
|
||||
|
||||
R2DProgress r2d_progress;
|
||||
@ -148,6 +150,7 @@ typedef struct {
|
||||
IniChkState ini_chk_state;
|
||||
|
||||
unsigned lap_count;
|
||||
unsigned lap_count_endu;
|
||||
float lap_last;
|
||||
float lap_best;
|
||||
|
||||
@ -191,7 +194,15 @@ typedef struct {
|
||||
ParamType last_param_confirmed;
|
||||
} VehicleState;
|
||||
|
||||
typedef struct {
|
||||
bool initialized;
|
||||
|
||||
uint8_t power_limit;
|
||||
uint8_t speed_limit;
|
||||
} DriverWishlist;
|
||||
|
||||
extern VehicleState vehicle_state;
|
||||
extern DriverWishlist wishlist;
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
||||
@ -80,31 +80,17 @@ void led_thread_entry(ULONG child_thread_stack_addr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
float speed =
|
||||
(vehicle_state.speed - LED_SPEED_MIN) / (LED_SPEED_MAX - LED_SPEED_MIN);
|
||||
float num_leds_exact = speed * N_LEDS;
|
||||
num_leds_exact = fmin(N_LEDS, fmax(0, num_leds_exact));
|
||||
int num_leds = num_leds_exact;
|
||||
float num_leds_frac = num_leds_exact - num_leds;
|
||||
|
||||
float hue =
|
||||
LED_SPEED_HUE_MIN - speed * (LED_SPEED_HUE_MIN - LED_SPEED_HUE_MAX);
|
||||
hue = fmin(LED_SPEED_HUE_MIN, fmax(LED_SPEED_HUE_MAX, hue));
|
||||
uint8_t r, g, b;
|
||||
led_hsv_to_rgb(hue, 1.0f, 1.0f, &r, &g, &b);
|
||||
|
||||
// Fully illuminate first n LEDs
|
||||
for (int i = 0; i < num_leds; i++) {
|
||||
led_set(i, r, g, b);
|
||||
for (int i = 0; i <= 3; i++) {
|
||||
int led_limit = (4 - i) * 3; // 3% per LED
|
||||
int red = (vehicle_state.bat_delta_last >= led_limit) ? 0xFF : 0;
|
||||
led_set(i, red, 0, 0);
|
||||
}
|
||||
// Partially illuminate n+1th LED
|
||||
if (num_leds < N_LEDS) {
|
||||
led_hsv_to_rgb(hue, 1.0f, num_leds_frac, &r, &g, &b);
|
||||
led_set(num_leds, r, g, b);
|
||||
}
|
||||
// Turn off all other LEDs
|
||||
for (int i = num_leds + 1; i < N_LEDS; i++) {
|
||||
led_set(i, 0, 0, 0);
|
||||
int blue = (vehicle_state.drs_active) ? 0xFF : 0;
|
||||
led_set(4, 0, 0, blue);
|
||||
for (int i = 5; i <= 9; i++) {
|
||||
int led_limit = -((i - 4) * 3); // 3% per LED
|
||||
int green = (vehicle_state.bat_delta_last <= led_limit) ? 0xFF : 0;
|
||||
led_set(i, 0, green, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -329,7 +329,7 @@ static void MX_FDCAN1_Init(void) {
|
||||
hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_8;
|
||||
hfdcan1.Init.TxEventsNbr = 0;
|
||||
hfdcan1.Init.TxBuffersNbr = 0;
|
||||
hfdcan1.Init.TxFifoQueueElmtsNbr = 1;
|
||||
hfdcan1.Init.TxFifoQueueElmtsNbr = 32;
|
||||
hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
|
||||
hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;
|
||||
if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) {
|
||||
|
||||
@ -24,10 +24,12 @@
|
||||
#define CAN_ID_CS_INTERNAL 0x108
|
||||
#define CAN_ID_ABX_MISC 0x109
|
||||
#define CAN_ID_ABX_HYDRAULICS 0x110
|
||||
#define CAN_ID_ABX_ENDURANCE 0x113
|
||||
#define CAN_ID_EPSC_OUT 0x321
|
||||
#define CAN_ID_MISSION_SELECTED 0x400
|
||||
#define CAN_ID_STW_BUTTONS 0x401
|
||||
#define CAN_ID_STW_PARAM_SET 0x402
|
||||
#define CAN_ID_STW_DRIVERWISHLIST 0x403
|
||||
#define CAN_ID_AS_MISSION_FB 0x410
|
||||
#define CAN_ID_STW_STATUS 0x412
|
||||
#define CAN_ID_ABX_PARAM_CONFIRMED 0x413
|
||||
@ -55,6 +57,7 @@
|
||||
void vehicle_thread_entry(ULONG hfdcan_addr) {
|
||||
memset(&vehicle_state, 0, sizeof(vehicle_state));
|
||||
memset(&vehicle_state.cone_pos, 0xFF, sizeof(vehicle_state.cone_pos));
|
||||
memset(&wishlist, 0, sizeof(wishlist));
|
||||
|
||||
ftcan_init((void *)hfdcan_addr);
|
||||
ftcan_add_filter(CAN_ID_AMS_SLAVE_PANIC, 0x7FF);
|
||||
@ -68,6 +71,7 @@ void vehicle_thread_entry(ULONG hfdcan_addr) {
|
||||
ftcan_add_filter(CAN_ID_ABX_BRAKE_T, 0x7FF);
|
||||
ftcan_add_filter(CAN_ID_CS_INTERNAL, 0x7FF);
|
||||
ftcan_add_filter(CAN_ID_ABX_MISC, 0x7FF);
|
||||
ftcan_add_filter(CAN_ID_ABX_ENDURANCE, 0x7FF);
|
||||
ftcan_add_filter(CAN_ID_ABX_HYDRAULICS, 0x7FF);
|
||||
ftcan_add_filter(CAN_ID_EPSC_OUT, 0x7FF);
|
||||
ftcan_add_filter(CAN_ID_AS_MISSION_FB, 0x7FF);
|
||||
@ -80,6 +84,7 @@ void vehicle_thread_entry(ULONG hfdcan_addr) {
|
||||
|
||||
while (1) {
|
||||
tx_thread_sleep(10);
|
||||
vehicle_broadcast_wishlist();
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,6 +107,17 @@ void vehicle_broadcast_buttons(GPIO_PinState *button_states) {
|
||||
ftcan_transmit(CAN_ID_STW_BUTTONS, &data, 1);
|
||||
}
|
||||
|
||||
void vehicle_broadcast_wishlist() {
|
||||
if (!wishlist.initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t data[2];
|
||||
data[0] = wishlist.power_limit;
|
||||
data[1] = wishlist.speed_limit;
|
||||
ftcan_transmit(CAN_ID_STW_DRIVERWISHLIST, data, 2);
|
||||
}
|
||||
|
||||
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
|
||||
const uint8_t *ptr;
|
||||
if ((id & CAN_ID_STW_CONES_MASK) == CAN_ID_STW_CONES_BASE) {
|
||||
@ -166,6 +182,18 @@ void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
|
||||
vehicle_state.hyd_press_b =
|
||||
((data[1] >> 4) | (data[2] << 4)) * CAN_ABX_DRIVER_PRESS_FACTOR;
|
||||
break;
|
||||
case CAN_ID_ABX_ENDURANCE:
|
||||
vehicle_state.power_limit = data[0];
|
||||
vehicle_state.speed_limit = data[1];
|
||||
if (!wishlist.initialized) {
|
||||
wishlist.initialized = true;
|
||||
wishlist.power_limit = vehicle_state.power_limit;
|
||||
wishlist.speed_limit = vehicle_state.speed_limit;
|
||||
}
|
||||
vehicle_state.lap_count_endu = data[2];
|
||||
vehicle_state.bat_delta_overall = ((int8_t)data[3]) * 1.0f;
|
||||
vehicle_state.bat_delta_last = ((int8_t)data[4]) * 1.0f;
|
||||
break;
|
||||
case CAN_ID_ABX_TIMINGS:
|
||||
vehicle_state.lap_best = (data[0] | (data[1] << 8)) * 0.01f;
|
||||
vehicle_state.lap_last = (data[2] | (data[3] << 8)) * 0.01f;
|
||||
@ -225,6 +253,7 @@ void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
|
||||
vehicle_state.errors.err_res = (data[5] >> 2) & 1;
|
||||
vehicle_state.errors.err_invl = (data[5] >> 3) & 1;
|
||||
vehicle_state.errors.err_invr = (data[5] >> 4) & 1;
|
||||
vehicle_state.drs_active = (data[5] >> 5) & 1;
|
||||
break;
|
||||
case CAN_ID_ABX_PARAM_CONFIRMED:
|
||||
vehicle_state.last_param_confirmed = data[0];
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#include "vehicle_state.h"
|
||||
|
||||
VehicleState vehicle_state;
|
||||
DriverWishlist wishlist;
|
||||
|
||||
const char *inichkstate_str(IniChkState state) {
|
||||
switch (vehicle_state.ini_chk_state) {
|
||||
|
||||
13
Makefile
13
Makefile
@ -1,5 +1,5 @@
|
||||
##########################################################################################################################
|
||||
# File automatically-generated by tool: [projectgenerator] version: [4.1.0] date: [Mon Jul 24 18:47:29 CEST 2023]
|
||||
# File automatically-generated by tool: [projectgenerator] version: [4.3.0-B58] date: [Wed Jun 12 17:44:56 CEST 2024]
|
||||
##########################################################################################################################
|
||||
|
||||
# ------------------------------------------------
|
||||
@ -228,7 +228,16 @@ Middlewares/ST/threadx/common/src/txe_timer_delete.c \
|
||||
Middlewares/ST/threadx/common/src/txe_timer_info_get.c \
|
||||
TouchGFX/App/app_touchgfx.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc_ex.c
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc_ex.c \
|
||||
TouchGFX/target/TouchGFXHAL.cpp \
|
||||
TouchGFX/target/STM32TouchController.cpp \
|
||||
TouchGFX/target/TouchGFXGPIO.cpp \
|
||||
TouchGFX/target/generated/TouchGFXConfiguration.cpp \
|
||||
TouchGFX/target/generated/TouchGFXGeneratedHAL.cpp \
|
||||
TouchGFX/target/generated/STM32DMA.cpp \
|
||||
TouchGFX/target/generated/OSWrappers.cpp \
|
||||
Core/Src/sysmem.c \
|
||||
Core/Src/syscalls.c
|
||||
|
||||
# ASM sources
|
||||
ASM_SOURCES = \
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 STMicroelectronics.
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 STMicroelectronics.
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
|
||||
@ -60,6 +60,11 @@ public:
|
||||
void updateDetails();
|
||||
void updateProgress();
|
||||
|
||||
void decreasePowerLimit() override;
|
||||
void increasePowerLimit() override;
|
||||
void decreaseSpeedLimit() override;
|
||||
void increaseSpeedLimit() override;
|
||||
|
||||
protected:
|
||||
BatDelta lastLapDelta;
|
||||
BatDelta overallDelta;
|
||||
@ -67,6 +72,8 @@ protected:
|
||||
ValueBuffer slimBuffer;
|
||||
ValueBuffer socBuffer;
|
||||
ValueBuffer tbatBuffer;
|
||||
|
||||
bool limitsChangable();
|
||||
};
|
||||
|
||||
#endif // ENDURANCEVIEW_HPP
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
#include "main.h"
|
||||
#include "touchgfx/Color.hpp"
|
||||
#include "touchgfx/Unicode.hpp"
|
||||
#include "vehicle_state.h"
|
||||
@ -5,6 +6,10 @@
|
||||
#include <cmath>
|
||||
#include <gui/endurance_screen/EnduranceView.hpp>
|
||||
|
||||
#ifndef SIMULATOR
|
||||
#include "stm32h7xx_hal_gpio.h"
|
||||
#endif
|
||||
|
||||
EnduranceView::EnduranceView()
|
||||
: lastLapDelta(lastLapBox, lastLapBat),
|
||||
overallDelta(overallBox, overallBat), plimBuffer(powerLimit, 2, 0),
|
||||
@ -39,6 +44,54 @@ void EnduranceView::updateDetails() {
|
||||
|
||||
void EnduranceView::updateProgress() { progressBar.update(); }
|
||||
|
||||
void EnduranceView::decreasePowerLimit() {
|
||||
if (!limitsChangable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (wishlist.power_limit > 15) {
|
||||
wishlist.power_limit--;
|
||||
}
|
||||
}
|
||||
|
||||
void EnduranceView::increasePowerLimit() {
|
||||
if (!limitsChangable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (wishlist.power_limit < 40) {
|
||||
wishlist.power_limit++;
|
||||
}
|
||||
}
|
||||
|
||||
void EnduranceView::decreaseSpeedLimit() {
|
||||
if (!limitsChangable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (wishlist.speed_limit > 40) {
|
||||
wishlist.speed_limit--;
|
||||
}
|
||||
}
|
||||
|
||||
void EnduranceView::increaseSpeedLimit() {
|
||||
if (!limitsChangable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (wishlist.speed_limit < 100) {
|
||||
wishlist.speed_limit++;
|
||||
}
|
||||
}
|
||||
|
||||
bool EnduranceView::limitsChangable() {
|
||||
#ifdef SIMULATOR
|
||||
return true;
|
||||
#else
|
||||
return HAL_GPIO_ReadPin(BTN3_GPIO_Port, BTN3_Pin) == GPIO_PIN_SET;
|
||||
#endif
|
||||
}
|
||||
|
||||
BatDelta::BatDelta(touchgfx::BoxWithBorder &box,
|
||||
touchgfx::TextAreaWithOneWildcard &field)
|
||||
: box(box), field(field), value(INT_MIN) {}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 STMicroelectronics.
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 STMicroelectronics.
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 STMicroelectronics.
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 STMicroelectronics.
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 STMicroelectronics.
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 STMicroelectronics.
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
|
||||
@ -36,7 +36,7 @@ FDCAN1.NominalTimeSeg1=63
|
||||
FDCAN1.NominalTimeSeg2=16
|
||||
FDCAN1.RxFifo0ElmtsNbr=16
|
||||
FDCAN1.StdFiltersNbr=32
|
||||
FDCAN1.TxFifoQueueElmtsNbr=1
|
||||
FDCAN1.TxFifoQueueElmtsNbr=32
|
||||
File.Version=6
|
||||
GPIO.groupedBy=Show All
|
||||
JPEG.IPParameters=JPEG_RGB_FORMAT
|
||||
@ -152,8 +152,8 @@ Mcu.Pin7=PF2
|
||||
Mcu.Pin70=VP_TIM1_VS_ClockSourceINT
|
||||
Mcu.Pin71=VP_TIM2_VS_ClockSourceINT
|
||||
Mcu.Pin72=VP_TIM17_VS_ClockSourceINT
|
||||
Mcu.Pin73=VP_STMicroelectronics.X-CUBE-AZRTOS-H7_VS_RTOSJjThreadX_6.1.12_3.0.0
|
||||
Mcu.Pin74=VP_STMicroelectronics.X-CUBE-TOUCHGFX_VS_GraphicsJjApplication_4.22.0
|
||||
Mcu.Pin73=VP_STMicroelectronics.X-CUBE-TOUCHGFX_VS_GraphicsJjApplication_4.22.0
|
||||
Mcu.Pin74=VP_STMicroelectronics.X-CUBE-AZRTOS-H7_VS_RTOSJjThreadX_6.1.12_3.0.0
|
||||
Mcu.Pin8=PF3
|
||||
Mcu.Pin9=PF4
|
||||
Mcu.PinsNb=75
|
||||
@ -448,7 +448,7 @@ ProjectManager.ToolChainLocation=
|
||||
ProjectManager.UAScriptAfterPath=
|
||||
ProjectManager.UAScriptBeforePath=
|
||||
ProjectManager.UnderRoot=false
|
||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_FDCAN1_Init-FDCAN1-false-HAL-true,5-MX_LTDC_Init-LTDC-false-HAL-true,6-MX_JPEG_Init-JPEG-false-HAL-true,7-MX_OCTOSPI1_Init-OCTOSPI1-false-HAL-true,8-MX_SPI3_Init-SPI3-false-HAL-true,9-MX_TIM1_Init-TIM1-false-HAL-true,10-MX_TIM2_Init-TIM2-false-HAL-true,11-MX_TIM4_Init-TIM4-false-HAL-true,12-MX_CRC_Init-CRC-false-HAL-true,13-MX_TIM17_Init-TIM17-false-HAL-true,14-MX_DMA2D_Init-DMA2D-false-HAL-true,16-MX_TouchGFX_Init-STMicroelectronics.X-CUBE-TOUCHGFX.4.21.2-false-HAL-false,17-MX_TouchGFX_Process-STMicroelectronics.X-CUBE-TOUCHGFX.4.21.2-false-HAL-false,0-MX_CORTEX_M7_Init-CORTEX_M7-false-HAL-true
|
||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_FDCAN1_Init-FDCAN1-false-HAL-true,5-MX_LTDC_Init-LTDC-false-HAL-true,6-MX_JPEG_Init-JPEG-false-HAL-true,7-MX_OCTOSPI1_Init-OCTOSPI1-false-HAL-true,8-MX_SPI3_Init-SPI3-false-HAL-true,9-MX_TIM1_Init-TIM1-false-HAL-true,10-MX_TIM2_Init-TIM2-false-HAL-true,11-MX_TIM4_Init-TIM4-false-HAL-true,12-MX_CRC_Init-CRC-false-HAL-true,13-MX_TIM17_Init-TIM17-false-HAL-true,14-MX_DMA2D_Init-DMA2D-false-HAL-true,15-MX_TouchGFX_Init-STMicroelectronics.X-CUBE-TOUCHGFX.4.22.0-false-HAL-false,16-MX_TouchGFX_Process-STMicroelectronics.X-CUBE-TOUCHGFX.4.22.0-false-HAL-false,0-MX_CORTEX_M7_Init-CORTEX_M7-false-HAL-true
|
||||
RCC.ADCFreq_Value=2000000
|
||||
RCC.AHB12Freq_Value=160000000
|
||||
RCC.AHB4Freq_Value=160000000
|
||||
|
||||
Reference in New Issue
Block a user